From 888b1ad38e01d38491bd1ac5f6d88e55f9a79f2d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Opala?= Date: Wed, 17 Jun 2020 11:53:35 +0200 Subject: [PATCH] v0.6 preflight_facts: fixing inability to disable kubernetes (#1346) (#1365) * preflight_facts: fixing critical regression problem with inability to disable kubernetes * validation: adding kubernetes components dependency check for the epiphany-cluster doc * updating changelogs for v0.6.1 --- CHANGELOG-0.6.md | 1 + .../image_registry/tasks/gather-facts.yml | 5 +- .../roles/preflight_facts/tasks/assert.yml | 4 +- .../preflight_facts/tasks/kubernetes.yml | 11 +- .../roles/repository/tasks/gather-facts.yml | 5 +- .../common/validation/epiphany-cluster.yml | 242 +++++++++--------- 6 files changed, 145 insertions(+), 123 deletions(-) diff --git a/CHANGELOG-0.6.md b/CHANGELOG-0.6.md index 2b396d163e..94a876149d 100644 --- a/CHANGELOG-0.6.md +++ b/CHANGELOG-0.6.md @@ -5,6 +5,7 @@ ### Fixed - [#1154](https://github.com/epiphany-platform/epiphany/issues/1154) - Node exporter is not installed on logging vms +- [#1183](https://github.com/epiphany-platform/epiphany/issues/1183) - Task 'Check if /etc/kubernetes/admin.conf file exists' fails when kubernetes\_master.count = 0 ## [0.6.0] 2020-04-06 diff --git a/core/src/epicli/data/common/ansible/playbooks/roles/image_registry/tasks/gather-facts.yml b/core/src/epicli/data/common/ansible/playbooks/roles/image_registry/tasks/gather-facts.yml index b16a164c4f..8319cedea7 100644 --- a/core/src/epicli/data/common/ansible/playbooks/roles/image_registry/tasks/gather-facts.yml +++ b/core/src/epicli/data/common/ansible/playbooks/roles/image_registry/tasks/gather-facts.yml @@ -2,4 +2,7 @@ - name: Produce final list of hosts to deploy image registries on set_fact: target_image_registry_hostnames: >- - {{ groups.image_registry | difference(groups.kubernetes_master) | union([resolved_image_registry_hostname]) | unique }} + {{ groups.image_registry | difference(available_masters) | union([resolved_image_registry_hostname]) | unique }} + vars: + available_masters: >- + {{ groups.kubernetes_master | default([]) }} diff --git a/core/src/epicli/data/common/ansible/playbooks/roles/preflight_facts/tasks/assert.yml b/core/src/epicli/data/common/ansible/playbooks/roles/preflight_facts/tasks/assert.yml index 8f6125ac01..807fb49ee9 100644 --- a/core/src/epicli/data/common/ansible/playbooks/roles/preflight_facts/tasks/assert.yml +++ b/core/src/epicli/data/common/ansible/playbooks/roles/preflight_facts/tasks/assert.yml @@ -11,7 +11,7 @@ fail_msg: "When promote_to_ha is enabled, use_ha_control_plane must be enabled as well." - assert: - that: not promote_to_ha or ((groups.kubernetes_master | length) == 1) + that: not promote_to_ha or ((available_masters | length) == 1) fail_msg: "When promote_to_ha is enabled, control plane must contain exactly one master." - assert: @@ -23,5 +23,5 @@ fail_msg: "When kubernetes is HA already, use_ha_control_plane must be enabled (downgrade is not supported)." - assert: - that: use_ha_control_plane or not ((groups.kubernetes_master | length) > 1) + that: use_ha_control_plane or not ((available_masters | length) > 1) fail_msg: "When use_ha_control_plane is disabled, number of masters must not be bigger than one." diff --git a/core/src/epicli/data/common/ansible/playbooks/roles/preflight_facts/tasks/kubernetes.yml b/core/src/epicli/data/common/ansible/playbooks/roles/preflight_facts/tasks/kubernetes.yml index 270fea75a0..d2cbea18e7 100644 --- a/core/src/epicli/data/common/ansible/playbooks/roles/preflight_facts/tasks/kubernetes.yml +++ b/core/src/epicli/data/common/ansible/playbooks/roles/preflight_facts/tasks/kubernetes.yml @@ -1,5 +1,10 @@ --- -- when: inventory_hostname in groups.kubernetes_master +- name: Collect available masters + set_fact: + available_masters: >- + {{ groups.kubernetes_master | default([]) }} + +- when: inventory_hostname in available_masters block: - name: Check if /etc/kubernetes/admin.conf file exists stat: @@ -37,8 +42,8 @@ - name: Collect registered masters set_fact: registered_masters: >- - {{ groups.kubernetes_master | map('extract', hostvars, ['master_already_joined']) - | zip(groups.kubernetes_master) + {{ available_masters | map('extract', hostvars, ['master_already_joined']) + | zip(available_masters) | selectattr(0) | map(attribute=1) | list }} diff --git a/core/src/epicli/data/common/ansible/playbooks/roles/repository/tasks/gather-facts.yml b/core/src/epicli/data/common/ansible/playbooks/roles/repository/tasks/gather-facts.yml index 6148193c97..1c473670d0 100644 --- a/core/src/epicli/data/common/ansible/playbooks/roles/repository/tasks/gather-facts.yml +++ b/core/src/epicli/data/common/ansible/playbooks/roles/repository/tasks/gather-facts.yml @@ -2,4 +2,7 @@ - name: Produce final list of hosts to deploy repositories on set_fact: target_repository_hostnames: >- - {{ groups.repository | difference(groups.kubernetes_master) | union([resolved_repository_hostname]) | unique }} + {{ groups.repository | difference(available_masters) | union([resolved_repository_hostname]) | unique }} + vars: + available_masters: >- + {{ groups.kubernetes_master | default([]) }} diff --git a/core/src/epicli/data/common/validation/epiphany-cluster.yml b/core/src/epicli/data/common/validation/epiphany-cluster.yml index e5a397ab50..914516dee2 100644 --- a/core/src/epicli/data/common/validation/epiphany-cluster.yml +++ b/core/src/epicli/data/common/validation/epiphany-cluster.yml @@ -1,116 +1,126 @@ -"$id": "#/specification" -title: "Cluster specification schema" -description: "The main cluster specification" -type: object -required: - - name - - admin_user - - components -properties: - prefix: - "$id": "#/properties/prefix" - title: "Cluster prefix" - description: "A prefix the can be prepended to the cluster name" - examples: - - prod01 - - dev02 - - test03 - - cust04 - type: string - pattern: "^[a-z0-9]{2,8}$" - name: - "$id": "#/properties/name" - title: "Cluster name" - description: "The name of the cluster" - examples: - - clustername01 - type: string - pattern: "^[a-z0-9\\-]{3,20}$" - admin_user: - "$id": "#/properties/admin_user" - title: "The admin_user Schema" - description: "Settings needed for the SSH connection to the cluster machines or VM's" - type: object - cloud: - "$id": "#/properties/specification/properties/cloud" - type: object - title: The Cloud Schema - properties: - subscription_name: - "$id": "#/properties/specification/properties/cloud/properties/subscription_name" - type: string - title: The Subscription_name Schema - default: '' - examples: - - subsciptionname - pattern: "^(.*)$" - vnet_address_pool: - "$id": "#/properties/specification/properties/cloud/properties/vnet_address_pool" - type: string - title: The Vnet_address_pool Schema - default: '' - examples: - - 10.1.0.0/20 - pattern: "^(.*)$" - use_public_ips: - "$id": "#/properties/specification/properties/cloud/properties/use_public_ips" - type: boolean - title: The Use_public_ips Schema - default: false - examples: - - false - use_service_principal: - "$id": "#/properties/specification/properties/cloud/properties/use_service_principal" - type: boolean - title: The Use_service_principal Schema - default: false - examples: - - false - region: - "$id": "#/properties/specification/properties/cloud/properties/region" - type: string - title: The Region Schema - default: '' - examples: - - eu-west-2 - pattern: "^(.*)$" - credentials: - "$id": "#/properties/specification/properties/cloud/properties/credentials" - type: object - title: The Credentials Schema - required: - - key - - secret - properties: - key: - "$id": "#/properties/specification/properties/cloud/properties/credentials/properties/key" - type: string - title: The Key Schema - pattern: "^(.*)$" - secret: - "$id": "#/properties/specification/properties/cloud/properties/credentials/properties/secret" - type: string - title: The Secret Schema - pattern: "^(.*)$" - network: - "$id": "#/properties/specification/properties/cloud/properties/network" - type: object - title: The Network Schema - properties: - use_network_security_groups: - "$id": "#/properties/specification/properties/cloud/properties/network/properties/use_network_security_groups" - type: boolean - title: The Use_network_security_groups Schema - default: false - examples: - - true - components: - "$id": "#/properties/components" - title: "Components schema" - description: "Cluster component layout specification" - type: object - - - - - +"$id": "#/specification" +title: "Cluster specification schema" +description: "The main cluster specification" +type: object +required: + - name + - admin_user + - components +properties: + prefix: + "$id": "#/properties/prefix" + title: "Cluster prefix" + description: "A prefix the can be prepended to the cluster name" + examples: + - prod01 + - dev02 + - test03 + - cust04 + type: string + pattern: "^[a-z0-9]{2,8}$" + name: + "$id": "#/properties/name" + title: "Cluster name" + description: "The name of the cluster" + examples: + - clustername01 + type: string + pattern: "^[a-z0-9\\-]{3,20}$" + admin_user: + "$id": "#/properties/admin_user" + title: "The admin_user Schema" + description: "Settings needed for the SSH connection to the cluster machines or VM's" + type: object + cloud: + "$id": "#/properties/specification/properties/cloud" + type: object + title: The Cloud Schema + properties: + subscription_name: + "$id": "#/properties/specification/properties/cloud/properties/subscription_name" + type: string + title: The Subscription_name Schema + default: '' + examples: + - subsciptionname + pattern: "^(.*)$" + vnet_address_pool: + "$id": "#/properties/specification/properties/cloud/properties/vnet_address_pool" + type: string + title: The Vnet_address_pool Schema + default: '' + examples: + - 10.1.0.0/20 + pattern: "^(.*)$" + use_public_ips: + "$id": "#/properties/specification/properties/cloud/properties/use_public_ips" + type: boolean + title: The Use_public_ips Schema + default: false + examples: + - false + use_service_principal: + "$id": "#/properties/specification/properties/cloud/properties/use_service_principal" + type: boolean + title: The Use_service_principal Schema + default: false + examples: + - false + region: + "$id": "#/properties/specification/properties/cloud/properties/region" + type: string + title: The Region Schema + default: '' + examples: + - eu-west-2 + pattern: "^(.*)$" + credentials: + "$id": "#/properties/specification/properties/cloud/properties/credentials" + type: object + title: The Credentials Schema + required: + - key + - secret + properties: + key: + "$id": "#/properties/specification/properties/cloud/properties/credentials/properties/key" + type: string + title: The Key Schema + pattern: "^(.*)$" + secret: + "$id": "#/properties/specification/properties/cloud/properties/credentials/properties/secret" + type: string + title: The Secret Schema + pattern: "^(.*)$" + network: + "$id": "#/properties/specification/properties/cloud/properties/network" + type: object + title: The Network Schema + properties: + use_network_security_groups: + "$id": "#/properties/specification/properties/cloud/properties/network/properties/use_network_security_groups" + type: boolean + title: The Use_network_security_groups Schema + default: false + examples: + - true + components: + "$id": "#/properties/components" + type: object + title: "Components schema" + description: "Cluster component layout specification" + # When "kubernetes_node" property exists, "kubernetes_master" must exist as well + dependencies: + kubernetes_node: [kubernetes_master] + allOf: + # When no master is deployed, there must be no nodes deployed as well + - if: + properties: + kubernetes_master: + properties: + count: { type: integer, enum: [0] } + then: + properties: + kubernetes_node: + properties: + count: { type: integer, enum: [0] }