Skip to content
This repository was archived by the owner on Dec 17, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions pkg/sync/sync_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,10 +152,11 @@ func WithResourceModificationChecker(enabled bool, diffResults *diff.DiffResultL
}

// WithNamespaceCreation will create non-exist namespace
func WithNamespaceCreation(createNamespace bool, namespaceModifier func(*unstructured.Unstructured) bool) SyncOpt {
func WithNamespaceCreation(createNamespace bool, namespaceModifier func(*unstructured.Unstructured) bool, namespaceCreator func(*unstructured.Unstructured) bool) SyncOpt {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it makes sense to make a unique type of func (*unstructured.Unstructured) bool, as the method signature becomes a little unreadable :)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Снимок экрана 2022-08-16 в 17 01 44
Not sure that it starts look better, maybe you can advice better naming

return func(ctx *syncContext) {
ctx.createNamespace = createNamespace
ctx.namespaceModifier = namespaceModifier
ctx.namespaceCreator = namespaceCreator
}
}

Expand Down Expand Up @@ -349,6 +350,7 @@ type syncContext struct {

createNamespace bool
namespaceModifier func(*unstructured.Unstructured) bool
namespaceCreator func(*unstructured.Unstructured) bool

syncWaveHook common.SyncWaveHook

Expand Down Expand Up @@ -792,7 +794,9 @@ func (sc *syncContext) autoCreateNamespace(tasks syncTasks) syncTasks {
}
}
} else if apierr.IsNotFound(err) {
tasks = append(tasks, &syncTask{phase: common.SyncPhasePreSync, targetObj: unstructuredObj, liveObj: nil})
if sc.namespaceCreator(unstructuredObj) {
tasks = append(tasks, &syncTask{phase: common.SyncPhasePreSync, targetObj: unstructuredObj, liveObj: nil})
}
} else {
task := &syncTask{phase: common.SyncPhasePreSync, targetObj: unstructuredObj}
sc.setResourceResult(task, common.ResultCodeSyncFailed, common.OperationError, fmt.Sprintf("Namespace auto creation failed: %s", err))
Expand Down
Loading