Skip to content

Commit d14cd21

Browse files
committed
deploy operator into kind during e2e tests so it can access any pod/service inside kind
On-behalf-of: @SAP [email protected]
1 parent 5c44ed1 commit d14cd21

File tree

5 files changed

+26
-34
lines changed

5 files changed

+26
-34
lines changed

Makefile

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -127,27 +127,33 @@ build-installer: manifests generate kustomize ## Generate a consolidated YAML wi
127127
cd config/manager && $(KUSTOMIZE) edit set image controller=${IMG}
128128
$(KUSTOMIZE) build config/default > dist/install.yaml
129129

130+
KIND_CLUSTER_NAME ?= kind
131+
132+
.PHONY: kind-load
133+
kind-load: ## Loads the docker image into a local kind cluster.
134+
kind load docker-image ${IMG} --name "$(KIND_CLUSTER_NAME)"
135+
130136
##@ Deployment
131137

132138
ifndef ignore-not-found
133139
ignore-not-found = false
134140
endif
135141

136142
.PHONY: install
137-
install: kubectl kustomize ## Install CRDs into the K8s cluster specified in ~/.kube/config.
143+
install: kubectl kustomize ## Install CRDs into the K8s cluster specified by $KUBECONFIG.
138144
$(KUSTOMIZE) build config/crd | $(KUBECTL) apply -f -
139145

140146
.PHONY: uninstall
141-
uninstall: kubectl kustomize ## Uninstall CRDs from the K8s cluster specified in ~/.kube/config. Call with ignore-not-found=true to ignore resource not found errors during deletion.
147+
uninstall: kubectl kustomize ## Uninstall CRDs from the K8s cluster specified by $KUBECONFIG. Call with ignore-not-found=true to ignore resource not found errors during deletion.
142148
$(KUSTOMIZE) build config/crd | $(KUBECTL) delete --ignore-not-found=$(ignore-not-found) -f -
143149

144150
.PHONY: deploy
145-
deploy: kubectl kustomize ## Deploy controller to the K8s cluster specified in ~/.kube/config.
151+
deploy: kubectl kustomize ## Deploy controller to the K8s cluster specified by $KUBECONFIG.
146152
cd config/manager && $(KUSTOMIZE) edit set image controller=${IMG}
147153
$(KUSTOMIZE) build config/default | $(KUBECTL) apply -f -
148154

149155
.PHONY: undeploy
150-
undeploy: kubectl kustomize ## Undeploy controller from the K8s cluster specified in ~/.kube/config. Call with ignore-not-found=true to ignore resource not found errors during deletion.
156+
undeploy: kubectl kustomize ## Undeploy controller from the K8s cluster specified by $KUBECONFIG. Call with ignore-not-found=true to ignore resource not found errors during deletion.
151157
$(KUSTOMIZE) build config/default | $(KUBECTL) delete --ignore-not-found=$(ignore-not-found) -f -
152158

153159
##@ Dependencies

config/manager/kustomization.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ resources:
55
images:
66
- name: controller
77
newName: ghcr.io/kcp-dev/kcp-operator
8+
newTag: e2e

config/manager/manager.yaml

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,19 +50,15 @@ spec:
5050
# - linux
5151
securityContext:
5252
runAsNonRoot: true
53-
# TODO(user): For common cases that do not require escalating privileges
54-
# it is recommended to ensure that all your Pods/Containers are restrictive.
55-
# More info: https://kubernetes.io/docs/concepts/security/pod-security-standards/#restricted
56-
# Please uncomment the following code if your project does NOT have to work on old Kubernetes
57-
# versions < 1.19 or on vendors versions which do NOT support this field by default (i.e. Openshift < 4.11 ).
58-
# seccompProfile:
59-
# type: RuntimeDefault
53+
seccompProfile:
54+
type: RuntimeDefault
6055
containers:
6156
- command:
6257
- /manager
6358
args:
6459
- --leader-elect
6560
- --health-probe-bind-address=:8081
61+
- --zap-time-encoding=iso8601
6662
image: controller:latest
6763
name: manager
6864
securityContext:

