Skip to content

Commit 572842d

Browse files
authored
replace kustomize with helm (#587)
1 parent ea6cb27 commit 572842d

38 files changed

+575
-552
lines changed

BUILD.md

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,31 @@
1-
TBD
1+
# Setup Development Environment
2+
3+
Clone the repo:
4+
5+
```sh
6+
git clone --branch v2 https://github.com/aws/aws-node-termination-handler.git
7+
```
8+
9+
Install build tools
10+
11+
```sh
12+
make toolchain
13+
```
14+
15+
Configure image repository location
16+
17+
```sh
18+
export KO_DOCKER_REPO=my.image.repo/path
19+
```
20+
21+
Build and deploy controller to Kubernetes cluster
22+
23+
```sh
24+
make apply
25+
```
26+
27+
Remove deployed controller from Kubernetes cluster
28+
29+
```sh
30+
make delete
31+
```

src/Makefile

Lines changed: 22 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
PROJECT_DIR := $(shell dirname $(abspath $(lastword $(MAKEFILE_LIST))))
2+
CONTROLLER_GEN = $(PROJECT_DIR)/bin/controller-gen
3+
KO = $(PROJECT_DIR)/bin/ko
4+
ENVTEST = $(PROJECT_DIR)/bin/setup-envtest
5+
16

27
# Image URL to use all building/pushing image targets
38
IMG ?= controller:latest
@@ -17,9 +22,6 @@ endif
1722
SHELL = /usr/bin/env bash -o pipefail
1823
.SHELLFLAGS = -ec
1924

20-
.PHONY: all
21-
all: build
22-
2325
##@ General
2426

2527
# The help target prints out all targets with their descriptions organized
@@ -37,22 +39,23 @@ all: build
3739
help: ## Display this help.
3840
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z_0-9-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)
3941

42+
.PHONY: toolchain
43+
toolchain: ## Download additional tools.
44+
@./scripts/toolchain.sh -d "$(PROJECT_DIR)/bin"
45+
4046
##@ Development
4147

4248
.PHONY: manifests
43-
manifests: controller-gen ## Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects.
49+
manifests: ## Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects.
4450
$(CONTROLLER_GEN) rbac:roleName=manager-role crd webhook paths="./..." output:crd:artifacts:config=config/crd/bases
4551

4652
.PHONY: generate
47-
generate: controller-gen ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.
53+
generate: ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.
4854
$(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./..."
4955

50-
.PHONY: fmt
51-
fmt: ## Run go fmt against code.
56+
.PHONY: verify
57+
verify: ## Run go fmt and go vet against code.
5258
go fmt ./...
53-
54-
.PHONY: vet
55-
vet: ## Run go vet against code.
5659
go vet ./...
5760

5861
.PHONY: test
@@ -61,70 +64,19 @@ test: manifests generate fmt vet envtest ## Run tests.
6164

6265
##@ Build
6366

64-
.PHONY: build
65-
build: generate fmt vet ## Build manager binary.
66-
go build -o bin/manager main.go
67-
6867
.PHONY: run
6968
run: manifests generate fmt vet ## Run a controller from your host.
7069
go run ./main.go
7170

72-
.PHONY: docker-build
73-
docker-build: test ## Build docker image with the manager.
74-
docker build -t ${IMG} .
75-
76-
.PHONY: docker-push
77-
docker-push: ## Push docker image with the manager.
78-
docker push ${IMG}
79-
8071
##@ Deployment
8172

82-
ifndef ignore-not-found
83-
ignore-not-found = false
84-
endif
73+
.PHONY: apply
74+
apply: ## Deploy the controller into the current kubernetes cluster.
75+
helm upgrade --install dev charts/aws-node-termination-handler-2 --namespace nthv2 --create-namespace \
76+
$(HELM_OPTS) \
77+
--set controller.image=$(shell $(KO) publish -B github.com/aws/aws-node-termination-handler) \
78+
--set fullnameOverride=nthv2
8579

86-
.PHONY: install
87-
install: manifests kustomize ## Install CRDs into the K8s cluster specified in ~/.kube/config.
88-
$(KUSTOMIZE) build config/crd | kubectl apply -f -
89-
90-
.PHONY: uninstall
91-
uninstall: manifests kustomize ## Uninstall CRDs from the K8s cluster specified in ~/.kube/config. Call with ignore-not-found=true to ignore resource not found errors during deletion.
92-
$(KUSTOMIZE) build config/crd | kubectl delete --ignore-not-found=$(ignore-not-found) -f -
93-
94-
.PHONY: deploy
95-
deploy: manifests kustomize ## Deploy controller to the K8s cluster specified in ~/.kube/config.
96-
cd config/manager && $(KUSTOMIZE) edit set image controller=${IMG}
97-
$(KUSTOMIZE) build config/default | kubectl apply -f -
98-
99-
.PHONY: undeploy
100-
undeploy: ## Undeploy controller from the K8s cluster specified in ~/.kube/config. Call with ignore-not-found=true to ignore resource not found errors during deletion.
101-
$(KUSTOMIZE) build config/default | kubectl delete --ignore-not-found=$(ignore-not-found) -f -
102-
103-
CONTROLLER_GEN = $(shell pwd)/bin/controller-gen
104-
.PHONY: controller-gen
105-
controller-gen: ## Download controller-gen locally if necessary.
106-
$(call go-get-tool,$(CONTROLLER_GEN),sigs.k8s.io/controller-tools/cmd/[email protected])
107-
108-
KUSTOMIZE = $(shell pwd)/bin/kustomize
109-
.PHONY: kustomize
110-
kustomize: ## Download kustomize locally if necessary.
111-
$(call go-get-tool,$(KUSTOMIZE),sigs.k8s.io/kustomize/kustomize/[email protected])
112-
113-
ENVTEST = $(shell pwd)/bin/setup-envtest
114-
.PHONY: envtest
115-
envtest: ## Download envtest-setup locally if necessary.
116-
$(call go-get-tool,$(ENVTEST),sigs.k8s.io/controller-runtime/tools/setup-envtest@latest)
117-
118-
# go-get-tool will 'go get' any package $2 and install it to $1.
119-
PROJECT_DIR := $(shell dirname $(abspath $(lastword $(MAKEFILE_LIST))))
120-
define go-get-tool
121-
@[ -f $(1) ] || { \
122-
set -e ;\
123-
TMP_DIR=$$(mktemp -d) ;\
124-
cd $$TMP_DIR ;\
125-
go mod init tmp ;\
126-
echo "Downloading $(2)" ;\
127-
GOBIN=$(PROJECT_DIR)/bin go get $(2) ;\
128-
rm -rf $$TMP_DIR ;\
129-
}
130-
endef
80+
.PHONY: delete
81+
delete: ## Delete controller from current kubernetes cluster.
82+
helm uninstall dev --namespace nthv2
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
apiVersion: v2
2+
name: aws-node-termination-handler-2
3+
description: A Helm chart for aws-node-termination-handler, an open-source component for gracefully handling termination events for node hosted in AWS.
4+
type: application
5+
version: 0.1.0
6+
appVersion: "2.0.0-0.1"
7+
kubeVersion: ">=1.16-0"
8+
keywords:
9+
- aws
10+
- ec2
11+
- ec2-spot
12+
- eks
13+
- node
14+
- node-termination
15+
- spot
16+
home: https://github.com/aws/eks-charts
17+
sources:
18+
- https://github.com/aws/aws-node-termination-handler
19+
- https://github.com/aws/eks-charts
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# AWS Node Termination Handler
2+
3+
AWS Node Termination Handler Helm chart for Kubernetes. For more information on this project see the project repo at [github.com/aws/aws-node-termination-handler](https://github.com/aws/aws-node-termination-handler).
4+
5+
## Prerequisites
6+
7+
- _Kubernetes_ >= 1.16
8+
9+
## Installing the Chart
10+
11+
Before you can install the chart you will need to add the `aws` repo to [Helm](https://helm.sh/).
12+
13+
```shell
14+
helm repo add eks https://aws.github.io/eks-charts/
15+
```
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
---
2+
apiVersion: apiextensions.k8s.io/v1
3+
kind: CustomResourceDefinition
4+
metadata:
5+
annotations:
6+
controller-gen.kubebuilder.io/version: v0.8.0
7+
creationTimestamp: null
8+
name: terminators.node.k8s.aws
9+
spec:
10+
group: node.k8s.aws
11+
names:
12+
kind: Terminator
13+
listKind: TerminatorList
14+
plural: terminators
15+
singular: terminator
16+
scope: Namespaced
17+
versions:
18+
- name: v1alpha1
19+
schema:
20+
openAPIV3Schema:
21+
description: Terminator is the Schema for the terminators API
22+
properties:
23+
apiVersion:
24+
description: 'APIVersion defines the versioned schema of this representation
25+
of an object. Servers should convert recognized schemas to the latest
26+
internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources'
27+
type: string
28+
kind:
29+
description: 'Kind is a string value representing the REST resource this
30+
object represents. Servers may infer this from the endpoint the client
31+
submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds'
32+
type: string
33+
metadata:
34+
type: object
35+
spec:
36+
description: TerminatorSpec defines the desired state of Terminator
37+
properties:
38+
foo:
39+
description: Foo is an example field of Terminator. Edit terminator_types.go
40+
to remove/update
41+
type: string
42+
type: object
43+
status:
44+
description: TerminatorStatus defines the observed state of Terminator
45+
type: object
46+
type: object
47+
served: true
48+
storage: true
49+
subresources:
50+
status: {}
51+
status:
52+
acceptedNames:
53+
kind: ""
54+
plural: ""
55+
conditions: []
56+
storedVersions: []
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
{{/*
2+
Expand the name of the chart.
3+
*/}}
4+
{{- define "aws-node-termination-handler.name" -}}
5+
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" -}}
6+
{{- end -}}
7+
8+
{{/*
9+
Create a default fully qualified app name.
10+
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
11+
If release name contains chart name it will be used as a full name.
12+
*/}}
13+
{{- define "aws-node-termination-handler.fullname" -}}
14+
{{- if .Values.fullnameOverride -}}
15+
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" -}}
16+
{{- else -}}
17+
{{- $name := default .Chart.Name .Values.nameOverride -}}
18+
{{- if contains $name .Release.Name -}}
19+
{{- .Release.Name | trunc 63 | trimSuffix "-" -}}
20+
{{- else -}}
21+
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" -}}
22+
{{- end -}}
23+
{{- end -}}
24+
{{- end -}}
25+
26+
{{/*
27+
Create chart name and version as used by the chart label.
28+
*/}}
29+
{{- define "aws-node-termination-handler.chart" -}}
30+
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}}
31+
{{- end -}}
32+
33+
{{/*
34+
Common labels
35+
*/}}
36+
{{- define "aws-node-termination-handler.labels" -}}
37+
helm.sh/chart: {{ include "aws-node-termination-handler.chart" . | quote }}
38+
{{ include "aws-node-termination-handler.selectorLabels" . }}
39+
{{- if .Chart.AppVersion }}
40+
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
41+
{{- end }}
42+
app.kubernetes.io/managed-by: {{ .Release.Service | quote }}
43+
{{- with .Values.labels }}
44+
{{ toYaml . }}
45+
{{- end }}
46+
{{- end }}
47+
48+
{{/*
49+
Selector labels
50+
*/}}
51+
{{- define "aws-node-termination-handler.selectorLabels" -}}
52+
app.kubernetes.io/name: {{ include "aws-node-termination-handler.name" . | quote }}
53+
app.kubernetes.io/instance: {{ .Release.Name | quote }}
54+
{{- end }}
55+
56+
{{/*
57+
Create the name of the service account to use
58+
*/}}
59+
{{- define "aws-node-termination-handler.serviceAccountName" -}}
60+
{{- if .Values.serviceAccount.create }}
61+
{{- default (include "aws-node-termination-handler.fullname" .) .Values.serviceAccount.name }}
62+
{{- else }}
63+
{{- default "default" .Values.serviceAccount.name }}
64+
{{- end }}
65+
{{- end }}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
{{- if .Values.rbac.create -}}
2+
apiVersion: rbac.authorization.k8s.io/v1
3+
kind: ClusterRole
4+
metadata:
5+
name: {{ include "aws-node-termination-handler.fullname" . }}
6+
labels:
7+
{{- include "aws-node-termination-handler.labels" . | nindent 8 }}
8+
{{- with .Values.annotations }}
9+
annotations:
10+
{{- toYaml . | nindent 8 }}
11+
{{- end }}
12+
rules:
13+
- apiGroups: ["node.k8s.aws"]
14+
resources: ["terminators"]
15+
verbs: ["get", "list", "watch"]
16+
17+
- apiGroups: ["node.k8s.aws"]
18+
resources: ["terminators/status"]
19+
verbs: ["create", "delete", "patch", "get", "list", "watch"]
20+
21+
- apiGroups: [""]
22+
resources: ["nodes"]
23+
verbs: ["get", "list", "patch", "update"]
24+
25+
- apiGroups: [""]
26+
resources: ["pods"]
27+
verbs: ["get", "list"]
28+
29+
- apiGroups: [""]
30+
resources: ["pods/eviction"]
31+
verbs: ["create"]
32+
33+
- apiGroups: ["apps", "extensions"]
34+
resources: ["daemonsets"]
35+
verbs: ["get"]
36+
37+
- apiGroups: ["admissionregistration.k8s.io"]
38+
resources: ["validatingwebhookconfigurations", "mutatingwebhookconfigurations"]
39+
verbs: ["get", "list", "watch", "update"]
40+
41+
{{- if .Values.emitKubernetesEvents }}
42+
- apiGroups: [""]
43+
resources: ["events"]
44+
verbs: ["create", "patch"]
45+
{{- end }}
46+
{{- end -}}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{{- if .Values.rbac.create -}}
2+
apiVersion: rbac.authorization.k8s.io/v1
3+
kind: ClusterRoleBinding
4+
metadata:
5+
name: {{ include "aws-node-termination-handler.fullname" . }}
6+
labels:
7+
{{- include "aws-node-termination-handler.labels" . | nindent 8 }}
8+
{{- with .Values.annotations }}
9+
annotations:
10+
{{- toYaml . | nindent 8 }}
11+
{{- end }}
12+
roleRef:
13+
apiGroup: rbac.authorization.k8s.io
14+
kind: ClusterRole
15+
name: {{ include "aws-node-termination-handler.fullname" . }}
16+
subjects:
17+
- kind: ServiceAccount
18+
name: {{ template "aws-node-termination-handler.serviceAccountName" . }}
19+
namespace: {{ .Release.Namespace }}
20+
{{- end }}

0 commit comments

Comments
 (0)