From 54a39d10907bbfeaaf040d86562a61fc1137a130 Mon Sep 17 00:00:00 2001 From: phani Date: Mon, 7 Jun 2021 10:06:20 -0700 Subject: [PATCH] Fix indentation of results file (#2174) --- .../missing-fn-config/.expected/results.yaml | 14 +-- .../.expected/results.yaml | 18 ++-- .../.expected/results.yaml | 90 +++++++++---------- .../.expected/results.yaml | 18 ++-- .../kubeval-failure/.expected/results.yaml | 90 +++++++++---------- .../.expected/results.yaml | 14 +-- internal/fnruntime/utils.go | 8 +- 7 files changed, 128 insertions(+), 124 deletions(-) diff --git a/e2e/testdata/fn-eval/missing-fn-config/.expected/results.yaml b/e2e/testdata/fn-eval/missing-fn-config/.expected/results.yaml index feee4667e8..7f356456bf 100644 --- a/e2e/testdata/fn-eval/missing-fn-config/.expected/results.yaml +++ b/e2e/testdata/fn-eval/missing-fn-config/.expected/results.yaml @@ -1,12 +1,12 @@ apiVersion: kpt.dev/v1alpha2 kind: FunctionResultList metadata: - name: fnresults + name: fnresults exitCode: 1 items: - - image: gcr.io/kpt-fn/set-namespace:v0.1.3 - stderr: '[error] /// : failed to configure function: input namespace cannot be empty' - exitCode: 1 - results: - - message: 'failed to configure function: input namespace cannot be empty' - severity: error + - image: gcr.io/kpt-fn/set-namespace:v0.1.3 + stderr: '[error] /// : failed to configure function: input namespace cannot be empty' + exitCode: 1 + results: + - message: 'failed to configure function: input namespace cannot be empty' + severity: error diff --git a/e2e/testdata/fn-eval/structured-results-in-stdout/.expected/results.yaml b/e2e/testdata/fn-eval/structured-results-in-stdout/.expected/results.yaml index 3aeba98a0c..9db28b44da 100755 --- a/e2e/testdata/fn-eval/structured-results-in-stdout/.expected/results.yaml +++ b/e2e/testdata/fn-eval/structured-results-in-stdout/.expected/results.yaml @@ -1,14 +1,14 @@ apiVersion: kpt.dev/v1alpha2 kind: FunctionResultList metadata: - name: fnresults + name: fnresults exitCode: 0 items: - - image: gcr.io/kpt-fn/search-replace:v0.1 - exitCode: 0 - results: - - message: Mutated field value to "4" - field: - path: spec.replicas - file: - path: resources.yaml \ No newline at end of file + - image: gcr.io/kpt-fn/search-replace:v0.1 + exitCode: 0 + results: + - message: Mutated field value to "4" + field: + path: spec.replicas + file: + path: resources.yaml \ No newline at end of file diff --git a/e2e/testdata/fn-render/fnresult-fn-failure/.expected/results.yaml b/e2e/testdata/fn-render/fnresult-fn-failure/.expected/results.yaml index 0b39f313f3..46dfdadc3b 100755 --- a/e2e/testdata/fn-render/fnresult-fn-failure/.expected/results.yaml +++ b/e2e/testdata/fn-render/fnresult-fn-failure/.expected/results.yaml @@ -1,50 +1,50 @@ apiVersion: kpt.dev/v1alpha2 kind: FunctionResultList metadata: - name: fnresults + name: fnresults exitCode: 1 items: - - image: gcr.io/kpt-fn/kubeval:v0.1.1 - exitCode: 1 - results: - - message: selector is required - severity: error - resourceRef: - apiVersion: apps/v1 - kind: Deployment - name: nginx-deployment - field: - path: selector - file: - path: resources.yaml - - message: template is required - severity: error - resourceRef: - apiVersion: apps/v1 - kind: Deployment - name: nginx-deployment - field: - path: template - file: - path: resources.yaml - - message: 'Invalid type. Expected: [integer,null], given: string' - severity: error - resourceRef: - apiVersion: apps/v1 - kind: Deployment - name: nginx-deployment - field: - path: spec.replicas - file: - path: resources.yaml - - message: | - Validating arbitrary CRDs is not supported yet. You can skip them by setting ignore_missing_schemas or skip_kinds in the function config: - ERR - stdin: Failed initializing schema file:///tmp/master-standalone-strict/custom-custom-v1.json: open /tmp/master-standalone-strict/custom-custom-v1.json: no such file or directory - severity: error - resourceRef: - apiVersion: custom.io/v1 - kind: Custom - name: custom - file: - path: resources.yaml - index: 1 + - image: gcr.io/kpt-fn/kubeval:v0.1.1 + exitCode: 1 + results: + - message: selector is required + severity: error + resourceRef: + apiVersion: apps/v1 + kind: Deployment + name: nginx-deployment + field: + path: selector + file: + path: resources.yaml + - message: template is required + severity: error + resourceRef: + apiVersion: apps/v1 + kind: Deployment + name: nginx-deployment + field: + path: template + file: + path: resources.yaml + - message: 'Invalid type. Expected: [integer,null], given: string' + severity: error + resourceRef: + apiVersion: apps/v1 + kind: Deployment + name: nginx-deployment + field: + path: spec.replicas + file: + path: resources.yaml + - message: | + Validating arbitrary CRDs is not supported yet. You can skip them by setting ignore_missing_schemas or skip_kinds in the function config: + ERR - stdin: Failed initializing schema file:///tmp/master-standalone-strict/custom-custom-v1.json: open /tmp/master-standalone-strict/custom-custom-v1.json: no such file or directory + severity: error + resourceRef: + apiVersion: custom.io/v1 + kind: Custom + name: custom + file: + path: resources.yaml + index: 1 diff --git a/e2e/testdata/fn-render/fnresult-fn-success/.expected/results.yaml b/e2e/testdata/fn-render/fnresult-fn-success/.expected/results.yaml index 32186de1c7..11f0d9e407 100755 --- a/e2e/testdata/fn-render/fnresult-fn-success/.expected/results.yaml +++ b/e2e/testdata/fn-render/fnresult-fn-success/.expected/results.yaml @@ -1,14 +1,14 @@ apiVersion: kpt.dev/v1alpha2 kind: FunctionResultList metadata: - name: fnresults + name: fnresults exitCode: 0 items: - - image: gcr.io/kpt-fn/search-replace:v0.1 - exitCode: 0 - results: - - message: Mutated field value to "4" - field: - path: spec.replicas - file: - path: resources.yaml + - image: gcr.io/kpt-fn/search-replace:v0.1 + exitCode: 0 + results: + - message: Mutated field value to "4" + field: + path: spec.replicas + file: + path: resources.yaml diff --git a/e2e/testdata/fn-render/kubeval-failure/.expected/results.yaml b/e2e/testdata/fn-render/kubeval-failure/.expected/results.yaml index 0b39f313f3..46dfdadc3b 100755 --- a/e2e/testdata/fn-render/kubeval-failure/.expected/results.yaml +++ b/e2e/testdata/fn-render/kubeval-failure/.expected/results.yaml @@ -1,50 +1,50 @@ apiVersion: kpt.dev/v1alpha2 kind: FunctionResultList metadata: - name: fnresults + name: fnresults exitCode: 1 items: - - image: gcr.io/kpt-fn/kubeval:v0.1.1 - exitCode: 1 - results: - - message: selector is required - severity: error - resourceRef: - apiVersion: apps/v1 - kind: Deployment - name: nginx-deployment - field: - path: selector - file: - path: resources.yaml - - message: template is required - severity: error - resourceRef: - apiVersion: apps/v1 - kind: Deployment - name: nginx-deployment - field: - path: template - file: - path: resources.yaml - - message: 'Invalid type. Expected: [integer,null], given: string' - severity: error - resourceRef: - apiVersion: apps/v1 - kind: Deployment - name: nginx-deployment - field: - path: spec.replicas - file: - path: resources.yaml - - message: | - Validating arbitrary CRDs is not supported yet. You can skip them by setting ignore_missing_schemas or skip_kinds in the function config: - ERR - stdin: Failed initializing schema file:///tmp/master-standalone-strict/custom-custom-v1.json: open /tmp/master-standalone-strict/custom-custom-v1.json: no such file or directory - severity: error - resourceRef: - apiVersion: custom.io/v1 - kind: Custom - name: custom - file: - path: resources.yaml - index: 1 + - image: gcr.io/kpt-fn/kubeval:v0.1.1 + exitCode: 1 + results: + - message: selector is required + severity: error + resourceRef: + apiVersion: apps/v1 + kind: Deployment + name: nginx-deployment + field: + path: selector + file: + path: resources.yaml + - message: template is required + severity: error + resourceRef: + apiVersion: apps/v1 + kind: Deployment + name: nginx-deployment + field: + path: template + file: + path: resources.yaml + - message: 'Invalid type. Expected: [integer,null], given: string' + severity: error + resourceRef: + apiVersion: apps/v1 + kind: Deployment + name: nginx-deployment + field: + path: spec.replicas + file: + path: resources.yaml + - message: | + Validating arbitrary CRDs is not supported yet. You can skip them by setting ignore_missing_schemas or skip_kinds in the function config: + ERR - stdin: Failed initializing schema file:///tmp/master-standalone-strict/custom-custom-v1.json: open /tmp/master-standalone-strict/custom-custom-v1.json: no such file or directory + severity: error + resourceRef: + apiVersion: custom.io/v1 + kind: Custom + name: custom + file: + path: resources.yaml + index: 1 diff --git a/e2e/testdata/fn-render/validate-resource-failure/.expected/results.yaml b/e2e/testdata/fn-render/validate-resource-failure/.expected/results.yaml index ce12af2729..02cfa6023e 100755 --- a/e2e/testdata/fn-render/validate-resource-failure/.expected/results.yaml +++ b/e2e/testdata/fn-render/validate-resource-failure/.expected/results.yaml @@ -1,12 +1,12 @@ apiVersion: kpt.dev/v1alpha2 kind: FunctionResultList metadata: - name: fnresults + name: fnresults exitCode: 1 items: - - image: gcr.io/kpt-fn/starlark:v0.1.0 - stderr: 'fail: could not find httpbin deployment' - exitCode: 1 - results: - - message: 'fail: could not find httpbin deployment' - severity: error + - image: gcr.io/kpt-fn/starlark:v0.1.0 + stderr: 'fail: could not find httpbin deployment' + exitCode: 1 + results: + - message: 'fail: could not find httpbin deployment' + severity: error diff --git a/internal/fnruntime/utils.go b/internal/fnruntime/utils.go index a7e80cd78f..854ba985a8 100644 --- a/internal/fnruntime/utils.go +++ b/internal/fnruntime/utils.go @@ -15,6 +15,7 @@ package fnruntime import ( + "bytes" "io/ioutil" "path/filepath" @@ -28,13 +29,16 @@ func SaveResults(resultsDir string, fnResults *fnresult.ResultList) (string, err return "", nil } filePath := filepath.Join(resultsDir, "results.yaml") + out := &bytes.Buffer{} - content, err := yaml.Marshal(fnResults) + // use kyaml encoder to ensure consistent indentation + e := yaml.NewEncoder(out) + err := e.Encode(fnResults) if err != nil { return "", err } - err = ioutil.WriteFile(filePath, content, 0744) + err = ioutil.WriteFile(filePath, out.Bytes(), 0744) if err != nil { return "", err }