Skip to content

Commit

Permalink
Merge pull request #681 from IBM/cp4i-2023.4.1
Browse files Browse the repository at this point in the history
Cp4i 2023.4.1
  • Loading branch information
fketelaars authored Apr 8, 2024
2 parents 4e261fc + 30d2b46 commit 4b4c9a8
Show file tree
Hide file tree
Showing 48 changed files with 1,215 additions and 294 deletions.
6 changes: 3 additions & 3 deletions automation-generators/generic/cp4i/preprocessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,7 @@ def preprocessor(attributes=None, fullConfig=None, moduleVariables=None):

g('project').isRequired()
g('openshift_cluster_name').expandWith('openshift[*]',remoteIdentifier='name')
openshift_cluster_name=g('openshift_cluster_name').getExpandedAttributes()['openshift_cluster_name']
g('cp4i_version').isRequired()
g('openshift_storage_name').expandWithSub('openshift', remoteIdentifier='name', remoteValue=openshift_cluster_name, listName='openshift_storage',listIdentifier='storage_name')
g('instances').isRequired()
g('use_case_files').isOptional().mustBeOneOf([True, False])
g('olm_utils').isOptional().mustBeOneOf([True, False])
Expand All @@ -74,7 +72,9 @@ def preprocessor(attributes=None, fullConfig=None, moduleVariables=None):
fc = g.getFullConfig()
ge=g.getExpandedAttributes()

# Check for cp4i:
# Check for cp4i:
openshift_cluster_name=g('openshift_cluster_name').getExpandedAttributes()['openshift_cluster_name']
g('openshift_storage_name').expandWithSub('openshift', remoteIdentifier='name', remoteValue=openshift_cluster_name, listName='openshift_storage',listIdentifier='storage_name')

# Check that version matches x.y.z pattern
if not re.match(r"[0-9]+\.[0-9]\.[0-9]+",str(ge['cp4i_version'])):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ while true;do
current_ts=$(date +%s)

log "Collecting OLM information"
oc get sub -n ${fs_project} \
oc get subscriptions.operators.coreos.com -n ${fs_project} \
--sort-by=.metadata.creationTimestamp \
--no-headers \
-o jsonpath='{range .items[*]}{.metadata.name}{","}{.metadata.creationTimestamp}{","}{.status.installedCSV}{","}{.status.state}{"\n"}{end}' > ${sub_file}
Expand Down Expand Up @@ -86,7 +86,7 @@ while true;do
while IFS=, read -r sub sub_ts csv sub_state;do
if [[ "${csv}" == "" ]];then
log "DIAG: Exporting subscription ${sub} to ${diag_dir}/sub-${sub}.yaml and deleting"
oc get sub -n ${fs_project} ${sub} -o yaml > ${diag_dir}/sub-${sub}.yaml
oc get subscriptions.operators.coreos.com -n ${fs_project} ${sub} -o yaml > ${diag_dir}/sub-${sub}.yaml
oc delete sub -n ${fs_project} ${sub}
fi
done < ${diag_dir}/sub-diag.csv
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
block:
- name: Retrieving state of all operators in project {{ foundational_services_project }}
shell: |
oc get sub -n {{ foundational_services_project }} \
oc get subscriptions.operators.coreos.com -n {{ foundational_services_project }} \
--no-headers \
--sort-by=.metadata.creationTimestamp \
-o jsonpath='{range .items[*]}{.metadata.name}{","}{.metadata.creationTimestamp}{","}{.status.installedCSV}{","}{.status.state}{"\n"}{end}'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ cp4d_login_username: admin
cp4d_repo_url: cp.icr.io/cp/cpd
cp4d_repo_username: cp

_v_template_dest_directory: "{{ status_dir }}/cp4d"

license_service_project: ibm-licensing
scheduling_service_project: cpd-scheduler
cert_manager_project: ibm-cert-manager
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
# Paramteres:
# - _p_template
# - _p_dest_name
#
# The other parameters, as they are defined in the template,
# must be provided when invoking this task

- name: "Prepare yaml file"
template:
src: "{{ _p_template }}"
dest: "{{ status_dir }}/cp4i/{{ _p_dest_name }}"

- name: "Apply {{ status_dir }}/cp4i/{{ _p_dest_name }}"
shell: |
oc apply -f {{ status_dir }}/cp4i/{{ _p_dest_name }}
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
---

