@@ -34,6 +34,7 @@ import (
3434 "sigs.k8s.io/controller-runtime/pkg/handler"
3535
3636 infrav1 "sigs.k8s.io/cluster-api-provider-packet/api/v1beta1"
37+ "sigs.k8s.io/cluster-api-provider-packet/internal/emlb"
3738 packet "sigs.k8s.io/cluster-api-provider-packet/pkg/cloud/packet"
3839 "sigs.k8s.io/cluster-api-provider-packet/pkg/cloud/packet/scope"
3940)
@@ -114,49 +115,63 @@ func (r *PacketClusterReconciler) reconcileNormal(ctx context.Context, clusterSc
114115
115116 packetCluster := clusterScope .PacketCluster
116117
117- ipReserv , err := r .PacketClient .GetIPByClusterIdentifier (ctx , clusterScope .Namespace (), clusterScope .Name (), packetCluster .Spec .ProjectID )
118118 switch {
119- case errors .Is (err , packet .ErrControlPlanEndpointNotFound ):
120- // Parse metro and facility from the cluster spec
121- var metro , facility string
122-
123- facility = packetCluster .Spec .Facility
124- metro = packetCluster .Spec .Metro
125-
126- // If both specified, metro takes precedence over facility
127- if metro != "" {
128- facility = ""
119+ case packetCluster .Spec .VIPManager == emlb .EMLBVIPID :
120+ if ! packetCluster .Spec .ControlPlaneEndpoint .IsValid () {
121+ // Create new EMLB object
122+ lb := emlb .NewEMLB (r .PacketClient .GetConfig ().DefaultHeader ["X-Auth-Token" ], packetCluster .Spec .ProjectID , packetCluster .Spec .Metro )
123+
124+ if err := lb .ReconcileLoadBalancer (ctx , clusterScope ); err != nil {
125+ log .Error (err , "Error Reconciling EMLB" )
126+ return err
127+ }
129128 }
130-
131- // There is not an ElasticIP with the right tags, at this point we can create one
132- ip , err := r .PacketClient .CreateIP (ctx , clusterScope .Namespace (), clusterScope .Name (), packetCluster .Spec .ProjectID , facility , metro )
133- if err != nil {
134- log .Error (err , "error reserving an ip" )
129+ case packetCluster .Spec .VIPManager == "KUBE_VIP" :
130+ log .Info ("KUBE_VIP VIPManager Detected" )
131+ if err := r .PacketClient .EnableProjectBGP (ctx , packetCluster .Spec .ProjectID ); err != nil {
132+ log .Error (err , "error enabling bgp for project" )
135133 return err
136134 }
137- clusterScope .PacketCluster .Spec .ControlPlaneEndpoint = clusterv1.APIEndpoint {
138- Host : ip .To4 ().String (),
139- Port : 6443 ,
140- }
141- case err != nil :
142- log .Error (err , "error getting cluster IP" )
143- return err
144- default :
145- // If there is an ElasticIP with the right tag just use it again
146- clusterScope .PacketCluster .Spec .ControlPlaneEndpoint = clusterv1.APIEndpoint {
147- Host : ipReserv .GetAddress (),
148- Port : 6443 ,
149- }
150135 }
151136
152- if clusterScope .PacketCluster .Spec .VIPManager == "KUBE_VIP" {
153- if err := r .PacketClient .EnableProjectBGP (ctx , packetCluster .Spec .ProjectID ); err != nil {
154- log .Error (err , "error enabling bgp for project" )
137+ if packetCluster .Spec .VIPManager != emlb .EMLBVIPID {
138+ ipReserv , err := r .PacketClient .GetIPByClusterIdentifier (ctx , clusterScope .Namespace (), clusterScope .Name (), packetCluster .Spec .ProjectID )
139+ switch {
140+ case errors .Is (err , packet .ErrControlPlanEndpointNotFound ):
141+ // Parse metro and facility from the cluster spec
142+ var metro , facility string
143+
144+ facility = packetCluster .Spec .Facility
145+ metro = packetCluster .Spec .Metro
146+
147+ // If both specified, metro takes precedence over facility
148+ if metro != "" {
149+ facility = ""
150+ }
151+
152+ // There is not an ElasticIP with the right tags, at this point we can create one
153+ ip , err := r .PacketClient .CreateIP (ctx , clusterScope .Namespace (), clusterScope .Name (), packetCluster .Spec .ProjectID , facility , metro )
154+ if err != nil {
155+ log .Error (err , "error reserving an ip" )
156+ return err
157+ }
158+ packetCluster .Spec .ControlPlaneEndpoint = clusterv1.APIEndpoint {
159+ Host : ip .To4 ().String (),
160+ Port : 6443 ,
161+ }
162+ case err != nil :
163+ log .Error (err , "error getting cluster IP" )
155164 return err
165+ default :
166+ // If there is an ElasticIP with the right tag just use it again
167+ packetCluster .Spec .ControlPlaneEndpoint = clusterv1.APIEndpoint {
168+ Host : ipReserv .GetAddress (),
169+ Port : 6443 ,
170+ }
156171 }
157172 }
158173
159- clusterScope . PacketCluster .Status .Ready = true
174+ packetCluster .Status .Ready = true
160175 conditions .MarkTrue (packetCluster , infrav1 .NetworkInfrastructureReadyCondition )
161176
162177 return nil
0 commit comments