-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathMakefile
More file actions
196 lines (161 loc) · 6.05 KB
/
Copy pathMakefile
File metadata and controls
196 lines (161 loc) · 6.05 KB
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
# Copyright 2018 The Kubernetes Authors.
#
# 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.
#
# Docker env
DOCKERFILES := $(shell find . -name '*Dockerfile*')
LINTER_VERSION := v1.17.5
BUILD_ENV := "buildenv/cloud-provider-osc:0.0"
BUILD_ENV_RUN := "build-cloud-provider-osc"
DEPLOY_NAME := "k8s-osc-ccm"
SOURCES := $(shell find ./ccm -name '*.go')
GOOS ?= $(shell go env GOOS)
VERSION ?= $(shell git describe --tags --always --dirty)
LDFLAGS := "-w -s -X 'github.com/outscale/cloud-provider-osc/ccm/utils.version=$(VERSION)'"
ARTIFACTS ?= ./single_az_test_e2e_report
GINGKO_VERSION ?= v2.23.4
GOPATH ?= $(shell go env GOPATH)
# Full log with -v -x
#GO_ADD_OPTIONS := -v -x
IMAGE = "outscale/cloud-provider-osc"
IMAGE_TAG = "${VERSION}"
export GO111MODULE=on
#GOPATH=$(PWD)
E2E_ENV_RUN := "e2e-cloud-provider"
E2E_ENV := "build-e2e-cloud-provider"
E2E_FOCUS ?= e2e
OSC_REGION ?= eu-west-2
TRIVY_IMAGE := aquasec/trivy:0.69.3
.PHONY: help
help:
@echo "help:"
@echo " - build : build binary"
@echo " - build-image : build Docker image"
@echo " - dockerlint : check Dockerfile"
@echo " - verify : check code"
@echo " - test : run all tests"
@echo " - test-e2e : run e2e tests"
@echo " - trivy-scan : run CVE check on Docker images"
@echo " - helm-docs : generate helm doc"
.PHONY: build
build: build-ccm build-labeler
.PHONY: build-ccm
build-ccm: $(SOURCES)
CGO_ENABLED=0 GOOS=$(GOOS) go build $(GO_ADD_OPTIONS) \
-ldflags $(LDFLAGS) \
-o osc-cloud-controller-manager \
cmd/osc-cloud-controller-manager/*.go
.PHONY: build-labeler
build-labeler: $(SOURCES)
CGO_ENABLED=0 GOOS=$(GOOS) go build $(GO_ADD_OPTIONS) \
-ldflags $(LDFLAGS) \
-o osc-labeler \
cmd/osc-labeler/*.go
.PHONY: verify
verify: verify-fmt vet
.PHONY: verify-fmt
verify-fmt:
./hack/verify-gofmt.sh
.PHONY: vet
vet:
go vet ./...
.PHONY: mock-generate
mock-generate:
./hack/update-gomock
.PHONY: test
test:
CGO_ENABLED=0 OSC_ACCESS_KEY=test OSC_SECRET_KEY=test go test -count=1 -v ./ccm/... ./deploy/...
.PHONY: build-image
build-image:
docker build --build-arg VERSION=$(VERSION) -t $(IMAGE):$(IMAGE_TAG) .
.PHONY: buildx-image
buildx-image:
docker buildx build --build-arg VERSION=$(VERSION) --load -t $(IMAGE):$(IMAGE_TAG) .
.PHONY: dockerlint
dockerlint:
@echo "Lint images => $(DOCKERFILES)"
$(foreach image,$(DOCKERFILES), echo "Lint ${image} " ; docker run --rm -i hadolint/hadolint:${LINTER_VERSION} hadolint --ignore DL3006 - < ${image} || exit 1 ; )
.PHONY: lint-reuse
lint-reuse:
docker run --rm --volume $(PWD):/data fsfe/reuse:5.1 lint
.PHONY: test-e2e
test-e2e:
@echo "e2e-test"
docker buildx build --load -t $(E2E_ENV):latest -f ./tests/e2e/docker/Dockerfile_e2eTest .
docker run --rm \
-v ${PWD}:/go/src/cloud-provider-osc \
-e AWS_ACCESS_KEY_ID=${OSC_ACCESS_KEY} \
-e AWS_SECRET_ACCESS_KEY=${OSC_SECRET_KEY} \
-e AWS_DEFAULT_REGION=${OSC_REGION} \
-e AWS_AVAILABILITY_ZONES="${OSC_REGION}a" \
-e KC="$${KC}" \
--name $(E2E_ENV_RUN) $(E2E_ENV):latest tests/e2e/docker/run_e2e_single_az.sh
.PHONY: e2etest
e2etest:
mkdir -p ${ARTIFACTS}
go test -v -coverprofile=covers.out ./tests/e2e -test.timeout 180m -ginkgo.timeout 180m -ginkgo.v -ginkgo.show-node-events -ginkgo.focus="${E2E_FOCUS}" -test.v
.PHONY: trivy-scan
trivy-scan:
docker pull $(TRIVY_IMAGE)
docker run --rm \
-v /var/run/docker.sock:/var/run/docker.sock \
-v ${PWD}/.trivyignore:/root/.trivyignore \
-v ${PWD}/.trivyscan/:/root/.trivyscan \
$(TRIVY_IMAGE) \
image \
--exit-code 1 \
--severity="HIGH,CRITICAL" \
--ignorefile /root/.trivyignore \
--security-checks vuln \
$(IMAGE):$(IMAGE_TAG)
# --format sarif -o /root/.trivyscan/report.sarif \
REGISTRY_IMAGE ?= $(IMAGE)
REGISTRY_TAG ?= $(IMAGE_TAG)
image-tag:
docker tag $(IMAGE):$(IMAGE_TAG) $(REGISTRY_IMAGE):$(REGISTRY_TAG)
image-push:
docker push $(REGISTRY_IMAGE):$(REGISTRY_TAG)
TARGET_IMAGE ?= $(IMAGE)
TARGET_TAG ?= $(IMAGE_TAG)
helm_deploy:
helm upgrade \
--install \
--wait \
--wait-for-jobs k8s-osc-ccm \
--set oscSecretName=osc-secret \
--set image.repository=$(TARGET_IMAGE) \
--set image.tag=$(TARGET_TAG) \
--set image.pullPolicy=Always \
deploy/k8s-osc-ccm
kubectl rollout restart ds/osc-cloud-controller-manager -n kube-system
kubectl rollout status ds/osc-cloud-controller-manager -n kube-system --timeout=30s
kubectl taint nodes --all node.cloudprovider.kubernetes.io/uninitialized=true:NoSchedule
helm-docs:
docker run --rm --volume "$$(pwd):/helm-docs" -u "$$(id -u)" jnorwood/helm-docs:v1.11.0 --output-file ../../docs/helm.md
check-helm-docs:
./hack/verify-helm-docs
helm-manifest:
@helm template test ./deploy/k8s-osc-ccm/ --set image.tag=v1.32.7 > deploy/osc-ccm-manifest-v1.32.yml
@helm template test ./deploy/k8s-osc-ccm/ --set image.tag=v1.33.7 > deploy/osc-ccm-manifest-v1.33.yml
@helm template test ./deploy/k8s-osc-ccm/ --set image.tag=v1.34.7 > deploy/osc-ccm-manifest-v1.34.yml
@helm template test ./deploy/k8s-osc-ccm/ --set image.tag=v1.35.7 > deploy/osc-ccm-manifest-v1.35.yml
@helm template test ./deploy/k8s-osc-ccm/ --set image.tag=v1.36.7 > deploy/osc-ccm-manifest-v1.36.yml
check-helm-manifest:
./hack/verify-helm-manifest.sh
helm-package:
# Copy docs into the archive for ArtfactHub, symlink does not work with helm-git
cp docs/CHANGELOG.md docs/README.md LICENSE deploy/k8s-osc-ccm/
helm package deploy/k8s-osc-ccm -d out-helm
rm deploy/k8s-osc-ccm/CHANGELOG.md deploy/k8s-osc-ccm/README.md deploy/k8s-osc-ccm/LICENSE
helm-push: helm-package
helm push out-helm/*.tgz oci://registry-1.docker.io/${DOCKER_USER}