Skip to content

Commit

Permalink
fix: fix nil pointer issue for skaff lint when encountering skaffold.…
Browse files Browse the repository at this point in the history
…yaml with no k8s manifests (#6832)
  • Loading branch information
aaron-prindle authored Nov 11, 2021
1 parent 2cd1bdb commit c70d294
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 10 deletions.
3 changes: 3 additions & 0 deletions pkg/skaffold/lint/k8smanifests.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
36 changes: 26 additions & 10 deletions pkg/skaffold/lint/k8smanifests_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}{
{
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit c70d294

Please sign in to comment.