Skip to content

Commit

Permalink
Create a swatch-unleash-importer clowdapp
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
mstead committed Oct 8, 2024
1 parent 2d29179 commit 69e4c78
Show file tree
Hide file tree
Showing 6 changed files with 139 additions and 200 deletions.
15 changes: 15 additions & 0 deletions .unleash/flags.json
Original file line number Diff line number Diff line change
@@ -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.",
Expand Down
12 changes: 11 additions & 1 deletion bin/build-images.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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
95 changes: 95 additions & 0 deletions deploy/rhsm-clowdapp.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"
}
]
}
199 changes: 0 additions & 199 deletions deploy/unleash-import-clowdapp.yaml

This file was deleted.

File renamed without changes.
18 changes: 18 additions & 0 deletions swatch-unleash-import/README.md
Original file line number Diff line number Diff line change
@@ -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).

0 comments on commit 69e4c78

Please sign in to comment.