Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
122 changes: 122 additions & 0 deletions HACKING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
# Local Development of must-gather-operator

The operator can be built and run locally provided a `KUBECONFIG` is set in your environment pointing to an OpenShift cluster. It is recommended that development be done using a cluster with `cluster-admin` permissions.

## Build and Run

Execute the following pre-requisite steps to setup the must-gather-operator namespace with required manifests.

```sh
oc apply -f deploy/crds/managed.openshift.io_mustgathers.yaml

oc new-project must-gather-operator

oc apply -f deploy/

# avoid running pods in the cluster for the operator
oc scale --replicas=0 -n must-gather-operator deploy/must-gather-operator
```

Build and run the operator:
```sh
go build .

export OPERATOR_NAMESPACE=must-gather-operator
export OPERATOR_NAME=must-gather-operator
export WATCH_NAMESPACE=must-gather-operator
export DEFAULT_MUST_GATHER_IMAGE='registry.redhat.io/openshift4/ose-must-gather-rhel9:latest'
export NAMESPACE=must-gather-operator

# the image for the operator is still required,
# it is used by the "upload" container in the Job's pod.
export OPERATOR_IMAGE="quay.io/swghosh/must-gather-operator:latest"

podman build -t "${OPERATOR_IMAGE}"

export OSDK_FORCE_RUN_MODE="local" # required to disable leader election
./must-gather-operator
```

## Example must-gather

```sh
oc create -f - << EOF
apiVersion: v1
kind: Namespace
metadata:
name: sandbox
labels:
name: sandbox
---
apiVersion: v1
kind: ServiceAccount
metadata:
name: sandbox-admin
namespace: sandbox
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: sandbox-admin-cluster-admin-binding
subjects:
- kind: ServiceAccount
name: sandbox-admin
namespace: sandbox
roleRef:
kind: ClusterRole
name: cluster-admin
apiGroup: rbac.authorization.k8s.io
---
apiVersion: v1
kind: Secret
metadata:
name: sftp-access-rh-creds
namespace: sandbox
type: Opaque
stringData:
username: some-username
password: a-password
---
apiVersion: managed.openshift.io/v1alpha1
kind: MustGather
metadata:
name: example
namespace: sandbox
spec:
caseID: '02527285'
caseManagementAccountSecretRef:
name: sftp-access-rh-creds
serviceAccountRef:
name: sandbox-admin
EOF
```

## Steps to deploy must-gather operator on cluster

```sh
# Build the image
podman build -f build/Dockerfile -t quay.io/{{user_id}}/mustgather:{{tag}} .

# Push the image
podman push quay.io/{{user_id}}/mustgather:{{tag}}

# Then update `container.image` on `line 32` and `OPERATOR_IMAGE` on `line 46` to new built image i.e. `quay.io/{{user_id}}/mustgather:{{tag}}`

oc apply -f deploy/crds/managed.openshift.io_mustgathers.yaml

# Create namespace must-gather-operator
oc new-project must-gather-operator

# Create must-gather-operator service account
oc apply -f examples/other_resources/01_must-gather-operator.ServiceAccount.yaml

# Create must-gather-admin service account
oc apply -f examples/other_resources/04_must-gather-admin.ServiceAccount.yaml

# Replace with actual user_name and password for upload to work
oc create secret generic case-management-creds --from-literal=username=test-user --from-literal=password=test-password -n must-gather-operator

oc apply -f deploy/

oc apply -f examples/mustgather_basic.yaml
```
22 changes: 1 addition & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,24 +86,4 @@ oc create secret generic case-management-creds --from-literal=username=<username

## Local Development

Execute the following steps to develop the functionality locally. It is recommended that development be done using a cluster with `cluster-admin` permissions.

In the operator's `Deployment.yaml` [file](deploy/99_must-gather-operator.Deployment.yaml), add a variable to the deployment's `spec.template.spec.containers.env` list called `OPERATOR_IMAGE` and set the value to your local copy of the image:
```shell
env:
- name: OPERATOR_IMAGE
value: "registry.example/repo/image:latest"
```
Then run:
```shell
go mod download
```

Using the [operator-sdk](https://github.com/operator-framework/operator-sdk), run the operator locally:

```shell
oc apply -f deploy/crds/managed.openshift.io_mustgathers_crd.yaml
oc new-project must-gather-operator
export DEFAULT_MUST_GATHER_IMAGE='quay.io/openshift/origin-must-gather:latest'
OPERATOR_NAME=must-gather-operator operator-sdk run --verbose --local --namespace ''
```
For local development notes, refer to [HACKING.md](./HACKING.md).
1 change: 1 addition & 0 deletions deploy/02_must-gather-operator.ClusterRole.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ rules:
verbs:
- list
- get
- watch
# leader election
- apiGroups:
- ""
Expand Down