@@ -50,7 +50,6 @@ type ServiceReconciler struct {
50
50
client.Client
51
51
Scheme * runtime.Scheme
52
52
CrusoeClient * crusoeapi.APIClient
53
- HostInstance * crusoeapi.InstanceV1Alpha5
54
53
}
55
54
56
55
// +kubebuilder:rbac:groups=core,resources=services,verbs=get;list;watch;create;update;patch;delete
@@ -233,26 +232,28 @@ func (r *ServiceReconciler) handleCreate(ctx context.Context, svc *corev1.Servic
233
232
234
233
// Prepare payload for the API call
235
234
// get vpc id
236
- cluster , _ , err := r .CrusoeClient .KubernetesClustersApi .GetCluster (ctx , r .HostInstance .ProjectId , viper .GetString (CrusoeClusterIDFlag ))
235
+ projectId := viper .GetString (CrusoeProjectIDFlag )
236
+ cluster , _ , err := r .CrusoeClient .KubernetesClustersApi .GetCluster (ctx , projectId , viper .GetString (CrusoeClusterIDFlag ))
237
237
if err != nil {
238
238
logger .Error (err , "Failed to get cluster" , "clusterID" , viper .GetString (CrusoeClusterIDFlag ))
239
239
return ctrl.Result {}, err
240
240
}
241
- subnet , _ , err := r .CrusoeClient .VPCSubnetsApi .GetVPCSubnet (ctx , r . HostInstance . ProjectId , cluster .SubnetId )
241
+ subnet , _ , err := r .CrusoeClient .VPCSubnetsApi .GetVPCSubnet (ctx , projectId , cluster .SubnetId )
242
242
if err != nil {
243
243
logger .Error (err , "Failed to get vpc network id from cluster subnet id " , "subnetID" , cluster .SubnetId )
244
244
return ctrl.Result {}, err
245
245
}
246
+
246
247
apiPayload := crusoeapi.ExternalLoadBalancerPostRequest {
247
248
VpcId : subnet .VpcNetworkId ,
248
249
Name : svc .Name ,
249
- Location : r . HostInstance .Location ,
250
+ Location : subnet .Location ,
250
251
Protocol : "LOAD_BALANCER_PROTOCOL_TCP" , // only TCP supported currently
251
252
ListenPortsAndBackends : listenPortsAndBackends ,
252
253
HealthCheckOptions : healthCheckOptions ,
253
254
}
254
255
255
- op_resp , http_resp , err := r .CrusoeClient .ExternalLoadBalancersApi .CreateExternalLoadBalancer (ctx , apiPayload , r . HostInstance . ProjectId )
256
+ op_resp , http_resp , err := r .CrusoeClient .ExternalLoadBalancersApi .CreateExternalLoadBalancer (ctx , apiPayload , projectId )
256
257
if err != nil {
257
258
logger .Error (err , "Failed to create load balancer via API" )
258
259
return ctrl.Result {}, nil
@@ -264,7 +265,7 @@ func (r *ServiceReconciler) handleCreate(ctx context.Context, svc *corev1.Servic
264
265
}
265
266
266
267
op , err := utils .WaitForOperation (ctx , "Creating ELB ..." ,
267
- op_resp .Operation , r . HostInstance . ProjectId , r .CrusoeClient .ExternalLoadBalancerOperationsApi .GetExternalLoadBalancerOperation )
268
+ op_resp .Operation , projectId , r .CrusoeClient .ExternalLoadBalancerOperationsApi .GetExternalLoadBalancerOperation )
268
269
if err != nil || op .State != string (OpSuccess ) {
269
270
logger .Error (err , "Failed to create LB Service" , "name" , svc .Name , "namespace" , svc .Namespace )
270
271
return ctrl.Result {}, err
@@ -275,7 +276,7 @@ func (r *ServiceReconciler) handleCreate(ctx context.Context, svc *corev1.Servic
275
276
return ctrl.Result {}, err
276
277
}
277
278
278
- logger .Info ("GOT THIS BACK " , "http_resp" , op .Result )
279
+ logger .Info ("RESULT " , "http_resp" , op .Result )
279
280
// update external IP of LB svc
280
281
externalIP := loadBalancer .Vip
281
282
patch := client .MergeFrom (svc .DeepCopy ())
@@ -309,14 +310,9 @@ func (r *ServiceReconciler) handleDelete(ctx context.Context, svc *corev1.Servic
309
310
310
311
loadBalancerID := svc .Annotations [loadbalancerIDLabelKey ]
311
312
312
- if r .HostInstance == nil { // in case node hosting controller dies, need to re-grab
313
- hostInstance , crusoeClient , _ := GetHostInstance (context .Background ())
314
- r .HostInstance = hostInstance
315
- r .CrusoeClient = crusoeClient
316
- }
317
-
318
313
// Call the API to delete the load balancer
319
- _ , httpResp , err := r .CrusoeClient .ExternalLoadBalancersApi .DeleteExternalLoadBalancer (ctx , r .HostInstance .ProjectId , loadBalancerID )
314
+ projectId := viper .GetString (CrusoeProjectIDFlag )
315
+ _ , httpResp , err := r .CrusoeClient .ExternalLoadBalancersApi .DeleteExternalLoadBalancer (ctx , projectId , loadBalancerID )
320
316
if err != nil {
321
317
statusCode := httpResp .StatusCode
322
318
switch statusCode {
0 commit comments