Skip to content
This repository has been archived by the owner on Dec 15, 2022. It is now read-only.

Cluster created from composition gets to an invalid state #63

Open
renescheepers opened this issue Jun 2, 2022 · 0 comments
Open

Cluster created from composition gets to an invalid state #63

renescheepers opened this issue Jun 2, 2022 · 0 comments
Labels
bug Something isn't working

Comments

@renescheepers
Copy link

What happened?

Creating a cluster using a composition results in a cluster with the wrong defaults being created. It's not possible to delete the cluster without manually fixing the issue.

How can we reproduce it?

XRD

apiVersion: apiextensions.crossplane.io/v1
kind: CompositeResourceDefinition
metadata:
  name: xclusters.shopify.com
  labels:
    app: crossplane-the-cloud
spec:
  group: shopify.com
  names:
    kind: XCluster
    plural: xclusters
  claimNames:
    kind: ClusterInstance
    plural: clusterinstances
  versions:
  - name: v1
    served: true
    referenceable: true
    additionalPrinterColumns:
      - name: Status
        type: string
        jsonPath: .status.status
      - name: Tier
        type: string
        jsonPath: .spec.parameters.tier
      - name: Role
        type: string
        jsonPath: .spec.parameters.role
      - name: Environment
        type: string
        jsonPath: .spec.parameters.environment
    schema:
      openAPIV3Schema:
        type: object
        properties:
          spec:
            required:
              - parameters
            properties:
              parameters:
                type: object
                properties:
                  tier:
                    description: Tier label
                    type: string
                  role:
                    description: Role label
                    type: string
                  environment: 
                    description: Environment the cluster is in
                    type: string
                  project:
                    description: In which project the cluster must be provisioned.
                    type: string
                  location:
                    description: Region or zone.
                    type: string
                  kubernetesVersion: 
                    description: Master version to use.
                    type: string
                  networkProject:
                    description: Project the network is hosted in.
                    type: string
                  network:
                    description: Name of the network.
                    type: string
                  maxPodsPerNode:
                    description: Maximum amount of pods per node.
                    type: number    
                  releaseChannel:
                    description: TODO
                    type: string
                required:
                  - tier
                  - role
                  - environment
                  - project
                  - location
                  - kubernetesVersion
                  - network
                  - networkProject
          status:
            type: object
            properties:
              status:
                description: Status of the cluster
                type: string

Composition

---
apiVersion: apiextensions.crossplane.io/v1
kind: Composition
metadata:
  name: cluster-composition-v1
  labels:
    app: crossplane-the-cloud
    crossplane.io/xrd: xclusters.shopify.com
    provider: gcp
spec:
  compositeTypeRef:
    apiVersion: shopify.com/v1
    kind: XCluster
  resources:
    - name: cluster
      base:
        apiVersion: container.gcp.jet.crossplane.io/v1alpha2
        kind: Cluster
        spec:
          forProvider:
            loggingService: none
            monitoringService: none
            # loggingConfig: [] # Uncommenting these fixes the problem
            # monitoringConfig: [] # Uncommenting these fixes the problem
            # nodeVersion: null # Uncommenting these fixes the problem
            binaryAuthorization:
              enabled: true
            ipAllocationPolicy:
              - clusterSecondaryRangeName: pods
                servicesSecondaryRangeName: services
            networkPolicy:
              - enabled: true
            # Needed when not creating a default node pool in the cluster.
            initialNodeCount: 1
            removeDefaultNodePool: true
      patches:
        # GCP Project
        - fromFieldPath: spec.parameters.project
          toFieldPath: spec.providerConfigRef.name
        # Make sure name in GCP matches name of claim.
        - fromFieldPath: metadata.annotations[crossplane.io/external-name]
          toFieldPath: metadata.annotations[crossplane.io/external-name]
        # Kubernetes version
        - fromFieldPath: spec.parameters.kubernetesVersion
          toFieldPath: spec.forProvider.minMasterVersion
        # Location
        - fromFieldPath: spec.parameters.location
          toFieldPath: spec.forProvider.location
        # Network
        - type: CombineFromComposite
          combine:
            variables:
              - fromFieldPath: spec.parameters.networkProject
              - fromFieldPath: spec.parameters.network
            strategy: string
            string:
              fmt: "projects/%s/global/networks/%s"
          toFieldPath: spec.forProvider.network
        # Subnetwork
        - fromFieldPath: metadata.annotations[crossplane.io/external-name]
          toFieldPath: spec.forProvider.subnetwork
        # Max pods per node
        - fromFieldPath: spec.parameters.maxPodsPerNode
          toFieldPath: spec.forProvider.defaultMaxPodsPerNode
        # Release channel
        - fromFieldPath: spec.parameters.releaseChannel
          toFieldPath: spec.forProvider.releaseChannel[0].channel
        # Tier label region
        - fromFieldPath: spec.parameters.tier
          toFieldPath: spec.forProvider.resourceLabels[tier]
        # Role label region
        - fromFieldPath: spec.parameters.role
          toFieldPath: spec.forProvider.resourceLabels[role]
        # Environment label region
        - fromFieldPath: spec.parameters.environment
          toFieldPath: spec.forProvider.resourceLabels[environment]
        # Resource label region
        - fromFieldPath: spec.parameters.location
          toFieldPath: spec.forProvider.resourceLabels[region]
        # Use managed resource status
        - type: ToCompositeFieldPath
          fromFieldPath: status.conditions[0].type
          toFieldPath: status.status

Claim

apiVersion: shopify.com/v1
kind: ClusterInstance
metadata:
  namespace: demo
  name: testing-cluster
  annotations:
    crossplane.io/external-name: testing-cluster
spec:
  compositionRef:
    name: cluster-composition-v1
  parameters:
    tier: infra
    role: sandbox
    environment: staging
    project: demo
    location: europe-west1
    kubernetesVersion: 1.22.9-gke.1300
    networkProject: demo
    network: default
    releaseChannel: RAPID
    maxPodsPerNode: 16

Result

apiVersion: container.gcp.jet.crossplane.io/v1alpha2
kind: Cluster
metadata:
  annotations:
    crossplane.io/composition-resource-name: cluster
    crossplane.io/external-create-pending: "2022-06-02T10:02:38Z"
    crossplane.io/external-create-succeeded: "2022-06-02T10:02:38Z"
    crossplane.io/external-name: testing-cluster
    terrajet.crossplane.io/provider-meta: '{"e2bfb730-ecaa-11e6-8f88-34363bc7c4c0":{"create":2400000000000,"delete":2400000000000,"read":2400000000000,"update":3600000000000},"schema_version":"1"}'
  creationTimestamp: "2022-06-02T10:02:36Z"
  finalizers:
  - finalizer.managedresource.crossplane.io
  generateName: testing-cluster-nqbvr-
  generation: 2
  labels:
    crossplane.io/claim-name: testing-cluster
    crossplane.io/claim-namespace: demo
    crossplane.io/composite: testing-cluster-nqbvr
  name: testing-cluster-nqbvr-69xkv
  ownerReferences:
  - apiVersion: shopify.com/v1
    controller: true
    kind: XCluster
    name: testing-cluster-nqbvr
    uid: 56318be5-d991-465d-b00d-327cbccfab63
  resourceVersion: "47119382"
  uid: 1ff7e76c-fd36-4766-9cd7-0614576ffe2a
spec:
  deletionPolicy: Delete
  forProvider:
    addonsConfig:
    - networkPolicyConfig:
      - disabled: false
    clusterAutoscaling:
    - enabled: false
    databaseEncryption:
    - state: DECRYPTED
    defaultMaxPodsPerNode: 16
    defaultSnatStatus:
    - disabled: false
    enableShieldedNodes: true
    initialNodeCount: 1
    ipAllocationPolicy:
    - clusterSecondaryRangeName: pods
      servicesSecondaryRangeName: services
    location: europe-west1
    loggingConfig:
    - enableComponents: []
    loggingService: none
    masterAuth:
    - clientCertificateConfig:
      - issueClientCertificate: false
    minMasterVersion: 1.22.9-gke.1300
    monitoringConfig:
    - enableComponents: []
    monitoringService: none
    network: projects/demo/global/networks/default
    networkPolicy:
    - enabled: true
    networkingMode: VPC_NATIVE
    nodeLocations:
    - europe-west1-b
    - europe-west1-c
    - europe-west1-d
    nodeVersion: 1.22.9-gke.1300
    project: demo
    releaseChannel:
    - channel: RAPID
    removeDefaultNodePool: true
    resourceLabels:
      environment: staging
      region: europe-west1
      role: sandbox
      tier: infra
    subnetwork: testing-cluster
  providerConfigRef:
    name: demo
status:
  atProvider:
    endpoint: 34.140.186.155
    id: projects/demo/locations/europe-west1/clusters/testing-cluster
    labelFingerprint: 702edb19
    masterVersion: 1.22.9-gke.1300
    selfLink: https://container.googleapis.com/v1/projects/demo/locations/europe-west1/clusters/testing-cluster
    servicesIpv4Cidr: 242.31.69.0/25
    tpuIpv4CidrBlock: ""
  conditions:
  - lastTransitionTime: "2022-06-02T10:09:10Z"
    reason: Available
    status: "True"
    type: Ready
  - lastTransitionTime: "2022-06-02T10:09:14Z"
    message: |-
      observe failed: cannot run refresh: refresh failed: Missing required argument: The argument "enable_components" is required, but no definition was found.: File name: main.tf.json
      Missing required argument: The argument "enable_components" is required, but no definition was found.: File name: main.tf.json
    reason: ReconcileError
    status: "False"
    type: Synced
  - lastTransitionTime: "2022-06-02T10:09:06Z"
    reason: Finished
    status: "True"
    type: AsyncOperation
  - lastTransitionTime: "2022-06-02T10:09:06Z"
    reason: Success
    status: "True"
    type: LastAsyncOperation
  • lastTransitionTime: "2022-06-02T10:09:14Z"
    message: |-
    observe failed: cannot run refresh: refresh failed: Missing required argument: The argument "enable_components" is required, but no definition was found.: File name: main.tf.json
    Missing required argument: The argument "enable_components" is required, but no definition was found.: File name: main.tf.json

What environment did it happen in?

Crossplane version: 1.8.0
Provider version: crossplane/provider-jet-gcp:v0.2.0-preview
Kubernetes version: v1.22.6-gke.300
Kubernetes distribution: GKE

@renescheepers renescheepers added the bug Something isn't working label Jun 2, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant