forked from kubermatic/machine-controller
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
138 lines (111 loc) · 4.23 KB
/
Copy pathMakefile
File metadata and controls
138 lines (111 loc) · 4.23 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
# Copyright 2019 The Machine Controller 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.
GO_VERSION = 1.13.8
export CGO_ENABLED := 0
export E2E_SSH_PUBKEY ?= $(shell test -f ~/.ssh/id_rsa.pub && cat ~/.ssh/id_rsa.pub)
export DOCKER_TAG ?= $(shell git tag --points-at HEAD)
export GOFLAGS?=-mod=readonly -trimpath
REGISTRY ?= docker.io
REGISTRY_NAMESPACE ?= kubermatic
LDFLAGS ?= -ldflags '-s -w'
IMAGE_TAG = \
$(shell echo $$(git rev-parse HEAD && if [[ -n $$(git status --porcelain) ]]; then echo '-dirty'; fi)|tr -d ' ')
IMAGE_NAME = $(REGISTRY)/$(REGISTRY_NAMESPACE)/machine-controller:$(IMAGE_TAG)
OS = centos coreos ubuntu sles rhel
USERDATA_BIN = $(patsubst %, machine-controller-userdata-%, $(OS))
.PHONY: all
all: build-machine-controller webhook
.PHONY: build-machine-controller
build-machine-controller: machine-controller $(USERDATA_BIN)
machine-controller-userdata-%: cmd/userdata/% $(shell find cmd/userdata/$* pkg -name '*.go')
go build -v \
$(LDFLAGS) \
-o $@ \
github.com/kubermatic/machine-controller/cmd/userdata/$*
%: cmd/% $(shell find cmd/$* pkg -name '*.go')
go build -v \
$(LDFLAGS) \
-o $@ \
github.com/kubermatic/machine-controller/cmd/$*
.PHONY: clean
clean:
rm -f machine-controller \
webhook \
$(USERDATA_BIN)
.PHONY: lint
lint:
golangci-lint run -v
.PHONY: docker-image
docker-image:
docker build --build-arg GO_VERSION=$(GO_VERSION) -t $(IMAGE_NAME) .
.PHONY: docker-image-publish
docker-image-publish: docker-image
docker push $(IMAGE_NAME)
if [[ -n "$(GIT_TAG)" ]]; then \
$(eval IMAGE_TAG = $(GIT_TAG)) \
docker build -t $(IMAGE_NAME) . && \
docker push $(IMAGE_NAME) && \
$(eval IMAGE_TAG = latest) \
docker build -t $(IMAGE_NAME) . ;\
docker push $(IMAGE_NAME) ;\
fi
.PHONY: test-unit-docker
test-unit-docker:
@docker run --rm \
-v $$PWD:/go/src/github.com/kubermatic/machine-controller \
-v $$PWD/.buildcache:/cache \
-e GOCACHE=/cache \
-w /go/src/github.com/kubermatic/machine-controller \
golang:$(GO_VERSION) \
make test-unit GOFLAGS=$(GOFLAGS)
.PHONY: test-unit
test-unit:
@#The `-race` flag requires CGO
CGO_ENABLED=1 go test -race ./...
.PHONY: e2e-cluster
e2e-cluster: machine-controller webhook
make -C test/tools/integration apply
./test/tools/integration/provision_master.sh do-not-deploy-machine-controller
KUBECONFIG=$(shell pwd)/.kubeconfig kubectl apply -f examples/machine-controller.yaml -l local-testing="true"
.PHONY: e2e-destroy
e2e-destroy:
./test/tools/integration/cleanup_machines.sh
make -C test/tools/integration destroy
examples/ca-key.pem:
openssl genrsa -out examples/ca-key.pem 4096
examples/ca-cert.pem: examples/ca-key.pem
openssl req -x509 -new -nodes -key examples/ca-key.pem \
-subj "/C=US/ST=CA/O=Acme/CN=k8s-machine-controller-ca" \
-sha256 -days 10000 -out examples/ca-cert.pem
examples/admission-key.pem: examples/ca-cert.pem
openssl genrsa -out examples/admission-key.pem 2048
chmod 0600 examples/admission-key.pem
examples/admission-cert.pem: examples/admission-key.pem
openssl req -new -sha256 \
-key examples/admission-key.pem \
-subj "/C=US/ST=CA/O=Acme/CN=machine-controller-webhook.kube-system.svc" \
-out examples/admission.csr
openssl x509 -req -in examples/admission.csr -CA examples/ca-cert.pem \
-CAkey examples/ca-key.pem -CAcreateserial \
-out examples/admission-cert.pem -days 10000 -sha256
.PHONY: deploy
deploy: examples/admission-cert.pem
@cat examples/machine-controller.yaml \
|sed "s/__admission_ca_cert__/$(shell cat examples/ca-cert.pem|base64 -w0)/g" \
|sed "s/__admission_cert__/$(shell cat examples/admission-cert.pem|base64 -w0)/g" \
|sed "s/__admission_key__/$(shell cat examples/admission-key.pem|base64 -w0)/g" \
|kubectl apply -f -
.PHONY: check-dependencies
check-dependencies:
go mod verify