Skip to content

Commit 2abf308

Browse files
authored
Merge pull request #19 from cybozu-go/add-vap
Add ValidatingAdmissionPolicy for imageprefetch and nodeimageset
2 parents af2bfa3 + 955b1fb commit 2abf308

29 files changed

+522
-511
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# Test binary, build with `go test -c`
22
*.test
3+
!vap.test
34

45
# Output of the go coverage tool, specifically when used with LiteIDE
56
*.out

Makefile

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ help: ## Display this help.
2222

2323
.PHONY: manifests
2424
manifests: controller-gen ## Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects.
25-
$(CONTROLLER_GEN) rbac:roleName=imageprefetch-controller-role crd webhook paths="./..." output:crd:artifacts:config=config/crd/bases
25+
$(CONTROLLER_GEN) rbac:roleName=imageprefetch-controller-role crd paths="./..." output:crd:artifacts:config=config/crd/bases
2626

2727
.PHONY: generate
2828
generate: controller-gen ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.
@@ -58,8 +58,9 @@ vet: ## Run go vet against code.
5858
go vet ./...
5959

6060
.PHONY: test
61-
test: manifests generate fmt vet envtest ginkgo ## Run tests.
61+
test: manifests generate fmt vet envtest ginkgo kaptest ## Run tests.
6262
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path)" $(GINKGO) run --skip-file e2e.* -r --coverprofile cover.out -v
63+
$(KAPTEST) run config/vap/vap.test/kaptest.yaml
6364

6465
# Utilize Kind or modify the e2e tests to load the image locally, enabling compatibility with other vendors.
6566
.PHONY: test-e2e # Run the e2e tests against a Kind k8s instance that is spun up.
@@ -136,6 +137,7 @@ GOLANGCI_LINT = $(LOCALBIN)/golangci-lint
136137
GINKGO = $(LOCALBIN)/ginkgo
137138
APPLYCONFIGURATION_GEN = $(LOCALBIN)/applyconfiguration-gen
138139
MODELS_SCHEMA = $(LOCALBIN)/models-schema
140+
KAPTEST ?= $(LOCALBIN)/kaptest
139141

140142
## Tool Versions
141143
KUSTOMIZE_VERSION ?= v5.6.0
@@ -145,6 +147,7 @@ GOLANGCI_LINT_VERSION ?= v2.1.6
145147
GINKGO_VERSION ?= v2.23.4
146148
CODE_GENERATOR_VERSION ?= v0.31.1
147149
MODELS_SCHEMA_VERSION ?= v1.31.1
150+
KAPTEST_VERSION ?= v0.1.2
148151

149152
.PHONY: kustomize
150153
kustomize: $(KUSTOMIZE) ## Download kustomize locally if necessary.
@@ -186,6 +189,13 @@ applyconfiguration-gen: $(APPLYCONFIGURATION_GEN) ## Download applyconfiguration
186189
$(APPLYCONFIGURATION_GEN): $(LOCALBIN)
187190
$(call go-install-tool,$(APPLYCONFIGURATION_GEN),k8s.io/code-generator/cmd/applyconfiguration-gen,$(CODE_GENERATOR_VERSION))
188191

192+
.PHONY: kaptest
193+
kaptest: $(KAPTEST) ## Download kaptest locally if necessary.
194+
$(KAPTEST): $(LOCALBIN)
195+
curl -sLO "https://github.com/pfnet/kaptest/releases/download/${KAPTEST_VERSION}/kaptest_Linux_x86_64.tar.gz" && \
196+
tar -xzf kaptest_Linux_x86_64.tar.gz -C $(LOCALBIN) kaptest && \
197+
rm -f kaptest_Linux_x86_64.tar.gz
198+
189199
# go-install-tool will 'go install' any package with custom target and name of binary, if it doesn't exist
190200
# $1 - target path with name of binary
191201
# $2 - package url which can be installed

PROJECT

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,6 @@ resources:
1313
kind: ImagePrefetch
1414
path: github.com/cybozu-go/ofen/api/v1
1515
version: v1
16-
webhooks:
17-
defaulting: true
18-
validation: true
19-
webhookVersion: v1
2016
- api:
2117
crdVersion: v1
2218
controller: true

cmd/imageprefetch-controller/main.go

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import (
1919

2020
ofenv1 "github.com/cybozu-go/ofen/api/v1"
2121
"github.com/cybozu-go/ofen/internal/controller"
22-
webhookofenv1 "github.com/cybozu-go/ofen/internal/webhook/v1"
2322
// +kubebuilder:scaffold:imports
2423
)
2524

@@ -141,13 +140,6 @@ func main() {
141140
setupLog.Error(err, "unable to create controller", "controller", "ImagePrefetch")
142141
os.Exit(1)
143142
}
144-
145-
if os.Getenv("ENABLE_WEBHOOKS") != "false" {
146-
if err = webhookofenv1.SetupImagePrefetchWebhookWithManager(mgr); err != nil {
147-
setupLog.Error(err, "unable to create webhook", "webhook", "ImagePrefetch")
148-
os.Exit(1)
149-
}
150-
}
151143
// +kubebuilder:scaffold:builder
152144

153145
if err := mgr.AddHealthzCheck("healthz", healthz.Ping); err != nil {

config/certmanager/certificate.yaml

Lines changed: 0 additions & 35 deletions
This file was deleted.

config/certmanager/kustomization.yaml

Lines changed: 0 additions & 5 deletions
This file was deleted.

config/certmanager/kustomizeconfig.yaml

Lines changed: 0 additions & 8 deletions
This file was deleted.

config/crd/kustomization.yaml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,16 @@ resources:
99
patches:
1010
# [WEBHOOK] To enable webhook, uncomment all the sections with [WEBHOOK] prefix.
1111
# patches here are for enabling the conversion webhook for each CRD
12-
- path: patches/webhook_in_imageprefetches.yaml
1312
# +kubebuilder:scaffold:crdkustomizewebhookpatch
1413

1514
# [CERTMANAGER] To enable cert-manager, uncomment all the sections with [CERTMANAGER] prefix.
1615
# patches here are for enabling the CA injection for each CRD
17-
- path: patches/cainjection_in_imageprefetches.yaml
16+
#- path: patches/cainjection_in_imageprefetches.yaml
1817
#- path: patches/cainjection_in_nodeimagesets.yaml
1918
# +kubebuilder:scaffold:crdkustomizecainjectionpatch
2019

2120
# [WEBHOOK] To enable webhook, uncomment the following section
2221
# the following config is for teaching kustomize how to do kustomization for CRDs.
2322

24-
configurations:
25-
- kustomizeconfig.yaml
23+
#configurations:
24+
#- kustomizeconfig.yaml

config/crd/patches/cainjection_in_imageprefetches.yaml

Lines changed: 0 additions & 7 deletions
This file was deleted.

config/crd/patches/webhook_in_imageprefetches.yaml

Lines changed: 0 additions & 16 deletions
This file was deleted.

0 commit comments

Comments
 (0)