Skip to content

Commit

Permalink
Merge pull request #927 from alvaroaleman/infer
Browse files Browse the repository at this point in the history
Automatically infer infra cr GVK
  • Loading branch information
openshift-merge-robot committed Jan 28, 2022
2 parents 8859e19 + ed51415 commit 20f42df
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 29 deletions.
Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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(),
Expand All @@ -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(),
},
Expand Down
Expand Up @@ -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
}

Expand Down
Expand Up @@ -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
}

Expand Down
Expand Up @@ -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
}

Expand Down
Expand Up @@ -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
}
Expand Down
Expand Up @@ -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,
},
Expand Down

0 comments on commit 20f42df

Please sign in to comment.