Skip to content

Commit 3b865fc

Browse files
intrandrbrenlucasreedmakoscafee
authored
skip incomplete or broken YAML - warn user (#678)
* skip broken yaml (eg, patch file) * skip in visitFile, not in parser * restore filepath.Walk() error handling * restore test; correct assertion * Update pkg/kube/resources_test.go Co-authored-by: Robert Brennan <[email protected]> * Fix tests * update kind Co-authored-by: Robert Brennan <[email protected]> Co-authored-by: Luke Reed <[email protected]> Co-authored-by: Barnabas Makonda <[email protected]> Co-authored-by: MAKOSCAFEE <[email protected]>
1 parent f71ca99 commit 3b865fc

File tree

3 files changed

+9
-6
lines changed

3 files changed

+9
-6
lines changed

.circleci/config.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,20 +32,20 @@ references:
3232
sudo apt-get install -yqq jq git
3333
3434
echo "Installing KIND"
35-
curl -sLO https://github.com/kubernetes-sigs/kind/releases/download/v0.8.1/kind-linux-amd64
35+
curl -sLO https://github.com/kubernetes-sigs/kind/releases/download/v0.14.0/kind-linux-amd64
3636
chmod 0755 kind-linux-amd64
3737
sudo mv kind-linux-amd64 /usr/local/bin/kind
3838
kind version
3939
4040
echo "Installing Kubectl"
41-
curl -sLO https://storage.googleapis.com/kubernetes-release/release/v1.18.6/bin/linux/amd64/kubectl
41+
curl -sLO https://storage.googleapis.com/kubernetes-release/release/v1.21.12/bin/linux/amd64/kubectl
4242
chmod 0755 kubectl
4343
sudo mv kubectl /usr/local/bin/
4444
kubectl version --client
4545
4646
4747
echo "Creating Kubernetes Cluster with Kind"
48-
kind create cluster --wait=90s --image kindest/node:v1.15.11
48+
kind create cluster --wait=90s --image kindest/node:v1.21.12
4949
docker ps -a
5050
5151
kubectl version

pkg/kube/resources.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,11 @@ func CreateResourceProviderFromPath(directory string) (*ResourceProvider, error)
215215
logrus.Errorf("Error reading file: %v", path)
216216
return err
217217
}
218-
return resources.addResourcesFromYaml(string(contents))
218+
err = resources.addResourcesFromYaml(string(contents))
219+
if err != nil {
220+
logrus.Warnf("Skipping %s: cannot add resource from YAML: %v", path, err)
221+
}
222+
return nil
219223
}
220224

221225
err := filepath.Walk(directory, visitFile)
@@ -443,7 +447,6 @@ func (resources *ResourceProvider) addResourceFromString(contents string) error
443447
decoder = k8sYaml.NewYAMLOrJSONDecoder(bytes.NewReader(contentBytes), 1000)
444448

445449
if err != nil {
446-
logrus.Errorf("Invalid YAML: %s", string(contents))
447450
return err
448451
}
449452
if resource.Kind == "Namespace" {

pkg/kube/resources_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ func TestGetMultipleResourceFromSingleFile(t *testing.T) {
7474

7575
func TestGetMultipleResourceFromBadFile(t *testing.T) {
7676
_, err := CreateResourceProviderFromPath("./test_files/test_3")
77-
assert.NotEqual(t, nil, err, "CreateResource From Path should fail with bad yaml")
77+
assert.Equal(t, nil, err, "CreateResource From Path should not fail with bad yaml")
7878
}
7979

8080
func TestAddResourcesFromReader(t *testing.T) {

0 commit comments

Comments
 (0)