@@ -48,11 +48,6 @@ import (
48
48
mcsv1a1 "sigs.k8s.io/mcs-api/pkg/apis/v1alpha1"
49
49
)
50
50
51
- const (
52
- serviceUnavailable = "ServiceUnavailable"
53
- invalidServiceType = "UnsupportedServiceType"
54
- )
55
-
56
51
type AgentConfig struct {
57
52
ServiceImportCounterName string
58
53
ServiceExportCounterName string
@@ -213,8 +208,8 @@ func (a *Controller) serviceExportToServiceImport(obj runtime.Object, _ int, op
213
208
if err != nil {
214
209
// some other error. Log and requeue
215
210
a .serviceExportClient .UpdateStatusConditions (ctx , svcExport .Name , svcExport .Namespace ,
216
- newServiceExportCondition (mcsv1a1 .ServiceExportValid , metav1 .ConditionUnknown , "ServiceRetrievalFailed" ,
217
- fmt .Sprintf ("Error retrieving the Service: %v" , err )))
211
+ mcsv1a1 . NewServiceExportCondition (mcsv1a1 .ServiceExportConditionValid , metav1 .ConditionUnknown ,
212
+ ServiceExportReasonRetrievalFailed , fmt .Sprintf ("Error retrieving the Service: %v" , err )))
218
213
logger .Errorf (err , "Error retrieving Service %s/%s" , svcExport .Namespace , svcExport .Name )
219
214
220
215
return nil , true
@@ -223,8 +218,8 @@ func (a *Controller) serviceExportToServiceImport(obj runtime.Object, _ int, op
223
218
if ! found {
224
219
logger .V (log .DEBUG ).Infof ("Service to be exported (%s/%s) doesn't exist" , svcExport .Namespace , svcExport .Name )
225
220
a .serviceExportClient .UpdateStatusConditions (ctx , svcExport .Name , svcExport .Namespace ,
226
- newServiceExportCondition (mcsv1a1 .ServiceExportValid , metav1 .ConditionFalse , serviceUnavailable ,
227
- "Service to be exported doesn't exist" ))
221
+ mcsv1a1 . NewServiceExportCondition (mcsv1a1 .ServiceExportConditionValid , metav1 .ConditionFalse ,
222
+ mcsv1a1 . ServiceExportReasonNoService , "Service to be exported doesn't exist" ))
228
223
229
224
return nil , false
230
225
}
@@ -235,8 +230,8 @@ func (a *Controller) serviceExportToServiceImport(obj runtime.Object, _ int, op
235
230
236
231
if ! ok {
237
232
a .serviceExportClient .UpdateStatusConditions (ctx , svcExport .Name , svcExport .Namespace ,
238
- newServiceExportCondition (mcsv1a1 .ServiceExportValid , metav1 .ConditionFalse , invalidServiceType ,
239
- fmt .Sprintf ("Service of type %v not supported" , svc .Spec .Type )))
233
+ mcsv1a1 . NewServiceExportCondition (mcsv1a1 .ServiceExportConditionValid , metav1 .ConditionFalse ,
234
+ mcsv1a1 . ServiceExportReasonInvalidServiceType , fmt .Sprintf ("Service of type %v not supported" , svc .Spec .Type )))
240
235
logger .Errorf (nil , "Service type %q not supported for Service (%s/%s)" , svc .Spec .Type , svcExport .Namespace , svcExport .Name )
241
236
242
237
err = a .localServiceImportFederator .Delete (ctx , a .newServiceImport (svcExport .Name , svcExport .Namespace ))
@@ -286,8 +281,8 @@ func (a *Controller) serviceExportToServiceImport(obj runtime.Object, _ int, op
286
281
svcExport .Namespace , svcExport .Name )
287
282
// Globalnet enabled but service doesn't have globalIp yet - update the status.
288
283
a .serviceExportClient .UpdateStatusConditions (ctx , svcExport .Name , svcExport .Namespace ,
289
- newServiceExportCondition (mcsv1a1 .ServiceExportValid , metav1 .ConditionFalse , ingressIP . unallocatedReason ,
290
- ingressIP .unallocatedMsg ))
284
+ mcsv1a1 . NewServiceExportCondition (mcsv1a1 .ServiceExportConditionValid , metav1 .ConditionFalse ,
285
+ ingressIP .unallocatedReason , ingressIP . unallocatedMsg ))
291
286
292
287
return nil , false
293
288
}
@@ -299,12 +294,12 @@ func (a *Controller) serviceExportToServiceImport(obj runtime.Object, _ int, op
299
294
}
300
295
301
296
a .serviceExportClient .UpdateStatusConditions (ctx , svcExport .Name , svcExport .Namespace ,
302
- newServiceExportCondition (mcsv1a1 .ServiceExportValid , metav1 .ConditionTrue , ExportValidReason , "" ))
297
+ mcsv1a1 . NewServiceExportCondition (mcsv1a1 .ServiceExportConditionValid , metav1 .ConditionTrue , mcsv1a1 . ServiceExportReasonValid , "" ))
303
298
304
- if a .serviceImportController .determineUseClusterSetIP (serviceImport ) &&
305
- slices .Contains (svc .Spec .IPFamilies , corev1 .IPv6Protocol ) {
299
+ if a .serviceImportController .determineUseClusterSetIP (serviceImport ) && slices .Contains (svc .Spec .IPFamilies , corev1 .IPv6Protocol ) {
306
300
a .serviceExportClient .UpdateStatusConditions (ctx , svcExport .Name , svcExport .Namespace ,
307
- newServiceExportCondition (constants .ServiceExportReady , metav1 .ConditionFalse , UnsupportedIPFamilyReason ,
301
+ mcsv1a1 .NewServiceExportCondition (mcsv1a1 .ServiceExportConditionReady , metav1 .ConditionFalse ,
302
+ ServiceExportReasonUnsupportedIPFamily ,
308
303
fmt .Sprintf ("Service has IP families %v and clusterset IP is enabled but only IPv4 is supported" ,
309
304
svc .Spec .IPFamilies )))
310
305
@@ -335,8 +330,8 @@ func (a *Controller) shouldProcessServiceExportUpdate(oldObj, newObj *unstructur
335
330
return true
336
331
}
337
332
338
- oldValidCond := meta .FindStatusCondition (a .toServiceExport (oldObj ).Status .Conditions , mcsv1a1 .ServiceExportValid )
339
- newValidCond := meta .FindStatusCondition (a .toServiceExport (newObj ).Status .Conditions , mcsv1a1 .ServiceExportValid )
333
+ oldValidCond := meta .FindStatusCondition (a .toServiceExport (oldObj ).Status .Conditions , string ( mcsv1a1 .ServiceExportConditionValid ) )
334
+ newValidCond := meta .FindStatusCondition (a .toServiceExport (newObj ).Status .Conditions , string ( mcsv1a1 .ServiceExportConditionValid ) )
340
335
341
336
if newValidCond != nil && ! reflect .DeepEqual (oldValidCond , newValidCond ) && newValidCond .Status == metav1 .ConditionFalse {
342
337
return true
@@ -371,8 +366,8 @@ func (a *Controller) serviceToRemoteServiceImport(obj runtime.Object, _ int, op
371
366
372
367
// Update the status and requeue
373
368
a .serviceExportClient .UpdateStatusConditions (context .Background (), svc .Name , svc .Namespace ,
374
- newServiceExportCondition (mcsv1a1 .ServiceExportValid , metav1 .ConditionFalse , serviceUnavailable ,
375
- "Service to be exported doesn't exist" ))
369
+ mcsv1a1 . NewServiceExportCondition (mcsv1a1 .ServiceExportConditionValid , metav1 .ConditionFalse ,
370
+ mcsv1a1 . ServiceExportReasonNoService , "Service to be exported doesn't exist" ))
376
371
377
372
return serviceImport , false
378
373
}
@@ -422,7 +417,7 @@ func (a *Controller) getIngressIP(name, namespace string) *IngressIP {
422
417
if ret == nil {
423
418
ret = & IngressIP {
424
419
namespace : namespace ,
425
- unallocatedReason : defaultReasonIPUnavailable ,
420
+ unallocatedReason : ServiceExportReasonGlobalIPUnavailable ,
426
421
unallocatedMsg : defaultMsgIPUnavailable ,
427
422
}
428
423
}
@@ -434,16 +429,6 @@ func (a *Controller) toServiceExport(obj runtime.Object) *mcsv1a1.ServiceExport
434
429
return a .serviceImportController .converter .toServiceExport (obj )
435
430
}
436
431
437
- func newServiceExportCondition (condType string , status metav1.ConditionStatus , reason , msg string ) metav1.Condition {
438
- return metav1.Condition {
439
- Type : condType ,
440
- Status : status ,
441
- LastTransitionTime : metav1 .Now (),
442
- Reason : reason ,
443
- Message : msg ,
444
- }
445
- }
446
-
447
432
func (c converter ) toServiceImport (obj runtime.Object ) * mcsv1a1.ServiceImport {
448
433
to := & mcsv1a1.ServiceImport {}
449
434
utilruntime .Must (c .scheme .Convert (obj , to , nil ))
0 commit comments