Skip to content

Commit

Permalink
add console plugin job
Browse files Browse the repository at this point in the history
  • Loading branch information
strangiato committed Apr 30, 2024
1 parent 11d35cd commit cd74001
Show file tree
Hide file tree
Showing 7 changed files with 152 additions and 0 deletions.
3 changes: 3 additions & 0 deletions openshift-gitops-operator/operator/base/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,6 @@ kind: Kustomization

resources:
- subscription.yaml

components:
- ../components/enable-console-plugin
21 changes: 21 additions & 0 deletions openshift-gitops-operator/operator/components/README.md
Original file line number Diff line number Diff line change
@@ -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
```
Original file line number Diff line number Diff line change
@@ -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
```
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit cd74001

Please sign in to comment.