Skip to content
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

Merged
merged 1 commit into from
Jul 6, 2022
Merged

Conversation

yuwenma
Copy link
Contributor

@yuwenma yuwenma commented Jul 1, 2022

Related issue: kptdev/kpt#3292
Design doc here: https://docs.google.com/document/d/1YwxalwS45V1BhvzwWrgHJQPL2mZ1xchIzTm_eI6jXsk/edit#

This PR contains 3 features:

  • Define our own ResourceIdentifier (so we do not import kustomize nor apimachinery)
  • Add two methods to return current identifier GetId and upstream identifier GetOriginId. original-id is the upstream identifier, which should be in the form of group|kind|namespace|name.
    • Group allows empty "" for core v1 resources
    • Namespace allows ~C for cluster scoped and unknown scoped resource, default for namespace scoped but not specified value.
  • Block methods that can change upstream-identifier annotation. (there's a SetOrDie that I haven't changed in this PR, I plan to remove it and support more type specific set functions)

go/fn/go.mod Outdated Show resolved Hide resolved
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
Copy link
Contributor

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~.

Copy link
Contributor Author

@yuwenma yuwenma Jul 2, 2022

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 or Cluster/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")
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor Author

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.

go/fn/object_test.go Outdated Show resolved Hide resolved
go/fn/origin.go Show resolved Hide resolved
Copy link
Contributor

@mengqiy mengqiy left a 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"
Copy link
Contributor

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.

Copy link
Contributor Author

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.

@yuwenma yuwenma merged commit 7181f45 into GoogleContainerTools:master Jul 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants