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

bug: CRD schema does not match with defined value.schema.json #43

Open
alfredo-milani-kiratech opened this issue May 10, 2024 · 2 comments
Assignees

Comments

@alfredo-milani-kiratech

Describe the bug
Once the CompositionDefinition is installed on the cluster, the CRD schema generated does not match with the one defined in value.schema.json.

To Reproduce
Steps to reproduce the behavior:

  1. Install Krateo v2.0.0 cluster with kind
  2. Apply the following CompositionDefinition
apiVersion: core.krateo.io/v1alpha1
kind: CompositionDefinition
metadata:
  annotations:
    krateo.io/connector-verbose: "true"
    meta.helm.sh/release-namespace: krateo-system
  labels:
    app.kubernetes.io/managed-by: Helm
  name: x
  namespace: demo-system
spec:
  chart:
    url: https://github.com/alfredo-milani-kiratech/krateo-v2-template-fireworksapp/releases/download/0.0.10/x-app-0.0.10.tgz
  deletionPolicy: Delete
  1. The CRD on the cluster shows:
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
  annotations:
    controller-gen.kubebuilder.io/version: v0.14.0
  creationTimestamp: "2024-05-10T10:40:13Z"
  generation: 1
  name: xapps.composition.krateo.io
  resourceVersion: "738"
  uid: 53b8c5a2-85e6-4878-9e3a-1fbb1f6e9ff7
spec:
  conversion:
    strategy: None
  group: composition.krateo.io
  names:
    categories:
    - compositions
    - comps
    kind: Xapp
    listKind: XappList
    plural: xapps
    singular: xapp
  scope: Namespaced
  versions:
  - name: v0-0-10
    schema:
      openAPIV3Schema:
        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/sig-architecture/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/sig-architecture/api-conventions.md#types-kinds
            type: string
          spec:
            properties:
              app:
                properties:
                  env:
                    default: dev
                    type: string
                  svc:
                    default: false
                    type: boolean
                required:
                - env
                - svc
                type: object
              deletionPolicy:
                default: Delete
                description: |-
                  DeletionPolicy specifies what will happen to the underlying external
                  when this managed resource is deleted - either "Delete" or "Orphan" the
                  external resource.
                enum:
                - Orphan
                - Delete
                type: string
              infra:
                properties:
                  env:
                    default: dev
                    type: string
                  svc:
                    default: false
                    type: boolean
                required:
                - env
                - svc
                type: object
            required:
            - app
            - infra
            type: object
        type: object
    served: true
    storage: true
status:
  acceptedNames:
    categories:
    - compositions
    - comps
    kind: Xapp
    listKind: XappList
    plural: xapps
    singular: xapp
  conditions:
  - lastTransitionTime: "2024-05-10T10:40:13Z"
    message: no conflicts found
    reason: NoConflicts
    status: "True"
    type: NamesAccepted
  - lastTransitionTime: "2024-05-10T10:40:13Z"
    message: the initial names have been accepted
    reason: InitialNamesAccepted
    status: "True"
    type: Established
  storedVersions:
  - v0-0-10

while the value.schema.json defined is:

{
  "type": "object",
  "$schema": "http://json-schema.org/draft-07/schema",
  "required": [
    "infra",
    "app"
  ],
  "properties": {
    "infra": {
      "type": "object",
      "title": "Helm Chart parameters section",
      "required": [
        "env",
        "svc"
      ],
      "properties": {
        "env": {
          "type": [
            "string"
          ],
          "title": "Helm Chart service parameters section",
          "default": "dev"
        },
        "svc": {
          "type": [
            "boolean"
          ],
          "title": "Helm Chart service parameters section",
          "default": false
        }
      }
    },
    "app": {
      "type": "object",
      "title": "Helm Chart parameters section",
      "required": [
        "service"
      ],
      "properties": {
        "service": {
          "type": "object",
          "title": "Helm Chart service parameters section",
          "required": [
            "type",
            "port"
          ],
          "properties": {
            "type": {
              "type": [
                "string",
                "boolean",
                "number",
                "object",
                "array"
              ],
              "enum": [
                "NodePort",
                "LoadBalancer"
              ],
              "title": "Helm Chart service type",
              "default": "NodePort"
            },
            "port": {
              "type": "integer",
              "minimum": 30000,
              "maximum": 32767,
              "title": "Helm Chart service port",
              "default": "31180"
            }
          }
        }
      }
    }
  }
}
@braghettos
Copy link
Member

What is the difference between the two?

@alfredo-milani-kiratech
Copy link
Author

A valid values file for the one associated with the value.schema.json is:

# @param {object} app Helm Chart parameters section
infra:
  # @param {string} app Helm Chart service parameters section
  env: dev
  # @param {boolean} app Helm Chart service parameters section
  svc: false

# @param {object} app Helm Chart parameters section
app:
  # @param {object} app Helm Chart service parameters section
  service:
    # @param {enum{NodePort,LoadBalancer}} app Helm Chart service type
    type: NodePort
    # @param {integer{min=30000,max=32767}} app Helm Chart service port
    port: 31180

But if I submit a CR, such as:

apiVersion: composition.krateo.io/v0-0-10
kind: Xapp
metadata:
  annotations:
    krateo.io/connector-verbose: "true"
    meta.helm.sh/release-namespace: krateo-system
  labels:
    app.kubernetes.io/managed-by: Helm
  name: x
  namespace: demo-system
spec:
  app:
    service:
      type: LoadBalancer
      port: 31555
  infra:
    env: dev
    svc: false

I got the following error:

Error from server (BadRequest): error when creating "xapp.cr.yaml": Xapp in version "v0-0-10" cannot be handled as a Xapp: strict decoding error: unknown field "spec.app.service"

Because the CRD has been installed on then cluster in a wrong way because it will accept a schema like:

apiVersion: composition.krateo.io/v0-0-10
kind: Xapp
metadata:
  annotations:
    krateo.io/connector-verbose: "true"
    meta.helm.sh/release-namespace: krateo-system
  labels:
    app.kubernetes.io/managed-by: Helm
  name: x
  namespace: demo-system
spec:
  app:
    env: dev
    svc: false
  infra:
    env: dev
    svc: false

But this is not the schema defined in the submitted CompositionDefinition.

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

3 participants