krateoplatformops / krateo

Run your Resources on Every Cloud
217 stars 8 forks source link

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

Open alfredo-milani-kiratech opened 4 months ago

alfredo-milani-kiratech commented 4 months ago

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
  3. 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 commented 4 months ago

What is the difference between the two?

alfredo-milani-kiratech commented 4 months ago

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.