From 3dcd520617b72c688f64c24758feef1c18e15afe Mon Sep 17 00:00:00 2001 From: Brett Tofel Date: Fri, 27 Sep 2024 12:16:37 -0400 Subject: [PATCH] Hack to allow local kind usage to see changes on cluster --- ...05_redhat_operators_clustercatalog.cr.yaml | 33 +++++++++++ hack/dev_hack.md | 56 +++++++++++++++++++ hack/kind-apply.sh | 35 ++++++++++++ 3 files changed, 124 insertions(+) create mode 100644 defaults/05_redhat_operators_clustercatalog.cr.yaml create mode 100644 hack/dev_hack.md create mode 100755 hack/kind-apply.sh diff --git a/defaults/05_redhat_operators_clustercatalog.cr.yaml b/defaults/05_redhat_operators_clustercatalog.cr.yaml new file mode 100644 index 000000000..70441e6e9 --- /dev/null +++ b/defaults/05_redhat_operators_clustercatalog.cr.yaml @@ -0,0 +1,33 @@ +apiVersion: olm.operatorframework.io/v1alpha1 +kind: ClusterCatalog +metadata: + name: redhat-operators + annotations: + target.workload.openshift.io/management: '{"effect": "PreferredDuringScheduling"}' +spec: + priority: -100 + source: + type: image + image: + ref: registry.redhat.io/redhat/redhat-operator-index:v4.18 + pollInterval: 10m + nodeSelector: + node-role.kubernetes.io/master: "" + kubernetes.io/os: "linux" + priorityClassName: "system-cluster-critical" + tolerations: + - key: "node-role.kubernetes.io/master" + operator: Exists + effect: NoSchedule + - key: "node.kubernetes.io/unreachable" + operator: "Exists" + effect: NoExecute + tolerationSeconds: 120 + - key: "node.kubernetes.io/not-ready" + operator: Exists + effect: "NoExecute" + tolerationSeconds: 120 + memoryTarget: 30Mi + extractContent: + cacheDir: /tmp/cache + catalogDir: /configs diff --git a/hack/dev_hack.md b/hack/dev_hack.md new file mode 100644 index 000000000..9f44b232f --- /dev/null +++ b/hack/dev_hack.md @@ -0,0 +1,56 @@ + +# Super Hacky Way to Get a Local Kind Cluster Working Enough to Manage OperatorHub and CatalogSource Objects + +## Prerequisites +To use the Dockerfiles in this guide, you must log in to `registry.ci`. + +### Get Your OpenShift Token +1. Navigate to [OpenShift Console](https://console-openshift-console.apps.ci.l2s4.p1.openshiftapps.com). +2. In the top-right corner, click the menu and select **Copy Login Command**. +3. Copy the login command and use it in the following steps. + +## Steps + +### 1. Log in to `registry.ci` +Use the `podman` command to log in to the OpenShift registry. Replace the username and password with your own credentials: + +```bash +podman login -u=btofel -p=sha256~ registry.ci.openshift.org +``` + +> **Note**: Ensure your token is valid before proceeding. + +### 2. Build the Marketplace Operator Docker Image +Now, you need to build the marketplace operator for ARM64 architecture: + +```bash +podman build --arch arm64 -t localhost/marketplace-operator:latest -f Dockerfile +``` + +This will create a Docker image tagged as `localhost/marketplace-operator:latest`. + +### 3. Save the Docker Image as a TAR File +Export the Docker image to a `.tar` file so it can be loaded into your `kind` cluster: + +```bash +podman save -o marketplace-operator.tar localhost/marketplace-operator:latest +``` + +### 4. Load the Image into the Kind Cluster +Use `kind` to load the Docker image into your cluster named `catalogd`: + +```bash +kind load image-archive marketplace-operator.tar --name=catalogd +``` + +### 5. Apply the Necessary Resources +Finally, apply the resources to the cluster using the following script: + +```bash +hack/kind-apply.sh +``` + +This script will configure your local `kind` cluster enough to manage `OperatorHub` and `CatalogSource` objects. + +> **Note**: This is a quick and dirty setup for local testing and development purposes. + \ No newline at end of file diff --git a/hack/kind-apply.sh b/hack/kind-apply.sh new file mode 100755 index 000000000..e3d95dec2 --- /dev/null +++ b/hack/kind-apply.sh @@ -0,0 +1,35 @@ +#!/bin/bash + +# Apply the CRD from GitHub first +kubectl apply -f https://raw.githubusercontent.com/openshift/api/600991d550ac9ee3afbfe994cf0889bf9805a3f5/config/v1/0000_03_marketplace-operator_01_operatorhub.crd.yaml + +# Apply the CatalogSource CRD from GitHub +kubectl apply -f https://raw.githubusercontent.com/operator-framework/operator-lifecycle-manager/b31bd89a23d597ca440024458d0099a273642f8c/deploy/upstream/quickstart/crds.yaml + +# Apply the first set of manifest files +kubectl apply -f manifests/0000_03_marketplace-operator_02_operatorhub.cr.yaml +kubectl apply -f manifests/01_namespace.yaml +kubectl apply -f manifests/04_service_account.yaml +kubectl apply -f manifests/05_role.yaml +kubectl apply -f manifests/06_role_binding.yaml +kubectl apply -f manifests/07_configmap.yaml +kubectl apply -f manifests/08_service.yaml + +# Save the localhost image to a tar file and load it into the kind cluster +#echo "Saving the image as a tarball and loading it into kind cluster..." +#podman save -o marketplace-operator.tar localhost/marketplace-operator:latest +#kind load image-archive marketplace-operator.tar + +# Apply the 09_operator.yaml with modifications on the fly (using localhost image) +yq eval ' + del(.spec.template.spec.nodeSelector) | + del(.spec.template.spec.tolerations[] | select(.key == "node-role.kubernetes.io/master")) | + del(.spec.template.spec.containers[].volumeMounts[] | select(.name == "marketplace-operator-metrics")) | + del(.spec.template.spec.volumes[] | select(.name == "marketplace-operator-metrics")) | + del(.spec.template.spec.containers[].args[] | select(. == "-tls-cert")) | + del(.spec.template.spec.containers[].args[] | select(. == "/var/run/secrets/serving-cert/tls.crt")) | + del(.spec.template.spec.containers[].args[] | select(. == "-tls-key")) | + del(.spec.template.spec.containers[].args[] | select(. == "/var/run/secrets/serving-cert/tls.key")) | + del(.spec.template.spec.securityContext.runAsNonRoot) | + .spec.template.spec.containers[0].image = "localhost/marketplace-operator:latest" +' manifests/09_operator.yaml | kubectl apply -f -