docs/content/contributing/local-setup.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,19 +58,20 @@ run the operator as a binary.
5858
Build the image:
5959

6060
```sh
61-
make docker-build IMG=ghcr.io/kcp-dev/kcp-operator:1
61+
export IMG=ghcr.io/kcp-dev/kcp-operator:local
62+
make docker-build
6263
```
6364

6465
Load the image into the kind cluster:
6566

6667
```sh
67-
kind load docker-image ghcr.io/kcp-dev/kcp-operator:1
68+
kind load docker-image "$IMG"
6869
```
6970

7071
Deploy the operator manifests into the cluster:
7172

7273
```sh
73-
make deploy IMG=ghcr.io/kcp-dev/kcp-operator:1
74+
make deploy
7475
```
7576

7677
### Option 2: Run Operator Directly
@@ -87,12 +88,12 @@ Then start the operator via `go run`:
8788
go run ./cmd/main.go
8889
```
8990

90-
## Create kcp Instance
91+
## Create kcp Instance
9192

9293
Now you can create a root shard:
9394

9495
```sh
95-
kubectl apply -f config/samples/operator.kcp.io_v1alpha1_rootshard.yaml
96+
kubectl apply -f config/samples/operator.kcp.io_v1alpha1_rootshard.yaml
9697
```
9798

9899
Create the additional shard:

hack/run-e2e-tests.sh

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
set -euo pipefail
1818

19-
KIND_CLUSTER_NAME="${KIND_CLUSTER_NAME:-e2e}"
19+
export KIND_CLUSTER_NAME="${KIND_CLUSTER_NAME:-e2e}"
2020
DATA_DIR=".e2e-$KIND_CLUSTER_NAME"
2121
OPERATOR_PID=0
2222
PROTOKOL_PID=0
@@ -35,12 +35,6 @@ kind create cluster --name "$KIND_CLUSTER_NAME"
3535
chmod 600 "$KUBECONFIG"
3636

3737
teardown_kind() {
38-
if [[ $OPERATOR_PID -gt 0 ]]; then
39-
echo "Stopping kcp-operator…"
40-
kill -TERM $OPERATOR_PID
41-
wait $OPERATOR_PID
42-
fi
43-
4438
if [[ $PROTOKOL_PID -gt 0 ]]; then
4539
echo "Stopping protokol…"
4640
kill -TERM $PROTOKOL_PID
@@ -60,7 +54,7 @@ echo "Kubeconfig is in $KUBECONFIG."
6054

6155
# deploying operator CRDs
6256
echo "Deploying operator CRDs…"
63-
kubectl apply --kustomize config/crd
57+
make --no-print-directory install
6458

6559
# deploying cert-manager
6660
echo "Deploying cert-manager…"
@@ -79,16 +73,10 @@ _tools/helm upgrade \
7973

8074
kubectl apply --filename hack/ci/testdata/clusterissuer.yaml
8175

82-
# start the operator locally
83-
echo "Starting kcp-operator…"
84-
_build/manager \
85-
-kubeconfig "$KUBECONFIG" \
86-
-zap-log-level debug \
87-
-zap-encoder console \
88-
-zap-time-encoding iso8601 \
89-
>"$DATA_DIR/kcp-operator.log" 2>&1 &
90-
OPERATOR_PID=$!
91-
echo "Running as process $OPERATOR_PID."
76+
# build operator image and deploy it into kind
77+
echo "Building and deploying kcp-operator…"
78+
export IMG="ghcr.io/kcp-dev/kcp-operator:e2e"
79+
make --no-print-directory docker-build kind-load deploy
9280

9381
if command -v protokol &> /dev/null; then
9482
protokol --namespace 'e2e-*' --output "$DATA_DIR/kind-logs" 2>/dev/null &

0 commit comments

Comments
 (0)