(base) (⎈ |kubernetes-admin@qa-u03:qa)➜ test-operator kubebuilder init --domain test.com --repo gitlab.qima-inc.com/test-operator INFO Writing kustomize manifests for you to edit... INFO Writing scaffold for you to edit... INFO Get controller runtime: $ go get sigs.k8s.io/controller-runtime@v0.17.2 INFO Update dependencies: $ go mod tidy go: go.mod file indicates go 1.21, but maximum version supported by tidy is 1.19 Error: failed to initialize project: unable to run post-scaffold tasks of "base.go.kubebuilder.io/v4": exit status 1
因为我默认是是go1.19所以版本达不到要求,这里两种处理方式
指定 –plugins go/v3 –project-version 3
切换高版本golang 这里我切换了go1.22
1 2 3 4 5 6 7 8 9
(base) (⎈ |kubernetes-admin@qa-u03:qa)➜ test-operator kubebuilder init --domain test.com --repo gitlab.qima-inc.com/test-operator INFO Writing kustomize manifests for you to edit... INFO Writing scaffold for you to edit... INFO Get controller runtime: $ go get sigs.k8s.io/controller-runtime@v0.17.2 INFO Update dependencies: $ go mod tidy Next: define a resource with: $ kubebuilder create api
生成核心组件Pod的API
1 2 3 4 5 6 7 8 9
(base) (⎈ |kubernetes-admin@qa-u03:qa)➜ test-operator kubebuilder create api --group core --version v1 --kind Pod INFO Create Resource [y/n] n INFO Create Controller [y/n] n INFO Writing kustomize manifests for you to edit... INFO Writing scaffold for you to edit... INFO Update dependencies: $ go mod tidy
(base) (⎈ |kubernetes-admin@qa-u03:qa)➜ test-operator kubebuilder create webhook --group core --version v1 --kind Pod --defaulting --programmatic-validation INFO Writing kustomize manifests for you to edit... ERRO Unable to find the target(s) #- path: patches/webhook/* to uncomment in the file config/crd/kustomization.yaml. ERRO Unable to find the target(s) #configurations: #- kustomizeconfig.yaml to uncomment in the file config/crd/kustomization.yaml. INFO Writing scaffold for you to edit... INFO api/v1/pod_webhook.go INFO api/v1/pod_webhook_test.go INFO api/v1/webhook_suite_test.go INFO Update dependencies: $ go mod tidy INFO Running make: $ make generate mkdir -p /Users/xxxx/test-operator/bin Downloading sigs.k8s.io/controller-tools/cmd/controller-gen@v0.14.0 /Users/xxxx/test-operator/bin/controller-gen-v0.14.0 object:headerFile="hack/boilerplate.go.txt" paths="./..." Next: implement your new Webhook and generate the manifests with: $ make manifests
/* Copyright 2024. 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. */
获取MutatingWebhookConfiguration和ValidatingWebhookConfiguration将caCert写入webhook config中的ClientConfig.CABundle(这里有个问题是webhook需要提前创建,CABundle可以写个临时值,等webhook server 启动覆盖)