Skip to content

Commit

Permalink
Added logic to handle nil during interface conversion of namespace. (#…
Browse files Browse the repository at this point in the history
…5001)

* Added logic to Handle nil during interface conversion of namespace.
Added unit test.

* Variable rename.
  • Loading branch information
PriyaModali authored Nov 6, 2020
1 parent 223fee0 commit 0bbcd9a
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
28 changes: 28 additions & 0 deletions pkg/skaffold/kubernetes/manifest/namespace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,34 @@ spec:
containers:
- image: gcr.io/k8s-skaffold/example
name: example
`)},
expected: []string{},
}, {
description: "single Pod manifest with nil namespace",
manifests: ManifestList{[]byte(`
apiVersion: v1
kind: Pod
metadata:
name: getting-started
namespace:
spec:
containers:
- image: gcr.io/k8s-skaffold/example
name: example
`)},
expected: []string{},
}, {
description: "single Pod manifest with empty namespace",
manifests: ManifestList{[]byte(`
apiVersion: v1
kind: Pod
metadata:
name: getting-started
namespace: ""
spec:
containers:
- image: gcr.io/k8s-skaffold/example
name: example
`)},
expected: []string{},
}, {
Expand Down
6 changes: 5 additions & 1 deletion pkg/skaffold/kubernetes/manifest/namespaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,11 @@ func (r *namespaceCollector) Visit(o map[string]interface{}, k string, v interfa
return true
}
if nsValue, present := metadata["namespace"]; present {
if ns := strings.TrimSpace(nsValue.(string)); ns != "" {
nsString, ok := nsValue.(string)
if !ok || nsString == "" {
return true
}
if ns := strings.TrimSpace(nsString); ns != "" {
r.namespaces[ns] = true
}
}
Expand Down

0 comments on commit 0bbcd9a

Please sign in to comment.