Skip to content

Commit

Permalink
Add apiVersion and kind for unstructured objects in "antctl mc" code (#…
Browse files Browse the repository at this point in the history
…5138)

Fix a deletion error during rollback after an antctl mc command failed:
"Failed to delete  kube-system/test-clusterset: Object 'Kind' is missing in
'unstructured object has no kind'".

apiVersion and kind are required fields in unstructured object to do deletion,
but DefaultUnstructuredConverter.ToUnstructured will not convert them
automatically.

Signed-off-by: Lan Luo <[email protected]>
  • Loading branch information
luolanzone authored Jun 29, 2023
1 parent fbfa97d commit dff1efd
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions pkg/antctl/raw/multicluster/common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ func CreateClusterClaim(cmd *cobra.Command, k8sClient client.Client, namespace s
} else {
fmt.Fprintf(cmd.OutOrStdout(), "ClusterClaim \"%s\" created in Namespace %s\n", multiclusterv1alpha2.WellKnownClusterClaimID, namespace)
unstructuredClusterClaim, _ = runtime.DefaultUnstructuredConverter.ToUnstructured(clusterClaim)
unstructuredClusterClaim["apiVersion"] = clusterClaim.APIVersion
unstructuredClusterClaim["kind"] = clusterClaim.Kind
*createdRes = append(*createdRes, unstructuredClusterClaim)
}

Expand All @@ -107,6 +109,8 @@ func CreateClusterClaim(cmd *cobra.Command, k8sClient client.Client, namespace s
} else {
fmt.Fprintf(cmd.OutOrStdout(), "ClusterClaim \"%s\" created in Namespace %s\n", multiclusterv1alpha2.WellKnownClusterClaimClusterSet, namespace)
unstructuredClusterClaim, _ = runtime.DefaultUnstructuredConverter.ToUnstructured(clusterClaim)
unstructuredClusterClaim["apiVersion"] = clusterClaim.APIVersion
unstructuredClusterClaim["kind"] = clusterClaim.Kind
*createdRes = append(*createdRes, unstructuredClusterClaim)
}

Expand All @@ -126,6 +130,8 @@ func CreateClusterSet(cmd *cobra.Command, k8sClient client.Client, namespace str
} else {
fmt.Fprintf(cmd.OutOrStdout(), "ClusterSet \"%s\" created in Namespace %s\n", clusterSet.Name, clusterSet.Namespace)
unstructuredClusterSet, _ := runtime.DefaultUnstructuredConverter.ToUnstructured(clusterSet)
unstructuredClusterSet["apiVersion"] = clusterSet.APIVersion
unstructuredClusterSet["kind"] = clusterSet.Kind
*createdRes = append(*createdRes, unstructuredClusterSet)
}

Expand Down Expand Up @@ -257,6 +263,8 @@ func CreateMemberToken(cmd *cobra.Command, k8sClient client.Client, name string,
} else {
fmt.Fprintf(cmd.OutOrStdout(), "ServiceAccount \"%s\" created\n", serviceAccount.Name)
unstructuredSA, _ := runtime.DefaultUnstructuredConverter.ToUnstructured(serviceAccount)
unstructuredSA["apiVersion"] = serviceAccount.APIVersion
unstructuredSA["kind"] = serviceAccount.Kind
*createdRes = append(*createdRes, unstructuredSA)
}

Expand All @@ -272,6 +280,8 @@ func CreateMemberToken(cmd *cobra.Command, k8sClient client.Client, name string,
} else {
fmt.Fprintf(cmd.OutOrStdout(), "RoleBinding \"%s\" created\n", roleBinding.Name)
unstructuredRoleBinding, _ := runtime.DefaultUnstructuredConverter.ToUnstructured(roleBinding)
unstructuredRoleBinding["apiVersion"] = roleBinding.APIVersion
unstructuredRoleBinding["kind"] = roleBinding.Kind
*createdRes = append(*createdRes, unstructuredRoleBinding)
}

Expand All @@ -286,6 +296,8 @@ func CreateMemberToken(cmd *cobra.Command, k8sClient client.Client, name string,
} else {
fmt.Fprintf(cmd.OutOrStdout(), "Secret \"%s\" created\n", secret.Name)
unstructuredSecret, _ := runtime.DefaultUnstructuredConverter.ToUnstructured(secret)
unstructuredSecret["apiVersion"] = secret.APIVersion
unstructuredSecret["kind"] = secret.Kind
*createdRes = append(*createdRes, unstructuredSecret)
}
// It will take one or two seconds to wait for the Data.token to be created.
Expand Down

0 comments on commit dff1efd

Please sign in to comment.