rancher-sandbox / cluster-api-provider-harvester

A Cluster API Infrastructure Provider for Harvester
Apache License 2.0
21 stars 6 forks source link

nil pointer exception occurs when a Harvester Kubeconfig has current-context != cluster.name #48

Closed belgaied2 closed 2 months ago

belgaied2 commented 2 months ago

What happened: Every time the Identity Secret to authenticate against Harvester has a current-context value doesn't exist in the name keys of the cluster section, the CAPHV controller will fail with nil pointer error.

What did you expect to happen: I expected that the Controller would continue to reconcile normally without CrashLooping.

How to reproduce it: Put in the cluster manifests, an identity secret that has different names for current-context and cluster.name and apply manifest to management cluster.

Anything else you would like to add: Problem is happening at this line in the code: https://github.com/rancher-sandbox/cluster-api-provider-harvester/blob/db1ee42374c58575ddf1b38d7f3f4222c0c397f4/controllers/harvestercluster_controller.go#L573 . Server is looked up in the cluster section of the kubeconfig using the current-context value, which might be different than the cluster.name matching it.

More generally, the whole section of the code seems to lack checking against nil values, which might cause the Crash Loop.

Environment:

belgaied2 commented 2 months ago

Fixed as of commit 5642e2aed6fa2bf705041fa6c8c7abd77807130f.