- name: Verify if the entitlement key secret already exists
shell: |
oc get secret ibm-entitlement-key -n {{ current_cp4i_cluster.project }} | grep -i '^ibm-entitlement-key' | wc -l
Expand All @@ -8,4 +7,4 @@
- name: Create secret ibm-entitlement-key
shell: |
oc create secret docker-registry ibm-entitlement-key --docker-username=cp --docker-password={{ibm_cp_entitlement_key}} --docker-server=cp.icr.io --namespace={{ current_cp4i_cluster.project }}
when: entitlement_key_secret_exists.stdout == "0"
when: "entitlement_key_secret_exists.stdout | trim == '0'"
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
# Global variables:
# - _use_entitled_registry

# Paramaters:
# - _p_case_file_name
# - _p_catalog_source_yaml
# - _p_case_version

- name: "Create Foundational Services catalog source when entitled registry is used"
shell: |
oc apply -f ~/.ibm-pak/data/mirror/{{ _p_case_file_name }}/{{ _p_case_version }}/{{ _p_catalog_source_yaml }}
when: _use_entitled_registry

- name: "Create Foundational Services catalog source when private registry is used"
shell: |
oc apply -f {{ status_dir }}/ibm-pak/data/mirror/{{ {{ _p_case_file_name }} }}/{{ _p_case_version }}/{{ _p_catalog_source_yaml }}
when: not _use_entitled_registry
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
---

- name: Create instance
- name: "Create instance"
block:

- debug:
msg: "### Creating instance of {{ current_cp4i_instance.type }} "

# ---------- FIND INSTANCE TYPE DEFINITION --------------

- name: Get instance type details
- name: "Get instance type details"
set_fact:
_inst_type_def: "{{ instance_types | json_query(query) | first | default({}) }}"
vars:
query: >-
[?type=='{{ current_cp4i_instance.type }}']
- name: Fail if the instance type cannot be found
- name: "Fail if the instance type cannot be found"
fail:
msg: "Case instance type for instance {{ current_cp4i_instance.name }} not found."
when: _inst_type_def=={}

# ---------- FIND VERSION PROPERTIES -----------------------

- name: Find version specific instance type properties
- name: "Find version specific instance type properties"
include_tasks: get-instance-properties.yml
# returns: instance_properties

# ---------- CREATE INSTANCE ----------------------------

Expand All @@ -32,19 +32,20 @@
oc get {{_inst_type_def.kind}} {{instance_properties.name}} -n {{current_cp4i_cluster.project}} | grep -i '^{{instance_properties.name}}' | wc -l
register: instance_exists

- name: Create instance if it does not already exist
- name: "Create instance if it does not already exist"
block:

- name: If instance type is enterprise-gateway create admin password secret
- name: "If instance type is enterprise-gateway create admin password secret"
include_tasks: create-dp-admin-password-secret.yml
when: instance_properties.type == 'enterprise-gateway'

- set_fact:

- name: "Get template from instance properties or use a default one defined for the instance type"
set_fact:
instance_template: "{{ instance_properties.template | default(default_template_name) }}"
vars:
default_template_name: "{{ _inst_type_def.default_template }}"

- name: Prepare yaml file for creating instance
- name: "Prepare yaml file for creating instance"
template:
src: "{{instance_template}}.j2"
dest: "{{ status_dir }}/cp4i/{{instance_properties.type}}-{{instance_properties.name}}.yml"
Expand All @@ -53,12 +54,11 @@
shell: |
oc apply -f {{ status_dir }}/cp4i/{{instance_properties.type}}-{{instance_properties.name}}.yml
when: instance_exists.stdout == "0"

when: "instance_exists.stdout | trim == '0'"

# ---------- WAITING FOR PLATFORM NAVIGATOR TO BECOME READY -------

- name: "Wait for the {{_inst_type_def.kind}} to become ready"
- name: "Waiting for the {{_inst_type_def.kind}} to become ready"
shell: |
oc get {{_inst_type_def.kind}} -n {{current_cp4i_cluster.project}} {{instance_properties.name}} -o json | jq -r '.status.conditions[] | select(.type=="Ready").status'
register: instance_status
Expand All @@ -67,7 +67,4 @@
until: instance_status.stdout == "True"
when: instance_properties.type == 'platform-navigator'


when: (current_cp4i_instance.state | default('installed')) == 'installed'


Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
# Parameters:
# - _p_project_name

- name: "Validate if OpenShift project {{ _p_project_name }} exists"
shell: "oc get projects | grep -i '^{{ _p_project_name }}' | wc -l"
register: _project_exists

- name: "Create OpenShift Project {{ _p_project_name }} if it does not exist"
command: "oc new-project {{ _p_project_name }}"
when: "_project_exists.stdout | trim == '0'"
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,14 @@
- name: Create mirror manifest when Entitled registry is used
shell: |
oc ibm-pak generate mirror-manifests {{ _instance_type_details.case_file_name }} --version {{ instance_properties.case_version }} icr.io
when: _use_entitled_registry

