forked from GoogleCloudPlatform/k8s-config-connector
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
160 lines (135 loc) · 7.75 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
# Copyright 2022 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
export GOFLAGS=-mod=vendor
PROJECT_ID := $(shell gcloud config get-value project)
SHORT_SHA := $(shell git rev-parse --short=7 HEAD)
BUILDER_IMG ?= gcr.io/${PROJECT_ID}/builder:${SHORT_SHA}
CONTROLLER_IMG ?= gcr.io/${PROJECT_ID}/controller:${SHORT_SHA}
RECORDER_IMG ?= gcr.io/${PROJECT_ID}/recorder:${SHORT_SHA}
WEBHOOK_IMG ?= gcr.io/${PROJECT_ID}/webhook:${SHORT_SHA}
DELETION_DEFENDER_IMG ?= gcr.io/${PROJECT_ID}/deletiondefender:${SHORT_SHA}
UNMANAGED_DETECTOR_IMG ?= gcr.io/${PROJECT_ID}/unmanageddetector:${SHORT_SHA}
# Use Docker BuildKit when building images to allow usage of 'setcap' in
# multi-stage builds (https://github.com/moby/moby/issues/38132)
DOCKER_BUILD := DOCKER_BUILDKIT=1 docker build
ifneq ($(origin KUBECONTEXT), undefined)
CONTEXT_FLAG := --context ${KUBECONTEXT}
endif
all: test manager operator config-connector
# Run tests
test: generate fmt vet manifests
make -C operator test
go test -v ./pkg/... ./cmd/... ./config/tests/... ./scripts/generate-go-crd-clients/... -coverprofile cover.out -count=1
# Build config-connector binary
config-connector: generate fmt vet
./scripts/config-connector/build.sh
# Build the operator's manager binary
operator:
make -C operator manager
# Build manager binary
manager: generate fmt vet
go build -o bin/manager github.com/GoogleCloudPlatform/k8s-config-connector/cmd/manager
# Generate manifests e.g. CRD, RBAC etc.
manifests: generate
make -C operator manifests
rm -rf config/crds/resources
rm -rf config/crds/tmp_resources
go build -o bin/generate-crds ./scripts/generate-crds && ./bin/generate-crds -output-dir=config/crds/tmp_resources
go run ./scripts/generate-cnrm-cluster-roles/main.go
# add kustomize patches on all CRDs
mkdir config/crds/resources
cp config/crds/kustomization.yaml kustomization.yaml
kustomize edit add resource config/crds/tmp_resources/*.yaml
kustomize build -o config/crds/resources
rm -rf config/crds/tmp_resources
rm kustomization.yaml
# Format code
fmt:
make -C operator fmt
goimports -w pkg cmd scripts config/tests
# 04bfe4ee9ca5764577b029acc6a1957fd1997153 includes fix to not log "Skipped" for each skipped file
GOFLAGS= go run github.com/google/addlicense@04bfe4ee9ca5764577b029acc6a1957fd1997153 -c "Google LLC" -l apache \
-ignore "vendor/**" -ignore "third_party/**" \
-ignore "config/crds/**" -ignore "config/cloudcodesnippets/**" \
-ignore "**/*.html" -ignore "config/installbundle/components/clusterroles/cnrm_admin.yaml" \
-ignore "config/installbundle/components/clusterroles/cnrm_viewer.yaml" \
-ignore "operator/channels/**" \
-ignore "operator/config/crd/bases/**" \
-ignore "operator/config/gke-addon/image_configmap.yaml" \
-ignore "operator/config/rbac/cnrm_viewer_role.yaml" \
-ignore "operator/vendor/**" \
-ignore "**/testdata/**" \
./
lint:
for f in `find pkg cmd -name "*.go"`; do golint -set_exit_status $$f || exit $?; done
# Run go vet against code
vet:
make -C operator vet
go vet -tags integration ./pkg/... ./cmd/... ./config/tests/...
# Generate code
generate:
# Don't run go generate on `pkg/clients/generated` in the normal development flow due to high latency.
# This path will be covered by `generate-go-client` target specifically.
go generate $$(go list ./pkg/... ./cmd/... ./scripts/resource-autogen/... | grep -v ./pkg/clients/generated)
make fmt
# Build the docker images
docker-build: docker-build-manager docker-build-recorder docker-build-webhook docker-build-deletiondefender docker-build-unmanageddetector
# build all the binaries into the builder docker image
docker-build-builder:
$(DOCKER_BUILD) . -f build/builder/Dockerfile -t ${BUILDER_IMG}
# Build the manager docker image
docker-build-manager: docker-build-builder
$(DOCKER_BUILD) -t ${CONTROLLER_IMG} --build-arg BUILDER_IMG=${BUILDER_IMG} - < build/manager/Dockerfile
@echo "updating kustomize image patch file for manager resource"
cp config/installbundle/components/manager/base/manager_image_patch_template.yaml config/installbundle/components/manager/base/manager_image_patch.yaml
sed -i'' -e 's@image: .*@image: '"${CONTROLLER_IMG}"'@' ./config/installbundle/components/manager/base/manager_image_patch.yaml
# Build the recorder docker image
docker-build-recorder: docker-build-builder
$(DOCKER_BUILD) -t ${RECORDER_IMG} --build-arg BUILDER_IMG=${BUILDER_IMG} - < build/recorder/Dockerfile
@echo "updating kustomize image patch file for recorder resource"
cp config/installbundle/components/recorder/recorder_image_patch_template.yaml config/installbundle/components/recorder/recorder_image_patch.yaml
sed -i'' -e 's@image: .*@image: '"${RECORDER_IMG}"'@' ./config/installbundle/components/recorder/recorder_image_patch.yaml
# Build the webhook docker image
docker-build-webhook: docker-build-builder
$(DOCKER_BUILD) -t ${WEBHOOK_IMG} --build-arg BUILDER_IMG=${BUILDER_IMG} - < build/webhook/Dockerfile
@echo "updating kustomize image patch file for webhook resource"
cp config/installbundle/components/webhook/webhook_image_patch_template.yaml config/installbundle/components/webhook/webhook_image_patch.yaml
sed -i'' -e 's@image: .*@image: '"${WEBHOOK_IMG}"'@' ./config/installbundle/components/webhook/webhook_image_patch.yaml
docker-build-deletiondefender: docker-build-builder
$(DOCKER_BUILD) -t ${DELETION_DEFENDER_IMG} --build-arg BUILDER_IMG=${BUILDER_IMG} - < build/deletiondefender/Dockerfile
@echo "updating kustomize image patch file for deletion defender resource"
cp config/installbundle/components/deletiondefender/deletiondefender_image_patch_template.yaml config/installbundle/components/deletiondefender/deletiondefender_image_patch.yaml
sed -i'' -e 's@image: .*@image: '"${DELETION_DEFENDER_IMG}"'@' ./config/installbundle/components/deletiondefender/deletiondefender_image_patch.yaml
docker-build-unmanageddetector: docker-build-builder
$(DOCKER_BUILD) -t ${UNMANAGED_DETECTOR_IMG} --build-arg BUILDER_IMG=${BUILDER_IMG} - < build/unmanageddetector/Dockerfile
@echo "updating kustomize image patch file for unmanaged detector resource"
cp config/installbundle/components/unmanageddetector/unmanageddetector_image_patch_template.yaml config/installbundle/components/unmanageddetector/unmanageddetector_image_patch.yaml
sed -i'' -e 's@image: .*@image: '"${UNMANAGED_DETECTOR_IMG}"'@' ./config/installbundle/components/unmanageddetector/unmanageddetector_image_patch.yaml
# Push the docker image
docker-push:
docker push ${CONTROLLER_IMG}
docker push ${RECORDER_IMG}
docker push ${WEBHOOK_IMG}
docker push ${DELETION_DEFENDER_IMG}
docker push ${UNMANAGED_DETECTOR_IMG}
# Deploy controller in the configured Kubernetes cluster in ~/.kube/config
deploy: manifests install
kustomize build config/installbundle/releases/scopes/cluster/withworkloadidentity | sed -e 's/$${PROJECT_ID?}/${PROJECT_ID}/g'| kubectl apply -f - ${CONTEXT_FLAG}
# Install CRDs into a cluster
install: manifests
kubectl apply -f config/crds/resources/ ${CONTEXT_FLAG}
# Deploy controller only, this will skip CRD install in the configured K8s and usually runs much
# faster than "make deploy". It is useful if you only want to quickly apply code change in controller
deploy-controller: docker-build docker-push
kustomize build config/installbundle/releases/scopes/cluster/withworkloadidentity | sed -e 's/$${PROJECT_ID?}/${PROJECT_ID}/g'| kubectl apply -f - ${CONTEXT_FLAG}