@@ -152,10 +152,11 @@ func WithResourceModificationChecker(enabled bool, diffResults *diff.DiffResultL
152
152
}
153
153
154
154
// WithNamespaceCreation will create non-exist namespace
155
- func WithNamespaceCreation (createNamespace bool , namespaceModifier func (* unstructured.Unstructured ) bool ) SyncOpt {
155
+ func WithNamespaceCreation (createNamespace bool , namespaceModifier func (* unstructured.Unstructured ) bool , namespaceCreator func ( * unstructured. Unstructured ) bool ) SyncOpt {
156
156
return func (ctx * syncContext ) {
157
157
ctx .createNamespace = createNamespace
158
158
ctx .namespaceModifier = namespaceModifier
159
+ ctx .namespaceCreator = namespaceCreator
159
160
}
160
161
}
161
162
@@ -349,6 +350,7 @@ type syncContext struct {
349
350
350
351
createNamespace bool
351
352
namespaceModifier func (* unstructured.Unstructured ) bool
353
+ namespaceCreator func (* unstructured.Unstructured ) bool
352
354
353
355
syncWaveHook common.SyncWaveHook
354
356
@@ -792,7 +794,9 @@ func (sc *syncContext) autoCreateNamespace(tasks syncTasks) syncTasks {
792
794
}
793
795
}
794
796
} else if apierr .IsNotFound (err ) {
795
- tasks = append (tasks , & syncTask {phase : common .SyncPhasePreSync , targetObj : unstructuredObj , liveObj : nil })
797
+ if sc .namespaceCreator (unstructuredObj ) {
798
+ tasks = append (tasks , & syncTask {phase : common .SyncPhasePreSync , targetObj : unstructuredObj , liveObj : nil })
799
+ }
796
800
} else {
797
801
task := & syncTask {phase : common .SyncPhasePreSync , targetObj : unstructuredObj }
798
802
sc .setResourceResult (task , common .ResultCodeSyncFailed , common .OperationError , fmt .Sprintf ("Namespace auto creation failed: %s" , err ))
0 commit comments