From 69e4c785875012112313eec7c068183adc18b121 Mon Sep 17 00:00:00 2001 From: Michael Stead Date: Wed, 2 Oct 2024 14:39:53 -0300 Subject: [PATCH] Create a swatch-unleash-importer clowdapp The swatch-unleash-importer clowdapp defines a job that will load an unleash instance with the defined feature flags used by the subscription watch components. This work had been previously done by awood, however, this patch makes some tweaks to allow the image to be built in the standard quay repo and gets it deployed automatically into the ephemeral environment. --- .unleash/flags.json | 15 ++ bin/build-images.sh | 12 +- deploy/rhsm-clowdapp.yaml | 95 +++++++++ deploy/unleash-import-clowdapp.yaml | 199 ------------------ .../Dockerfile | 0 swatch-unleash-import/README.md | 18 ++ 6 files changed, 139 insertions(+), 200 deletions(-) delete mode 100644 deploy/unleash-import-clowdapp.yaml rename .unleash/Dockerfile.unleash => swatch-unleash-import/Dockerfile (100%) create mode 100644 swatch-unleash-import/README.md diff --git a/.unleash/flags.json b/.unleash/flags.json index 87ead5aeab..6aa3910e34 100644 --- a/.unleash/flags.json +++ b/.unleash/flags.json @@ -1,6 +1,21 @@ { "version": 1, "features": [ + { + "name": "swatch.swatch-metrics-hbi.emit-events", + "description": "Enable sending of HBI events to the Swatch events after conversion.", + "type": "operational", + "project": "default", + "stale": false, + "strategies": [ + { + "name": "default", + "parameters": {} + } + ], + "variants": [], + "createdAt": "2024-10-01T09:18:27.111Z" + }, { "name": "hbi.api.disable-xjoin", "description": "A list of org_id for customers allow listed for postgres direct querying.", diff --git a/bin/build-images.sh b/bin/build-images.sh index 7a9c72af89..16045ca76a 100755 --- a/bin/build-images.sh +++ b/bin/build-images.sh @@ -46,6 +46,7 @@ if [ ${#projects[@]} -eq 0 ]; then projects[5]="swatch-metrics" projects[6]="swatch-billable-usage" projects[7]="swatch-metrics-hbi" + projects[8]="swatch-unleash-import" fi quay_user=$(podman login --get-login quay.io) @@ -108,7 +109,13 @@ for p in "${projects[@]}"; do -t quay.io/$quay_user/swatch-metrics-hbi:$tag \ --label "git-commit=${commit}" --ulimit nofile=2048:2048 ;; - *) echo "Please use values from the set \"rhsm\", \"conduit\", \"swatch-producer-aws\", \"swatch-contracts\", \"swatch-producer-azure\", \"swatch-metrics\", \"swatch-billable-usage\", \"swatch-metrics-hbi\"";; + "swatch-unleash-import") + podman build . -f swatch-unleash-import/Dockerfile \ + --build-arg-file bin/dev-argfile.conf \ + -t quay.io/$quay_user/swatch-unleash-import:$tag \ + --label "git-commit=${commit}" --ulimit nofile=2048:2048 + ;; + *) echo "Please use values from the set \"rhsm\", \"conduit\", \"swatch-producer-aws\", \"swatch-contracts\", \"swatch-producer-azure\", \"swatch-metrics\", \"swatch-billable-usage\", \"swatch-metrics-hbi\", \"swatch-unleash-import\"";; esac done @@ -146,5 +153,8 @@ for p in "${projects[@]}"; do "swatch-metrics-hbi") push_and_clean "quay.io/$quay_user/swatch-metrics-hbi:$tag" ;; + "swatch-unleash-import") + push_and_clean "quay.io/$quay_user/swatch-unleash-import:$tag" + ;; esac done diff --git a/deploy/rhsm-clowdapp.yaml b/deploy/rhsm-clowdapp.yaml index f3e34c7e32..69aedd345b 100644 --- a/deploy/rhsm-clowdapp.yaml +++ b/deploy/rhsm-clowdapp.yaml @@ -12,6 +12,25 @@ parameters: value: quay.io/cloudservices/rhsm-subscriptions - name: IMAGE_TAG value: latest + - name: SWATCH_UNLEASH_IMPORT_IMAGE + value: quay.io/cloudservices/swatch-unleash-import + - name: SWATCH_UNLEASH_IMPORT_IMAGE_TAG + value: latest + - name: SWATCH_UNLEASH_IMPORT_MEMORY_REQUEST + value: 10Mi + - name: SWATCH_UNLEASH_IMPORT_MEMORY_LIMIT + value: 50Mi + - name: SWATCH_UNLEASH_IMPORT_CPU_REQUEST + value: 100m + - name: SWATCH_UNLEASH_IMPORT_CPU_LIMIT + value: 100m + - name: SWATCH_UNLEASH_USER + value: admin + - name: SWATCH_UNLEASH_PASSWORD + value: unleash4all + # When needed bump SWATCH_UNLEASH_IMPORT_RUN_NUMBER + - name: SWATCH_UNLEASH_IMPORT_RUN_NUMBER + value: "1" objects: - apiVersion: cloud.redhat.com/v1alpha1 @@ -24,3 +43,79 @@ objects: # IQE plugin your ClowdApp is associated with testing: iqePlugin: rhsm-subscriptions + + - apiVersion: cloud.redhat.com/v1alpha1 + kind: ClowdApp + metadata: + name: swatch-unleash-import + spec: + envName: ${ENV_NAME} + featureFlags: true + pullSecrets: + name: ${IMAGE_PULL_SECRET} + + jobs: + - name: swatch-unleash-import-job-${SWATCH_UNLEASH_IMPORT_RUN_NUMBER} + activeDeadlineSeconds: 1800 + successfulJobsHistoryLimit: 1 + podSpec: + image: ${SWATCH_UNLEASH_IMPORT_IMAGE}:${SWATCH_UNLEASH_IMPORT_IMAGE_TAG} + command: ["/bin/bash", "-x"] + args: + - /opt/unleash/import-features.sh + - /unleash/flags.json + env: + - name: UNLEASH_USER + value: ${SWATCH_UNLEASH_USER} + - name: UNLEASH_PASSWORD + value: ${SWATCH_UNLEASH_PASSWORD} + resources: + requests: + cpu: ${SWATCH_UNLEASH_IMPORT_CPU_REQUEST} + memory: ${SWATCH_UNLEASH_IMPORT_MEMORY_REQUEST} + limits: + cpu: ${SWATCH_UNLEASH_IMPORT_CPU_LIMIT} + memory: ${SWATCH_UNLEASH_IMPORT_MEMORY_LIMIT} + volumeMounts: + - name: unleash-json + mountPath: /unleash + volumes: + - name: unleash-json + configMap: + name: unleash-json + + - apiVersion: cloud.redhat.com/v1alpha1 + kind: ClowdJobInvocation + metadata: + name: swatch-unleash-import-${SWATCH_UNLEASH_IMPORT_RUN_NUMBER} + spec: + appName: swatch-unleash-import + jobs: + - swatch-unleash-import-job-${SWATCH_UNLEASH_IMPORT_RUN_NUMBER} + + - apiVersion: v1 + kind: ConfigMap + metadata: + name: unleash-json + data: + flags.json: |- + { + "version": 1, + "features": [ + { + "name": "swatch.swatch-metrics-hbi.emit-events", + "description": "Enable sending of HBI events to the Swatch events after conversion.", + "type": "operational", + "project": "default", + "stale": false, + "strategies": [ + { + "name": "default", + "parameters": {} + } + ], + "variants": [], + "createdAt": "2024-01-10T20:20:42.531Z" + } + ] + } diff --git a/deploy/unleash-import-clowdapp.yaml b/deploy/unleash-import-clowdapp.yaml deleted file mode 100644 index dfa44d8d9b..0000000000 --- a/deploy/unleash-import-clowdapp.yaml +++ /dev/null @@ -1,199 +0,0 @@ ---- -apiVersion: template.openshift.io/v1 -kind: Template -metadata: - name: unleash-import -parameters: - - name: IMAGE_PULL_SECRET - value: quay-cloudservices-pull - - name: ENV_NAME - value: env-rhsm - # When needed bump UNLEASH_IMPORT_RUN_NUMBER - - name: UNLEASH_IMPORT_RUN_NUMBER - value: "1" - - name: UNLEASH_IMPORT_IMAGE - value: quay.io/awood/unleash-import - - name: UNLEASH_IMPORT_IMAGE_TAG - value: latest - - name: UNLEASH_IMPORT_MEMORY_REQUEST - value: 500Mi - - name: UNLEASH_IMPORT_MEMORY_LIMIT - value: 800Mi - - name: UNLEASH_IMPORT_CPU_REQUEST - value: 350m - - name: UNLEASH_IMPORT_CPU_LIMIT - value: 500m - - name: UNLEASH_USER - value: admin - - name: UNLEASH_PASSWORD - value: unleash4all - -objects: - - apiVersion: cloud.redhat.com/v1alpha1 - kind: ClowdApp - metadata: - name: unleash-import - spec: - envName: ${ENV_NAME} - featureFlags: true - pullSecrets: - name: ${IMAGE_PULL_SECRET} - - jobs: - - name: unleash-import-job-${UNLEASH_IMPORT_RUN_NUMBER} - activeDeadlineSeconds: 1800 - successfulJobsHistoryLimit: 1 - podSpec: - image: ${UNLEASH_IMPORT_IMAGE}:${UNLEASH_IMPORT_IMAGE_TAG} - command: ["/bin/bash", "-x"] - args: - - /opt/unleash/import-features.sh - - /unleash/flags.json - env: - - name: UNLEASH_USER - value: ${UNLEASH_USER} - - name: UNLEASH_PASSWORD - value: ${UNLEASH_PASSWORD} - resources: - requests: - cpu: ${UNLEASH_IMPORT_CPU_REQUEST} - memory: ${UNLEASH_IMPORT_MEMORY_REQUEST} - limits: - cpu: ${UNLEASH_IMPORT_CPU_LIMIT} - memory: ${UNLEASH_IMPORT_MEMORY_LIMIT} - volumeMounts: - - name: unleash-json - mountPath: /unleash - volumes: - - name: unleash-json - configMap: - name: unleash-json - - - apiVersion: cloud.redhat.com/v1alpha1 - kind: ClowdJobInvocation - metadata: - name: unleash-import-${UNLEASH_IMPORT_RUN_NUMBER} - spec: - appName: unleash-import - jobs: - - unleash-import-job-${UNLEASH_IMPORT_RUN_NUMBER} - - - apiVersion: v1 - kind: ConfigMap - metadata: - name: unleash-json - data: - flags.json: |- - { - "version": 1, - "features": [ - { - "name": "hbi.api.disable-xjoin-test", - "description": "A list of org_id for customers allow listed for postgres direct querying.", - "type": "operational", - "project": "default", - "enabled": true, - "stale": false, - "strategies": [ - { - "name": "default", - "parameters": {} - } - ], - "variants": [], - "createdAt": "2024-01-09T18:49:38.445Z" - }, - { - "name": "hbi.api.disable-xjoin", - "description": "A list of org_id for customers allow listed for postgres direct querying.", - "type": "operational", - "project": "default", - "enabled": true, - "stale": false, - "strategies": [ - { - "name": "default", - "parameters": {} - } - ], - "variants": [], - "createdAt": "2024-01-09T18:49:38.445Z" - }, - { - "name": "hbi.group-assignment-rules", - "description": "If active, newly-created hosts will automatically be assigned to groups based on the account's assignment rules.", - "type": "release", - "project": "default", - "stale": false, - "enabled": true, - "strategies": [ - { - "name": "default", - "parameters": {} - } - ], - "variants": [], - "createdAt": "2024-01-10T20:16:35.042Z" - }, - { - "name": "hbi.custom-staleness", - "description": "If active, Custom host staleness/culling features will be enabled in the API and UI", - "type": "release", - "project": "default", - "stale": false, - "enabled": true, - "strategies": [ - { - "name": "default", - "parameters": {} - } - ], - "variants": [], - "createdAt": "2024-01-10T20:18:18.842Z" - }, - { - "name": "hbi.api.hide-edge-by-default", - "description": "If this is toggled, the HBI API will hide Edge hosts by default on all requests. If the request has a host-type filter, that is used instead.", - "type": "release", - "project": "default", - "stale": false, - "strategies": [ - { - "name": "default", - "parameters": {} - } - ], - "variants": [], - "createdAt": "2024-01-10T20:19:30.848Z" - }, - { - "name": "edgeParity.groups-migration", - "description": "In the context of edge-parity, enables the migrate of edge management groups to insights inventory groups.", - "type": "release", - "project": "default", - "stale": false, - "strategies": [ - { - "name": "default", - "parameters": {} - } - ], - "variants": [], - "createdAt": "2024-01-10T20:20:42.531Z" - } - ], - "strategies": [ - { - "name": "schema-strategy", - "description": "Enablement based on account/schema number", - "parameters": [ - { - "name": "schema-name", - "type": "list", - "description": "values must begin with `acct` or `org`", - "required": false - } - ] - } - ] - } diff --git a/.unleash/Dockerfile.unleash b/swatch-unleash-import/Dockerfile similarity index 100% rename from .unleash/Dockerfile.unleash rename to swatch-unleash-import/Dockerfile diff --git a/swatch-unleash-import/README.md b/swatch-unleash-import/README.md new file mode 100644 index 0000000000..b9634bc106 --- /dev/null +++ b/swatch-unleash-import/README.md @@ -0,0 +1,18 @@ +# swatch-unleash-import + +Defines an image that can be run to create/update unleash feature +flags in an ephemeral environment. + +## NOTES +**./Dockerfile** +This file is used when building the image that runs the `bin/import-features.sh` script that +loads all the feature flags into the target environment. + +**deploy/rhsm-clowdapp.yaml** +This file defines the Job/ConfigMap that will be run to update the feature flags on deployment. +This is only ever done for the epehemeral environment (see app-interface). + +**.unleash/flags.json** +This defines the flags that are created in our containers when deploying our +service dependancies via docker/podman (docker-compose). +