Kubebuilder: CronJob make install failed.

Created on 8 Apr 2020  路  9Comments  路  Source: kubernetes-sigs/kubebuilder

follow the qiuck start book to build CronJob, when run make install, It failed with:

controller-gen "crd:trivialVersions=true" rbac:roleName=manager-role webhook paths="./..." output:crd:artifacts:config=config/crd/bases
kustomize build config/crd | kubectl apply -f -
The CustomResourceDefinition "cronjobs.batch.tutorial.kubebuilder.io" is invalid: 
* spec.validation.openAPIV3Schema.properties[spec].properties[jobTemplate].properties[spec].properties[template].properties[spec].properties[initContainers].items.properties[ports].items.properties[protocol].default: Required value: this property is in x-kubernetes-list-map-keys, so it must have a default or be a required property
* spec.validation.openAPIV3Schema.properties[spec].properties[jobTemplate].properties[spec].properties[template].properties[spec].properties[containers].items.properties[ports].items.properties[protocol].default: Required value: this property is in x-kubernetes-list-map-keys, so it must have a default or be a required property
Makefile:30: recipe for target 'install' failed
make: *** [install] Error 1
kubebuilder version
Version: version.Version{KubeBuilderVersion:"2.3.0", KubernetesVendor:"1.16.4", GitCommit:"800f63a7e41a6a8016d4cb9d583e1705b0812c9d", BuildDate:"2020-02-28T19:15:41Z", GoOs:"unknown", GoArch:"unknown"}
kinsupport

Most helpful comment

@mingliangguo @zzxwill @yaa110 You can create a kustomize patch to get around this pretty trivially. That said, the controller-tools project merged a fix for this with #480; however, it is not in a release at this point in time.

Workaround:

config/crd/patches/k8s_list_map_keys.yaml

- op: replace
  path: /spec/validation/openAPIV3Schema/properties/spec/properties/jobTemplate/properties/spec/properties/template/properties/spec/properties/initContainers/items/properties/ports/items/required
  value:
  - containerPort
  - protocol

- op: replace
  path: /spec/validation/openAPIV3Schema/properties/spec/properties/jobTemplate/properties/spec/properties/template/properties/spec/properties/containers/items/properties/ports/items/required
  value:
  - containerPort
  - protocol

config/crd/kustomization.yaml

...
patchesJson6902:
- target:
    group: apiextensions.k8s.io
    version: v1beta1
    kind: CustomResourceDefinition
    name: cronjobs.batch.tutorial.kubebuilder.io
  path: patches/k8s_list_map_keys.yaml
...

All 9 comments

switch test it on k8s v1.16.7. it worked. the error is under k8s v1.18.

I am also running into this problem.

@chenyg0911 could you share with me the command you used to downgrade your Kubernetes APIs?

I've included my go.mod and the errors I'm getting running make install.

module tutorial

go 1.13

require (
        github.com/go-logr/logr v0.1.0
        github.com/onsi/ginkgo v1.11.0
        github.com/onsi/gomega v1.8.1
        github.com/robfig/cron v1.2.0
        k8s.io/api v0.17.2
        k8s.io/apimachinery v0.17.2
        k8s.io/client-go v0.17.2
        sigs.k8s.io/controller-runtime v0.5.0
)

The CustomResourceDefinition "cronjobs.batch.kubebuildertutorial.kubebuilder.io" is invalid: 
* spec.validation.openAPIV3Schema.properties[spec].properties[jobTemplate].properties[spec].properties[template].properties[spec].properties[initContainers].items.properties[ports].items.properties[protocol].default: Required value: this property is in x-kubernetes-list-map-keys, so it must have a default or be a required property
* spec.validation.openAPIV3Schema.properties[spec].properties[jobTemplate].properties[spec].properties[template].properties[spec].properties[containers].items.properties[ports].items.properties[protocol].default: Required value: this property is in x-kubernetes-list-map-keys, so it must have a default or be a required property
make: *** [Makefile:30: install] Error 1

Oops... I didn't read the error message well enough and didn't realize that the problem is with the server version of Kubernetes, not the linked Go libraries.

I restarted my minikube using:

minikube start --kubernetes-version=v1.16.7

as a workaround.

I don't think it's a good idea to do this workaround. We're using the latest kubebuilder version, and it even need lower version kubernetes release!

Should we update the tutorial code and fix this issue?

I ran into the exact same issue with the latest tutorial. And I also saw some discussions about the same issue in https://github.com/kubernetes-sigs/controller-tools/issues/444

Does it mean this will not be fixed in kubebuilder until the issue is fixed in controller-tools?

Hit the same issue.

Same issue with k8s 1.19.

I think the issue should be reopened.

@mingliangguo @zzxwill @yaa110 You can create a kustomize patch to get around this pretty trivially. That said, the controller-tools project merged a fix for this with #480; however, it is not in a release at this point in time.

Workaround:

config/crd/patches/k8s_list_map_keys.yaml

- op: replace
  path: /spec/validation/openAPIV3Schema/properties/spec/properties/jobTemplate/properties/spec/properties/template/properties/spec/properties/initContainers/items/properties/ports/items/required
  value:
  - containerPort
  - protocol

- op: replace
  path: /spec/validation/openAPIV3Schema/properties/spec/properties/jobTemplate/properties/spec/properties/template/properties/spec/properties/containers/items/properties/ports/items/required
  value:
  - containerPort
  - protocol

config/crd/kustomization.yaml

...
patchesJson6902:
- target:
    group: apiextensions.k8s.io
    version: v1beta1
    kind: CustomResourceDefinition
    name: cronjobs.batch.tutorial.kubebuilder.io
  path: patches/k8s_list_map_keys.yaml
...

The workaround https://github.com/kubernetes-sigs/kubebuilder/issues/1466#issuecomment-712444882 shows valid for projects built with v2 go plugin. If you use the go/v3-alpha plugin it should be solved as well. ( kubebuilder init --plugins=go/v3-alpha )

Was this page helpful?
0 / 5 - 0 ratings

Related issues

derailed picture derailed  路  5Comments

champak picture champak  路  4Comments

narayanasamyr picture narayanasamyr  路  4Comments

functicons picture functicons  路  4Comments

bingosummer picture bingosummer  路  6Comments