Skip to content

Commit 17ac016

Browse files
authored
chore: adapt Makefile for local dev deployment + introduce report logs for e2e-tests (#359)
Signed-off-by: odubajDT <[email protected]>
1 parent 5fcf637 commit 17ac016

File tree

5 files changed

+88
-10
lines changed

5 files changed

+88
-10
lines changed

.github/scripts/create-reports.sh

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#!/bin/bash
2+
3+
ignore="--ignore-not-found"
4+
logsDir="logs"
5+
6+
createResourceReport () {
7+
path=$1
8+
namespace=$2
9+
resource=$3
10+
withLogs=$4
11+
12+
mkdir -p "$path/$resource"
13+
14+
kubectl get "$resource" -n "$namespace" "$ignore" > "$path/$resource/list-$resource.txt"
15+
16+
for r in $(kubectl get "$resource" -n "$namespace" "$ignore" -o jsonpath='{.items[*].metadata.name}'); do
17+
kubectl describe "$resource/$r" -n "$namespace" > "$path/$resource/$r-describe.txt"
18+
19+
if $withLogs ; then
20+
kubectl logs "$resource/$r" --all-containers=true -n "$namespace" > "$path/$resource/$r-logs.txt"
21+
fi
22+
done
23+
}
24+
25+
# Go through each namespace in the cluster
26+
for namespace in $(kubectl get namespaces -o jsonpath='{.items[*].metadata.name}'); do
27+
28+
mkdir -p "$logsDir/$namespace"
29+
createResourceReport "$logsDir/$namespace" "$namespace" "Pods" true
30+
createResourceReport "$logsDir/$namespace" "$namespace" "Deployments" false
31+
createResourceReport "$logsDir/$namespace" "$namespace" "Daemonsets" false
32+
createResourceReport "$logsDir/$namespace" "$namespace" "Statefulsets" false
33+
createResourceReport "$logsDir/$namespace" "$namespace" "Jobs" false
34+
createResourceReport "$logsDir/$namespace" "$namespace" "FeatureFlagConfiguration" false
35+
createResourceReport "$logsDir/$namespace" "$namespace" "FlagSourceConfiguration" false
36+
37+
done

.github/workflows/pr-checks.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,3 +143,14 @@ jobs:
143143
run: |
144144
IMG=open-feature-operator-local:${{ github.sha }} make deploy-operator
145145
IMG=open-feature-operator-local:${{ github.sha }} make e2e-test
146+
- name: Create reports
147+
if: always()
148+
working-directory: ./.github/scripts
149+
run: ./create-reports.sh
150+
151+
- name: Upload cluster logs
152+
if: always()
153+
uses: actions/upload-artifact@v3
154+
with:
155+
name: e2e-tests
156+
path: .github/scripts/logs

CONTRIBUTING.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,15 @@ Thanks! Issues and pull requests following these guidelines are welcome.
1818
### FeatureFlagConfiguration custom resource definition versioning
1919
Custom resource definitions support multiple versions. The kubebuilder framework exposes a system to seamlessly convert between versions (using a "hub and spoke" model) maintaining backwards compatibility. It does this by injecting conversion webhooks that call our defined convert functions. The hub version of the `FeatureFlagConfiguration` custom resource definition (the version to which all other versions are converted) is `v1alpha1`.
2020
Follow [this tutorial](https://book.kubebuilder.io/multiversion-tutorial/conversion-concepts.html) to implement a new version of the custom resource definition.
21+
22+
### Local build
23+
The operator can be build and deployed to your cluster by using a single command:
24+
25+
```
26+
make build-deploy-operator TAG=myTag RELEASE_REGISTRY=docker.io/user1 RELEASE_NAME=myImgName
27+
```
28+
29+
Which will result in building the operator image `docker.io/user1/myImgName:myTag`, uploading it to your image registry
30+
and deploying to your cluster. Please be aware that it is using the cluster your current kube-context is pointing to.
31+
32+
**Note:** All bash variables are optional, the default values are set and will result in an image `ghcr.io/openfeature/operator:latest`

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Build the manager binary
2-
FROM --platform=$BUILDPLATFORM golang:1.19-alpine AS builder
2+
FROM --platform=$BUILDPLATFORM golang:1.20.1-alpine3.16 AS builder
33

44
WORKDIR /workspace
55
ARG TARGETOS

Makefile

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1-
2-
# Image URL to use all building/pushing image targets
3-
IMG ?= controller:latest
1+
RELEASE_REGISTRY?=ghcr.io/openfeature
2+
TAG?=latest
3+
RELEASE_NAME?=operator
4+
RELEASE_IMAGE?=$(RELEASE_NAME):$(TAG)
5+
ARCH?=amd64
6+
IMG?=$(RELEASE_REGISTRY)/$(RELEASE_IMAGE)
47
# customize overlay to be used in the build, DEFAULT or HELM
58
KUSTOMIZE_OVERLAY ?= DEFAULT
69
# ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary.
@@ -89,12 +92,20 @@ run: manifests generate fmt vet ## Run a controller from your host.
8992
go run ./main.go
9093

9194
.PHONY: docker-build
92-
docker-build: update-flagd ## Build docker image with the manager.
93-
docker buildx build --platform="linux/amd64,linux/arm64" -t ${IMG} . --push
95+
docker-build: update-flagd clean ## Build docker image with the manager.
96+
DOCKER_BUILDKIT=1 docker build \
97+
-t $(IMG)-$(ARCH) \
98+
--platform linux/$(ARCH) \
99+
.
100+
docker tag $(IMG)-$(ARCH) $(IMG)
94101

95102
.PHONY: docker-push
96103
docker-push: ## Push docker image with the manager.
97-
docker push ${IMG}
104+
docker push $(IMG)
105+
106+
.PHONY: clean
107+
clean:
108+
rm -rf ./bin
98109

99110
##@ Deployment
100111

@@ -112,7 +123,7 @@ uninstall: manifests kustomize ## Uninstall CRDs from the K8s cluster specified
112123

113124
.PHONY: release-manifests
114125
release-manifests: manifests kustomize
115-
cd config/manager && $(KUSTOMIZE) edit set image controller=${IMG}
126+
cd config/manager && $(KUSTOMIZE) edit set image controller=$(IMG)
116127
mkdir -p config/rendered/
117128
@if [ ${KUSTOMIZE_OVERLAY} = DEFAULT ]; then\
118129
echo building default overlay;\
@@ -125,20 +136,27 @@ release-manifests: manifests kustomize
125136

126137
.PHONY: deploy
127138
deploy: generate manifests kustomize ## Deploy controller to the K8s cluster specified in ~/.kube/config.
128-
cd config/manager && $(KUSTOMIZE) edit set image controller=${IMG}
139+
cd config/manager && $(KUSTOMIZE) edit set image controller=$(IMG)
129140
$(KUSTOMIZE) build config/default | kubectl apply -f -
130141

131142
.PHONY: undeploy
132143
undeploy: generate ## Undeploy controller from the K8s cluster specified in ~/.kube/config. Call with ignore-not-found=true to ignore resource not found errors during deletion.
133144
$(KUSTOMIZE) build config/default | kubectl delete --ignore-not-found=$(ignore-not-found) -f -
134145

146+
.PHONY: deploy-operator
135147
deploy-operator:
136148
kubectl create ns 'open-feature-operator-system' --dry-run=client -o yaml | kubectl apply -f -
137-
kubectl apply -f https://github.com/cert-manager/cert-manager/releases/download/v1.9.1/cert-manager.yaml
149+
kubectl apply -f https://github.com/cert-manager/cert-manager/releases/download/v1.11.0/cert-manager.yaml
138150
kubectl wait --for=condition=Available=True deploy --all -n 'cert-manager'
139151
make deploy
140152
kubectl wait --for=condition=Available=True deploy --all -n 'open-feature-operator-system'
141153

154+
.PHONY: build-deploy-operator
155+
build-deploy-operator:
156+
make docker-build
157+
make docker-push
158+
make deploy-operator
159+
142160
deploy-demo:
143161
kubectl apply -f https://raw.githubusercontent.com/open-feature/playground/main/config/k8s/end-to-end.yaml
144162
kubectl wait -l app=open-feature-demo --for=condition=Available=True deploy

0 commit comments

Comments
 (0)