Skip to content
Closed
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
18 changes: 17 additions & 1 deletion controller/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,19 @@ func (m *appStateManager) SyncAppState(app *v1alpha1.Application, state *v1alpha
}
trackingMethod := argo.GetTrackingMethod(m.settingsMgr)

namespaceMetadataModifier := func(un *unstructured.Unstructured) bool {
createNamespaceMetadata := app.Spec.SyncPolicy.CreateNamespaceMetadata
if un != nil && len(createNamespaceMetadata.Labels) > 0 {
un.SetLabels(createNamespaceMetadata.Labels)
return true
}
if un != nil && len(createNamespaceMetadata.Annotations) > 0 {
un.SetAnnotations(createNamespaceMetadata.Annotations)
return true
}
return false
}

syncCtx, cleanup, err := sync.NewSyncContext(
compareResult.syncStatus.Revision,
reconciliationResult,
Expand Down Expand Up @@ -244,7 +257,10 @@ func (m *appStateManager) SyncAppState(app *v1alpha1.Application, state *v1alpha
kube.UnsetLabel(un, cdcommon.LabelKeyAppInstance)
return true
}
return false
return namespaceMetadataModifier(un)
}, func(un *unstructured.Unstructured) bool {
namespaceMetadataModifier(un)
return true
}),
sync.WithSyncWaveHook(delayBetweenSyncWaves),
sync.WithPruneLast(syncOp.SyncOptions.HasOption(common.SyncOptionPruneLast)),
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ require (
github.com/TomOnTime/utfutil v0.0.0-20180511104225-09c41003ee1d
github.com/alicebob/miniredis v2.5.0+incompatible
github.com/alicebob/miniredis/v2 v2.14.2
github.com/argoproj/gitops-engine v0.7.1-0.20220804190909-2bc3fef13e07
github.com/argoproj/gitops-engine v0.7.1-0.20220818164807-a56a8030319e
github.com/argoproj/notifications-engine v0.3.1-0.20220812180936-4d8552b0775f
github.com/argoproj/pkg v0.11.1-0.20211203175135-36c59d8fafe0
github.com/aws/aws-sdk-go v1.38.49
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,8 @@ github.com/antonmedv/expr v1.8.9/go.mod h1:5qsM3oLGDND7sDmQGDXHkYfkjYMUX14qsgqmH
github.com/apache/thrift v0.12.0/go.mod h1:cp2SuWMxlEZw2r+iP2GNCdIi4C1qmUzdZFSVb+bacwQ=
github.com/apache/thrift v0.13.0/go.mod h1:cp2SuWMxlEZw2r+iP2GNCdIi4C1qmUzdZFSVb+bacwQ=
github.com/appscode/go v0.0.0-20190808133642-1d4ef1f1c1e0/go.mod h1:iy07dV61Z7QQdCKJCIvUoDL21u6AIceRhZzyleh2ymc=
github.com/argoproj/gitops-engine v0.7.1-0.20220804190909-2bc3fef13e07 h1:d9zthkVnQATgEQz1wel4ge8JzcmYFPRtFuTEWzhniWA=
github.com/argoproj/gitops-engine v0.7.1-0.20220804190909-2bc3fef13e07/go.mod h1:WpA/B7tgwfz+sdNE3LqrTrb7ArEY1FOPI2pAGI0hfPc=
github.com/argoproj/gitops-engine v0.7.1-0.20220818164807-a56a8030319e h1:6LtEKwTexv7Fubf7g7c9xYwCk9ZIMIk2T92cFWXY5wg=
github.com/argoproj/gitops-engine v0.7.1-0.20220818164807-a56a8030319e/go.mod h1:WpA/B7tgwfz+sdNE3LqrTrb7ArEY1FOPI2pAGI0hfPc=
github.com/argoproj/notifications-engine v0.3.1-0.20220812180936-4d8552b0775f h1:xTts6TJ/SBbY9zV8qpueokUd3+SlJN6Abt4W6lAjOKM=
github.com/argoproj/notifications-engine v0.3.1-0.20220812180936-4d8552b0775f/go.mod h1:R3zlopt+/juYlebQc9Jarn9vBQ2xZruWOWjUNkfGY9M=
github.com/argoproj/pkg v0.11.1-0.20211203175135-36c59d8fafe0 h1:Cfp7rO/HpVxnwlRqJe0jHiBbZ77ZgXhB6HWlYD02Xdc=
Expand Down
11 changes: 11 additions & 0 deletions manifests/core-install.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -741,6 +741,17 @@ spec:
(default: false)'
type: boolean
type: object
createNamespaceMetadata:
properties:
annotations:
additionalProperties:
type: string
type: object
labels:
additionalProperties:
type: string
type: object
type: object
retry:
description: Retry controls failed sync retry behavior
properties:
Expand Down
11 changes: 11 additions & 0 deletions manifests/crds/application-crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -740,6 +740,17 @@ spec:
(default: false)'
type: boolean
type: object
createNamespaceMetadata:
properties:
labels:
additionalProperties:
type: string
type: object
annotations:
additionalProperties:
type: string
type: object
type: object
retry:
description: Retry controls failed sync retry behavior
properties:
Expand Down
11 changes: 11 additions & 0 deletions manifests/ha/install.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -741,6 +741,17 @@ spec:
(default: false)'
type: boolean
type: object
createNamespaceMetadata:
properties:
annotations:
additionalProperties:
type: string
type: object
labels:
additionalProperties:
type: string
type: object
type: object
retry:
description: Retry controls failed sync retry behavior
properties:
Expand Down
11 changes: 11 additions & 0 deletions manifests/install.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -741,6 +741,17 @@ spec:
(default: false)'
type: boolean
type: object
createNamespaceMetadata:
properties:
annotations:
additionalProperties:
type: string
type: object
labels:
additionalProperties:
type: string
type: object
type: object
retry:
description: Retry controls failed sync retry behavior
properties:
Expand Down
10 changes: 9 additions & 1 deletion pkg/apis/application/v1alpha1/generated.proto

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 7 additions & 1 deletion pkg/apis/application/v1alpha1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -698,14 +698,20 @@ func (o SyncOptions) HasOption(option string) bool {
return false
}

type CreateNamespaceMetadata struct {
Labels map[string]string `json:"labels,omitempty" protobuf:"bytes,1,opt,name=labels"`
Annotations map[string]string `json:"annotations,omitempty" protobuf:"bytes,2,opt,name=annotations"`
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Maybe better providing the name here as well?
Or even make this struct just have a ObjectMeta reference in it?

something like:

type CreateNamespaceMetadata struct {
	metav1.ObjectMeta `json:"metadata"`

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.

The name is inferred from the resource referencing the to-be-created namespace.

}

// SyncPolicy controls when a sync will be performed in response to updates in git
type SyncPolicy struct {
// Automated will keep an application synced to the target revision
Automated *SyncPolicyAutomated `json:"automated,omitempty" protobuf:"bytes,1,opt,name=automated"`
// Options allow you to specify whole app sync-options
SyncOptions SyncOptions `json:"syncOptions,omitempty" protobuf:"bytes,2,opt,name=syncOptions"`
// Retry controls failed sync retry behavior
Retry *RetryStrategy `json:"retry,omitempty" protobuf:"bytes,3,opt,name=retry"`
Retry *RetryStrategy `json:"retry,omitempty" protobuf:"bytes,3,opt,name=retry"`
CreateNamespaceMetadata CreateNamespaceMetadata `json:"createNamespaceMetadata,omitempty" protobuf:"bytes,4,opt,name=createNamespaceMetadata"`
}

// IsZero returns true if the sync policy is empty
Expand Down
31 changes: 31 additions & 0 deletions pkg/apis/application/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.