-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
Keep empty map in kustomize output #2805
Conversation
Hi @Shell32-Natsu. Thanks for your PR. I'm waiting for a kubernetes-sigs member to verify that this patch is reasonable to test. If it is, they should reply with Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: Shell32-Natsu The full list of commands accepted by this bot can be found here.
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
/assign @monopole |
/ok-to-test |
@@ -91,15 +91,14 @@ kind: Deployment | |||
{description: `remove scalar -- empty in src`, | |||
source: ` | |||
kind: Deployment | |||
field: {} |
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.
So this PR also retains scalar nulls?
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.
This null is in input. Because {}
is not considered as empty so only null
can be used as empty in input.
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.
looks good, but i think the API is getting odd
@@ -44,16 +44,17 @@ func IsMissingOrNull(node *RNode) bool { | |||
return node == nil || node.YNode() == nil || node.YNode().Tag == NullNodeTag | |||
} | |||
|
|||
// IsEmpty returns true if the RNode is MissingOrNull, or is either a MappingNode with | |||
// no fields. | |||
// IsEmpty returns true if the RNode is MissingOrNull | |||
func IsEmpty(node *RNode) bool { |
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.
It now seems we have:
IsMissingOrNull(n) => n == nil || n.YNode() == nil || n.YNode().Tag == NullNodeTag
IsEmpty(n) => IsMissingOrNull(n)
IsNull(n) => n != nil && n.YNode() != nil && n.YNode().Tag == NullNodeTag
IsEmptyMap(n) => IsEmpty(n) ||
(n.YNode().Kind == yaml.MappingNode && len(n.YNode().Content) == 0)
This feels random. And we have this strange contest between
Kind
and Tag
, which i'm not sure how to resolve yet.
We've not hit 1.0 yet, so we can change the API.
How about we try:
IsNil(n) => n == nil || n.YNode() == nil
IsEmptyDoc(n) => !IsNodeNil(n) && n.YNode().Tag == NodeTagNull
IsEmptyMap(n) => !IsNodeNil(n) &&
n.YNode().Kind == yaml.MappingNode &&
len(n.YNode().Content) == 0
with this, the tags are hidden, and we start a pattern where
IsEmptyFoo
means the object is non-nil with a defined type -
so empty docs, lists and maps are different things.
Translation:
IsNull
becomesIsEmptyDoc
IsEmpty
andIsMissingOrNull
are written asIsNil || IsEmptyDoc
The compiler can optimize away redundancy.
So L54 in kyaml/yaml/walk/associative_sequence.go
which currently reads
if yaml.IsEmpty(val) || yaml.IsEmptyMap(val) {
becomes
if yaml.IsNil(val) || yaml.IsEmptyDoc(val) || yaml.IsEmptyMap(val) {
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.
That sounds good. But because these methods are fundamental and widely used so if we change them, we need to update a lot of files.
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.
What about create another issue about this refactoring?
ack /lgtm Fixes #2734 |
#2734
kptdev/kpt#913