Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions api/types/kustomization.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ const (
deprecatedPatchesStrategicMergeMessage = "# Warning: 'patchesStrategicMerge' is deprecated. Please use 'patches' instead." + " " + deprecatedWarningToRunEditFix
deprecatedVarsMessage = "# Warning: 'vars' is deprecated. Please use 'replacements' instead." + " " + deprecatedWarningToRunEditFixExperimential
deprecatedCommonLabelsWarningMessage = "# Warning: 'commonLabels' is deprecated. Please use 'labels' instead." + " " + deprecatedWarningToRunEditFix
deprecationWarningAPIVersionandKind = "# Warning: 'apiVersion' and 'kind' fields are required in future releases. Please set it explicitly."
)

// CheckDeprecatedFields check deprecated field is used or not.
Expand All @@ -214,6 +215,9 @@ func (k *Kustomization) CheckDeprecatedFields() *[]string {
if k.Vars != nil {
warningMessages = append(warningMessages, deprecatedVarsMessage)
}
if k.APIVersion == "" || k.Kind == "" {
warningMessages = append(warningMessages, deprecationWarningAPIVersionandKind)
}
return &warningMessages
}

Expand Down
33 changes: 33 additions & 0 deletions api/types/kustomization_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,45 +25,76 @@ func TestKustomization_CheckDeprecatedFields(t *testing.T) {
{
name: "using_bases",
k: Kustomization{
TypeMeta: TypeMeta{
APIVersion: "kustomize.config.k8s.io/v1beta1",
Kind: "Kustomization",
},
Bases: []string{"base"},
},
want: &[]string{deprecatedBaseWarningMessage},
},
{
name: "using_CommonLabels",
k: Kustomization{
TypeMeta: TypeMeta{
APIVersion: "kustomize.config.k8s.io/v1beta1",
Kind: "Kustomization",
},
CommonLabels: map[string]string{},
},
want: &[]string{deprecatedCommonLabelsWarningMessage},
},
{
name: "using_ImageTags",
k: Kustomization{
TypeMeta: TypeMeta{
APIVersion: "kustomize.config.k8s.io/v1beta1",
Kind: "Kustomization",
},
ImageTags: []Image{},
},
want: &[]string{deprecatedImageTagsWarningMessage},
},
{
name: "usingPatchesJson6902",
k: Kustomization{
TypeMeta: TypeMeta{
APIVersion: "kustomize.config.k8s.io/v1beta1",
Kind: "Kustomization",
},
PatchesJson6902: []Patch{},
},
want: &[]string{deprecatedPatchesJson6902Message},
},
{
name: "usingPatchesStrategicMerge",
k: Kustomization{
TypeMeta: TypeMeta{
APIVersion: "kustomize.config.k8s.io/v1beta1",
Kind: "Kustomization",
},
PatchesStrategicMerge: []PatchStrategicMerge{},
},
want: &[]string{deprecatedPatchesStrategicMergeMessage},
},
{
name: "usingVar",
k: Kustomization{
TypeMeta: TypeMeta{
APIVersion: "kustomize.config.k8s.io/v1beta1",
Kind: "Kustomization",
},
Vars: []Var{},
},
want: &[]string{deprecatedVarsMessage},
},
{
name: "usingAPIVersionandKind",
Copy link
Member

Choose a reason for hiding this comment

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

I believe this name must be missingAPIVersionandKind, isn't it?

k: Kustomization{
TypeMeta: TypeMeta{},
},
want: &[]string{deprecationWarningAPIVersionandKind},
},
{
name: "usingAll",
k: Kustomization{
Expand All @@ -73,6 +104,7 @@ func TestKustomization_CheckDeprecatedFields(t *testing.T) {
PatchesJson6902: []Patch{},
PatchesStrategicMerge: []PatchStrategicMerge{},
Vars: []Var{},
TypeMeta: TypeMeta{},
},
want: &[]string{
deprecatedBaseWarningMessage,
Expand All @@ -81,6 +113,7 @@ func TestKustomization_CheckDeprecatedFields(t *testing.T) {
deprecatedPatchesJson6902Message,
deprecatedPatchesStrategicMergeMessage,
deprecatedVarsMessage,
deprecationWarningAPIVersionandKind,
},
},
}
Expand Down
Loading