Skip to content

Commit

Permalink
SeparateApiLayerApplySetters
Browse files Browse the repository at this point in the history
  • Loading branch information
phanimarupaka committed May 1, 2021
1 parent ae6c687 commit aaf7a40
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 15 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main
package api

import (
"fmt"
Expand Down Expand Up @@ -275,3 +275,11 @@ func clean(input string) string {
input = strings.TrimSpace(input)
return strings.TrimSuffix(strings.TrimPrefix(input, "${"), "}")
}

// Decode decodes the input yaml node into Set struct
func Decode(rn *yaml.RNode, fcd *ApplySetters) error {
for k, v := range rn.GetDataMap() {
fcd.Setters = append(fcd.Setters, Setter{Name: k, Value: v})
}
return nil
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main
package api

import (
"io/ioutil"
Expand Down Expand Up @@ -310,7 +310,7 @@ spec:
if !assert.NoError(t, err) {
t.FailNow()
}
err = decode(node, s)
err = Decode(node, s)
if !assert.NoError(t, err) {
t.FailNow()
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main
package api

import (
"sigs.k8s.io/kustomize/kyaml/yaml"
Expand Down
15 changes: 4 additions & 11 deletions functions/go/apply-setters/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"os"

"github.com/GoogleContainerTools/kpt-functions-catalog/functions/go/apply-setters/api"
"github.com/GoogleContainerTools/kpt-functions-catalog/functions/go/apply-setters/generated"
"sigs.k8s.io/kustomize/kyaml/fn/framework"
kyaml "sigs.k8s.io/kustomize/kyaml/yaml"
Expand Down Expand Up @@ -37,8 +38,8 @@ func main() {
}

// getSetters retrieve the setters from input config
func getSetters(fc interface{}) (ApplySetters, error) {
var fcd ApplySetters
func getSetters(fc interface{}) (api.ApplySetters, error) {
var fcd api.ApplySetters
f, ok := fc.(map[string]interface{})
if !ok {
return fcd, fmt.Errorf("function config %#v is not valid", fc)
Expand All @@ -48,13 +49,5 @@ func getSetters(fc interface{}) (ApplySetters, error) {
return fcd, fmt.Errorf("failed to parse input from function config: %w", err)
}

return fcd, decode(rn, &fcd)
}

// decode decodes the input yaml node into Set struct
func decode(rn *kyaml.RNode, fcd *ApplySetters) error {
for k, v := range rn.GetDataMap() {
fcd.Setters = append(fcd.Setters, Setter{Name: k, Value: v})
}
return nil
return fcd, api.Decode(rn, &fcd)
}

0 comments on commit aaf7a40

Please sign in to comment.