Management Cluster (MC) upgrade fails with below error:
Installing the default ClusterClass...
Error: unable to install the default ClusterClass: failed to apply /home/<user-name>/.config/tanzu/tkg/clusterclassconfigs/tkg-vsphere-default-vX.X.X.yaml: kubectl apply failed
Error from server (Invalid): error when applying patch:
....
to:
Resource: "infrastructure.cluster.x-k8s.io/v1beta1, Resource=vspheremachinetemplates", GroupVersionKind: "infrastructure.cluster.x-k8s.io/v1beta1, Kind=VSphereMachineTemplate"
Name: "tkg-vsphere-default-vX.X.X-control-plane", Namespace: "tkg-system"
....
to:
Resource: "infrastructure.cluster.x-k8s.io/v1beta1, Resource=vspheremachinetemplates", GroupVersionKind: "infrastructure.cluster.x-k8s.io/v1beta1, Kind=VSphereMachineTemplate"
Name: "tkg-vsphere-default-vX.X.X-worker", Namespace: "tkg-system"
....
VSphereMachineTemplate spec.template.spec field is immutable. Please create a new resource instead.
The issue occurs when there's a mismatch between the .spec.template.spec
field in /home/<user-name>/.config/tanzu/tkg/clusterclassconfigs/tkg-vsphere-default-vX.X.X.yaml
and the "tkg-vsphere-default-vX.X.X-control-plane"
and "tkg-vsphere-default-vX.X.X-worker"
VSphereMachineTemplate objects in the cluster.
# kubectl get vspheremachinetemplate -n tkg-system
ubuntu@jumpbox:~$ kubectl get vspheremachinetemplate -n tkg-system
NAME AGE
mgmt-slot34rp35-control-plane-5fqnv 50d
mgmt-slot34rp35-md-0-infra-x2lkw 50d
tkg-vsphere-default-v1.1.1-control-plane 28h
tkg-vsphere-default-v1.1.1-worker 50d
.spec.template.spec
field in "tkg-vsphere-default-vX.X.X-control-plane"
and "tkg-vsphere-default-vX.X.X-worker"
VSphereMachineTemplate objects:# kubectl get vspheremachinetemplate -n tkg-system tkg-vsphere-default-vX.X.X-control-plane -o yaml
# kubectl get vspheremachinetemplate -n tkg-system tkg-vsphere-default-vX.X.X-worker -o yaml
ubuntu@jumpbox:~$ kubectl get vspheremachinetemplate -n tkg-system tkg-vsphere-default-v1.1.1-control-plane -o yaml
apiVersion: infrastructure.cluster.x-k8s.io/v1beta1
kind: VSphereMachineTemplate
metadata:
annotations:
kubectl.kubernetes.io/last-applied-configuration: |
{"apiVersion":"infrastructure.cluster.x-k8s.io/v1beta1","kind":"VSphereMachineTemplate","metadata":{"annotations":{},"creationTimestamp":"2024-06-26T15:53:12Z","generation":1,"name":"tkg-vsphere-default-v1.1.1-control-plane","namespace":"tkg-system","ownerReferences":[{"apiVersion":"cluster.x-k8s.io/v1beta1","kind":"ClusterClass","name":"tkg-vsphere-default-v1.1.1","uid":"<uid>"}],"resourceVersion":"4874","uid":"<uid>"},"spec":{"template":{"spec":{"cloneMode":"fullClone","datacenter":"/<datacenter-name>","datastore":"/<datastore-path>","diskGiB":40,"folder":"/<folder-path>","memoryMiB":8192,"network":{"devices":[{"dhcp4":true,"networkName":"/<network-name>"}]},"numCPUs":4,"resourcePool":"/<resourcePool-path>","server":"<server>","storagePolicyName":"","template":" "}}}}
creationTimestamp: "2024-08-15T10:00:01Z"
generation: 1
name: tkg-vsphere-default-v1.1.1-control-plane
namespace: tkg-system
ownerReferences:
- apiVersion: cluster.x-k8s.io/v1beta1
kind: ClusterClass
name: tkg-vsphere-default-v1.1.1
uid: <uid>
resourceVersion: "23975096"
uid: <uid>
spec:
template:
spec:
cloneMode: fullClone
datacenter: /<datacenter-name>
datastore: /<datastore-path>
diskGiB: 40
folder: /<folder-path>
memoryMiB: 8192
network:
devices:
- dhcp4: true
networkName: /<network-name>
numCPUs: 4
resourcePool: /<resourcePool-path>
server: <server>
storagePolicyName: ""
template: ' '
.spec.template.spec
field of the "tkg-vsphere-default-vX.X.X-control-plane"
and "tkg-vsphere-default-vX.X.X-worker"
VSphereMachineTemplate sections in /home/<user-name>/.config/tanzu/tkg/clusterclassconfigs/tkg-vsphere-default-vX.X.X.yaml
file with the above./home/<user-name>/.config/tanzu/tkg/clusterclassconfigs/tkg-vsphere-default-vX.X.X.yaml
contents come from secret "tkg-pkg-tkg-system-values"
in the tkg-system namespace.# kubectl get secret -n tkg-system tkg-pkg-tkg-system-values -o jsonpath='{.data.tkgpackagevalues\.yaml}' | base64 -d > tkgpackagevalues.yaml
tkgpackagevalues.yaml
file and look for the differences you located in step #3..spec.template.spec.resourcePool
is different, this field corresponds to "VSPHERE_RESOURCE_POOL"
in tkgpackagevalues.yaml
file.tkgpackagevalues.yaml
file with the correct ones:# vim tkgpackagevalues.yaml
"tkg-pkg-tkg-system-values"
secret with the new values:# kubectl patch secret -n tkg-system tkg-pkg-tkg-system-values --patch "{\"data\":{\"tkgpackagevalues.yaml\":\"$(base64 -w 0 tkgpackagevalues.yaml)\"}}"
# kubectl get secret -n tkg-system tkg-pkg-tkg-system-values -o jsonpath='{.data.tkgpackagevalues\.yaml}' | base64 -d
Next time you trigger the upgrade you shouldn't see the original error messages again as /home/<user-name>/.config/tanzu/tkg/clusterclassconfigs/tkg-vsphere-default-vX.X.X.yaml
file will have been updated with the new expected values.