Skip to content

Commit

Permalink
Fix indentation of results file (#2174)
Browse files Browse the repository at this point in the history
  • Loading branch information
phanimarupaka committed Jun 7, 2021
1 parent 59e01de commit 54a39d1
Show file tree
Hide file tree
Showing 7 changed files with 128 additions and 124 deletions.
14 changes: 7 additions & 7 deletions 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
@@ -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
90 changes: 45 additions & 45 deletions 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
@@ -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
90 changes: 45 additions & 45 deletions 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
@@ -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
8 changes: 6 additions & 2 deletions internal/fnruntime/utils.go
Expand Up @@ -15,6 +15,7 @@
package fnruntime

import (
"bytes"
"io/ioutil"
"path/filepath"

Expand All @@ -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
}
Expand Down

0 comments on commit 54a39d1

Please sign in to comment.