Skip to content

Commit 7786db8

Browse files
sfotonyadriananeci
andauthored
add ability to detect drifted/labeled nodes, park them (#336)
* add ability to detect drifted/labeled nodes, park them * compatible helm chart will be introduced in a subsequent PR Co-authored-by: adriananeci <[email protected]>
1 parent a415a02 commit 7786db8

34 files changed

+2330
-616
lines changed

.github/workflows/ci-chart.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ jobs:
4141
- name: Create kind cluster
4242
if: steps.list-changed.outputs.changed == 'true'
4343
uses: helm/[email protected]
44+
with:
45+
version: v0.29.0
4446

4547
- name: Run chart-testing (install)
4648
if: steps.list-changed.outputs.changed == 'true'

.github/workflows/ci.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ jobs:
2727
uses: helm/[email protected]
2828
with:
2929
install_only: true
30+
version: v0.29.0
3031
- name: Prepare test environment
3132
run: make local-test
3233
- name: Run e2e tests

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@
33
.DS_Store?
44

55
# build artifacts
6-
kubeconfig
6+
kubeconfig*
77
dist
88
k8s-shredder
9+
my-k8s-shredder-values.yaml
910

1011
# Test binary, build with `go test -c`
1112
*.test

.goreleaser.yml

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1+
version: 2
2+
13
project_name: k8s-shredder
4+
25
release:
36
github:
47
owner: adobe
@@ -26,18 +29,18 @@ builds:
2629
# all files (including the sboms) are included in the checksum, so we don't need to sign each one if we don't want to
2730
# https://goreleaser.com/customization/sign
2831
signs:
29-
- cmd: cosign
30-
env:
31-
- COSIGN_EXPERIMENTAL=1
32-
certificate: '${artifact}.pem'
33-
args:
34-
- sign-blob
35-
- '--output-certificate=${certificate}'
36-
- '--output-signature=${signature}'
37-
- '${artifact}'
38-
- "--yes" # needed on cosign 2.0.0+
39-
artifacts: checksum
40-
output: true
32+
- cmd: cosign
33+
env:
34+
- COSIGN_EXPERIMENTAL=1
35+
certificate: '${artifact}.pem'
36+
args:
37+
- sign-blob
38+
- '--output-certificate=${certificate}'
39+
- '--output-signature=${signature}'
40+
- '${artifact}'
41+
- "--yes" # needed on cosign 2.0.0+
42+
artifacts: checksum
43+
output: true
4144

4245
dockers:
4346
- image_templates: ["ghcr.io/adobe/{{ .ProjectName }}:v{{ .Version }}-amd64"]
@@ -52,7 +55,7 @@ dockers:
5255
- "--label=org.opencontainers.image.version=v{{ .Version }}"
5356
- "--label=org.opencontainers.image.created={{ .Date }}"
5457
- "--label=org.opencontainers.image.revision={{ .FullCommit }}"
55-
- "--label=org.opencontainers.image.licenses=Apache2.0"
58+
- "--label=org.opencontainers.image.licenses=Apache-2.0"
5659
- image_templates: ["ghcr.io/adobe/{{ .ProjectName }}:v{{ .Version }}-arm64v8"]
5760
use: buildx
5861
goarch: arm64
@@ -66,7 +69,7 @@ dockers:
6669
- "--label=org.opencontainers.image.version=v{{ .Version }}"
6770
- "--label=org.opencontainers.image.created={{ .Date }}"
6871
- "--label=org.opencontainers.image.revision={{ .FullCommit }}"
69-
- "--label=org.opencontainers.image.licenses=Apache2.0"
72+
- "--label=org.opencontainers.image.licenses=Apache-2.0"
7073
docker_manifests:
7174
- name_template: ghcr.io/adobe/{{.ProjectName}}:v{{.Version}}
7275
image_templates:
@@ -80,12 +83,12 @@ docker_manifests:
8083
# signs our docker image
8184
# https://goreleaser.com/customization/docker_sign
8285
docker_signs:
83-
- cmd: cosign
84-
env:
85-
- COSIGN_EXPERIMENTAL=1
86-
artifacts: images
87-
output: true
88-
args:
89-
- 'sign'
90-
- '${artifact}'
91-
- "--yes" # needed on cosign 2.0.0+
86+
- cmd: cosign
87+
env:
88+
- COSIGN_EXPERIMENTAL=1
89+
artifacts: images
90+
output: true
91+
args:
92+
- 'sign'
93+
- '${artifact}'
94+
- "--yes" # needed on cosign 2.0.0+

Makefile

Lines changed: 35 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
1-
.PHONY: default help format lint vet security build build-prereq push unit-test local-test ci clean e2e-tests check-license
1+
.PHONY: default help format lint vet security build build-prereq push unit-test local-test local-test-karpenter local-test-node-labels ci clean e2e-tests check-license
22

33
NAME ?= adobe/k8s-shredder
44
K8S_SHREDDER_VERSION ?= "dev"
5-
KINDNODE_VERSION ?= "v1.30.4"
5+
KINDNODE_VERSION ?= "v1.31.9"
66
COMMIT ?= $(shell git rev-parse --short HEAD)
77
TEST_CLUSTERNAME ?= "k8s-shredder-test-cluster"
8+
TEST_CLUSTERNAME_KARPENTER ?= "k8s-shredder-test-cluster-karpenter"
9+
TEST_CLUSTERNAME_NODE_LABELS ?= "k8s-shredder-test-cluster-node-labels"
10+
KUBECONFIG_LOCALTEST ?= "kubeconfig-localtest"
11+
KUBECONFIG_KARPENTER ?= "kubeconfig-local-test-karpenter"
12+
KUBECONFIG_NODE_LABELS ?= "kubeconfig-local-test-node-labels"
813

914
GOSEC=gosec -quiet -exclude=G107
1015

@@ -59,11 +64,31 @@ build: check-license lint vet security unit-test ## Builds the local Docker cont
5964

6065
# TEST
6166
# -----------
62-
local-test: build ## Test docker image in a kind cluster
67+
local-test: build ## Test docker image in a kind cluster (with Karpenter drift and node label detection disabled)
6368
@hash kind 2>/dev/null && { \
6469
echo "Test docker image in a kind cluster..."; \
65-
./internal/testing/local_env_prep.sh "${K8S_SHREDDER_VERSION}" "${KINDNODE_VERSION}" "${TEST_CLUSTERNAME}" && \
66-
./internal/testing/cluster_upgrade.sh "${TEST_CLUSTERNAME}" || \
70+
./internal/testing/local_env_prep.sh "${K8S_SHREDDER_VERSION}" "${KINDNODE_VERSION}" "${TEST_CLUSTERNAME}" "${KUBECONFIG_LOCALTEST}" && \
71+
./internal/testing/cluster_upgrade.sh "${TEST_CLUSTERNAME}" "${KUBECONFIG_LOCALTEST}" || \
72+
exit 1; \
73+
} || { \
74+
echo >&2 "[WARN] I require kind but it's not installed(see https://kind.sigs.k8s.io). Assuming a cluster is already accessible."; \
75+
}
76+
77+
local-test-karpenter: build ## Test docker image in a kind cluster with Karpenter and drift detection enabled
78+
@hash kind 2>/dev/null && { \
79+
echo "Test docker image in a kind cluster with Karpenter..."; \
80+
./internal/testing/local_env_prep_karpenter.sh "${K8S_SHREDDER_VERSION}" "${KINDNODE_VERSION}" "${TEST_CLUSTERNAME_KARPENTER}" "${KUBECONFIG_KARPENTER}" && \
81+
./internal/testing/cluster_upgrade_karpenter.sh "${TEST_CLUSTERNAME_KARPENTER}" "${KUBECONFIG_KARPENTER}" || \
82+
exit 1; \
83+
} || { \
84+
echo >&2 "[WARN] I require kind but it's not installed(see https://kind.sigs.k8s.io). Assuming a cluster is already accessible."; \
85+
}
86+
87+
local-test-node-labels: build ## Test docker image in a kind cluster with node label detection enabled
88+
@hash kind 2>/dev/null && { \
89+
echo "Test docker image in a kind cluster with node label detection..."; \
90+
./internal/testing/local_env_prep_node_labels.sh "${K8S_SHREDDER_VERSION}" "${KINDNODE_VERSION}" "${TEST_CLUSTERNAME_NODE_LABELS}" "${KUBECONFIG_NODE_LABELS}" && \
91+
./internal/testing/cluster_upgrade_node_labels.sh "${TEST_CLUSTERNAME_NODE_LABELS}" "${KUBECONFIG_NODE_LABELS}" || \
6792
exit 1; \
6893
} || { \
6994
echo >&2 "[WARN] I require kind but it's not installed(see https://kind.sigs.k8s.io). Assuming a cluster is already accessible."; \
@@ -76,7 +101,7 @@ unit-test: ## Run unit tests
76101

77102
e2e-tests: ## Run e2e tests for k8s-shredder deployed in a local kind cluster
78103
@echo "Run e2e tests for k8s-shredder..."
79-
@KUBECONFIG=${PWD}/kubeconfig go test internal/testing/e2e_test.go -v
104+
@KUBECONFIG=${PWD}/${KUBECONFIG_LOCALTEST} go test internal/testing/e2e_test.go -v
80105

81106
# DEMO targets
82107
# -----------
@@ -103,8 +128,10 @@ publish: ## Release a new version
103128
# -----------
104129
clean: ## Clean up local testing environment
105130
@echo "Cleaning up your local testing environment..."
106-
@kind delete cluster --name="${TEST_CLUSTERNAME}" > /dev/null 2>&1 || true
131+
@kind delete cluster --name="${TEST_CLUSTERNAME}" ## > /dev/null 2>&1 || true
132+
@kind delete cluster --name="${TEST_CLUSTERNAME_KARPENTER}" ## > /dev/null 2>&1 || true
133+
@kind delete cluster --name="${TEST_CLUSTERNAME_NODE_LABELS}" ## > /dev/null 2>&1 || true
107134
@echo "Removing all generated files and directories"
108-
@rm -rf dist/ k8s-shredder kubeconfig
135+
@rm -rf dist/ k8s-shredder kubeconfig ${KUBECONFIG_LOCALTEST} ${KUBECONFIG_KARPENTER} ${KUBECONFIG_NODE_LABELS}
109136
@echo "Done!"
110137

0 commit comments

Comments
 (0)