Skip to content

Commit

Permalink
feat: explicitly check for cluster labels
Browse files Browse the repository at this point in the history
Signed-off-by: Carlos Salas <[email protected]>
  • Loading branch information
salasberryfin committed Feb 16, 2024
1 parent ac48e7e commit 5a2706f
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion internal/controllers/import_controller_v3.go
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,23 @@ func (r *CAPIImportManagementV3Reconciler) rancherClusterToCapiCluster(ctx conte
log := log.FromContext(ctx)

return func(_ context.Context, o client.Object) []ctrl.Request {
labels := o.GetLabels()
cluster, ok := o.(*managementv3.Cluster)
if !ok {
log.Error(nil, fmt.Sprintf("Expected a rancher cluster but got a %T", o))
return nil
}

labels := cluster.GetLabels()
if _, ok := labels[capiClusterOwner]; !ok {
log.Error(fmt.Errorf("missing label %s", capiClusterOwner), "getting rancher cluster labels")
return nil
}

if _, ok := labels[capiClusterOwnerNamespace]; !ok {
log.Error(fmt.Errorf("missing label %s", capiClusterOwnerNamespace), "getting rancher cluster labels")
return nil
}

capiCluster := &clusterv1.Cluster{ObjectMeta: metav1.ObjectMeta{
Name: labels[capiClusterOwner],
Namespace: labels[capiClusterOwnerNamespace],
Expand Down

0 comments on commit 5a2706f

Please sign in to comment.