diff --git a/pkg/skaffold/lint/k8smanifests.go b/pkg/skaffold/lint/k8smanifests.go index 69ee2651ac7..d6192f6abf7 100644 --- a/pkg/skaffold/lint/k8smanifests.go +++ b/pkg/skaffold/lint/k8smanifests.go @@ -67,6 +67,9 @@ func GetK8sManifestsLintResults(ctx context.Context, opts Options) (*[]Result, e } for _, c := range cfgs { + if c.Deploy.KubectlDeploy == nil { + continue + } for _, pattern := range c.Deploy.KubectlDeploy.Manifests { // NOTE: pattern is a pattern that can have wildcards, eg: leeroy-app/kubernetes/* if util.IsURL(pattern) { diff --git a/pkg/skaffold/lint/k8smanifests_test.go b/pkg/skaffold/lint/k8smanifests_test.go index a76586876db..bfff228ffd0 100644 --- a/pkg/skaffold/lint/k8smanifests_test.go +++ b/pkg/skaffold/lint/k8smanifests_test.go @@ -62,14 +62,15 @@ func TestGetK8sManifestsLintResults(t *testing.T) { ruleIDToK8sManifestRule[k8sManifestLintRules[i].RuleID] = &k8sManifestLintRules[i] } tests := []struct { + shouldErr bool + k8sManifestIsNil bool description string - rules []RuleID - moduleAndSkaffoldYamls map[string]string - profiles []string - modules []string k8sManifestText string - shouldErr bool err error + profiles []string + modules []string + rules []RuleID + moduleAndSkaffoldYamls map[string]string expected map[string]*[]Result }{ { @@ -97,6 +98,12 @@ func TestGetK8sManifestsLintResults(t *testing.T) { moduleAndSkaffoldYamls: map[string]string{"cfg0": testSkaffoldYaml}, shouldErr: true, }, + { + rules: []RuleID{}, + description: "no k8sManifest file for skaffold.yaml", + k8sManifestIsNil: true, + moduleAndSkaffoldYamls: map[string]string{"cfg0": testSkaffoldYaml}, + }, } for _, test := range tests { testutil.Run(t, test.description, func(t *testutil.T) { @@ -124,11 +131,20 @@ func TestGetK8sManifestsLintResults(t *testing.T) { if err != nil { t.Fatalf("error creating deployment.yaml %s: %v", mp, err) } - configSet = append(configSet, &parser.SkaffoldConfigEntry{SkaffoldConfig: &v1.SkaffoldConfig{ - Metadata: v1.Metadata{Name: module}, - Pipeline: v1.Pipeline{Deploy: v1.DeployConfig{DeployType: v1.DeployType{KubectlDeploy: &v1.KubectlDeploy{Manifests: []string{mp}}}}}, - }, - }) + if test.k8sManifestIsNil { + configSet = append(configSet, &parser.SkaffoldConfigEntry{SkaffoldConfig: &v1.SkaffoldConfig{ + Metadata: v1.Metadata{Name: module}, + Pipeline: v1.Pipeline{}, + }, + }) + } else { + configSet = append(configSet, &parser.SkaffoldConfigEntry{SkaffoldConfig: &v1.SkaffoldConfig{ + Metadata: v1.Metadata{Name: module}, + Pipeline: v1.Pipeline{Deploy: v1.DeployConfig{DeployType: v1.DeployType{KubectlDeploy: &v1.KubectlDeploy{Manifests: []string{mp}}}}}, + }, + }) + } + // test overwrites file paths for expected K8sManifestRules as they are made dynamically results := test.expected[module] if results == nil {