@@ -20,8 +20,7 @@ type NamespaceAction interface {
2020 MethodName () string
2121 GetNamespaceEntity (nsTypeService EnvironmentTypeService ) (* tenant.Namespace , error )
2222 UpdateNamespace (env * environment.EnvData , cluster * cluster.Cluster , namespace * tenant.Namespace , failed bool )
23- GetOperationSets (toSort environment.Objects , client Client , namespaceName string ) (OperationSet , error )
24- Filter () FilterFunc
23+ GetOperationSets (envService EnvironmentTypeService , client Client ) (* environment.EnvData , []OperationSet , error )
2524 ForceMasterTokenGlobally () bool
2625 HealingStrategy () HealingFuncGenerator
2726 ManageAndUpdateResults (errorChan chan error , envTypes []environment.Type , healing Healing ) error
@@ -91,11 +90,29 @@ func (c *commonNamespaceAction) MethodName() string {
9190 return c .method
9291}
9392
94- func (c * commonNamespaceAction ) GetOperationSets (toSort environment.Objects , client Client , namespaceName string ) (OperationSet , error ) {
95- operationSets := OperationSet {}
96- sort .Sort (environment .ByKind (toSort ))
97- operationSets [c .method ] = toSort
98- return operationSets , nil
93+ func (c * commonNamespaceAction ) getOperationSets (envService EnvironmentTypeService , client Client , filterFunc FilterFunc ) (* environment.EnvData , []OperationSet , error ) {
94+ env , objects , err := envService .GetEnvDataAndObjects (filterFunc )
95+ if err != nil {
96+ return env , nil , errors .Wrap (err , "getting environment data and objects failed" )
97+ }
98+
99+ operationSets := []OperationSet {NewOperationSet (c .method , objects )}
100+
101+ object , shouldBeAdded := envService .AdditionalObject ()
102+ if len (object ) > 0 {
103+ action := c .method
104+ if ! shouldBeAdded {
105+ action = http .MethodDelete
106+ }
107+ if action == c .method {
108+ operationSets [0 ].Objects = append (operationSets [0 ].Objects , object )
109+ } else {
110+ operationSets = append (operationSets , NewOperationSet (action , []environment.Object {object }))
111+ }
112+ }
113+
114+ sort .Sort (environment .ByKind (operationSets [0 ].Objects ))
115+ return env , operationSets , nil
99116}
100117
101118func (c * commonNamespaceAction ) Filter () FilterFunc {
@@ -210,6 +227,10 @@ func (c *CreateAction) ForceMasterTokenGlobally() bool {
210227 return false
211228}
212229
230+ func (c * CreateAction ) GetOperationSets (envService EnvironmentTypeService , client Client ) (* environment.EnvData , []OperationSet , error ) {
231+ return c .getOperationSets (envService , client , c .Filter ())
232+ }
233+
213234func NewDeleteAction (tenantRepo tenant.Repository , existingNamespaces []* tenant.Namespace , deleteOpts * DeleteActionOption ) * DeleteAction {
214235 return & DeleteAction {
215236 withExistingNamespacesAction : & withExistingNamespacesAction {
@@ -269,50 +290,58 @@ var AllToGetAndDelete = []string{environment.ValKindService}
269290
270291var AllKindsToClean = append (AllToDeleteAll , AllToGetAndDelete ... )
271292
272- func (d * DeleteAction ) GetOperationSets (toSort environment.Objects , client Client , namespaceName string ) (OperationSet , error ) {
273- operationSets := OperationSet {}
293+ func (d * DeleteAction ) GetOperationSets (envService EnvironmentTypeService , client Client ) (* environment.EnvData , []OperationSet , error ) {
294+ env , objectsToDelete , err := envService .GetEnvDataAndObjects (d .Filter ())
295+ if err != nil {
296+ return env , nil , errors .Wrap (err , "getting environment data and objects failed" )
297+ }
298+ var operationSets []OperationSet
299+
274300 if ! d .deleteOptions .removeFromCluster {
275301 var deleteAllSet environment.Objects
276302 for _ , kind := range AllToDeleteAll {
277- obj := newObject (kind , namespaceName , "" )
303+ obj := NewObject (kind , envService . GetNamespaceName () , "" )
278304 deleteAllSet = append (deleteAllSet , obj )
279305 }
280306 sort .Sort (sort .Reverse (environment .ByKind (deleteAllSet )))
281- operationSets [ MethodDeleteAll ] = deleteAllSet
307+ operationSets = append ( operationSets , NewOperationSet ( MethodDeleteAll , deleteAllSet ))
282308
283309 for _ , kind := range AllToGetAndDelete {
284- kindToGet := newObject (kind , namespaceName , "" )
310+ kindToGet := NewObject (kind , envService . GetNamespaceName () , "" )
285311 result , err := Apply (client , http .MethodGet , kindToGet )
286312 if err != nil {
287- return nil , errors .Wrapf (err , "unable to get list of current objects of kind %s in namespace %s" , kindToGet , namespaceName )
313+ return env , nil , errors .Wrapf (err ,
314+ "unable to get list of current objects of kind %s in namespace %s" , kindToGet , envService .GetNamespaceName ())
288315 }
289316 var returnedObj environment.Object
290317 err = yaml .Unmarshal (result .Body , & returnedObj )
291318 if err != nil {
292- return nil , errors .Wrapf (err ,
293- "unable unmarshal object responded from OS while getting list of current objects of kind %s in namespace %s" , kindToGet , namespaceName )
319+ return env , nil , errors .Wrapf (err , "unable unmarshal object responded from OS " +
320+ "while getting list of current objects of kind %s in namespace %s" , kindToGet , envService . GetNamespaceName () )
294321 }
295322
296323 if items , itemsFound := returnedObj ["items" ]; itemsFound {
297324 if objects , isSlice := items .([]interface {}); isSlice && len (objects ) > 0 {
298325 for _ , obj := range objects {
299326 if object , isObj := obj .(environment.Object ); isObj {
300327 if name := environment .GetName (object ); name != "" {
301- toSort = append (toSort , newObject (kind , namespaceName , name ))
328+ objectsToDelete = append (objectsToDelete , NewObject (kind , envService . GetNamespaceName () , name ))
302329 }
303330 }
304331 }
305332 }
306333 }
307334 }
308335 }
309- sort .Sort (sort .Reverse (environment .ByKind (toSort )))
310- operationSets [d .method ] = toSort
311336
312- return operationSets , nil
337+ sort .Sort (sort .Reverse (environment .ByKind (objectsToDelete )))
338+ deleteOpSet := NewOperationSet (d .method , objectsToDelete )
339+ operationSets = append (operationSets , deleteOpSet )
340+
341+ return env , operationSets , nil
313342}
314343
315- func newObject (kind , namespaceName string , name string ) environment.Object {
344+ func NewObject (kind , namespaceName string , name string ) environment.Object {
316345 return environment.Object {
317346 "kind" : kind ,
318347 "metadata" : environment.Object {
@@ -411,6 +440,10 @@ func (u *UpdateAction) Filter() FilterFunc {
411440 return isNotOfKind (environment .ValKindProjectRequest )
412441}
413442
443+ func (u * UpdateAction ) GetOperationSets (envService EnvironmentTypeService , client Client ) (* environment.EnvData , []OperationSet , error ) {
444+ return u .getOperationSets (envService , client , u .Filter ())
445+ }
446+
414447func (u * UpdateAction ) HealingStrategy () HealingFuncGenerator {
415448 return u .redoStrategy (func (openShiftService * ServiceBuilder , nsTypes []environment.Type , existingNamespaces []* tenant.Namespace ) error {
416449 return openShiftService .Update (nsTypes , existingNamespaces , u .actionOptions .DisableSelfHealing ())
0 commit comments