Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automatically infer infra cr GVK #927

Merged
merged 1 commit into from
Jan 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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