-
Notifications
You must be signed in to change notification settings - Fork 41
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support identifier annotation #600
Conversation
go/fn/const.go
Outdated
// It is in the form of <GROUP>|<KIND>|<NAMESPACE>|<NAME> | ||
UpstreamIdentifier = KptUseOnlyPrefix + "upstream-identifier" | ||
|
||
// UnkownNamespace is the special char for cluster-scoped or unknown-scoped resources. This is only used in upstream-identifier |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the special char
It's not a single character. It's more accurate to call it a special string. ~C
doesn't seems so meaningful and special. I'd suggest using something like ~UNKNOWN~
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
~C
doesn't seems so meaningful and special. I'd suggest using something like~UNKNOWN~
.
Yeah, that's true. 😞 Some more context:
- This represents both cluster-scoped and unknown resources.
- Neither
Unknown/U
orCluster/C
give helpful info to explain this field. The good news is this is kpt only fields so we don't expect users to know this. - Kustomize uses "nonenamespacable", which is too long.
So we are suggested to use "~C"
https://docs.google.com/document/d/1YwxalwS45V1BhvzwWrgHJQPL2mZ1xchIzTm_eI6jXsk/edit?disco=AAAAbLmue7Y
func TestInternalAnnotationsUntouchable(t *testing.T) { | ||
o := NewEmptyKubeObject() | ||
// Verify the "upstream-identifier" annotation cannot be changed via SetNestedStringMap | ||
o.SetNestedStringMap(map[string]string{"owner": "kpt"}, "metadata", "annotations") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not using the helper? https://pkg.go.dev/github.com/GoogleContainerTools/kpt-functions-sdk/go/fn#KubeObject.SetAnnotation
Same comment below.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh, this group of tests is to make sure there's no way users can change the upstream-identifier annotation via SDK methods. So we test all cases including setAnnotation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
one minor comment. LGTM otherwise
UpstreamIdentifier = KptUseOnlyPrefix + "upstream-identifier" | ||
|
||
// UnknownNamespace is the special char for cluster-scoped or unknown-scoped resources. This is only used in upstream-identifier | ||
UnknownNamespace = "~C" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Per #600 (comment), if we don't want user to know it, we should make it private.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
my bad. I should be more specific: users are not required to deal with UnknownNamespace. Because this is mainly used between kpt (upstream-identifier annotation) and set-namespace.
This const has to be public so set-namespace can use.
Related issue: kptdev/kpt#3292
Design doc here: https://docs.google.com/document/d/1YwxalwS45V1BhvzwWrgHJQPL2mZ1xchIzTm_eI6jXsk/edit#
This PR contains 3 features:
ResourceIdentifier
(so we do not import kustomize nor apimachinery)GetId
and upstream identifierGetOriginId
. original-id is the upstream identifier, which should be in the form ofgroup|kind|namespace|name
.~C
for cluster scoped and unknown scoped resource,default
for namespace scoped but not specified value.SetOrDie
that I haven't changed in this PR, I plan to remove it and support more type specificset
functions)