-
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
Emit a warning on build when deprecated fields are used #4723
Emit a warning on build when deprecated fields are used #4723
Conversation
/assign @natasha41575 |
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 pretty good! A few small comments. Thanks for picking this up.
api/types/kustomization_test.go
Outdated
k Kustomization | ||
want *[]string | ||
}{ | ||
// TODO: Add test cases. |
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.
is this TODO still needed?
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.
A few tests are already added, and It isn't needed.
I'll delete this comment.
api/types/kustomization.go
Outdated
const ( | ||
deprecatedBaseWarningMessage = "# Warning: bases was deprecated, Please use resources or try `kustomize edit fix`." | ||
deprecatedPatchesJson6902Message = "# Warning: patchesJson6902 is deprecated, Please use patches or try `kustomize edit fix`." | ||
deprecatedPatchesStrategicMergeMessage = "# Warning: bases is patchesStrategicMerge, Please use patches or try `kustomize edit fix`." |
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 looks like patchesStrategicMerge
isn't handled by kustomize edit fix
at the moment, so I think we should either wait for that change to go in first, or we need to change this error message to not mention kustomize edit fix yet.
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 fixed this message.
So, I add edit fix
function with #4733
If you have time, Could you watch this?
api/types/kustomization.go
Outdated
const ( | ||
deprecatedBaseWarningMessage = "# Warning: bases was deprecated, Please use resources or try `kustomize edit fix`." | ||
deprecatedPatchesJson6902Message = "# Warning: patchesJson6902 is deprecated, Please use patches or try `kustomize edit fix`." | ||
deprecatedPatchesStrategicMergeMessage = "# Warning: bases is patchesStrategicMerge, Please use patches or try `kustomize edit fix`." |
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.
deprecatedPatchesStrategicMergeMessage = "# Warning: bases is patchesStrategicMerge, Please use patches or try `kustomize edit fix`." | |
deprecatedPatchesStrategicMergeMessage = "# Warning: patchesStrategicMerge is deprecated, Please use patches or try `kustomize edit fix`." |
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.
Thanks! I fix.
api/types/kustomization.go
Outdated
@@ -172,6 +172,31 @@ type Kustomization struct { | |||
BuildMetadata []string `json:"buildMetadata,omitempty" yaml:"buildMetadata,omitempty"` | |||
} | |||
|
|||
const ( | |||
deprecatedBaseWarningMessage = "# Warning: bases was deprecated, Please use resources or try `kustomize edit fix`." |
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.
nit: quote the field names (here, and in the other messages as well)
# Warning: bases was deprecated, please use 'resources' or try `kustomize edit fix`.
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 fixed it.
@koba1t: This PR has multiple commits, and the default merge method is: merge. 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. |
✅ Deploy Preview for kubernetes-sigs-kustomize canceled.
|
hi @natasha41575 |
api/types/kustomization.go
Outdated
deprecatedBaseWarningMessage = "# Warning: bases was deprecated, Please use 'resources' or try `kustomize edit fix`." | ||
deprecatedPatchesJson6902Message = "# Warning: patchesJson6902 is deprecated, Please use 'patches' or try `kustomize edit fix`." | ||
deprecatedPatchesStrategicMergeMessage = "# Warning: patchesStrategicMerge is deprecated, Please use 'patches'." | ||
deprecatedVarsMessage = "# Warning: vars is deprecated, Please use 'replacements'." |
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.
@KnVerey Would you like to take a look a these warning messages before we merge?
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 change the commas after "deprecated" to periods.
- Please quote the names of the old fields, to match the names of the new.
- Since the point of
kustomize edit fix
is to do these updates for you, it isn't really an alternative to using the new fields. How aboutWarning: 'X' is deprecated. Please use 'Y' instead. Run 'kustomize edit fix' to update your Kustomization automatically.
. - For replacements, we can add something like "(EXPERIMENTAL)" to the edit fix part.
- If this merges before add
edit fix
for patchesStrategicMerge to patches #4733, that PR will need to update the message.
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.
Hi @KnVerey
I think I completed to fix from your comment.
If this merges before #4733, that PR will need to update the message.
I think it is better to merge first to #4733 if I can.
I added a warning message to patchesStrategicMerge
in this PR.
@natasha41575
Would you review #4733 before merging this PR?
e12bf75
to
90231f4
Compare
api/types/kustomization.go
Outdated
deprecatedBaseWarningMessage = "# Warning: bases was deprecated, Please use 'resources' or try `kustomize edit fix`." | ||
deprecatedPatchesJson6902Message = "# Warning: patchesJson6902 is deprecated, Please use 'patches' or try `kustomize edit fix`." | ||
deprecatedPatchesStrategicMergeMessage = "# Warning: patchesStrategicMerge is deprecated, Please use 'patches'." | ||
deprecatedVarsMessage = "# Warning: vars is deprecated, Please use 'replacements'." |
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 change the commas after "deprecated" to periods.
- Please quote the names of the old fields, to match the names of the new.
- Since the point of
kustomize edit fix
is to do these updates for you, it isn't really an alternative to using the new fields. How aboutWarning: 'X' is deprecated. Please use 'Y' instead. Run 'kustomize edit fix' to update your Kustomization automatically.
. - For replacements, we can add something like "(EXPERIMENTAL)" to the edit fix part.
- If this merges before add
edit fix
for patchesStrategicMerge to patches #4733, that PR will need to update the message.
6b200a3
to
16a10df
Compare
api/types/kustomization.go
Outdated
const ( | ||
deprecatedWarningToRunEditFix = "# Warning: Run 'kustomize edit fix' to update your Kustomization automatically." | ||
deprecatedWarningToRunEditFixExperimential = "# Warning: [EXPERIMENTAL]Run 'kustomize edit fix' to update your Kustomization automatically." | ||
deprecatedBaseWarningMessage = "# Warning: 'bases' is deprecated. Please use 'resources' instead." + "\n" + deprecatedWarningToRunEditFix |
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.
since this is a single problem, I would prefer to have it printed on one line, without the second "warning" text
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 restore it to one-line warning messages.
@@ -69,6 +70,15 @@ func (kt *KustTarget) Load() error { | |||
if err != nil { | |||
return err | |||
} | |||
|
|||
// show warning message when using deprecated fields. | |||
warningMessages := k.CheckDeprecatedFields() |
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.
Are we sure this is going to work, given that FixKustomizationPreUnmarshalling
above mutates the file to accommodate some of the deprecated fields?
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 like FixKustomizationPreUnmarshalling
is fixing for raw []byte
data before unmarshaling to yaml.
Lines 12 to 32 in f61b075
// FixKustomizationPreUnmarshalling modifies the raw data | |
// before marshalling - e.g. changes old field names to | |
// new field names. | |
func FixKustomizationPreUnmarshalling(data []byte) ([]byte, error) { | |
deprecatedFieldsMap := map[string]string{ | |
"imageTags:": "images:", | |
} | |
for oldname, newname := range deprecatedFieldsMap { | |
pattern := regexp.MustCompile(oldname) | |
data = pattern.ReplaceAll(data, []byte(newname)) | |
} | |
doLegacy, err := useLegacyPatch(data) | |
if err != nil { | |
return nil, err | |
} | |
if doLegacy { | |
pattern := regexp.MustCompile("patches:") | |
data = pattern.ReplaceAll(data, []byte("patchesStrategicMerge:")) | |
} | |
return data, nil | |
} |
I think this function doesn't affect some of the deprecated fields in Kustomization
struct.
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.
Interestingly, this changes imageTags
to images
, which is a deprecation I wasn't even aware of. Also, it makes it seem like the field called patchesStrategicMerge
was originally called patches
, and we later re-introduced patches
with a different meaning. 🤦
Ideally, I think we should warn about imageTags
too, so we can get rid of FixKustomizationPreUnmarshalling
along with all the deprecated fields.
Also, I wonder if folks using the super old version of patches
would get a weird warning about patchesStrategicMerge
(which they aren't using) because of this method. Can we check this please?
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.
Ideally, I think we should warn about imageTags too, so we can get rid of FixKustomizationPreUnmarshalling along with all the deprecated fields.
I think it is hard to delete the FixKustomizationPreUnmarshalling
function while we support the super old version of patches.
Because super old patches
(It is called patchesStrategicMerge
today) have a different struct to today's patches
field.
I think we will get an error when unmarshaling []byte
to Kustomization
struct if we delete the pre unmarshalling process.
kustomize/api/types/kustomization.go
Lines 66 to 76 in 4fc0249
PatchesStrategicMerge []PatchStrategicMerge `json:"patchesStrategicMerge,omitempty" yaml:"patchesStrategicMerge,omitempty"` | |
// JSONPatches is a list of JSONPatch for applying JSON patch. | |
// Format documented at https://tools.ietf.org/html/rfc6902 | |
// and http://jsonpatch.com | |
PatchesJson6902 []Patch `json:"patchesJson6902,omitempty" yaml:"patchesJson6902,omitempty"` | |
// Patches is a list of patches, where each one can be either a | |
// Strategic Merge Patch or a JSON patch. | |
// Each patch can be applied to multiple target objects. | |
Patches []Patch `json:"patches,omitempty" yaml:"patches,omitempty"` |
type PatchStrategicMerge string |
Lines 8 to 24 in 4fc0249
// Patch represent either a Strategic Merge Patch or a JSON patch | |
// and its targets. | |
// The content of the patch can either be from a file | |
// or from an inline string. | |
type Patch struct { | |
// Path is a relative file path to the patch file. | |
Path string `json:"path,omitempty" yaml:"path,omitempty"` | |
// Patch is the content of a patch. | |
Patch string `json:"patch,omitempty" yaml:"patch,omitempty"` | |
// Target points to the resources that the patch is applied to | |
Target *Selector `json:"target,omitempty" yaml:"target,omitempty"` | |
// Options is a list of options for the patch | |
Options map[string]bool `json:"options,omitempty" yaml:"options,omitempty"` | |
} |
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.
Also, I wonder if folks using the super old version of patches would get a weird warning about patchesStrategicMerge (which they aren't using) because of this method. Can we check this please?
That is right. If we use very old style patches
, the warning message of patchesStrategicMerge
appear...
api/types/kustomization.go
Outdated
@@ -116,7 +119,7 @@ type Kustomization struct { | |||
// CRDs themselves are not modified. | |||
Crds []string `json:"crds,omitempty" yaml:"crds,omitempty"` | |||
|
|||
// Deprecated. | |||
// Deprecated: Replace with the Resources. |
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.
Instead of adding a line, add "Deprecated:" to the existing message 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.
Hi @KnVerey |
4c7bfde
to
21ee7f7
Compare
/remove-hold |
Nice!
/approve |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: koba1t, natasha41575 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 |
/lgtm |
fix #4706