diff --git a/openshift-gitops-operator/operator/base/kustomization.yaml b/openshift-gitops-operator/operator/base/kustomization.yaml index 00078e0a..dbedd759 100644 --- a/openshift-gitops-operator/operator/base/kustomization.yaml +++ b/openshift-gitops-operator/operator/base/kustomization.yaml @@ -3,3 +3,6 @@ kind: Kustomization resources: - subscription.yaml + +components: + - ../components/enable-console-plugin diff --git a/openshift-gitops-operator/operator/components/README.md b/openshift-gitops-operator/operator/components/README.md new file mode 100644 index 00000000..f4a94f72 --- /dev/null +++ b/openshift-gitops-operator/operator/components/README.md @@ -0,0 +1,21 @@ +# OpenShift GitOps Components + +The included components are intended to be common patching patterns used on top of the default OpenShift Gitops operator to configure additional features of the operator. Components are composable patches that can be added at the overlays layer on top of a base or overlay + +This repo currently contains the following components: + +* [enable-console-plugin](enable-console-plugin) +* [openshift-gitops-operator](openshift-gitops-operator) + +## Usage + +Components can be added to a base by adding the `components` section to your overlay `kustomization.yaml` file: + +``` +apiVersion: kustomize.config.k8s.io/v1beta1 +kind: Kustomization +resources: + - ../../base +components: + - ../../components/enable-console-plugin +``` diff --git a/openshift-gitops-operator/operator/components/enable-console-plugin/README.md b/openshift-gitops-operator/operator/components/enable-console-plugin/README.md new file mode 100644 index 00000000..5dd441c5 --- /dev/null +++ b/openshift-gitops-operator/operator/components/enable-console-plugin/README.md @@ -0,0 +1,17 @@ +# enable-console-plugin + +## Purpose +This component is designed to enable the OpenShift GitOps Console Plugin. + +## Usage + +This component can be added to a base by adding the `components` section to your overlay `kustomization.yaml` file: + +``` +apiVersion: kustomize.config.k8s.io/v1beta1 +kind: Kustomization +resources: + - ../../base +components: + - ../../components/enable-console-plugin +``` diff --git a/openshift-gitops-operator/operator/components/enable-console-plugin/console-plugin-job.sh b/openshift-gitops-operator/operator/components/enable-console-plugin/console-plugin-job.sh new file mode 100755 index 00000000..e2339bcc --- /dev/null +++ b/openshift-gitops-operator/operator/components/enable-console-plugin/console-plugin-job.sh @@ -0,0 +1,30 @@ +#!/usr/bin/env bash + +enable_console_plugin(){ + [ -z "${PLUGIN_NAME}" ] && return 1 + + echo "Attempting to enable ${PLUGIN_NAME} plugin" + echo "" + + # Create the plugins section on the object if it doesn't exist + if [ -z "$(oc get consoles.operator.openshift.io cluster -o=jsonpath='{.spec.plugins}')" ]; then + echo "Creating plugins object" + oc patch consoles.operator.openshift.io cluster --patch '{ "spec": { "plugins": [] } }' --type=merge + fi + + INSTALLED_PLUGINS=$(oc get consoles.operator.openshift.io cluster -o=jsonpath='{.spec.plugins}') + echo "Current plugins:" + echo "${INSTALLED_PLUGINS}" + + if [[ "${INSTALLED_PLUGINS}" == *"${PLUGIN_NAME}"* ]]; then + echo "${PLUGIN_NAME} is already enabled" + else + echo "Enabling plugin: ${PLUGIN_NAME}" + oc patch consoles.operator.openshift.io cluster --type=json --patch '[{"op": "add", "path": "/spec/plugins/-", "value": "'"${PLUGIN_NAME}"'"}]' + fi + + sleep 6 + oc get consoles.operator.openshift.io cluster -o=jsonpath='{.spec.plugins}' +} + +enable_console_plugin diff --git a/openshift-gitops-operator/operator/components/enable-console-plugin/console-plugin-job.yaml b/openshift-gitops-operator/operator/components/enable-console-plugin/console-plugin-job.yaml new file mode 100644 index 00000000..b25b2f9e --- /dev/null +++ b/openshift-gitops-operator/operator/components/enable-console-plugin/console-plugin-job.yaml @@ -0,0 +1,64 @@ +--- +apiVersion: v1 +kind: ServiceAccount +metadata: + name: job-gitops-console-plugin +--- +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRole +metadata: + name: job-gitops-console-plugin +rules: + - apiGroups: + - operator.openshift.io + resources: + - consoles + verbs: + - get + - list + - patch + - label +--- +kind: ClusterRoleBinding +apiVersion: rbac.authorization.k8s.io/v1 +metadata: + name: job-gitops-console-plugin +subjects: + - kind: ServiceAccount + name: job-gitops-console-plugin +roleRef: + apiGroup: rbac.authorization.k8s.io + kind: ClusterRole + name: job-gitops-console-plugin +--- +apiVersion: batch/v1 +kind: Job +metadata: + name: job-gitops-console-plugin + annotations: + argocd.argoproj.io/sync-wave: "10" +spec: + template: + spec: + containers: + - name: minion + image: registry.redhat.io/openshift4/ose-cli + env: + - name: PLUGIN_NAME + value: gitops-plugin + command: + - /bin/bash + - -c + - /scripts/console-plugin-job.sh + volumeMounts: + - name: scripts + mountPath: /scripts + volumes: + - name: scripts + configMap: + name: job-gitops-console-plugin + defaultMode: 0755 + restartPolicy: Never + serviceAccount: job-gitops-console-plugin + serviceAccountName: job-gitops-console-plugin + backoffLimit: 4 diff --git a/openshift-gitops-operator/operator/components/enable-console-plugin/kustomization.yaml b/openshift-gitops-operator/operator/components/enable-console-plugin/kustomization.yaml new file mode 100644 index 00000000..9cfd50df --- /dev/null +++ b/openshift-gitops-operator/operator/components/enable-console-plugin/kustomization.yaml @@ -0,0 +1,15 @@ +apiVersion: kustomize.config.k8s.io/v1alpha1 +kind: Component + +namespace: openshift-gitops + +resources: +- console-plugin-job.yaml + +generatorOptions: + disableNameSuffixHash: true + +configMapGenerator: + - name: job-gitops-console-plugin + files: + - console-plugin-job.sh diff --git a/openshift-gitops-operator/operator/components/openshift-gitops-operator/README.md b/openshift-gitops-operator/operator/components/openshift-gitops-operator/README.md index adda1f77..31cb0794 100644 --- a/openshift-gitops-operator/operator/components/openshift-gitops-operator/README.md +++ b/openshift-gitops-operator/operator/components/openshift-gitops-operator/README.md @@ -3,6 +3,8 @@ ## Purpose This component is creates a `Namespace` and `OperatorGroup` to enable the installation of the OpenShift GitOps Operator. +As of OpenShift GitOps 1.11, the operator should be installed in the openshift-gitops-operator namespace by default. + ## Usage This component can be added to a base by adding the `components` section to your overlay `kustomization.yaml` file: