rancher-sandbox / cluster-api-addon-provider-fleet

Cluster API Add-on Provider for Fleet will auto register child clusters with fleet.
Apache License 2.0
2 stars 3 forks source link

Error when reconciling cluster that uses cluster class #21

Closed richardcase closed 2 months ago

richardcase commented 2 months ago

When the provider reconciles the following cluster definition:

apiVersion: cluster.x-k8s.io/v1beta1
kind: Cluster
metadata:
  name: cluster1
  namespace: default
  labels:
    cni: kindnet
    env: "dev"
spec:
  clusterNetwork:
    pods:
      cidrBlocks:
      - 192.168.0.0/16
    serviceDomain: cluster.local
    services:
      cidrBlocks:
      - 10.128.0.0/12
  topology:
    class: quick-start
    controlPlane:
      metadata: {}
      replicas: 1
    variables:
    - name: imageRepository
      value: ""
    - name: etcdImageTag
      value: ""
    - name: coreDNSImageTag
      value: ""
    - name: podSecurityStandard
      value:
        audit: restricted
        enabled: true
        enforce: baseline
        warn: restricted
    version: v1.28.0
    workers:
      machineDeployments:
      - class: default-worker
        name: md-0
        replicas: 1

I am seeing the following error:

2024-04-24T08:45:30.604910Z  WARN kube_client::client: {"apiVersion":"cluster.x-k8s.io/v1beta1","items":[{"apiVersion":"cluster.x-k8s.io/v1beta1","kind":"Cluster","metadata":{"annotations":{"kubectl.kubernetes.io/last-applied-configuration":"{\"apiVersion\":\"cluster.x-k8s.io/v1beta1\",\"kind\":\"Cluster\",\"metadata\":{\"annotations\":{},\"labels\":{\"cni\":\"kindnet\",\"env\":\"dev\"},\"name\":\"cluster1\",\"namespace\":\"default\"},\"spec\":{\"clusterNetwork\":{\"pods\":{\"cidrBlocks\":[\"192.168.0.0/16\"]},\"serviceDomain\":\"cluster.local\",\"services\":{\"cidrBlocks\":[\"10.128.0.0/12\"]}},\"topology\":{\"class\":\"quick-start\",\"controlPlane\":{\"metadata\":{},\"replicas\":1},\"variables\":[{\"name\":\"imageRepository\",\"value\":\"\"},{\"name\":\"etcdImageTag\",\"value\":\"\"},{\"name\":\"coreDNSImageTag\",\"value\":\"\"},{\"name\":\"podSecurityStandard\",\"value\":{\"audit\":\"restricted\",\"enabled\":true,\"enforce\":\"baseline\",\"warn\":\"restricted\"}}],\"version\":\"v1.28.0\",\"workers\":{\"machineDeployments\":[{\"class\":\"default-worker\",\"name\":\"md-0\",\"replicas\":1}]}}}}\n"},"creationTimestamp":"2024-04-24T06:55:48Z","finalizers":["cluster.cluster.x-k8s.io"],"generation":3,"labels":{"cluster.x-k8s.io/cluster-name":"cluster1","cni":"kindnet","env":"dev","topology.cluster.x-k8s.io/owned":""},"managedFields":[{"apiVersion":"cluster.x-k8s.io/v1beta1","fieldsType":"FieldsV1","fieldsV1":{"f:metadata":{"f:labels":{"f:cluster.x-k8s.io/cluster-name":{},"f:topology.cluster.x-k8s.io/owned":{}}},"f:spec":{"f:controlPlaneRef":{},"f:infrastructureRef":{}}},"manager":"capi-topology","operation":"Apply","time":"2024-04-24T06:55:48Z"},{"apiVersion":"cluster.x-k8s.io/v1beta1","fieldsType":"FieldsV1","fieldsV1":{"f:metadata":{"f:annotations":{".":{},"f:kubectl.kubernetes.io/last-applied-configuration":{}},"f:labels":{".":{},"f:cni":{},"f:env":{}}},"f:spec":{".":{},"f:clusterNetwork":{".":{},"f:pods":{".":{},"f:cidrBlocks":{}},"f:serviceDomain":{},"f:services":{".":{},"f:cidrBlocks":{}}},"f:topology":{".":{},"f:class":{},"f:controlPlane":{".":{},"f:metadata":{},"f:replicas":{}},"f:variables":{},"f:version":{},"f:workers":{".":{},"f:machineDeployments":{}}}}},"manager":"kubectl-client-side-apply","operation":"Update","time":"2024-04-24T06:55:48Z"},{"apiVersion":"cluster.x-k8s.io/v1beta1","fieldsType":"FieldsV1","fieldsV1":{"f:metadata":{"f:finalizers":{".":{},"v:\"cluster.cluster.x-k8s.io\"":{}}},"f:spec":{"f:controlPlaneEndpoint":{"f:host":{},"f:port":{}}}},"manager":"manager","operation":"Update","time":"2024-04-24T06:55:48Z"},{"apiVersion":"cluster.x-k8s.io/v1beta1","fieldsType":"FieldsV1","fieldsV1":{"f:status":{".":{},"f:conditions":{},"f:controlPlaneReady":{},"f:infrastructureReady":{},"f:observedGeneration":{},"f:phase":{}}},"manager":"manager","operation":"Update","subresource":"status","time":"2024-04-24T06:57:07Z"}],"name":"cluster1","namespace":"default","resourceVersion":"5371","uid":"d8f0cf88-38f8-4360-8e25-c55d8c727905"},"spec":{"clusterNetwork":{"pods":{"cidrBlocks":["192.168.0.0/16"]},"serviceDomain":"cluster.local","services":{"cidrBlocks":["10.128.0.0/12"]}},"controlPlaneEndpoint":{"host":"172.19.0.3","port":6443},"controlPlaneRef":{"apiVersion":"controlplane.cluster.x-k8s.io/v1beta1","kind":"KubeadmControlPlane","name":"cluster1-cdhv9","namespace":"default"},"infrastructureRef":{"apiVersion":"infrastructure.cluster.x-k8s.io/v1beta1","kind":"DockerCluster","name":"cluster1-vdwrk","namespace":"default"},"topology":{"class":"quick-start","controlPlane":{"metadata":{},"replicas":1},"variables":[{"name":"imageRepository","value":""},{"name":"etcdImageTag","value":""},{"name":"coreDNSImageTag","value":""},{"name":"podSecurityStandard","value":{"audit":"restricted","enabled":true,"enforce":"baseline","warn":"restricted"}}],"version":"v1.28.0","workers":{"machineDeployments":[{"class":"default-worker","metadata":{},"name":"md-0","replicas":1}]}}},"status":{"conditions":[{"lastTransitionTime":"2024-04-24T06:56:53Z","status":"True","type":"Ready"},{"lastTransitionTime":"2024-04-24T06:56:53Z","status":"True","type":"ControlPlaneInitialized"},{"lastTransitionTime":"2024-04-24T06:56:53Z","status":"True","type":"ControlPlaneReady"},{"lastTransitionTime":"2024-04-24T06:55:48Z","status":"True","type":"InfrastructureReady"},{"lastTransitionTime":"2024-04-24T06:55:48Z","status":"True","type":"TopologyReconciled"}],"controlPlaneReady":true,"infrastructureReady":true,"observedGeneration":3,"phase":"Provisioned"}}],"kind":"ClusterList","metadata":{"continue":"","resourceVersion":"35668"}}
, Error("invalid type: string \"\", expected a map", line: 1, column: 3559)

Looking at the column position it relates to the empty value in this part:

{"name":"imageRepository","value":""}

And then looking at the where value is defined:

I am using kpoium v0.18.0

richardcase commented 2 months ago

I think we get the same problem with ClusterClass as well because it uses the same struct, for example: https://github.com/kubernetes-sigs/cluster-api/blob/main/api/v1beta1/clusterclass_types.go#L429