-
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
add typemeta to kustomization #265
Conversation
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: Liujingfang1 The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
pkg/commands/kustomizationfile.go
Outdated
@@ -203,6 +203,9 @@ func isCommentOrBlankLine(line []byte) bool { | |||
// If the field wasn't in the original kustomization.yaml file or wasn't added, | |||
// an empty []byte is returned. | |||
func marshalField(field string, kustomization *types.Kustomization) ([]byte, error) { | |||
if field == "apiVersion" { |
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.
Can you add a comment explaining why you need to do this? I don't quite understand.
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.
ditto
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.
In current marshalField
function, the filed is assumed to be in a pattern that the correct field name can be get by strings.Title
, such as kind
--> Kind
. However, apiVersion
doesn't follow this pattern. Let me know if the assumption is to strong.
In addition, I found that KIND
or Kind
are supported by yaml. So I assume we also need to support them when we parse the kustomization.yaml file. That's why I added a (?i)
in the regexp.
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.
I refactored the code for finding the matching field. See if it looks better.
pkg/commands/kustomizationfile.go
Outdated
@@ -35,8 +35,8 @@ import ( | |||
) | |||
|
|||
var ( | |||
kustomizationFields = []string{"resources", "bases", "namePrefix", "namespace", "crds", "commonLabels", "commonAnnotations", "patches", "configMapGenerator", "secretGenerator", "vars", "imageTags"} | |||
recognizedFields = regexp.MustCompile("^(" + strings.Join(kustomizationFields, "|") + "):") | |||
kustomizationFields = []string{"apiVersion", "kind", "resources", "bases", "namePrefix", "namespace", "crds", "commonLabels", "commonAnnotations", "patches", "configMapGenerator", "secretGenerator", "vars", "imageTags"} |
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.
please add linebreaks for readability, e.g.
kustomizationFields = []string{
"resources",
"bases",
pkg/commands/kustomizationfile.go
Outdated
kustomizationFields = []string{"resources", "bases", "namePrefix", "namespace", "crds", "commonLabels", "commonAnnotations", "patches", "configMapGenerator", "secretGenerator", "vars", "imageTags"} | ||
recognizedFields = regexp.MustCompile("^(" + strings.Join(kustomizationFields, "|") + "):") | ||
kustomizationFields = []string{"apiVersion", "kind", "resources", "bases", "namePrefix", "namespace", "crds", "commonLabels", "commonAnnotations", "patches", "configMapGenerator", "secretGenerator", "vars", "imageTags"} | ||
recognizedFields = regexp.MustCompile("^(" + "(?i)" + strings.Join(kustomizationFields, "|") + "):") |
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.
Please add a comment explaining (?i)
pkg/commands/kustomizationfile.go
Outdated
@@ -203,6 +203,9 @@ func isCommentOrBlankLine(line []byte) bool { | |||
// If the field wasn't in the original kustomization.yaml file or wasn't added, | |||
// an empty []byte is returned. | |||
func marshalField(field string, kustomization *types.Kustomization) ([]byte, error) { | |||
if field == "apiVersion" { |
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.
ditto
pkg/commands/kustomizationfile.go
Outdated
} else { | ||
matched, field := findMatchedField(line) | ||
if matched { | ||
mf.originalFields = append(mf.originalFields, &commentedField{field: field, comment: bytes.Join(comments, []byte(``))}) |
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.
Please add some line feeds and use a helper to increase readbility.
eg
func squash(x [][]byte) []byte {
return bytes.Join(x, []byte(``))
}
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.
sounds good. Will add it.
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.
done
@@ -158,7 +160,7 @@ vars: | |||
kind: Service | |||
name: my-service | |||
|
|||
bases: | |||
BASES: |
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 just tests case insensitivity? nice.
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.
yes
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.
/lgtm
Fix #144