diff --git a/example-config/dev/cluster1/instance1/ibm-mas-instance-base.yaml b/example-config/dev/cluster1/instance1/ibm-mas-instance-base.yaml index 86d09dd2a..90fd59c27 100644 --- a/example-config/dev/cluster1/instance1/ibm-mas-instance-base.yaml +++ b/example-config/dev/cluster1/instance1/ibm-mas-instance-base.yaml @@ -16,3 +16,13 @@ instance: sm: aws_access_key_id: "" aws_secret_access_key: "" + +# Additional Resources Configuration Example +additional_resources: + instances: + - name: instance-name-1 + cost: 100 + reasonCode: 101 + - name: instance-name-2 + cost: 250 + reasonCode: 102 diff --git a/instance-applications/130-ibm-mas-suite/templates/01-postdelete-crs-resources.yaml b/instance-applications/130-ibm-mas-suite/templates/01-postdelete-crs-resources.yaml index d9c738747..2b58bb336 100644 --- a/instance-applications/130-ibm-mas-suite/templates/01-postdelete-crs-resources.yaml +++ b/instance-applications/130-ibm-mas-suite/templates/01-postdelete-crs-resources.yaml @@ -63,6 +63,15 @@ rules: - "config.mas.ibm.com" resources: - "*" + - verbs: + - delete + - get + - list + - watch + apiGroups: + - addons.mas.ibm.com + resources: + - genericaddons --- kind: ServiceAccount diff --git a/instance-applications/550-ibm-mas-addons-config/templates/08-additional-resources-cr.yaml b/instance-applications/550-ibm-mas-addons-config/templates/08-additional-resources-cr.yaml new file mode 100644 index 000000000..846febca9 --- /dev/null +++ b/instance-applications/550-ibm-mas-addons-config/templates/08-additional-resources-cr.yaml @@ -0,0 +1,31 @@ +{{- if .Values.additional_resources }} +--- +apiVersion: addons.mas.ibm.com/v1 +kind: GenericAddon +metadata: + name: "{{ .Values.instance_id }}-addons-additional-resources" + namespace: mas-{{ .Values.instance_id }}-core + annotations: + argocd.argoproj.io/sync-wave: "559" + labels: + mas.ibm.com/configScope: system + mas.ibm.com/instanceId: {{ .Values.instance_id }} +{{- if .Values.custom_labels }} +{{ .Values.custom_labels | toYaml | indent 4 }} +{{- end }} +spec: + displayName: "{{ .Values.instance_id }}-AdditionalResources" + addonType: additional-resources + config: + addonIdentifier: {{ .Values.instance_id }} + instances: +{{- if .Values.additional_resources.instances }} +{{- range .Values.additional_resources.instances }} + - name: {{ .name }} + cost: {{ .cost }} + reasonCode: {{ .reasonCode }} +{{- end }} +{{- else }} + [] +{{- end }} +{{- end }} diff --git a/instance-applications/550-ibm-mas-addons-config/templates/postdelete-delete-cr.yaml b/instance-applications/550-ibm-mas-addons-config/templates/postdelete-delete-cr.yaml new file mode 100644 index 000000000..7acbf1626 --- /dev/null +++ b/instance-applications/550-ibm-mas-addons-config/templates/postdelete-delete-cr.yaml @@ -0,0 +1,109 @@ +{{- if .Values.use_postdelete_hooks }} + +{{- /* +Use the build/bin/set-cli-image-digest.sh script to update this value across all charts. +*/}} +{{- $_cli_image_digest := "sha256:55b5d6dd185503f14c112836a9a4899347d28e7b6545e0b9cf21d87f9526fb40" }} + +{{- $_addon_type := "additional-resources" }} +{{- $_addon_cr_name := printf "%s-addons-%s" .Values.instance_id $_addon_type }} + +{{ $job_name := printf "postdelete-delete-cr-job-%s" $_addon_cr_name }} + +# NOTE: depends on resources created in ibm-mas-suite chart (01-postdelete-crs-resources) +# The values below must align with the values in that file +{{ $role_name := "postdelete-delete-cr-r" }} +{{ $sa_name := "postdelete-delete-cr-sa" }} +{{ $rb_name := "postdelete-delete-cr-rb" }} +{{ $np_name := "postdelete-delete-cr-np" }} +{{ $job_label := "postdelete-delete-cr-job" }} +{{ $ns := printf "mas-%s-core" .Values.instance_id }} + +--- +apiVersion: batch/v1 +kind: Job +metadata: + name: {{ $job_name }} + namespace: {{ $ns }} + annotations: + argocd.argoproj.io/hook: PostDelete + argocd.argoproj.io/hook-delete-policy: BeforeHookCreation +{{- if .Values.custom_labels }} + labels: +{{ .Values.custom_labels | toYaml | indent 4 }} +{{- end }} +spec: + template: + metadata: + labels: + app: {{ $job_label }} +{{- if .Values.custom_labels }} +{{ .Values.custom_labels | toYaml | indent 8 }} +{{- end }} + spec: + containers: + - name: run + image: {{ .Values.cli_image_repo | default "quay.io/ibmmas/cli" }}@{{ $_cli_image_digest }} + imagePullPolicy: IfNotPresent + resources: + limits: + cpu: 200m + memory: 512Mi + requests: + cpu: 10m + memory: 64Mi + env: + - name: CR_NAMESPACE + value: {{ $ns }} + - name: CR_NAME + value: {{ $_addon_cr_name }} + - name: CR_API_VERSION + value: addons.mas.ibm.com/v1 + - name: CR_KIND + value: GenericAddon + command: + - /bin/sh + - -c + - | + set -e + function delete_oc_resource(){ + RESOURCE=$1 + NAMESPACE=$2 + echo + echo "------------------------------------------------------------------" + echo "Check if resource $RESOURCE is present in namespace $NAMESPACE " + # don't want a non-zero rc from oc delete to cause the job to fail + # so, temporarily set +e + set +e + RESOURCE_NAME=$(oc get $RESOURCE -n $NAMESPACE -o=jsonpath="{.metadata.name}") + set -e + if [[ -z "${RESOURCE_NAME}" ]]; then + echo "$RESOURCE not found, skipping" + return 0 + fi + echo "oc delete resource $RESOURCE in namespace $NAMESPACE " + # don't want a non-zero rc from oc delete to cause the job to fail (since we then want to try patching out the finalizers) + # so, temporarily set +e + set +e + oc delete $RESOURCE -n $NAMESPACE --timeout=300s --wait=true + return_code=$? + set -e + echo "Verify that resource $RESOURCE is now absent in namespace $NAMESPACE " + # don't want a non-zero rc from oc delete to cause the job to fail + # so, temporarily set +e + set +e + RESOURCE_NAME=$(oc get $RESOURCE -n $NAMESPACE -o=jsonpath="{.metadata.name}") + set -e + if [[ -n "${RESOURCE_NAME}" ]]; then + echo "$RESOURCE still present, failing job" + exit 1 + fi + echo "... verified" + return 0 + + } + delete_oc_resource "${CR_KIND} ${CR_NAME}" "${CR_NAMESPACE}" + restartPolicy: Never + serviceAccountName: {{ $sa_name }} + backoffLimit: 4 +{{- end }} diff --git a/root-applications/ibm-mas-instance-root/templates/550-ibm-mas-addons-config.yaml b/root-applications/ibm-mas-instance-root/templates/550-ibm-mas-addons-config.yaml index c971cbc6c..c54b96646 100644 --- a/root-applications/ibm-mas-instance-root/templates/550-ibm-mas-addons-config.yaml +++ b/root-applications/ibm-mas-instance-root/templates/550-ibm-mas-addons-config.yaml @@ -1,4 +1,4 @@ -{{ if or (not (empty .Values.allow_list)) (.Values.enhanced_dr) (.Values.extensions) (.Values.additional_vpn) (.Values.application_configuration) (not (empty .Values.ibm_db2u_databases)) (.Values.cluster_nonshared) }} +{{ if or (not (empty .Values.allow_list)) (.Values.enhanced_dr) (.Values.extensions) (.Values.additional_vpn) (.Values.application_configuration) (not (empty .Values.ibm_db2u_databases)) (.Values.cluster_nonshared) (.Values.additional_resources) }} --- # IBM Maximo Operator Catalog apiVersion: argoproj.io/v1alpha1 @@ -20,6 +20,8 @@ metadata: argocd.argoproj.io/sync-options: PruneLast=true finalizers: - resources-finalizer.argocd.argoproj.io + - post-delete-finalizer.argocd.argoproj.io + - post-delete-finalizer.argocd.argoproj.io/cleanup spec: project: "{{ .Values.argo.projects.apps }}" destination: @@ -44,6 +46,10 @@ spec: additional_vpn: {{ .Values.additional_vpn }} cluster_nonshared: {{ .Values.cluster_nonshared }} application_configuration: {{ .Values.application_configuration }} + use_postdelete_hooks: {{ .Values.use_postdelete_hooks | default true }} + {{- if .Values.additional_resources }} + additional_resources: {{ .Values.additional_resources | toYaml | nindent 14 }} + {{- end }} databases: {{- range $val := .Values.ibm_db2u_databases }} {{- if and (contains "sdb" $val.db2_instance_name) ($val.replica_db) }} @@ -80,4 +86,4 @@ spec: syncOptions: - CreateNamespace=true - RespectIgnoreDifferences=true -{{ end }} \ No newline at end of file +{{ end }}