This repository has been archived by the owner on Nov 16, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 280
/
Makefile
203 lines (176 loc) · 8.96 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
# Other contants
NAMESPACE=keycloak
PROJECT=keycloak-operator
PKG=github.com/keycloak/keycloak-operator
OPERATOR_SDK_VERSION=v0.18.2
OPERATOR_SDK_DOWNLOAD_URL=https://github.com/operator-framework/operator-sdk/releases/download/$(OPERATOR_SDK_VERSION)/operator-sdk-$(OPERATOR_SDK_VERSION)-x86_64-linux-gnu
MINIKUBE_DOWNLOAD_URL=https://github.com/kubernetes/minikube/releases/download/v1.9.2/minikube-linux-amd64
KUBECTL_DOWNLOAD_URL=https://storage.googleapis.com/kubernetes-release/release/v1.18.0/bin/linux/amd64/kubectl
# Compile constants
COMPILE_TARGET=./tmp/_output/bin/$(PROJECT)
GOOS=${GOOS:-${GOHOSTOS}}
GOARCH=${GOACH:-${GOHOSTARCH}}
CGO_ENABLED=0
##############################
# Operator Management #
##############################
.PHONY: cluster/prepare
cluster/prepare:
@kubectl apply -f deploy/crds/ || true
@kubectl create namespace $(NAMESPACE) || true
@which oc 2>/dev/null ; if [ $$? -eq 0 ]; then \
oc project $(NAMESPACE) || true; \
fi
@kubectl apply -f deploy/role.yaml -n $(NAMESPACE) || true
@kubectl apply -f deploy/role_binding.yaml -n $(NAMESPACE) || true
@kubectl apply -f deploy/service_account.yaml -n $(NAMESPACE) || true
.PHONY: cluster/clean
cluster/clean:
@kubectl get all -n $(NAMESPACE) --no-headers=true -o name | xargs kubectl delete -n $(NAMESPACE) || true
@kubectl get roles,rolebindings,serviceaccounts keycloak-operator -n $(NAMESPACE) --no-headers=true -o name | xargs kubectl delete -n $(NAMESPACE) || true
@kubectl get pv,pvc -n $(NAMESPACE) --no-headers=true -o name | xargs kubectl delete -n $(NAMESPACE) || true
# Remove all CRDS with keycloak.org in the name
@kubectl get crd --no-headers=true -o name | awk '/keycloak.org/{print $1}' | xargs kubectl delete || true
@kubectl delete namespace $(NAMESPACE) || true
.PHONY: cluster/clean/monitoring
cluster/clean/monitoring:
@kubectl delete -n $(NAMESPACE) --all blackboxtargets
@kubectl delete -n $(NAMESPACE) --all grafanadashboards
@kubectl delete -n $(NAMESPACE) --all grafanadatasources
@kubectl delete -n $(NAMESPACE) --all applicationmonitorings
@kubectl delete crd grafanas.integreatly.org
@kubectl delete crd grafanadashboards.integreatly.org
@kubectl delete crd grafanadatasources.integreatly.org
@kubectl delete crd blackboxtargets.applicationmonitoring.integreatly.org
@kubectl delete crd applicationmonitorings.applicationmonitoring.integreatly.org
@kubectl delete namespace application-monitoring
.PHONY: cluster/prepare/monitoring
cluster/prepare/monitoring:
$(eval _OS_PROMETHEUS_USER=$(shell oc get secrets -n openshift-monitoring grafana-datasources -o 'go-template={{index .data "prometheus.yaml"}}' | base64 --decode | jq -r '.datasources[0].basicAuthUser'))
$(eval _OS_PROMETHEUS_PASS=$(shell oc get secrets -n openshift-monitoring grafana-datasources -o 'go-template={{index .data "prometheus.yaml"}}' | base64 --decode | jq -r '.datasources[0].basicAuthPassword'))
kubectl label namespace $(NAMESPACE) monitoring-key=middleware || true
git clone --depth=1 [email protected]:integr8ly/application-monitoring-operator.git /tmp/keycloak-operator || true
$(MAKE) -C /tmp/keycloak-operator cluster/install
cat ./deploy/examples/monitoring/federation.yaml | sed -e 's/<user>/'"$(_OS_PROMETHEUS_USER)"'/g' | \
sed -e 's@<pass>@'"$(_OS_PROMETHEUS_PASS)"'@g' > /tmp/keycloak-operator/integreatly-additional.yaml || true
kubectl create secret generic integreatly-additional-scrape-configs --from-file=/tmp/keycloak-operator/integreatly-additional.yaml --dry-run=client -o yaml | kubectl apply -n application-monitoring -f -
rm -rf /tmp/keycloak-operator/
.PHONY: cluster/create/examples
cluster/create/examples:
@kubectl create -f deploy/examples/keycloak/keycloak.yaml -n $(NAMESPACE)
@kubectl create -f deploy/examples/realm/basic_realm.yaml -n $(NAMESPACE)
##############################
# Tests #
##############################
.PHONY: test/unit
test/unit:
@echo Running tests:
@go test -v -tags=unit -coverpkg ./... -coverprofile cover-unit.coverprofile -covermode=count -mod=vendor ./pkg/...
.PHONY: test/e2e
test/e2e: setup/operator-sdk
@echo Running e2e local tests:
operator-sdk test local --go-test-flags "-tags=integration -coverpkg ./... -coverprofile cover-e2e.coverprofile -covermode=count -timeout 0" --operator-namespace $(NAMESPACE) --up-local --debug --verbose ./test/e2e
.PHONY: test/e2e-latest-image
test/e2e-latest-image:
@echo Running the latest operator image in the cluster:
# Doesn't need cluster/prepare as it's done by operator-sdk. Uses a randomly generated namespace (instead of keycloak namespace) to support parallel test runs.
operator-sdk run local ./test/e2e --go-test-flags "-tags=integration -coverpkg ./... -coverprofile cover-e2e.coverprofile -covermode=count" --debug --verbose
.PHONY: test/ibm-validation
test/ibm-validation:
@echo Running the operator image in the cluster
operator-sdk test local ./test/e2e --go-test-flags "-tags=integration -coverpkg ./... -coverprofile cover-e2e.coverprofile -covermode=count -timeout 0" --operator-namespace $(NAMESPACE) --debug --verbose --global-manifest=deploy/empty-init.yaml --namespaced-manifest=deploy/operator.yaml
.PHONY: test/e2e-local-image cluster/prepare setup/operator-sdk
test/e2e-local-image: cluster/prepare setup/operator-sdk
@echo Running e2e tests with a fresh built operator image in the cluster:
docker build . -t keycloak-operator:test
@echo Running tests:
operator-sdk test local --go-test-flags "-tags=integration -coverpkg ./... -coverprofile cover-e2e.coverprofile -covermode=count -timeout 0" --image="keycloak-operator:test" --namespace $(NAMESPACE) --up-local --debug --verbose ./test/e2e
.PHONY: test/coverage/prepare
test/coverage/prepare:
@echo Preparing coverage file:
@echo "mode: count" > cover-all.coverprofile
@echo "mode: count" > cover-e2e.coverprofile
@tail -n +2 cover-unit.coverprofile >> cover-all.coverprofile
@tail -n +2 cover-e2e.coverprofile >> cover-all.coverprofile
@echo Running test coverage generation:
@which cover 2>/dev/null ; if [ $$? -eq 1 ]; then \
go get golang.org/x/tools/cmd/cover; \
fi
@go tool cover -html=cover-all.coverprofile -o cover.html
.PHONY: test/coverage
test/coverage: test/coverage/prepare
@go tool cover -html=cover-all.coverprofile -o cover.html
##############################
# Local Development #
##############################
.PHONY: setup
setup: setup/mod setup/githooks code/gen
.PHONY: setup/githooks
setup/githooks:
@echo Setting up Git hooks:
ln -sf $$PWD/.githooks/* $$PWD/.git/hooks/
.PHONY: setup/mod
setup/mod:
@echo Adding vendor directory
go mod vendor
@echo setup complete
.PHONY: setup/mod/verify
setup/mod/verify:
go mod verify
.PHONY: setup/operator-sdk
setup/operator-sdk:
@echo Installing Operator SDK
@curl -Lo operator-sdk ${OPERATOR_SDK_DOWNLOAD_URL} && chmod +x operator-sdk && sudo mv operator-sdk /usr/local/bin/
.PHONY: setup/linter
setup/linter:
@echo Installing Linter
@curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(shell go env GOPATH)/bin v1.26.0
.PHONY: code/run
code/run:
@operator-sdk run local --watch-namespace=${NAMESPACE}
.PHONY: code/compile
code/compile:
@GOOS=${GOOS} GOARCH=${GOARCH} CGO_ENABLED=${CGO_ENABLED} go build -o=$(COMPILE_TARGET) -mod=vendor ./cmd/manager
.PHONY: code/gen
code/gen:
operator-sdk generate k8s
operator-sdk generate crds --crd-version v1beta1
# This is a copy-paste part of `operator-sdk generate openapi` command (suggested by the manual)
which ./bin/openapi-gen > /dev/null || go build -o ./bin/openapi-gen k8s.io/kube-openapi/cmd/openapi-gen
./bin/openapi-gen --logtostderr=true -o "" -i ./pkg/apis/keycloak/v1alpha1 -O zz_generated.openapi -p ./pkg/apis/keycloak/v1alpha1 -h ./hack/boilerplate.go.txt -r "-"
.PHONY: code/check
code/check:
@echo go fmt
go fmt $$(go list ./... | grep -v /vendor/)
.PHONY: code/fix
code/fix:
# goimport = gofmt + optimize imports
@which goimports 2>/dev/null ; if [ $$? -eq 1 ]; then \
go get golang.org/x/tools/cmd/goimports; \
fi
@goimports -w `find . -type f -name '*.go' -not -path "./vendor/*"`
.PHONY: code/lint
code/lint:
@echo "--> Running golangci-lint"
@$(shell go env GOPATH)/bin/golangci-lint run --timeout 10m
##############################
# CI #
##############################
.PHONY: setup/github
setup/github:
@echo Installing Kubectl
@curl -Lo kubectl ${KUBECTL_DOWNLOAD_URL} && chmod +x kubectl && sudo mv kubectl /usr/local/bin/
@echo Installing Minikube
@curl -Lo minikube ${MINIKUBE_DOWNLOAD_URL} && chmod +x minikube && sudo mv minikube /usr/local/bin/
@echo Booting Minikube up, see Travis env. variables for more information
@mkdir -p $HOME/.kube $HOME/.minikube
@touch $KUBECONFIG
@sudo minikube start --vm-driver=none
@sudo ./hack/modify_etc_hosts.sh "keycloak.local"
@sudo minikube addons enable ingress
.PHONY: test/goveralls
test/goveralls: test/coverage/prepare
@echo "Preparing goveralls file"
go get -u github.com/mattn/goveralls
@echo "Running goveralls"
@goveralls -v -coverprofile=cover-all.coverprofile -service=github