Skip to content

Commit 262b9e5

Browse files
authored
[host-ocp4-hcp-cnv-{install,destroy}] use vHCP (#9271)
* Update kubeconfig.yaml * Update kubeconfig.yaml * Update main.yaml * Update main.yaml * Update main.yaml * Update certificate.yaml * Update kubeconfig.yaml * Update setup_htpasswd_authentication.yml * Update kubeconfig.yaml * Update main.yaml * Update hostedcluster.yaml * Update hostedcluster.yaml * Update hostedcluster.yaml * Update hostedcluster.yaml * Update hostedcluster.yaml * Update main.yaml * Update main.yaml * Update main.yaml * Update hostedcluster.yaml * Update main.yaml * Update main.yaml * Update main.yaml * Update main.yaml * Update main.yaml * Update main.yaml * Update main.yaml * Update main.yaml * Update main.yaml * Update hostedcluster.yaml * Update hostedcluster.yaml * Update hostedcluster.yaml * Update main.yaml * Update main.yaml * Update main.yaml * Update workers_svc.yaml * Update workload.yml * Update hostedcluster.yaml * Update main.yaml * Update main.yaml * Update main.yaml * Update main.yaml * Update main.yaml * Update hostedcluster.yaml * Update nodepool.yaml
1 parent 70d4754 commit 262b9e5

9 files changed

Lines changed: 123 additions & 57 deletions

File tree

‎ansible/roles/host-ocp4-hcp-cnv-destroy/tasks/main.yaml‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
- name: Install OCP using HCP
1111
module_defaults:
1212
group/k8s:
13-
host: "{{ sandbox_openshift_api_url }}"
14-
api_key: "{{ k8s_auth_results.k8s_auth.api_key | default(sandbox_openshift_api_key) }}"
13+
host: "{{ sandbox_hcp.sandbox_openshift_api_url }}"
14+
api_key: "{{ k8s_auth_results.k8s_auth.api_key | default(sandbox_hcp.sandbox_openshift_api_key) }}"
1515
validate_certs: false
1616

1717
block:
@@ -20,7 +20,7 @@
2020
api_version: hypershift.openshift.io/v1beta1
2121
kind: HostedCluster
2222
name: "hcp-{{ guid }}"
23-
namespace: "{{ hcp_ocp_namespace }}"
23+
namespace: "{{ sandbox_hcp.sandbox_openshift_namespace }}"
2424
state: absent
2525
wait: true
2626
wait_timeout: 1800

‎ansible/roles/host-ocp4-hcp-cnv-install/defaults/main.yaml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ hcp_cluster_version: "{{ ocp4_installer_version | default('4.16') }}"
55
hcp_storage_class: "ocs-external-storagecluster-ceph-rbd"
66
hcp_etcd_storage_class: "{{ hcp_storage_class }}"
77
hcp_ocp_namespace: "{{ sandbox_openshift_namespace | default(env_type + '-' + guid)}}"
8-
hcp_cluster_issuer: "letsencrypt"
8+
hcp_cluster_issuer: "letsencrypt-production-ec2"
99
hcp_admin_password_length: 16
1010
hcp_user_password_length: 16
1111
hcp_user_base: "user"

‎ansible/roles/host-ocp4-hcp-cnv-install/tasks/main.yaml‎

Lines changed: 105 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -35,21 +35,6 @@
3535
retries: 10
3636
delay: 30
3737

38-
- name: Get list of OpenShift images from Quay.io
39-
uri:
40-
url: "{{ hcp_quay_api_url }}"
41-
return_content: true
42-
register: r_quay_response
43-
44-
- name: Find the latest OpenShift image for the specified version
45-
set_fact:
46-
_ocp_latest_image: "{{ r_quay_response.json.tags | first | replace('multi-','') }}"
47-
48-
- name: Show the latest OpenShift image
49-
debug:
50-
msg: "The latest OpenShift image for version {{ hcp_cluster_version }} is: {{ _ocp_latest_image.name }}"
51-
52-
5338
- name: Log in (obtain access token)
5439
community.okd.openshift_auth:
5540
username: "{{ sandbox_openshift_username }}"
@@ -61,39 +46,124 @@
6146
- name: Install OCP using HCP
6247
module_defaults:
6348
group/k8s:
64-
host: "{{ sandbox_openshift_api_url }}"
65-
api_key: "{{ k8s_auth_results.k8s_auth.api_key | default(sandbox_openshift_api_key) }}"
49+
host: "{{ sandbox_hcp.sandbox_openshift_api_url }}"
50+
api_key: "{{ k8s_auth_results.k8s_auth.api_key | default(sandbox_hcp.sandbox_openshift_api_key) }}"
6651
validate_certs: false
6752

6853
block:
54+
- name: Check if x.y.z version exists
55+
when: hcp_cluster_version is match("^[0-9]+\\.[0-9]+\\.[0-9]+$")
56+
block:
57+
- name: Check if exists
58+
register: r_check_image_set
59+
kubernetes.core.k8s_info:
60+
api_version: hive.openshift.io/v1
61+
kind: ClusterImageSet
62+
name: img{{ hcp_cluster_version }}-x86-64-appsub
63+
64+
- name: Fail if version not available
65+
fail:
66+
msg: "Version {{ hcp_cluster_version }} not available"
67+
when:
68+
- r_check_image_set.resources | default([]) | length == 0
69+
70+
- name: Set releaseImage
71+
set_fact:
72+
ocp_release_image: "{{ r_check_image_set.resources[0].spec.releaseImage }}"
73+
74+
- name: Select the latest image when x.y is specified
75+
when: hcp_cluster_version is match("^[0-9]+\\.[0-9]+$")
76+
block:
77+
- name: "Get available ClusterImageSets"
78+
kubernetes.core.k8s_info:
79+
api_version: hive.openshift.io/v1
80+
kind: ClusterImageSet
81+
register: cis_list
82+
83+
- name: "Filter ClusterImageSets matching version {{ hcp_cluster_version }}"
84+
set_fact:
85+
filtered_image: >-
86+
{{
87+
cis_list.resources
88+
| selectattr('metadata.name', 'match', "img" + hcp_cluster_version|string + "\.\d+-x86-64-appsub")
89+
| sort(attribute='metadata.name', reverse=True)
90+
| first | default(None)
91+
}}
92+
93+
- name: Fail if version not available
94+
fail:
95+
msg: "Version {{ hcp_cluster_version }} not available"
96+
when: filtered_image == ""
97+
98+
- name: Set releaseImage
99+
set_fact:
100+
ocp_release_image: "{{ filtered_image.spec.releaseImage }}"
101+
- debug:
102+
msg: "Selected HCP version {{ ocp_release_image }}"
103+
69104
- name: Add the certificate definition for OAuth service
70105
kubernetes.core.k8s:
71106
definition: "{{ lookup('ansible.builtin.template', 'certificate.yaml') }}"
72107
wait: true
73108
wait_timeout: 300
74109
vars:
75-
namespace: "{{ hcp_ocp_namespace }}"
110+
namespace: "{{ sandbox_hcp.sandbox_openshift_namespace }}"
76111

77112
- name: Wait until Oauth Certificate is ready
113+
ignore_errors: true
114+
register: r_oauth
78115
kubernetes.core.k8s_info:
79116
api_version: cert-manager.io/v1
80117
kind: Certificate
81118
name: oauth-{{ guid }}
82-
namespace: "{{ hcp_ocp_namespace }}"
119+
namespace: "{{ sandbox_hcp.sandbox_openshift_namespace }}"
83120
wait: true
84121
wait_sleep: 5
85122
wait_timeout: 800
86123
wait_condition:
87124
type: "Ready"
88125
status: "True"
89-
126+
127+
- name: Restart OAuth request if it fails
128+
when: r_oauth is failed
129+
block:
130+
- name: Delete failed OAuth Certificate
131+
kubernetes.core.k8s:
132+
api_version: cert-manager.io/v1
133+
kind: Certificate
134+
name: oauth-{{ guid }}
135+
namespace: "{{ sandbox_hcp.sandbox_openshift_namespace }}"
136+
state: absent
137+
138+
- name: Add the certificate definition for OAuth service
139+
kubernetes.core.k8s:
140+
definition: "{{ lookup('ansible.builtin.template', 'certificate.yaml') }}"
141+
wait: true
142+
wait_timeout: 300
143+
vars:
144+
namespace: "{{ sandbox_hcp.sandbox_openshift_namespace }}"
145+
146+
- name: Wait until Oauth Certificate is ready
147+
kubernetes.core.k8s_info:
148+
api_version: cert-manager.io/v1
149+
kind: Certificate
150+
name: oauth-{{ guid }}
151+
namespace: "{{ sandbox_hcp.sandbox_openshift_namespace }}"
152+
register: r_oauth
153+
wait: true
154+
wait_sleep: 5
155+
wait_timeout: 800
156+
wait_condition:
157+
type: "Ready"
158+
status: "True"
159+
90160
- name: Add the pull secret
91161
kubernetes.core.k8s:
92162
definition: "{{ lookup('ansible.builtin.template', 'pullsecret.yaml') }}"
93163
wait: true
94164
wait_timeout: 300
95165
vars:
96-
namespace: "{{ hcp_ocp_namespace }}"
166+
namespace: "{{ sandbox_hcp.sandbox_openshift_namespace }}"
97167

98168
- name: Set variable for kubeconfig
99169
set_fact:
@@ -107,7 +177,7 @@
107177
wait: true
108178
wait_timeout: 300
109179
vars:
110-
namespace: "{{ hcp_ocp_namespace }}"
180+
namespace: "{{ sandbox_hcp.sandbox_openshift_namespace }}"
111181

112182
- name: Create htpasswd secret for admin and userX
113183
include_tasks: setup_htpasswd_authentication.yml
@@ -118,22 +188,23 @@
118188
wait: true
119189
wait_timeout: 300
120190
vars:
121-
namespace: "{{ hcp_ocp_namespace }}"
191+
namespace: "{{ sandbox_hcp.sandbox_openshift_namespace }}"
192+
target_namespace: "{{ sandbox_openshift_namespace }}"
122193

123194
- name: Create the NodePool
124195
kubernetes.core.k8s:
125196
definition: "{{ lookup('ansible.builtin.template', 'nodepool.yaml') }}"
126197
wait: true
127198
wait_timeout: 300
128199
vars:
129-
namespace: "{{ hcp_ocp_namespace }}"
200+
namespace: "{{ sandbox_hcp.sandbox_openshift_namespace }}"
130201

131202
- name: Get HostedCluster
132203
kubernetes.core.k8s_info:
133204
api_version: hypershift.openshift.io/v1beta1
134205
kind: HostedCluster
135206
name: "hcp-{{ guid }}"
136-
namespace: "{{ hcp_ocp_namespace }}"
207+
namespace: "{{ sandbox_hcp.sandbox_openshift_namespace }}"
137208
register: r_hosted_cluster
138209
retries: 120
139210
delay: 10
@@ -147,7 +218,7 @@
147218
api_version: v1
148219
kind: Secret
149220
name: hcp-{{ guid }}-admin-kubeconfig
150-
namespace: "{{ hcp_ocp_namespace }}"
221+
namespace: "{{ sandbox_hcp.sandbox_openshift_namespace }}"
151222
register: kubeadmin_secret_result
152223

153224
- name: Get the OpenShift secret
@@ -156,22 +227,22 @@
156227
api_version: v1
157228
kind: Secret
158229
name: hcp-{{ guid }}-kubeadmin-password
159-
namespace: "{{ hcp_ocp_namespace }}"
230+
namespace: "{{ sandbox_hcp.sandbox_openshift_namespace }}"
160231
register: password_secret_result
161232

162233
- name: Decode the kubeconfig secret
163234
set_fact:
164235
kubeconfig_decoded: "{{ kubeadmin_secret_result.resources[0].data.kubeconfig | b64decode }}"
165-
236+
166237
- name: Decode the kubeadmin password secret
167238
when: hcp_authentication | default('') != 'htpasswd'
168239
set_fact:
169240
kubeadmin_password: "{{ password_secret_result.resources[0].data.password | b64decode }}"
170241

171-
- name: Generate /tmp/kubeconfig
172-
copy:
173-
dest: /tmp/kubeconfig
174-
content: "{{ kubeconfig_decoded }}"
242+
- name: Generate /tmp/kubeconfig
243+
copy:
244+
dest: /tmp/kubeconfig
245+
content: "{{ kubeconfig_decoded }}"
175246

176247
- name: Get information about the router-nodeport-default service
177248
kubernetes.core.k8s_info:
@@ -209,15 +280,15 @@
209280
wait: true
210281
wait_timeout: 300
211282
vars:
212-
namespace: "{{ hcp_ocp_namespace }}"
283+
namespace: "{{ sandbox_openshift_namespace }}"
213284

214285
- name: Wait for the LoadBalancer value - workers
215286
register: svc_apps
216287
kubernetes.core.k8s_info:
217288
api_version: v1
218289
kind: Service
219290
name: "svc-{{ guid }}-apps"
220-
namespace: "{{ hcp_ocp_namespace }}"
291+
namespace: "{{ sandbox_openshift_namespace }}"
221292
until: svc_apps.resources[0].status.loadBalancer.ingress[0].ip | default('') != ''
222293
retries: 10
223294
delay: 2

‎ansible/roles/host-ocp4-hcp-cnv-install/tasks/setup_htpasswd_authentication.yml‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
api_version: v1
5252
kind: Secret
5353
name: "htpasswd-{{ guid }}"
54-
namespace: "{{ hcp_ocp_namespace }}"
54+
namespace: "{{ sandbox_hcp.sandbox_openshift_namespace }}"
5555
register: r_htpasswd_secret_absent
5656
retries: 5
5757
delay: 10
@@ -62,7 +62,7 @@
6262
state: present
6363
definition: "{{ lookup('template', 'secret-htpasswd.yaml') | from_yaml }}"
6464
vars:
65-
namespace: "{{ hcp_ocp_namespace }}"
65+
namespace: "{{ sandbox_hcp.sandbox_openshift_namespace }}"
6666

6767
- name: Save admin user information
6868
agnosticd_user_info:

‎ansible/roles/host-ocp4-hcp-cnv-install/templates/certificate.yaml‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ metadata:
55
name: oauth-{{ guid }}
66
namespace: {{ namespace }}
77
spec:
8-
commonName: "{{ guid }}.{{ sandbox_openshift_apps_domain }}"
8+
commonName: "{{ guid }}.{{ sandbox_hcp.sandbox_openshift_apps_domain }}"
99
dnsNames:
10-
- "{{ guid }}.{{ sandbox_openshift_apps_domain }}"
11-
- "oauth-{{ namespace }}-hcp-{{ guid }}.{{ sandbox_openshift_apps_domain }}"
10+
- "{{ guid }}.{{ sandbox_hcp.sandbox_openshift_apps_domain }}"
11+
- "oauth-{{ namespace }}-hcp-{{ guid }}.{{ sandbox_hcp.sandbox_openshift_apps_domain }}"
1212
isCA: false
1313
issuerRef:
1414
group: cert-manager.io

‎ansible/roles/host-ocp4-hcp-cnv-install/templates/hostedcluster.yaml‎

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ spec:
1414
- servingCertificate:
1515
name: oauth-{{ guid }}
1616
names:
17-
- oauth-{{ namespace }}-hcp-{{ guid }}.{{ sandbox_openshift_apps_domain }}
17+
- oauth-{{ namespace }}-hcp-{{ guid }}.{{ sandbox_hcp.sandbox_openshift_apps_domain }}
1818
{% if hcp_authentication | default('none') == "htpasswd" %}
1919
oauth:
2020
identityProviders:
@@ -42,7 +42,6 @@ spec:
4242
storage:
4343
persistentVolume:
4444
size: {{ hcp_etcd_pvc_size }}
45-
storageClassName: {{ hcp_etcd_storage_class }}
4645
type: PersistentVolume
4746
managementType: Managed
4847
fips: false
@@ -61,7 +60,7 @@ spec:
6160
infraKubeConfigSecret:
6261
key: kubeconfig
6362
name: hcp-{{ guid }}-infra-credentials
64-
infraNamespace: {{ namespace }}
63+
infraNamespace: {{ target_namespace }}
6564
{% if hcp_disable_storage_class | default(False) %}
6665
storageDriver:
6766
type: None
@@ -70,7 +69,7 @@ spec:
7069
pullSecret:
7170
name: hcp-{{ guid }}-pull-secret
7271
release:
73-
image: quay.io/openshift-release-dev/ocp-release:{{ _ocp_latest_image.name }}
72+
image: {{ ocp_release_image }}
7473
services:
7574
- service: APIServer
7675
servicePublishingStrategy:
@@ -88,7 +87,3 @@ spec:
8887
servicePublishingStrategy:
8988
type: Route
9089
sshKey: {}
91-
status:
92-
controlPlaneEndpoint:
93-
host: ""
94-
port: 0

‎ansible/roles/host-ocp4-hcp-cnv-install/templates/kubeconfig.yaml‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ clusters:
77
contexts:
88
- context:
99
cluster: {{ sandbox_openshift_api_url_name }}
10-
user: system:serviceaccount:{{ hcp_ocp_namespace }}:sandbox/{{ sandbox_openshift_api_url_name }}
11-
name: /{{ sandbox_openshift_api_url_name }}/system:serviceaccount:{{ hcp_ocp_namespace }}:sandbox
12-
current-context: /{{ sandbox_openshift_api_url_name }}/system:serviceaccount:{{ hcp_ocp_namespace }}:sandbox
10+
user: system:serviceaccount:{{ sandbox_openshift_namespace }}:sandbox/{{ sandbox_openshift_api_url_name }}
11+
name: /{{ sandbox_openshift_api_url_name }}/system:serviceaccount:{{ sandbox_openshift_namespace }}:sandbox
12+
current-context: /{{ sandbox_openshift_api_url_name }}/system:serviceaccount:{{ sandbox_openshift_namespace }}:sandbox
1313
kind: Config
1414
preferences: {}
1515
users:
16-
- name: system:serviceaccount:{{ hcp_ocp_namespace }}:sandbox/{{ sandbox_openshift_api_url_name }}
16+
- name: system:serviceaccount:{{ sandbox_openshift_namespace }}:sandbox/{{ sandbox_openshift_api_url_name }}
1717
user:
1818
token: {{ sandbox_openshift_api_key }}

‎ansible/roles/host-ocp4-hcp-cnv-install/templates/nodepool.yaml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ spec:
2424
type: Persistent
2525
type: KubeVirt
2626
release:
27-
image: quay.io/openshift-release-dev/ocp-release:{{ _ocp_latest_image.name }}
27+
image: {{ ocp_release_image }}
2828
{% if hcp_worker_autoscale %}
2929
autoScaling:
3030
min: {{ hcp_worker_instance_min_count | int }}

‎ansible/roles/host-ocp4-hcp-cnv-install/templates/workers_svc.yaml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,5 @@ spec:
1717
protocol: TCP
1818
targetPort: {{ nodeport_http }}
1919
selector:
20-
kubevirt.io: virt-launcher
20+
cluster.x-k8s.io/role: worker
2121
type: LoadBalancer

0 commit comments

Comments
 (0)