diff --git a/hypershift-operator/controllers/hostedcluster/hostedcluster_controller.go b/hypershift-operator/controllers/hostedcluster/hostedcluster_controller.go index 4530b3c1c8..d9f39d9140 100644 --- a/hypershift-operator/controllers/hostedcluster/hostedcluster_controller.go +++ b/hypershift-operator/controllers/hostedcluster/hostedcluster_controller.go @@ -38,6 +38,7 @@ import ( configv1 "github.com/openshift/api/config/v1" routev1 "github.com/openshift/api/route/v1" agentv1 "github.com/openshift/cluster-api-provider-agent/api/v1alpha1" + "github.com/openshift/hypershift/api" hyperv1 "github.com/openshift/hypershift/api/v1alpha1" "github.com/openshift/hypershift/control-plane-operator/controllers/hostedcontrolplane/kas" "github.com/openshift/hypershift/hypershift-operator/controllers/hostedcluster/internal/platform" @@ -81,6 +82,7 @@ import ( capiv1 "sigs.k8s.io/cluster-api/api/v1beta1" ctrl "sigs.k8s.io/controller-runtime" "sigs.k8s.io/controller-runtime/pkg/client" + "sigs.k8s.io/controller-runtime/pkg/client/apiutil" "sigs.k8s.io/controller-runtime/pkg/controller" "sigs.k8s.io/controller-runtime/pkg/controller/controllerutil" "sigs.k8s.io/controller-runtime/pkg/handler" @@ -2215,6 +2217,10 @@ func reconcileCAPICluster(cluster *capiv1.Cluster, hcluster *hyperv1.HostedClust if !cluster.CreationTimestamp.IsZero() { return nil } + infraCRGVK, err := apiutil.GVKForObject(infraCR, api.Scheme) + if err != nil { + return fmt.Errorf("failed to get gvk for %T: %w", infraCR, err) + } cluster.Annotations = map[string]string{ hostedClusterAnnotation: client.ObjectKeyFromObject(hcluster).String(), @@ -2228,8 +2234,8 @@ func reconcileCAPICluster(cluster *capiv1.Cluster, hcluster *hyperv1.HostedClust Name: hcp.Name, }, InfrastructureRef: &corev1.ObjectReference{ - APIVersion: infraCR.GetObjectKind().GroupVersionKind().GroupVersion().String(), - Kind: infraCR.GetObjectKind().GroupVersionKind().Kind, + APIVersion: infraCRGVK.GroupVersion().String(), + Kind: infraCRGVK.Kind, Namespace: infraCR.GetNamespace(), Name: infraCR.GetName(), }, diff --git a/hypershift-operator/controllers/hostedcluster/internal/platform/agent/agent.go b/hypershift-operator/controllers/hostedcluster/internal/platform/agent/agent.go index 7a0ac20572..8cbf113629 100644 --- a/hypershift-operator/controllers/hostedcluster/internal/platform/agent/agent.go +++ b/hypershift-operator/controllers/hostedcluster/internal/platform/agent/agent.go @@ -50,13 +50,6 @@ func (p Agent) ReconcileCAPIInfraCR(ctx context.Context, c client.Client, create return nil, err } - // reconciliation strips TypeMeta. We repopulate the static values since they are necessary for - // downstream reconciliation of the CAPI Cluster resource. - agentCluster.TypeMeta = metav1.TypeMeta{ - Kind: "AgentCluster", - APIVersion: agentv1.GroupVersion.String(), - } - return agentCluster, nil } diff --git a/hypershift-operator/controllers/hostedcluster/internal/platform/aws/aws.go b/hypershift-operator/controllers/hostedcluster/internal/platform/aws/aws.go index b09a2a05ec..49bed76708 100644 --- a/hypershift-operator/controllers/hostedcluster/internal/platform/aws/aws.go +++ b/hypershift-operator/controllers/hostedcluster/internal/platform/aws/aws.go @@ -44,12 +44,6 @@ func (p AWS) ReconcileCAPIInfraCR(ctx context.Context, c client.Client, createOr if err != nil { return nil, err } - // reconciliation strips TypeMeta. We repopulate the static values since they are necessary for - // downstream reconciliation of the CAPI Cluster resource. - awsCluster.TypeMeta = metav1.TypeMeta{ - Kind: "AWSCluster", - APIVersion: capiawsv1.GroupVersion.String(), - } return awsCluster, nil } diff --git a/hypershift-operator/controllers/hostedcluster/internal/platform/ibmcloud/ibmcloud.go b/hypershift-operator/controllers/hostedcluster/internal/platform/ibmcloud/ibmcloud.go index c9e39d2b32..ad39a31708 100644 --- a/hypershift-operator/controllers/hostedcluster/internal/platform/ibmcloud/ibmcloud.go +++ b/hypershift-operator/controllers/hostedcluster/internal/platform/ibmcloud/ibmcloud.go @@ -50,12 +50,6 @@ func (p IBMCloud) ReconcileCAPIInfraCR(ctx context.Context, c client.Client, cre if err != nil { return nil, err } - // reconciliation strips TypeMeta. We repopulate the static values since they are necessary for - // downstream reconciliation of the CAPI Cluster resource. - ibmCluster.TypeMeta = metav1.TypeMeta{ - Kind: "IBMVPCCluster", - APIVersion: capiibmv1.GroupVersion.String(), - } return ibmCluster, nil } diff --git a/hypershift-operator/controllers/hostedcluster/internal/platform/kubevirt/kubevirt.go b/hypershift-operator/controllers/hostedcluster/internal/platform/kubevirt/kubevirt.go index ed940897c4..a0cda013cc 100644 --- a/hypershift-operator/controllers/hostedcluster/internal/platform/kubevirt/kubevirt.go +++ b/hypershift-operator/controllers/hostedcluster/internal/platform/kubevirt/kubevirt.go @@ -38,10 +38,6 @@ func (p Kubevirt) ReconcileCAPIInfraCR(ctx context.Context, c client.Client, cre }); err != nil { return nil, err } - kubevirtCluster.TypeMeta = metav1.TypeMeta{ - Kind: "KubevirtCluster", - APIVersion: capikubevirt.GroupVersion.String(), - } return kubevirtCluster, nil } diff --git a/hypershift-operator/controllers/hostedcluster/internal/platform/kubevirt/kubevirt_test.go b/hypershift-operator/controllers/hostedcluster/internal/platform/kubevirt/kubevirt_test.go index 43fb1a815a..5fc4cae1af 100644 --- a/hypershift-operator/controllers/hostedcluster/internal/platform/kubevirt/kubevirt_test.go +++ b/hypershift-operator/controllers/hostedcluster/internal/platform/kubevirt/kubevirt_test.go @@ -34,10 +34,6 @@ func TestReconcileCAPIInfraCR(t *testing.T) { capiv1.ManagedByAnnotation: "external", }, }, - TypeMeta: metav1.TypeMeta{ - Kind: "KubevirtCluster", - APIVersion: capikubevirt.GroupVersion.String(), - }, Status: capikubevirt.KubevirtClusterStatus{ Ready: true, },