@@ -31,12 +31,7 @@ import (
31
31
32
32
type UpdateFunc func (object client.Object ) (bool , error )
33
33
34
- func IsServiceAvailable (m api.LifeCycleLabelManager , target client.Object ) bool {
35
- _ , exists := target .GetLabels ()[m .Get (api .ServiceAvailableLabel )]
36
- return exists
37
- }
38
-
39
- // IDToLabelsMap returns a map of pod id to labels map and a map of operation type to number of pods.
34
+ // IDToLabelsMap returns a map of target id to labels map and a map of operation type to number of targets.
40
35
func IDToLabelsMap (m * LabelManagerImpl , target client.Object ) (map [string ]map [string ]string , map [string ]int , error ) {
41
36
idToLabelsMap := map [string ]map [string ]string {}
42
37
typeToNumsMap := map [string ]int {}
@@ -77,7 +72,7 @@ func IDToLabelsMap(m *LabelManagerImpl, target client.Object) (map[string]map[st
77
72
return idToLabelsMap , typeToNumsMap , nil
78
73
}
79
74
80
- // NumOfLifecycleOnTarget returns the nums of lifecycles on pod
75
+ // NumOfLifecycleOnTarget returns the nums of lifecycles on target
81
76
func NumOfLifecycleOnTarget (m * LabelManagerImpl , target client.Object ) (int , error ) {
82
77
if target == nil {
83
78
return 0 , nil
@@ -310,6 +305,21 @@ func IsLifecycleOnTarget(m api.LifeCycleLabelManager, operatingID string, target
310
305
return false , nil
311
306
}
312
307
308
+ func CancelOpsLifecycle (m api.LifeCycleLabelManager , client client.Client , adapter api.LifecycleAdapter , target client.Object ) error {
309
+ if target == nil {
310
+ return nil
311
+ }
312
+
313
+ // only cancel when lifecycle exist on target
314
+ if exist , err := IsLifecycleOnTarget (m , adapter .GetID (), target ); err != nil {
315
+ return fmt .Errorf ("fail to check %s TargetOpsLifecycle on Target %s/%s: %w" , adapter .GetID (), target .GetNamespace (), target .GetName (), err )
316
+ } else if ! exist {
317
+ return nil
318
+ }
319
+
320
+ return Undo (m , client , adapter , target )
321
+ }
322
+
313
323
func DefaultUpdateAll (target client.Object , updateFuncs ... UpdateFunc ) (updated bool , err error ) {
314
324
for _ , updateFunc := range updateFuncs {
315
325
ok , updateErr := updateFunc (target )
0 commit comments