Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

x-kubernetes-map-type=atomic is required if a containing array has x-kubernetes-list-type=set #752

Closed
tatsuhiro-t opened this issue Dec 20, 2022 · 4 comments · Fixed by #753

Comments

@tatsuhiro-t
Copy link
Contributor

I encountered validation error when applying the generated CRD containing PodSpec which has new ResourceClaim in https://pkg.go.dev/k8s.io/api@v0.26.0/core/v1#ResourceRequirements added in k8s v1.26.
It sets +listType=set.

When applying generated CRD, I got the following error:

... .properties[spec].properties[initContainers].items.properties[resources].properties[claims].items.x-kubernetes-map-type: Invalid value: "null": must be atomic as item of a list with x-kubernetes-list-type=set

This validation seems to be happened at https://github.com/kubernetes/apiextensions-apiserver/blob/9746985976f9fee21736250e3afb0eae27026633/pkg/apis/apiextensions/validation/validation.go#L945

Adding x-kubernetes-map-type=atomic under items fixes this issue.

I'm wondering whether this is a lack of x-kubernetes-map-type=atomic in ResourceClaim, or something that CRD generator must deal with.

The following patch automatically adds x-kubernetes-map-type=atomic to items when x-kubernetes-list-type=set is seen, but I feel this is hacky and probably not a correct way:

--- a/pkg/crd/markers/topology.go
+++ b/pkg/crd/markers/topology.go
@@ -116,6 +116,14 @@ func (l ListType) ApplyToSchema(schema *apiext.JSONSchemaProps) error {
        }
        p := string(l)
        schema.XListType = &p
+
+       if l == "set" {
+               if itemSchema := schema.Items.Schema; itemSchema != nil {
+                       v := "atomic"
+                       itemSchema.XMapType = &v
+               }
+       }
+
        return nil
 }
@kluevandrew
Copy link

Same issue for me, any workaround?

@kluevandrew
Copy link

Same issue for me, any workaround?

I found a workaround by myself, modify according to your resources

# ./config/crd/kustomization.yaml

  # the following config is for teaching kustomize how to do kustomization for CRDs.
  configurations:
    - kustomizeconfig.yaml
+
+ patchesJson6902:
+  - path: patches/workaround_in_roles.yaml
+   target:
+      group: apiextensions.k8s.io
+      version: v1
+      kind: CustomResourceDefinition
+      name: roles.tarantool.io
# ./config/crd/patches/workaround_in_roles.yaml

+ - op: add
+   path: /spec/versions/0/schema/openAPIV3Schema/properties/spec/properties/storageTemplate/properties/spec/properties/template/properties/spec/properties/ephemeralContainers/items/properties/resources/properties/claims/items/x-kubernetes-map-type
+   value: atomic
+ - op: add
+   path: /spec/versions/0/schema/openAPIV3Schema/properties/spec/properties/storageTemplate/properties/spec/properties/template/properties/spec/properties/containers/items/properties/resources/properties/claims/items/x-kubernetes-map-type
+   value: atomic
+ - op: add
+   path: /spec/versions/0/schema/openAPIV3Schema/properties/spec/properties/storageTemplate/properties/spec/properties/template/properties/spec/properties/initContainers/items/properties/resources/properties/claims/items/x-kubernetes-map-type
+   value: atomic
+ - op: add
+   path: /spec/versions/0/schema/openAPIV3Schema/properties/spec/properties/storageTemplate/properties/spec/properties/template/properties/spec/properties/volumes/items/properties/ephemeral/properties/volumeClaimTemplate/properties/spec/properties/resources/properties/claims/items/x-kubernetes-map-type
+   value: atomic
+ - op: add
+   path: /spec/versions/0/schema/openAPIV3Schema/properties/spec/properties/storageTemplate/properties/spec/properties/volumeClaimTemplates/items/properties/spec/properties/resources/properties/claims/items/x-kubernetes-map-type
+   value: atomic
+ - op: add
+   path: /spec/versions/1/schema/openAPIV3Schema/properties/spec/properties/replicasetTemplate/properties/volumeClaimTemplates/items/properties/spec/properties/resources/properties/claims/items/x-kubernetes-map-type
+   value: atomic
+ - op: add
+   path: /spec/versions/1/schema/openAPIV3Schema/properties/spec/properties/replicasetTemplate/properties/podTemplate/properties/spec/properties/containers/items/properties/resources/properties/claims/items/x-kubernetes-map-type
+   value: atomic
+ - op: add
+   path: /spec/versions/1/schema/openAPIV3Schema/properties/spec/properties/replicasetTemplate/properties/podTemplate/properties/spec/properties/ephemeralContainers/items/properties/resources/properties/claims/items/x-kubernetes-map-type
+   value: atomic
+ - op: add
+   path: /spec/versions/1/schema/openAPIV3Schema/properties/spec/properties/replicasetTemplate/properties/podTemplate/properties/spec/properties/volumes/items/properties/ephemeral/properties/volumeClaimTemplate/properties/spec/properties/resources/properties/claims/items/x-kubernetes-map-type
+   value: atomic
+ - op: add
+   path: /spec/versions/1/schema/openAPIV3Schema/properties/spec/properties/replicasetTemplate/properties/podTemplate/properties/spec/properties/initContainers/items/properties/resources/properties/claims/items/x-kubernetes-map-type
+   value: atomic
+ 

@kluevandrew
Copy link

kluevandrew commented Dec 22, 2022

It is still not fixed as i can see, 0.11.1 has a revert commit of fix. I think you need to re-open that issue.

@kluevandrew
Copy link

Found discussion here #753

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants