Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
logandavies181 committed Dec 26, 2022
1 parent 29a84bf commit 166aaba
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 8 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/logandavies181/kustomize-krm-envsubst
go 1.19

require (
github.com/drone/envsubst v1.0.3
github.com/logandavies181/envsubst v0.1.0-alpha
sigs.k8s.io/kustomize/kyaml v0.13.10
)

Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/docopt/docopt-go v0.0.0-20180111231733-ee0de3bc6815/go.mod h1:WwZ+bS3ebgob9U8Nd0kOddGdZWjyMGR8Wziv+TBNwSE=
github.com/drone/envsubst v1.0.3 h1:PCIBwNDYjs50AsLZPYdfhSATKaRg/FJmDc2D6+C2x8g=
github.com/drone/envsubst v1.0.3/go.mod h1:N2jZmlMufstn1KEqvbHjw40h1KyTmnVzHcSc9bFiJ2g=
github.com/emicklei/go-restful v0.0.0-20170410110728-ff4f55a20633/go.mod h1:otzb+WCGbkyDHkqmQmT5YD2WR4BBwUdeQoFo8l/7tVs=
github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
Expand Down Expand Up @@ -72,6 +70,8 @@ github.com/kr/pretty v0.2.1 h1:Fmg33tUaq4/8ym9TJN1x7sLJnHVwhP33CNkpYV/7rwI=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/logandavies181/envsubst v0.1.0-alpha h1:WGYPOFu3KU5lQG09hH2YOz7MF1pTq7BrHM7gf63Qo3Y=
github.com/logandavies181/envsubst v0.1.0-alpha/go.mod h1:K+kTkKpymkTMlyFnK1haZYd4dXmVas5J+C9XNnG3Szo=
github.com/mailru/easyjson v0.0.0-20190614124828-94de47d64c63/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc=
github.com/mailru/easyjson v0.0.0-20190626092158-b2ccc519800e/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc=
github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0=
Expand Down
17 changes: 13 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,22 @@ import (
"fmt"
"os"

"github.com/drone/envsubst"
"github.com/logandavies181/envsubst"

"sigs.k8s.io/kustomize/kyaml/fn/framework"
"sigs.k8s.io/kustomize/kyaml/fn/framework/command"
"sigs.k8s.io/kustomize/kyaml/kio"
"sigs.k8s.io/kustomize/kyaml/yaml"
)

func envMapping(str string, nodeInfo envsubst.NodeInfo) (string, bool) {
if str == "FOO" {
return nodeInfo.Orig(), false
}

return "", true
}

func walkSequenceNode(in *yaml.RNode) error {
_, err := filter(in)
if err != nil {
Expand Down Expand Up @@ -54,9 +63,9 @@ func filter(in *yaml.RNode) (*yaml.RNode, error) {
return nil, fmt.Errorf("Could not parse node into string: %v", err)
}

substed, err := envsubst.EvalEnv(str)
substed, err := envsubst.EvalAdvanced(str, envsubst.AdvancedMapping(envMapping))
if err != nil {
return nil, fmt.Errorf("Could not envsubt: %v", err)
return nil, fmt.Errorf("Could not envsubst: %v", err)
}

if substed == str {
Expand Down Expand Up @@ -87,7 +96,7 @@ func main() {
for i := range items {
err := items[i].PipeE(yaml.FilterFunc(filter))
if err != nil {
return nil, fmt.Errorf("kustomize-krm-envsubt: %v", err)
return nil, fmt.Errorf("kustomize-krm-envsubst: %v", err)
}
}
return items, nil
Expand Down
2 changes: 1 addition & 1 deletion test/transformer.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ metadata:
annotations:
config.kubernetes.io/function: |
exec:
path: ./kustomize-krm-envsubst
path: ../kustomize-krm-envsubst

0 comments on commit 166aaba

Please sign in to comment.