#
# Mirror manifest when private registry is used
#
# - name: Create mirror manifest when private registry is used
# shell: |
# oc ibm-pak generate mirror-manifests {{ _instance_type_details.case_file_name }} --version {{ instance_properties.case_version }} {{ current_cp4i_cluster.image_registry_url }}
# when: not (_use_entitled_registry | bool)
- name: Create mirror manifest when private registry is used
shell: |
oc ibm-pak generate mirror-manifests {{ _instance_type_details.case_file_name }} --version {{ instance_properties.case_version }} {{ current_cp4i_cluster.image_registry_url }}
when: not (_use_entitled_registry | bool)

when: (current_cp4i_instance.state | default('installed')) == 'installed'
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
---

# Global variables:
# - current_cp4i_cluster
# - _use_entitled_registry

# Returns:
# - _fs_case_file_name
# - _fs_catalog_source_yaml
# - _fs_case_version
# - _fs_channel

- name: "Find Foundational Services instance type"
set_fact:
_instance_type_details: "{{ instance_types | json_query(query) | first | default({}) }}"
vars:
query: >-
[?type=='foundational-services']
- fail:
msg: "An instance type foundational-services was not found"
when: _instance_type_details == {}

- name: "Include version details variables"
include_vars: versions.yml

- name: "Select cloud pak version"
set_fact:
_cloud_pak_ver: "{{ version_specific_properties | json_query(query) | first | default({}) }}"
vars:
query: >-
[?cp4i_version=='{{ current_cp4i_cluster.cp4i_version }}']
- fail:
msg: "Cloud Pak version {{ current_cp4i_cluster.cp4i_version }} not defined"
when: _cloud_pak_ver == {}

- name: "Get Foundational Services version specific details"
set_fact:
_foundational_services_details: "{{ _cloud_pak_ver.instance_types | json_query(query) | first | default({}) }}"
vars:
query: >-
[?type=='foundational-services']
- fail:
msg: "Foundational Services not defined in CP4I version {{ current_cp4i_cluster.cp4i_version }}"
when: _foundational_services_details == {}

- name: "Get Foundational Services CASE name, CASE version and channel"
set_fact:
_fs_case_file_name: "{{ _instance_type_details.case_file_name }}"
_fs_catalog_source_yaml: "{{ _instance_type_details.catalog_source_yaml_name }}"
_fs_case_version: "{{ _foundational_services_details.case_version }}"
_fs_channel: "{{ _foundational_services_details.channel }}"

- name: "Save Foundational Services CASE file"
shell: |
oc ibm-pak get {{ _fs_case_file_name }} --version {{ _fs_case_version }}
- name: "Create Foundational Services mirror manifest when Entitled registry is used"
shell: |
oc ibm-pak generate mirror-manifests {{ _fs_case_file_name }} --version {{ _fs_case_version }} icr.io
when: _use_entitled_registry

- name: "Create Foundational Services mirror manifest when private registry is used"
shell: |
oc ibm-pak generate mirror-manifests {{ _fs_case_file_name }} --version {{ _fs_case_version }} {{ current_cp4i_cluster.image_registry_url }}
when: not _use_entitled_registry


Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,3 @@
- name: Combine properties
set_fact:
instance_properties: "{{ _inst_type_ver | combine(current_cp4i_instance) }}"


Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
---

- name: "Create project cert-manager-operator"
include_tasks: create-project.yml
vars:
_p_project_name: "cert-manager-operator"

- name: "Create operator group for cert-manager-operator"
include_tasks: apply-template.yml
vars:
_p_template: "operator-group.j2"
_p_dest_name: "cert-manager-operator-group.yml"
operator_group_name: "cert-manager-operator-group"
operator_group_namespace: "cert-manager-operator"

- name: "Install cert manager operator"
# Note: this step is architecture dependent
# In case of installing on Power or Z an IBM operator
# should be used instead of one provided by RedHat
include_tasks: install-operator.yml
vars:
_p_subscr_name: "openshift-cert-manager-operator"
_p_namespace: "cert-manager-operator"
_p_channel: "stable-v1"
_p_subscr_source: "redhat-operators"

- name: "Return default project back to {{ current_cp4i_cluster.project }}"
include_tasks: set-default-project.yml
vars:
_p_project_name: "{{ current_cp4i_cluster.project }}"
Loading

0 comments on commit 4b4c9a8

Please sign in to comment.