Skip to content
This repository was archived by the owner on May 8, 2025. It is now read-only.

Introduce CRD v1: fix CRD generation bugs and enable field validation #436

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .circleci/release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ main() {
sed -i 's/replicas: 1/replicas: {{ .Values.replicas }}/g' flink-operator.yaml
sed -i "s/$IMG/{{ .Values.operatorImage.name }}/g" flink-operator.yaml
mv flink-operator.yaml helm-chart/flink-operator/templates/flink-operator.yaml
cp flink-on-k8s-operator/config/crd/bases/flinkoperator.k8s.io_flinkclusters.yaml helm-chart/flink-operator/templates/flink-cluster-crd.yaml
kustomize build flink-on-k8s-operator/config/crd > helm-chart/flink-operator/templates/flink-cluster-crd.yaml
sed -i '1s/^/{{ if .Values.rbac.create }}\n/' helm-chart/flink-operator/templates/flink-cluster-crd.yaml
sed -i -e "\$a{{ end }}\n" helm-chart/flink-operator/templates/flink-cluster-crd.yaml
awk '{sub(/\{\{\$clusterName\}\}\.example\.com/, "clusterName.example.com")}1' helm-chart/flink-operator/templates/flink-cluster-crd.yaml > temp.yaml && mv temp.yaml helm-chart/flink-operator/templates/flink-cluster-crd.yaml
Expand Down
8 changes: 5 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ build: generate fmt vet

# Run tests.
test: generate fmt vet manifests
mkdir -p config/crd/test
kubectl kustomize config/crd > config/crd/test/crd.yaml
go test ./... -coverprofile cover.out
go mod tidy
echo $(FLINK_OPERATOR_NAMESPACE)
Expand Down Expand Up @@ -62,7 +64,7 @@ ifeq (, $(shell which controller-gen))
CONTROLLER_GEN_TMP_DIR=$$(mktemp -d) ;\
cd $$CONTROLLER_GEN_TMP_DIR ;\
go mod init tmp ;\
go get sigs.k8s.io/controller-tools/cmd/controller-gen@v0.3.0 ;\
go get sigs.k8s.io/controller-tools/cmd/controller-gen@v0.5.0 ;\
rm -rf $$CONTROLLER_GEN_TMP_DIR ;\
}
CONTROLLER_GEN=$(shell go env GOPATH)/bin/controller-gen
Expand Down Expand Up @@ -91,7 +93,7 @@ push-operator-image:

# Install CRDs into a cluster
install: manifests
kubectl apply -f config/crd/bases
kubectl apply -k config/crd

# Deploy cert-manager which is required by webhooks of the operator.
webhook-cert:
Expand Down Expand Up @@ -135,7 +137,7 @@ endif
@printf "$(GREEN)Flink Operator deployed, image=$(IMG), operator_namespace=$(FLINK_OPERATOR_NAMESPACE), watch_namespace=$(WATCH_NAMESPACE)$(RESET)\n"

undeploy-crd:
kubectl delete -f config/crd/bases
kubectl delete -k config/crd

undeploy-controller: build-overlay
kubectl kustomize config/deploy \
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ The operator is under active development, backward compatibility of the APIs is

## Prerequisites

* Version >= 1.15 of Kubernetes
* Version >= 1.15 of kubectl (with kustomize)
* Version >= 1.16 of Kubernetes
* Version >= 1.16 of kubectl (with kustomize)
* Version >= 1.7 of Apache Flink

## Overview
Expand Down
4 changes: 2 additions & 2 deletions api/v1beta1/flinkcluster_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ This marker is responsible for generating a mutating webhook manifest.
The meaning of each marker can be found [here](/reference/markers/webhook.md).
*/

// +kubebuilder:webhook:path=/mutate-flinkoperator-k8s-io-v1beta1-flinkcluster,mutating=true,failurePolicy=fail,groups=flinkoperator.k8s.io,resources=flinkclusters,verbs=create;update,versions=v1beta1,name=mflinkcluster.flinkoperator.k8s.io
// +kubebuilder:webhook:webhookVersions=v1beta1,path=/mutate-flinkoperator-k8s-io-v1beta1-flinkcluster,mutating=true,failurePolicy=fail,groups=flinkoperator.k8s.io,resources=flinkclusters,verbs=create;update,versions=v1beta1,name=mflinkcluster.flinkoperator.k8s.io

/*
We use the `webhook.Defaulter` interface to set defaults to our CRD.
Expand All @@ -63,7 +63,7 @@ func (cluster *FlinkCluster) Default() {
This marker is responsible for generating a validating webhook manifest.
*/

// +kubebuilder:webhook:path=/validate-flinkoperator-k8s-io-v1beta1-flinkcluster,mutating=false,failurePolicy=fail,groups=flinkoperator.k8s.io,resources=flinkclusters,verbs=create;update,versions=v1beta1,name=vflinkcluster.flinkoperator.k8s.io
// +kubebuilder:webhook:webhookVersions=v1beta1,path=/validate-flinkoperator-k8s-io-v1beta1-flinkcluster,mutating=false,failurePolicy=fail,groups=flinkoperator.k8s.io,resources=flinkclusters,verbs=create;update,versions=v1beta1,name=vflinkcluster.flinkoperator.k8s.io

var _ webhook.Validator = &FlinkCluster{}
var validator = Validator{}
Expand Down
2 changes: 1 addition & 1 deletion api/v1beta1/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ var _ = BeforeSuite(func(done Done) {

By("bootstrapping test environment")
testEnv = &envtest.Environment{
CRDDirectoryPaths: []string{filepath.Join("..", "..", "config", "crd", "bases")},
CRDDirectoryPaths: []string{filepath.Join("..", "..", "config", "crd", "test")},
}

err := SchemeBuilder.AddToScheme(scheme.Scheme)
Expand Down
16 changes: 15 additions & 1 deletion api/v1beta1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading