Skip to content

Commit c5f4ec8

Browse files
committed
Drop ExternalInfraCluster CRD in favour of AWSCluster
This PR drops the ExternalInfraCluster CRD in favour of AWSCluster. Originally we added support for externally managed infra in CAPA via the ExternalInfraCluster CRD kubernetes-sigs/cluster-api-provider-aws#2124 and we used that commit of CAPA in hypershift. Later on we decided to revert that approach upstream and reuse the existing ${infra}Cluster CRDs with an annotation to support externally managed infrastructure kubernetes-sigs/cluster-api#4135 This PR bring latest CAPI/CAPA with one additional patch on top kubernetes-sigs/cluster-api#4709 kubernetes-sigs/cluster-api-provider-aws#2453 to avoid running webhooks. As a follow up we need to rebuild the images from the main branch once those patches are merged or otherwise enable webhooks.
1 parent e0fcae6 commit c5f4ec8

File tree

6 files changed

+51
-189
lines changed

6 files changed

+51
-189
lines changed

hypershift-operator/controllers/externalinfracluster/externalinfracluster_controller.go

Lines changed: 0 additions & 149 deletions
This file was deleted.

hypershift-operator/controllers/hostedcluster/hostedcluster_controller.go

Lines changed: 46 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ import (
5050
"github.com/openshift/hypershift/hypershift-operator/controllers/manifests/controlplaneoperator"
5151
hyperutil "github.com/openshift/hypershift/hypershift-operator/controllers/util"
5252
capiv1 "github.com/openshift/hypershift/thirdparty/clusterapi/api/v1alpha4"
53+
capiawsv1 "github.com/openshift/hypershift/thirdparty/clusterapiprovideraws/v1alpha4"
5354
)
5455

5556
const (
@@ -79,7 +80,7 @@ func (r *HostedClusterReconciler) SetupWithManager(mgr ctrl.Manager) error {
7980
}
8081
return ctrl.NewControllerManagedBy(mgr).
8182
For(&hyperv1.HostedCluster{}).
82-
Watches(&source.Kind{Type: &hyperv1.ExternalInfraCluster{}}, handler.EnqueueRequestsFromMapFunc(enqueueParentHostedCluster)).
83+
Watches(&source.Kind{Type: &capiawsv1.AWSCluster{}}, handler.EnqueueRequestsFromMapFunc(enqueueParentHostedCluster)).
8384
Watches(&source.Kind{Type: &hyperv1.HostedControlPlane{}}, handler.EnqueueRequestsFromMapFunc(enqueueParentHostedCluster)).
8485
Watches(&source.Kind{Type: &capiv1.Cluster{}}, handler.EnqueueRequestsFromMapFunc(enqueueParentHostedCluster)).
8586
WithOptions(controller.Options{
@@ -322,15 +323,6 @@ func (r *HostedClusterReconciler) Reconcile(ctx context.Context, req ctrl.Reques
322323
}
323324
}
324325

325-
// Reconcile the CAPI ExternalInfraCluster
326-
externalInfraCluster := controlplaneoperator.ExternalInfraCluster(controlPlaneNamespace.Name, hcluster.Name)
327-
_, err = controllerutil.CreateOrUpdate(ctx, r.Client, externalInfraCluster, func() error {
328-
return reconcileExternalInfraCluster(externalInfraCluster, hcluster)
329-
})
330-
if err != nil {
331-
return ctrl.Result{}, fmt.Errorf("failed to reconcile externalinfracluster: %w", err)
332-
}
333-
334326
// Reconcile the HostedControlPlane
335327
hcp := controlplaneoperator.HostedControlPlane(controlPlaneNamespace.Name, hcluster.Name)
336328
_, err = controllerutil.CreateOrUpdate(ctx, r.Client, hcp, func() error {
@@ -340,10 +332,24 @@ func (r *HostedClusterReconciler) Reconcile(ctx context.Context, req ctrl.Reques
340332
return ctrl.Result{}, fmt.Errorf("failed to reconcile hostedcontrolplane: %w", err)
341333
}
342334

335+
// Reconcile external AWSCluster
336+
if err := r.Client.Get(ctx, client.ObjectKeyFromObject(hcp), hcp); err != nil {
337+
r.Log.Error(err, "failed to get control plane ref")
338+
return reconcile.Result{}, err
339+
}
340+
341+
awsCluster := controlplaneoperator.ExternalInfraCluster(controlPlaneNamespace.Name, hcluster.Name)
342+
_, err = controllerutil.CreateOrPatch(ctx, r.Client, awsCluster, func() error {
343+
return reconcileAWSCluster(awsCluster, hcluster, hcp.Status.ControlPlaneEndpoint)
344+
})
345+
if err != nil {
346+
return ctrl.Result{}, fmt.Errorf("failed to reconcile AWSCluster: %w", err)
347+
}
348+
343349
// Reconcile the CAPI Cluster resource
344350
capiCluster := controlplaneoperator.CAPICluster(controlPlaneNamespace.Name, hcluster.Spec.InfraID)
345351
_, err = controllerutil.CreateOrUpdate(ctx, r.Client, capiCluster, func() error {
346-
return reconcileCAPICluster(capiCluster, hcluster, hcp, externalInfraCluster)
352+
return reconcileCAPICluster(capiCluster, hcluster, hcp, awsCluster)
347353
})
348354
if err != nil {
349355
return ctrl.Result{}, fmt.Errorf("failed to reconcile capi cluster: %w", err)
@@ -522,7 +528,9 @@ func (r *HostedClusterReconciler) reconcileCAPIManager(ctx context.Context, hclu
522528
// Reconcile CAPI manager deployment
523529
capiManagerDeployment := clusterapi.ClusterAPIManagerDeployment(controlPlaneNamespace.Name)
524530
_, err = controllerutil.CreateOrUpdate(ctx, r.Client, capiManagerDeployment, func() error {
525-
return reconcileCAPIManagerDeployment(capiManagerDeployment, capiManagerServiceAccount, "quay.io/hypershift/cluster-api:hypershift")
531+
// TODO (alberto): This image builds from https://github.com/kubernetes-sigs/cluster-api/pull/4709
532+
// We need to build from main branch and push to quay.io/hypershift once this is merged or otherwise enable webhooks.
533+
return reconcileCAPIManagerDeployment(capiManagerDeployment, capiManagerServiceAccount, "quay.io/enxebre/capi:latest")
526534
})
527535
if err != nil {
528536
return fmt.Errorf("failed to reconcile capi manager deployment: %w", err)
@@ -568,7 +576,9 @@ func (r *HostedClusterReconciler) reconcileCAPIAWSProvider(ctx context.Context,
568576
// Reconcile CAPI AWS provider deployment
569577
capiAwsProviderDeployment := clusterapi.CAPIAWSProviderDeployment(controlPlaneNamespace.Name)
570578
_, err = controllerutil.CreateOrUpdate(ctx, r.Client, capiAwsProviderDeployment, func() error {
571-
return reconcileCAPIAWSProviderDeployment(capiAwsProviderDeployment, capiAwsProviderServiceAccount, "quay.io/hypershift/cluster-api-provider-aws:master")
579+
// TODO (alberto): This image builds from https://github.com/kubernetes-sigs/cluster-api-provider-aws/pull/2453
580+
// We need to build from main branch and push to quay.io/hypershift once this is merged or otherwise enable webhooks.
581+
return reconcileCAPIAWSProviderDeployment(capiAwsProviderDeployment, capiAwsProviderServiceAccount, "quay.io/enxebre/capiaws:latest")
572582
})
573583
if err != nil {
574584
return fmt.Errorf("failed to reconcile capi aws provider deployment: %w", err)
@@ -869,24 +879,27 @@ func reconcileControlPlaneOperatorRoleBinding(binding *rbacv1.RoleBinding, role
869879
return nil
870880
}
871881

872-
func reconcileExternalInfraCluster(eic *hyperv1.ExternalInfraCluster, hcluster *hyperv1.HostedCluster) error {
882+
func reconcileAWSCluster(awsCluster *capiawsv1.AWSCluster, hcluster *hyperv1.HostedCluster, apiEndpoint hyperv1.APIEndpoint) error {
873883
// We only create this resource once and then let CAPI own it
874-
if !eic.CreationTimestamp.IsZero() {
875-
return nil
876-
}
877-
878-
eic.Annotations = map[string]string{
879-
hostedClusterAnnotation: ctrlclient.ObjectKeyFromObject(hcluster).String(),
884+
awsCluster.Annotations = map[string]string{
885+
hostedClusterAnnotation: ctrlclient.ObjectKeyFromObject(hcluster).String(),
886+
capiv1.ManagedByAnnotation: "external",
880887
}
881888

882889
if hcluster.Spec.Platform.AWS != nil {
883-
eic.Spec.Region = hcluster.Spec.Platform.AWS.Region
890+
awsCluster.Spec.Region = hcluster.Spec.Platform.AWS.Region
884891
}
885892

893+
// Set the values for upper level controller
894+
awsCluster.Status.Ready = true
895+
awsCluster.Spec.ControlPlaneEndpoint = capiv1.APIEndpoint{
896+
Host: apiEndpoint.Host,
897+
Port: apiEndpoint.Port,
898+
}
886899
return nil
887900
}
888901

889-
func reconcileCAPICluster(cluster *capiv1.Cluster, hcluster *hyperv1.HostedCluster, hcp *hyperv1.HostedControlPlane, eic *hyperv1.ExternalInfraCluster) error {
902+
func reconcileCAPICluster(cluster *capiv1.Cluster, hcluster *hyperv1.HostedCluster, hcp *hyperv1.HostedControlPlane, eic *capiawsv1.AWSCluster) error {
890903
// We only create this resource once and then let CAPI own it
891904
if !cluster.CreationTimestamp.IsZero() {
892905
return nil
@@ -905,8 +918,8 @@ func reconcileCAPICluster(cluster *capiv1.Cluster, hcluster *hyperv1.HostedClust
905918
Name: hcp.Name,
906919
},
907920
InfrastructureRef: &corev1.ObjectReference{
908-
APIVersion: "hypershift.openshift.io/v1alpha1",
909-
Kind: "ExternalInfraCluster",
921+
APIVersion: "infrastructure.cluster.x-k8s.io/v1alpha4",
922+
Kind: "AWSCluster",
910923
Namespace: eic.Namespace,
911924
Name: eic.Name,
912925
},
@@ -947,7 +960,10 @@ func reconcileCAPIManagerDeployment(deployment *appsv1.Deployment, sa *corev1.Se
947960
},
948961
},
949962
Command: []string{"/manager"},
950-
Args: []string{"--namespace", "$(MY_NAMESPACE)", "--alsologtostderr", "--v=4"},
963+
Args: []string{"--namespace", "$(MY_NAMESPACE)",
964+
"--alsologtostderr",
965+
"--webhook-port=0",
966+
"--v=4"},
951967
},
952968
},
953969
},
@@ -1005,8 +1021,6 @@ func reconcileCAPIManagerRole(role *rbacv1.Role) error {
10051021
Resources: []string{
10061022
"hostedcontrolplanes",
10071023
"hostedcontrolplanes/status",
1008-
"externalinfraclusters",
1009-
"externalinfraclusters/status",
10101024
},
10111025
Verbs: []string{"*"},
10121026
},
@@ -1101,7 +1115,11 @@ func reconcileCAPIAWSProviderDeployment(deployment *appsv1.Deployment, sa *corev
11011115
},
11021116
},
11031117
Command: []string{"/manager"},
1104-
Args: []string{"--namespace", "$(MY_NAMESPACE)", "--alsologtostderr", "--v=4"},
1118+
Args: []string{"--namespace", "$(MY_NAMESPACE)",
1119+
"--alsologtostderr",
1120+
"--v=4",
1121+
"--webhook-port=0",
1122+
},
11051123
Ports: []corev1.ContainerPort{
11061124
{
11071125
Name: "healthz",

hypershift-operator/controllers/manifests/controlplaneoperator/manifests.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package controlplaneoperator
22

33
import (
4+
capiawsv1 "github.com/openshift/hypershift/thirdparty/clusterapiprovideraws/v1alpha4"
45
appsv1 "k8s.io/api/apps/v1"
56
corev1 "k8s.io/api/core/v1"
67
rbacv1 "k8s.io/api/rbac/v1"
@@ -80,8 +81,8 @@ func HostedControlPlane(controlPlaneNamespace string, hostedClusterName string)
8081
}
8182
}
8283

83-
func ExternalInfraCluster(controlPlaneNamespace string, hostedClusterName string) *hyperv1.ExternalInfraCluster {
84-
return &hyperv1.ExternalInfraCluster{
84+
func ExternalInfraCluster(controlPlaneNamespace string, hostedClusterName string) *capiawsv1.AWSCluster {
85+
return &capiawsv1.AWSCluster{
8586
ObjectMeta: metav1.ObjectMeta{
8687
Namespace: controlPlaneNamespace,
8788
Name: hostedClusterName,

hypershift-operator/controllers/nodepool/manifests.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import (
55

66
hyperv1 "github.com/openshift/hypershift/api/v1alpha1"
77
capiv1 "github.com/openshift/hypershift/thirdparty/clusterapi/api/v1alpha4"
8-
capiaws "github.com/openshift/hypershift/thirdparty/clusterapiprovideraws/v1alpha3"
8+
capiaws "github.com/openshift/hypershift/thirdparty/clusterapiprovideraws/v1alpha4"
99
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1010
k8sutilspointer "k8s.io/utils/pointer"
1111
ctrlclient "sigs.k8s.io/controller-runtime/pkg/client"

hypershift-operator/controllers/nodepool/nodepool_controller.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import (
1414
capiv1 "github.com/openshift/hypershift/thirdparty/clusterapi/api/v1alpha4"
1515
"github.com/openshift/hypershift/thirdparty/clusterapi/util"
1616
"github.com/openshift/hypershift/thirdparty/clusterapi/util/patch"
17-
capiaws "github.com/openshift/hypershift/thirdparty/clusterapiprovideraws/v1alpha3"
17+
capiaws "github.com/openshift/hypershift/thirdparty/clusterapiprovideraws/v1alpha4"
1818
"github.com/pkg/errors"
1919
corev1 "k8s.io/api/core/v1"
2020
"k8s.io/apimachinery/pkg/api/equality"

hypershift-operator/main.go

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import (
2323

2424
hyperapi "github.com/openshift/hypershift/api"
2525
"github.com/openshift/hypershift/control-plane-operator/releaseinfo"
26-
"github.com/openshift/hypershift/hypershift-operator/controllers/externalinfracluster"
2726
"github.com/openshift/hypershift/hypershift-operator/controllers/hostedcluster"
2827
"github.com/openshift/hypershift/hypershift-operator/controllers/machineconfigserver"
2928
"github.com/openshift/hypershift/hypershift-operator/controllers/nodepool"
@@ -172,13 +171,6 @@ func NewStartCommand() *cobra.Command {
172171
os.Exit(1)
173172
}
174173

175-
if err := (&externalinfracluster.ExternalInfraClusterReconciler{
176-
Client: mgr.GetClient(),
177-
}).SetupWithManager(mgr); err != nil {
178-
setupLog.Error(err, "unable to create controller", "controller", "ExternalInfraCluster")
179-
os.Exit(1)
180-
}
181-
182174
// +kubebuilder:scaffold:builder
183175

184176
setupLog.Info("starting manager")

0 commit comments

Comments
 (0)