|
| 1 | +# Contributing |
| 2 | + |
| 3 | +These guidelines will help you get started with the Starboard Operator project. |
| 4 | + |
| 5 | +## Prerequisites |
| 6 | + |
| 7 | +1. Install Go |
| 8 | + |
| 9 | + The project requires [Go 1.14][go-download] or later. We also assume that you're familiar with |
| 10 | + Go's [GOPATH workspace][go-code] convention, and have the appropriate environment variables set. |
| 11 | +2. Get the source code: |
| 12 | + |
| 13 | + ``` |
| 14 | + $ git clone [email protected]:aquasecurity/starboard-operator.git |
| 15 | + $ cd starboard-operator |
| 16 | + ``` |
| 17 | +3. Access to a dev Kubernetes cluster. We assume that you're using a single-node [KIND][kind] cluster created with the |
| 18 | + following command: |
| 19 | + |
| 20 | + ``` |
| 21 | + $ kind create cluster |
| 22 | + ``` |
| 23 | + |
| 24 | +## Deployment |
| 25 | + |
| 26 | +You'll deploy the operator in the `starboard-operator` Namespace and configure it to watch the `starboard-operator` |
| 27 | +Namespace. In OLM terms such install mode is called `OwnNamespace` and is suitable for end users who want to install |
| 28 | +the operator in the same namespace as supervised workloads. |
| 29 | + |
| 30 | +> The `OwnNamespace` mode is good to get started with a basic development workflow. For other install modes see |
| 31 | +> [Operator Multitenancy with OperatorGroups][olm-operator-groups]. |
| 32 | +
|
| 33 | +### Prerequisites |
| 34 | + |
| 35 | +1. Build Docker images: |
| 36 | + |
| 37 | + ``` |
| 38 | + $ export GOOS=linux |
| 39 | + $ make docker-build |
| 40 | + ``` |
| 41 | + |
| 42 | + This will build the `docker.io/aquasec/starboard-operator:dev` as well as `docker.io/aquasec/starboard-scanner-aqua:dev` |
| 43 | + images. The second image is only used when you enable the Aqua CSP scanner. By default Trivy is used as vulnerability |
| 44 | + scanner by pulling its official image accessible from DockerHub (`docker.io/aquasec/trivy:$TRIVY_VERSION`). |
| 45 | +2. Load Docker images into the cluster node: |
| 46 | + |
| 47 | + ``` |
| 48 | + $ kind load docker-image aquasec/starboard-operator:dev |
| 49 | + $ kind load docker-image aquasec/starboard-scanner-aqua:dev |
| 50 | + ``` |
| 51 | +3. Send the definition of the VulnerabilityReport custom resource to the Kubernetes API: |
| 52 | + |
| 53 | + ``` |
| 54 | + $ kubectl apply -f https://raw.githubusercontent.com/aquasecurity/starboard/master/kube/crd/vulnerabilityreports-crd.yaml |
| 55 | + ``` |
| 56 | +4. Send the following Kubernetes objects definitions to the Kubernetes API: |
| 57 | + |
| 58 | + ``` |
| 59 | + $ kubectl apply -f deploy/kubectl/01-starboard-operator.ns.yaml \ |
| 60 | + -f deploy/kubectl/02-starboard-operator.sa.yaml |
| 61 | + -f deploy/kubectl/03-starboard-operator.role.yaml |
| 62 | + -f deploy/kubectl/04-starboard-operator.rolebinding.yaml |
| 63 | + ``` |
| 64 | + |
| 65 | + This will create the `starboard-operator` Namespace, and the `starboard-operator` ServiceAccount. Beyond that, |
| 66 | + it will create the `starboard-operator` Role and bind it to the `starboard-operator` ServiceAccount in the |
| 67 | + `starboard-operator` Namespace via the `starboard-operator` RoleBinding. |
| 68 | + |
| 69 | +### In cluster |
| 70 | + |
| 71 | +1. Create the `starboard-operator` Deployment in the `starboard-operator` namespace to run the operator's container: |
| 72 | + |
| 73 | + ``` |
| 74 | + $ kubectl apply -f deploy/kubectl/05-starboard-operator.deployment.yaml |
| 75 | + ``` |
| 76 | + |
| 77 | +### Out of cluster |
| 78 | + |
| 79 | +1. Run the main method of the operator program: |
| 80 | + |
| 81 | + ``` |
| 82 | + $ go run cmd/operator/main.go |
| 83 | + ``` |
| 84 | + |
| 85 | +### Enable Aqua CSP scanner |
| 86 | + |
| 87 | +1. Create the `starboard-operator` secret in the `starboard-operator` namespace that holds the scanner's configuration: |
| 88 | + |
| 89 | + ``` |
| 90 | + $ kubectl create secret generic starboard-operator \ |
| 91 | + --namespace starboard-operator \ |
| 92 | + --from-literal OPERATOR_SCANNER_AQUA_CSP_USERNAME=$AQUA_CONSOLE_USERNAME \ |
| 93 | + --from-literal OPERATOR_SCANNER_AQUA_CSP_PASSWORD=$AQUA_CONSOLE_PASSWORD \ |
| 94 | + --from-literal OPERATOR_SCANNER_AQUA_CSP_VERSION=$AQUA_VERSION \ |
| 95 | + --from-literal OPERATOR_SCANNER_AQUA_CSP_HOST=http://csp-console-svc.aqua:8080 |
| 96 | + ``` |
| 97 | + |
| 98 | +## Operator Lifecycle Manager |
| 99 | + |
| 100 | +### Prerequisites |
| 101 | + |
| 102 | +1. Install [Operator Lifecycle Manager][olm] (OLM) and [Operator Marketplace][operator-marketplace]: |
| 103 | + |
| 104 | + ``` |
| 105 | + $ ./deploy/olm/install.sh |
| 106 | + ``` |
| 107 | + |
| 108 | +2. Install [Operator Courier][operator-courier]: |
| 109 | + |
| 110 | + ``` |
| 111 | + $ pip3 install operator-courier |
| 112 | + ``` |
| 113 | +3. [Sign up][quay] for a free Quay.io account if you're a new user. |
| 114 | + |
| 115 | +### Build OLM bundle |
| 116 | + |
| 117 | +1. Lint the OLM bundle: |
| 118 | + |
| 119 | + ``` |
| 120 | + $ BUNDLE_SRC_DIR=deploy/olm/bundle |
| 121 | + $ operator-courier verify $BUNDLE_SRC_DIR |
| 122 | + ``` |
| 123 | +2. Retrieve a Quay.io token: |
| 124 | + ``` |
| 125 | + $ QUAY_USERNAME=<your quay.io username> |
| 126 | + $ QUAY_PASSWORD=<your quay.io password> |
| 127 | + $ QUAY_URL=https://quay.io/cnr/api/v1/users/login |
| 128 | +
|
| 129 | + $ QUAY_TOKEN=$(curl -s -H "Content-Type: application/json" -XPOST $QUAY_URL -d \ |
| 130 | + '{"user":{"username":"'"${QUAY_USERNAME}"'","password": "'"${QUAY_PASSWORD}"'"}}' | |
| 131 | + jq -r .token) |
| 132 | + ``` |
| 133 | +3. Push the OLM bundle to Quay.io: |
| 134 | + ``` |
| 135 | + $ QUAY_NAMESPACE=<quay.io namespace> |
| 136 | + $ PACKAGE_NAME=starboard-operator |
| 137 | + $ PACKAGE_VERSION=<next package version> |
| 138 | +
|
| 139 | + $ operator-courier push "$BUNDLE_SRC_DIR" "$QUAY_NAMESPACE" \ |
| 140 | + "$PACKAGE_NAME" "$PACKAGE_VERSION" "$QUAY_TOKEN" |
| 141 | + ``` |
| 142 | + |
| 143 | +### Create ClusterServiceVersion |
| 144 | + |
| 145 | +1. Create the OperatorSource resource: |
| 146 | + |
| 147 | + ``` |
| 148 | + QUAY_FULL_NAME=<your quay.io full name> |
| 149 | + $ cat << EOF | kubectl apply -f - |
| 150 | + apiVersion: operators.coreos.com/v1 |
| 151 | + kind: OperatorSource |
| 152 | + metadata: |
| 153 | + name: $QUAY_USERNAME-operators |
| 154 | + namespace: marketplace |
| 155 | + spec: |
| 156 | + type: appregistry |
| 157 | + endpoint: https://quay.io/cnr |
| 158 | + displayName: "$QUAY_FULL_NAME Quay.io Applications" |
| 159 | + publisher: "$QUAY_FULL_NAME" |
| 160 | + registryNamespace: "$QUAY_USERNAME" |
| 161 | + EOF |
| 162 | + ``` |
| 163 | + |
| 164 | + An OperatorSource resource defines the external data store used to host operator bundles. In this case, you will be |
| 165 | + defining an OperatorSource to point to your Quay.io account, which will provide access to its hosted OLM bundles. |
| 166 | + |
| 167 | +2. Create the OperatorGroup resource: |
| 168 | + |
| 169 | + ``` |
| 170 | + $ cat << EOF | kubectl apply -f - |
| 171 | + apiVersion: operators.coreos.com/v1alpha2 |
| 172 | + kind: OperatorGroup |
| 173 | + metadata: |
| 174 | + name: workloads |
| 175 | + namespace: marketplace |
| 176 | + spec: |
| 177 | + targetNamespaces: |
| 178 | + - marketplace |
| 179 | + EOF |
| 180 | + ``` |
| 181 | + |
| 182 | + You'll need an OperatorGroup to denote which namespaces the operator should watch. It must exist in the namespace |
| 183 | + where you want to deploy the operator. |
| 184 | + |
| 185 | +3. Create the Subscription resource: |
| 186 | + |
| 187 | + ``` |
| 188 | + cat << EOF | kubectl apply -f - |
| 189 | + apiVersion: operators.coreos.com/v1alpha1 |
| 190 | + kind: Subscription |
| 191 | + metadata: |
| 192 | + name: starboard-operator |
| 193 | + namespace: marketplace |
| 194 | + spec: |
| 195 | + channel: alpha |
| 196 | + name: starboard-operator |
| 197 | + source: $QUAY_NAMESPACE-operators |
| 198 | + sourceNamespace: marketplace |
| 199 | + EOF |
| 200 | + ``` |
| 201 | + |
| 202 | + A Subscription links the previous steps together by selecting an operator and one of its channels. OLM uses this |
| 203 | + information to start the corresponding operator Pod. The example above creates a new Subscription to the `alpha` |
| 204 | + channel for the Starboard Operator. |
| 205 | + |
| 206 | +[go-download]: https://golang.org/dl/ |
| 207 | +[go-code]: https://golang.org/doc/code.html |
| 208 | +[kind]: https://github.com/kubernetes-sigs/kind |
| 209 | +[olm]: https://github.com/operator-framework/operator-lifecycle-manager |
| 210 | +[operator-marketplace]: https://github.com/operator-framework/operator-marketplace |
| 211 | +[operator-courier]: https://github.com/operator-framework/operator-courier |
| 212 | +[olm-operator-groups]: https://github.com/operator-framework/operator-lifecycle-manager/blob/master/doc/design/operatorgroups.md |
| 213 | +[quay]: https://quay.io |
0 commit comments