@@ -50,6 +50,7 @@ import (
50
50
"github.com/openshift/hypershift/hypershift-operator/controllers/manifests/controlplaneoperator"
51
51
hyperutil "github.com/openshift/hypershift/hypershift-operator/controllers/util"
52
52
capiv1 "github.com/openshift/hypershift/thirdparty/clusterapi/api/v1alpha4"
53
+ capiawsv1 "github.com/openshift/hypershift/thirdparty/clusterapiprovideraws/v1alpha4"
53
54
)
54
55
55
56
const (
@@ -79,7 +80,7 @@ func (r *HostedClusterReconciler) SetupWithManager(mgr ctrl.Manager) error {
79
80
}
80
81
return ctrl .NewControllerManagedBy (mgr ).
81
82
For (& hyperv1.HostedCluster {}).
82
- Watches (& source.Kind {Type : & hyperv1. ExternalInfraCluster {}}, handler .EnqueueRequestsFromMapFunc (enqueueParentHostedCluster )).
83
+ Watches (& source.Kind {Type : & capiawsv1. AWSCluster {}}, handler .EnqueueRequestsFromMapFunc (enqueueParentHostedCluster )).
83
84
Watches (& source.Kind {Type : & hyperv1.HostedControlPlane {}}, handler .EnqueueRequestsFromMapFunc (enqueueParentHostedCluster )).
84
85
Watches (& source.Kind {Type : & capiv1.Cluster {}}, handler .EnqueueRequestsFromMapFunc (enqueueParentHostedCluster )).
85
86
WithOptions (controller.Options {
@@ -322,15 +323,6 @@ func (r *HostedClusterReconciler) Reconcile(ctx context.Context, req ctrl.Reques
322
323
}
323
324
}
324
325
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
-
334
326
// Reconcile the HostedControlPlane
335
327
hcp := controlplaneoperator .HostedControlPlane (controlPlaneNamespace .Name , hcluster .Name )
336
328
_ , err = controllerutil .CreateOrUpdate (ctx , r .Client , hcp , func () error {
@@ -340,10 +332,24 @@ func (r *HostedClusterReconciler) Reconcile(ctx context.Context, req ctrl.Reques
340
332
return ctrl.Result {}, fmt .Errorf ("failed to reconcile hostedcontrolplane: %w" , err )
341
333
}
342
334
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
+
343
349
// Reconcile the CAPI Cluster resource
344
350
capiCluster := controlplaneoperator .CAPICluster (controlPlaneNamespace .Name , hcluster .Spec .InfraID )
345
351
_ , err = controllerutil .CreateOrUpdate (ctx , r .Client , capiCluster , func () error {
346
- return reconcileCAPICluster (capiCluster , hcluster , hcp , externalInfraCluster )
352
+ return reconcileCAPICluster (capiCluster , hcluster , hcp , awsCluster )
347
353
})
348
354
if err != nil {
349
355
return ctrl.Result {}, fmt .Errorf ("failed to reconcile capi cluster: %w" , err )
@@ -522,7 +528,9 @@ func (r *HostedClusterReconciler) reconcileCAPIManager(ctx context.Context, hclu
522
528
// Reconcile CAPI manager deployment
523
529
capiManagerDeployment := clusterapi .ClusterAPIManagerDeployment (controlPlaneNamespace .Name )
524
530
_ , 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" )
526
534
})
527
535
if err != nil {
528
536
return fmt .Errorf ("failed to reconcile capi manager deployment: %w" , err )
@@ -568,7 +576,9 @@ func (r *HostedClusterReconciler) reconcileCAPIAWSProvider(ctx context.Context,
568
576
// Reconcile CAPI AWS provider deployment
569
577
capiAwsProviderDeployment := clusterapi .CAPIAWSProviderDeployment (controlPlaneNamespace .Name )
570
578
_ , 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" )
572
582
})
573
583
if err != nil {
574
584
return fmt .Errorf ("failed to reconcile capi aws provider deployment: %w" , err )
@@ -869,24 +879,27 @@ func reconcileControlPlaneOperatorRoleBinding(binding *rbacv1.RoleBinding, role
869
879
return nil
870
880
}
871
881
872
- func reconcileExternalInfraCluster ( eic * hyperv1. ExternalInfraCluster , hcluster * hyperv1.HostedCluster ) error {
882
+ func reconcileAWSCluster ( awsCluster * capiawsv1. AWSCluster , hcluster * hyperv1.HostedCluster , apiEndpoint hyperv1. APIEndpoint ) error {
873
883
// 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" ,
880
887
}
881
888
882
889
if hcluster .Spec .Platform .AWS != nil {
883
- eic .Spec .Region = hcluster .Spec .Platform .AWS .Region
890
+ awsCluster .Spec .Region = hcluster .Spec .Platform .AWS .Region
884
891
}
885
892
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
+ }
886
899
return nil
887
900
}
888
901
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 {
890
903
// We only create this resource once and then let CAPI own it
891
904
if ! cluster .CreationTimestamp .IsZero () {
892
905
return nil
@@ -905,8 +918,8 @@ func reconcileCAPICluster(cluster *capiv1.Cluster, hcluster *hyperv1.HostedClust
905
918
Name : hcp .Name ,
906
919
},
907
920
InfrastructureRef : & corev1.ObjectReference {
908
- APIVersion : "hypershift.openshift. io/v1alpha1 " ,
909
- Kind : "ExternalInfraCluster " ,
921
+ APIVersion : "infrastructure.cluster.x-k8s. io/v1alpha4 " ,
922
+ Kind : "AWSCluster " ,
910
923
Namespace : eic .Namespace ,
911
924
Name : eic .Name ,
912
925
},
@@ -947,7 +960,10 @@ func reconcileCAPIManagerDeployment(deployment *appsv1.Deployment, sa *corev1.Se
947
960
},
948
961
},
949
962
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" },
951
967
},
952
968
},
953
969
},
@@ -1005,8 +1021,6 @@ func reconcileCAPIManagerRole(role *rbacv1.Role) error {
1005
1021
Resources : []string {
1006
1022
"hostedcontrolplanes" ,
1007
1023
"hostedcontrolplanes/status" ,
1008
- "externalinfraclusters" ,
1009
- "externalinfraclusters/status" ,
1010
1024
},
1011
1025
Verbs : []string {"*" },
1012
1026
},
@@ -1101,7 +1115,11 @@ func reconcileCAPIAWSProviderDeployment(deployment *appsv1.Deployment, sa *corev
1101
1115
},
1102
1116
},
1103
1117
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
+ },
1105
1123
Ports : []corev1.ContainerPort {
1106
1124
{
1107
1125
Name : "healthz" ,
0 commit comments