feat: Ability to create custom labels for namespaces created with syncOptions CreateNamespace#443
Conversation
Signed-off-by: pashavictorovich <pavel@codefresh.io>
Codecov Report
@@ Coverage Diff @@
## master #443 +/- ##
==========================================
+ Coverage 55.22% 55.27% +0.05%
==========================================
Files 41 41
Lines 4449 4452 +3
==========================================
+ Hits 2457 2461 +4
+ Misses 1803 1802 -1
Partials 189 189
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. |
pkg/sync/sync_context.go
Outdated
| unstructuredObjCopy := unstructuredObj.DeepCopy() | ||
| if sc.namespaceCreator(unstructuredObjCopy) { | ||
| tasks = append(tasks, &syncTask{phase: common.SyncPhasePreSync, targetObj: unstructuredObjCopy, liveObj: nil}) | ||
| } |
There was a problem hiding this comment.
My expectation as a user would be that when I set the createNamespaceMetadata field, all auto-created namespaces will be updated with that metadata.
What if in WithNamespaceCreation we accepted multiple namespaceModifier functions and run them in series where they are currently being run?
There was a problem hiding this comment.
@crenshaw-dev Do you want to add ns metadata to the already created auto namespace?
There was a problem hiding this comment.
yes, use case is
User creates an app with autocreate namespaces
User syncs the app, and namespaces are auto-created
User adds a new label to the createNamespaceMetadata.labels field
User syncs the app, and the label is applied to already-auto-created namespaces
Working on this
There was a problem hiding this comment.
@ashutosh16 @crenshaw-dev this use case is covered now
when the app is going to be synced namespaceModifier will be called and labels will be added to namespace
pkg/sync/sync_context.go
Outdated
| unstructuredObjCopy := unstructuredObj.DeepCopy() | ||
| if sc.namespaceCreator(unstructuredObjCopy) { | ||
| tasks = append(tasks, &syncTask{phase: common.SyncPhasePreSync, targetObj: unstructuredObjCopy, liveObj: nil}) | ||
| } |
There was a problem hiding this comment.
Is there a good reason for using a copy of unstructuredObj here instead of just using the original?
There was a problem hiding this comment.
it is in same way for modifier, i decided to do in same way here for prevent issues, probably no
https://github.com/argoproj/gitops-engine/pull/443/files#diff-74e77a4722803a7d3f87b956ec81b82d3c5a0dd50de299922aa2208fec57e6e9R791
There was a problem hiding this comment.
yes, it can be removed
pkg/sync/sync_context_test.go
Outdated
| "encoding/json" | ||
| "errors" | ||
| "fmt" | ||
| errors2 "k8s.io/apimachinery/pkg/api/errors" |
There was a problem hiding this comment.
Just a nit: Could we please rename the import to apierrors or something more obvious than errors2?
There was a problem hiding this comment.
yes, it was autogenerated, sry
|
|
||
| // 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 { |
There was a problem hiding this comment.
I think it makes sense to make a unique type of func (*unstructured.Unstructured) bool, as the method signature becomes a little unreadable :)
Signed-off-by: pashavictorovich <pavel@codefresh.io>
Signed-off-by: pashavictorovich <pavel@codefresh.io>
|
Kudos, SonarCloud Quality Gate passed!
|
|
Also, looking at the appropriate code in Argo CD, is there a reason we need a new modifier function and do not reuse the existing one here: https://github.com/argoproj/argo-cd/blob/2d544b42c9c41be85a7fcb25535e3013d2ae3350/controller/sync.go#L243? This would save us an API change in gitops-engine. |
|
because modifier is calling only if namespace already exist, this hook is not calling when namespace not exist |
jannfis
left a comment
There was a problem hiding this comment.
Sorry for coming back so late.
LGTM.
…with syncOptions CreateNamespace (argoproj#443)" This reverts commit a56a803.
#455) * Revert "feat: Ability to create custom labels for namespaces created with syncOptions CreateNamespace (#443)" This reverts commit a56a803. * remove import Signed-off-by: pashavictorovich <pavel@codefresh.io> * fix test Signed-off-by: pashavictorovich <pavel@codefresh.io> Signed-off-by: pashavictorovich <pavel@codefresh.io>
This builds upon argoproj#443; the main difference here is that we keep the existing API and do a bit more logic in the downstream client to determine whether this namespace should be updated or not. Signed-off-by: Blake Pettersson <blake.pettersson@gmail.com>
This builds upon argoproj#443; the main difference here is that we keep the existing API and do a bit more logic in the downstream client to determine whether this namespace should be updated or not. Signed-off-by: Blake Pettersson <blake.pettersson@gmail.com>
This builds upon argoproj#443; the main difference here is that we keep the existing API and do a bit more logic in the downstream client to determine whether this namespace should be updated or not. Signed-off-by: Blake Pettersson <blake.pettersson@gmail.com>









argoproj/argo-cd#7799