Skip to content

Commit dbc76c5

Browse files
committed
fix: fix nil pointer issue for skaff lint when encountering skaffold.yaml with no k8s manifests
1 parent b32a1e8 commit dbc76c5

File tree

2 files changed

+29
-10
lines changed

2 files changed

+29
-10
lines changed

pkg/skaffold/lint/k8smanifests.go

+3
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ func GetK8sManifestsLintResults(ctx context.Context, opts Options) (*[]Result, e
6666
}
6767

6868
for _, c := range cfgs {
69+
if c.Deploy.KubectlDeploy == nil {
70+
continue
71+
}
6972
for _, pattern := range c.Deploy.KubectlDeploy.Manifests {
7073
// NOTE: pattern is a pattern that can have wildcards, eg: leeroy-app/kubernetes/*
7174
if util.IsURL(pattern) {

pkg/skaffold/lint/k8smanifests_test.go

+26-10
Original file line numberDiff line numberDiff line change
@@ -62,14 +62,15 @@ func TestGetK8sManifestsLintResults(t *testing.T) {
6262
ruleIDToK8sManifestRule[k8sManifestLintRules[i].RuleID] = &k8sManifestLintRules[i]
6363
}
6464
tests := []struct {
65+
shouldErr bool
66+
k8sManifestIsNil bool
6567
description string
66-
rules []RuleID
67-
moduleAndSkaffoldYamls map[string]string
68-
profiles []string
69-
modules []string
7068
k8sManifestText string
71-
shouldErr bool
7269
err error
70+
profiles []string
71+
modules []string
72+
rules []RuleID
73+
moduleAndSkaffoldYamls map[string]string
7374
expected map[string]*[]Result
7475
}{
7576
{
@@ -97,6 +98,12 @@ func TestGetK8sManifestsLintResults(t *testing.T) {
9798
moduleAndSkaffoldYamls: map[string]string{"cfg0": testSkaffoldYaml},
9899
shouldErr: true,
99100
},
101+
{
102+
rules: []RuleID{},
103+
description: "no k8sManifest file for skaffold.yaml",
104+
k8sManifestIsNil: true,
105+
moduleAndSkaffoldYamls: map[string]string{"cfg0": testSkaffoldYaml},
106+
},
100107
}
101108
for _, test := range tests {
102109
testutil.Run(t, test.description, func(t *testutil.T) {
@@ -124,11 +131,20 @@ func TestGetK8sManifestsLintResults(t *testing.T) {
124131
if err != nil {
125132
t.Fatalf("error creating deployment.yaml %s: %v", mp, err)
126133
}
127-
configSet = append(configSet, &parser.SkaffoldConfigEntry{SkaffoldConfig: &v1.SkaffoldConfig{
128-
Metadata: v1.Metadata{Name: module},
129-
Pipeline: v1.Pipeline{Deploy: v1.DeployConfig{DeployType: v1.DeployType{KubectlDeploy: &v1.KubectlDeploy{Manifests: []string{mp}}}}},
130-
},
131-
})
134+
if test.k8sManifestIsNil {
135+
configSet = append(configSet, &parser.SkaffoldConfigEntry{SkaffoldConfig: &v1.SkaffoldConfig{
136+
Metadata: v1.Metadata{Name: module},
137+
Pipeline: v1.Pipeline{},
138+
},
139+
})
140+
} else {
141+
configSet = append(configSet, &parser.SkaffoldConfigEntry{SkaffoldConfig: &v1.SkaffoldConfig{
142+
Metadata: v1.Metadata{Name: module},
143+
Pipeline: v1.Pipeline{Deploy: v1.DeployConfig{DeployType: v1.DeployType{KubectlDeploy: &v1.KubectlDeploy{Manifests: []string{mp}}}}},
144+
},
145+
})
146+
}
147+
132148
// test overwrites file paths for expected K8sManifestRules as they are made dynamically
133149
results := test.expected[module]
134150
if results == nil {

0 commit comments

Comments
 (0)