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

Example CRD file #480

Closed
lswith opened this issue Oct 18, 2018 · 3 comments
Closed

Example CRD file #480

lswith opened this issue Oct 18, 2018 · 3 comments

Comments

@lswith
Copy link
Contributor

lswith commented Oct 18, 2018

It seems that when I use the crd below it can't marshal the yaml into the common. OpenAPIDefinition.

Example Kustomization file

# kustomization.yaml

crds:
- example.yaml

Example CRD

# example.yaml
apiVersion: apiextensions.k8s.io/v1beta1
kind: CustomResourceDefinition
metadata:
  name: foos.samplecontroller.k8s.io
spec:
  group: samplecontroller.k8s.io
  version: v1alpha1
  names:
    kind: Foo
    plural: foos
  scope: Namespaced
  subresources:
    status: {}

Is there anyway I could see what an example crd file looks like?

@Liujingfang1
Copy link
Contributor

@iswith Please take a look at this example https://github.com/kubernetes-sigs/kustomize/tree/master/pkg/commands/build/testdata/testcase-crds/crd

The purpose of crds is to register proper configs for Kusotmize transformers. As we recently developed transformer/config package. There is an easier way to register crd related configs. We'll write more docs for that.

@Liujingfang1 Liujingfang1 mentioned this issue Oct 18, 2018
@lswith
Copy link
Contributor Author

lswith commented Oct 18, 2018

I'd love to know how to generate these CRD files from the current CRDs.
I have currently used: kubectl get crd -o yaml --export which gives something of the form

apiVersion: apiextensions.k8s.io/v1beta1
kind: CustomResourceDefinition
metadata:
  creationTimestamp: null
  generation: 1
  name: prometheuses.monitoring.coreos.com
  selfLink: /apis/apiextensions.k8s.io/v1beta1/customresourcedefinitions/prometheuses.monitoring.coreos.com
spec:
  group: monitoring.coreos.com
  names:
    kind: Prometheus
    listKind: PrometheusList
    plural: prometheuses
    singular: prometheus
  scope: Namespaced
  validation:
    openAPIV3Schema:
      description: Prometheus defines a Prometheus deployment.
      properties:
        apiVersion:
          description: 'APIVersion defines the versioned schema of this representation
            of an object. Servers should convert recognized schemas to the latest
            internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#resources'
          type: string
        kind:
          description: 'Kind is a string value representing the REST resource this
            object represents. Servers may infer this from the endpoint the client
            submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#types-kinds'
          type: string
        spec:
          description: 'Specification of the desired behavior of the Prometheus cluster.
            More info: https://github.com/kubernetes/community/blob/master/contributors/devel/api-conventions.md#spec-and-status'
          properties:
            additionalAlertManagerConfigs:
              description: SecretKeySelector selects a key of a Secret.
              properties:
                key:
                  description: The key of the secret to select from.  Must be a valid
                    secret key.
                  type: string
                name:
                  description: 'Name of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names'
                  type: string
                optional:
                  description: Specify whether the Secret or it's key must be defined
                  type: boolean
              required:
              - key
            additionalScrapeConfigs:
              description: SecretKeySelector selects a key of a Secret.
              properties:
                key:
                  description: The key of the secret to select from.  Must be a valid
                    secret key.
                  type: string
                name:
                  description: 'Name of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names'
                  type: string
                optional:
                  description: Specify whether the Secret or it's key must be defined
                  type: boolean
              required:
              - key
       ...
        status:
          description: 'Most recent observed status of the Prometheus cluster. Read-only.
            Not included when requesting from the apiserver, only from the Prometheus
            Operator API itself. More info: https://github.com/kubernetes/community/blob/master/contributors/devel/api-conventions.md#spec-and-status'
          properties:
            availableReplicas:
              description: Total number of available pods (ready for at least minReadySeconds)
                targeted by this Prometheus deployment.
              format: int32
          ...
      required:
      - spec
  version: v1
status:
  acceptedNames:
    kind: ""
    plural: ""
  conditions: null

It seems these CRDs are totally different to the ones required by kustomize.

@Liujingfang1
Copy link
Contributor

crds field only accepts json files generated by openAPI definitions. It is not able to consume yaml file for a CRD. The reason is that we couldn't find a way to annotate yaml fields. In the example you provided. additionalScrapeConfigs.name could be a reference of a secret. To make sure Kusotmize understand that as we understand it, we need some annotations like

"x-kubernetes-object-ref-api-version": "v1",
"x-kubernetes-object-ref-kind": "Secret",

In CRD yaml files, we couldn't find a field to hold these annotations.

To support crd in kustomize, you have an easier way. It is documented #498, please take a look.

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

No branches or pull requests

2 participants