Skip to content

Commit 9af6cad

Browse files
Merge pull request #9 from ContainerSolutions/upgrade-kustomize-to-1.0.9
Upgrade kustomize to 1.0.10
2 parents 59509a2 + 8d7e327 commit 9af6cad

24 files changed

Lines changed: 233 additions & 307 deletions

cmd/convert.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ import (
1818
"github.com/golang/glog"
1919
"github.com/spf13/cobra"
2020
"google.golang.org/grpc/status"
21-
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
2221
k8syaml "k8s.io/apimachinery/pkg/util/yaml"
2322
helm_env "k8s.io/helm/pkg/helm/environment"
2423
"k8s.io/helm/pkg/helm/helmpath"
2524
"k8s.io/helm/pkg/hooks"
25+
"sigs.k8s.io/kustomize/k8sdeps/kunstruct"
2626
"sigs.k8s.io/kustomize/pkg/resource"
2727
ktypes "sigs.k8s.io/kustomize/pkg/types"
2828
)
@@ -248,13 +248,15 @@ func (k *convertCmd) run() error {
248248

249249
func newResources(in []byte) ([]*resource.Resource, error) {
250250
decoder := k8syaml.NewYAMLOrJSONDecoder(bytes.NewReader(in), 1024)
251+
rf := resource.NewFactory(kunstruct.NewKunstructuredFactoryImpl())
252+
251253
var result []*resource.Resource
252254
var err error
253255
for err == nil || isEmptyYamlError(err) {
254-
var out unstructured.Unstructured
256+
var out map[string]interface{}
255257
err = decoder.Decode(&out)
256258
if err == nil {
257-
result = append(result, resource.NewResourceFromUnstruct(out))
259+
result = append(result, rf.FromMap(out))
258260
}
259261
}
260262
if err != io.EOF {

go.mod

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ require (
77
github.com/aokoli/goutils v1.0.1 // indirect
88
github.com/aws/aws-sdk-go v1.15.44 // indirect
99
github.com/bgentry/go-netrc v0.0.0-20140422174119-9fd32a8b3d3d // indirect
10-
github.com/davecgh/go-spew v1.1.1
10+
github.com/davecgh/go-spew v1.1.1 // indirect
1111
github.com/ghodss/yaml v1.0.0
1212
github.com/gobwas/glob v0.2.3 // indirect
1313
github.com/gogo/protobuf v1.1.1 // indirect
@@ -24,6 +24,7 @@ require (
2424
github.com/inconshreveable/mousetrap v1.0.0 // indirect
2525
github.com/json-iterator/go v1.1.5 // indirect
2626
github.com/jtolds/gls v4.2.1+incompatible // indirect
27+
github.com/kylelemons/godebug v0.0.0-20170820004349-d65d576e9348
2728
github.com/mitchellh/go-homedir v1.0.0 // indirect
2829
github.com/mitchellh/go-testing-interface v1.0.0 // indirect
2930
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
@@ -37,6 +38,7 @@ require (
3738
github.com/stretchr/testify v1.2.2 // indirect
3839
github.com/ulikunitz/xz v0.5.4 // indirect
3940
golang.org/x/crypto v0.0.0-20181009213950-7c1a557ab941 // indirect
41+
golang.org/x/net v0.0.0-20181005035420-146acd28ed58 // indirect
4042
google.golang.org/grpc v1.15.0
4143
gopkg.in/inf.v0 v0.9.1 // indirect
4244
gopkg.in/yaml.v1 v1.0.0-20140924161607-9f9df34309c0 // indirect
@@ -45,5 +47,5 @@ require (
4547
k8s.io/apimachinery v0.0.0-20180621070125-103fd098999d
4648
k8s.io/client-go v7.0.0+incompatible // indirect
4749
k8s.io/helm v2.11.0-rc.4+incompatible
48-
sigs.k8s.io/kustomize v1.0.9-0.20180927233047-30597252c70c
50+
sigs.k8s.io/kustomize v1.0.10
4951
)

go.sum

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ github.com/aws/aws-sdk-go v1.15.44/go.mod h1:mFuSZ37Z9YOHbQEwBWztmVzqXrEkub65tZo
1212
github.com/bgentry/go-netrc v0.0.0-20140422174119-9fd32a8b3d3d h1:xDfNPAt8lFiC1UJrqV3uuy861HCTo708pDMbjHHdCas=
1313
github.com/bgentry/go-netrc v0.0.0-20140422174119-9fd32a8b3d3d/go.mod h1:6QX/PXZ00z/TKoufEY6K/a0k6AhaJrQKdFe6OfVXsa4=
1414
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
15+
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
1516
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
1617
github.com/ghodss/yaml v1.0.0 h1:wQHKEahhL6wmXdzwWG11gIVCkOv05bNOh+Rxn0yngAk=
1718
github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
@@ -31,6 +32,7 @@ github.com/google/gofuzz v0.0.0-20170612174753-24818f796faf h1:+RRA9JqSOZFfKrOeq
3132
github.com/google/gofuzz v0.0.0-20170612174753-24818f796faf/go.mod h1:HP5RmnzzSNb993RKQDq4+1A4ia9nllfqcQFTQJedwGI=
3233
github.com/google/uuid v1.0.0 h1:b4Gk+7WdP/d3HZH8EJsZpvV7EtDOgaZLtnaNGIu1adA=
3334
github.com/google/uuid v1.0.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
35+
github.com/gopherjs/gopherjs v0.0.0-20181004151105-1babbf986f6f h1:JJ2EP5vV3LAD2U1CxQtD7PTOO15Y96kXmKDz7TjxGHs=
3436
github.com/gopherjs/gopherjs v0.0.0-20181004151105-1babbf986f6f/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY=
3537
github.com/hashicorp/go-cleanhttp v0.5.0 h1:wvCrVc9TjDls6+YGAF2hAifE1E5U1+b4tH6KdvN3Gig=
3638
github.com/hashicorp/go-cleanhttp v0.5.0/go.mod h1:JpRdi6/HCYpAwUzNwuwqhbovhLtngrth3wmdIIUrZ80=
@@ -44,27 +46,38 @@ github.com/huandu/xstrings v1.2.0 h1:yPeWdRnmynF7p+lLYz0H2tthW9lqhMJrQV/U7yy4wX0
4446
github.com/huandu/xstrings v1.2.0/go.mod h1:DvyZB1rfVYsBIigL8HwpZgxHwXozlTgGqn63UyNX5k4=
4547
github.com/imdario/mergo v0.0.0-20141206190957-6633656539c1 h1:FeeCi0I2Fu8kA8IXrdVPtGzym+mW9bzfj9f26EaES9k=
4648
github.com/imdario/mergo v0.0.0-20141206190957-6633656539c1/go.mod h1:2EnlNZ0deacrJVfApfmtdGgDfMuh/nq6Ok1EcJh5FfA=
49+
github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NHg9XEKhtSvM=
4750
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
4851
github.com/jmespath/go-jmespath v0.0.0-20160202185014-0b12d6b521d8 h1:12VvqtR6Aowv3l/EQUlocDHW2Cp4G9WJVH7uyH8QFJE=
4952
github.com/jmespath/go-jmespath v0.0.0-20160202185014-0b12d6b521d8/go.mod h1:Nht3zPeWKUH0NzdCt2Blrr5ys8VGpn0CEB0cQHVjt7k=
53+
github.com/json-iterator/go v1.1.5 h1:gL2yXlmiIo4+t+y32d4WGwOjKGYcGOuyrg46vadswDE=
5054
github.com/json-iterator/go v1.1.5/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU=
55+
github.com/jtolds/gls v4.2.1+incompatible h1:fSuqC+Gmlu6l/ZYAoZzx2pyucC8Xza35fpRVWLVmUEE=
5156
github.com/jtolds/gls v4.2.1+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU=
5257
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
58+
github.com/kylelemons/godebug v0.0.0-20170820004349-d65d576e9348 h1:MtvEpTB6LX3vkb4ax0b5D2DHbNAUsen0Gx5wZoq3lV4=
59+
github.com/kylelemons/godebug v0.0.0-20170820004349-d65d576e9348/go.mod h1:B69LEHPfb2qLo0BaaOLcbitczOKLWTsrBG9LczfCD4k=
5360
github.com/mitchellh/go-homedir v1.0.0 h1:vKb8ShqSby24Yrqr/yDYkuFz8d0WUjys40rvnGC8aR0=
5461
github.com/mitchellh/go-homedir v1.0.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
5562
github.com/mitchellh/go-testing-interface v1.0.0 h1:fzU/JVNcaqHQEcVFAKeR41fkiLdIPrefOvVG1VZ96U0=
5663
github.com/mitchellh/go-testing-interface v1.0.0/go.mod h1:kRemZodwjscx+RGhAo8eIhFbs2+BFgRtFPeD/KE+zxI=
64+
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg=
5765
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
66+
github.com/modern-go/reflect2 v1.0.1 h1:9f412s+6RmYXLWZSEzVVgPGK7C2PphHj5RJrvfx9AWI=
5867
github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
5968
github.com/pkg/errors v0.8.0 h1:WdK/asTD0HN+q6hsWO3/vpuAkAr+tw6aNJNDFFf0+qw=
6069
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
70+
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
6171
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
72+
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d h1:zE9ykElWQ6/NYmHa3jpm/yHnI4xSofP+UP6SpjHcSeM=
6273
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc=
74+
github.com/smartystreets/goconvey v0.0.0-20180222194500-ef6db91d284a h1:JSvGDIbmil4Ui/dDdFBExb7/cmkNjyX5F97oglmvCDo=
6375
github.com/smartystreets/goconvey v0.0.0-20180222194500-ef6db91d284a/go.mod h1:XDJAKZRPZ1CvBcN2aX5YOUTYGHki24fSF0Iv48Ibg0s=
6476
github.com/spf13/cobra v0.0.3 h1:ZlrZ4XsMRm04Fr5pSFxBgfND2EBVa1nLpiy1stUsX/8=
6577
github.com/spf13/cobra v0.0.3/go.mod h1:1l0Ry5zgKvJasoi3XT1TypsSe7PqH0Sj9dhYf7v3XqQ=
6678
github.com/spf13/pflag v1.0.2 h1:Fy0orTDgHdbnzHcsOgfCN4LtHf0ec3wwtiwJqwvf3Gc=
6779
github.com/spf13/pflag v1.0.2/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
80+
github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1w=
6881
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
6982
github.com/ulikunitz/xz v0.5.4 h1:zATC2OoZ8H1TZll3FpbX+ikwmadbO699PE06cIkm9oU=
7083
github.com/ulikunitz/xz v0.5.4/go.mod h1:2bypXElzHzzJZwzH67Y6wb67pO62Rzfn7BSiF4ABRW8=
@@ -73,20 +86,26 @@ golang.org/x/crypto v0.0.0-20181009213950-7c1a557ab941/go.mod h1:6SG95UA2DQfeDnf
7386
golang.org/x/lint v0.0.0-20180702182130-06c8688daad7/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
7487
golang.org/x/net v0.0.0-20180826012351-8a410e7b638d h1:g9qWBGx4puODJTMVyoPrpoxPFgVGd+z1DZwjfRu4d0I=
7588
golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
89+
golang.org/x/net v0.0.0-20181005035420-146acd28ed58 h1:otZG8yDCO4LVps5+9bxOeNiCvgmOyt96J3roHTYs7oE=
90+
golang.org/x/net v0.0.0-20181005035420-146acd28ed58/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
7691
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
92+
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f h1:wMNYb4v58l5UBM7MYRLPG6ZhfOqbKu7X5eyFl8ZhKvA=
7793
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
7894
golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
7995
golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg=
8096
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
97+
golang.org/x/tools v0.0.0-20180828015842-6cd1fcedba52 h1:JG/0uqcGdTNgq7FdU+61l5Pdmb8putNZlXb65bJBROs=
8198
golang.org/x/tools v0.0.0-20180828015842-6cd1fcedba52/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
8299
google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM=
83100
google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8 h1:Nw54tB0rB7hY/N0NQvRW8DG4Yk3Q6T9cu9RcFQDu1tc=
84101
google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc=
85102
google.golang.org/grpc v1.15.0 h1:Az/KuahOM4NAidTEuJCv/RonAA7rYsTPkqXVjr+8OOw=
86103
google.golang.org/grpc v1.15.0/go.mod h1:0JHn/cJsOMiMfNA9+DeHDlAU7KAAB5GDlYFpa9MZMio=
104+
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
87105
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
88106
gopkg.in/inf.v0 v0.9.1 h1:73M5CoZyi3ZLMOyDlQh031Cx6N9NDJ2Vvfl76EDAgDc=
89107
gopkg.in/inf.v0 v0.9.1/go.mod h1:cWUDdTG/fYaXco+Dcufb5Vnc6Gp2YChqWtbxRZE0mXw=
108+
gopkg.in/yaml.v1 v1.0.0-20140924161607-9f9df34309c0 h1:POO/ycCATvegFmVuPpQzZFJ+pGZeX22Ufu6fibxDVjU=
90109
gopkg.in/yaml.v1 v1.0.0-20140924161607-9f9df34309c0/go.mod h1:WDnlLJ4WF5VGsH/HVa3CI79GS0ol3YnhVnKP89i0kNg=
91110
gopkg.in/yaml.v2 v2.2.1 h1:mUhvW9EsL+naU5Q3cakzfE91YhliOondGd6ZrsDBHQE=
92111
gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
@@ -99,5 +118,5 @@ k8s.io/client-go v7.0.0+incompatible h1:kiH+Y6hn+pc78QS/mtBfMJAMIIaWevHi++JvOGEE
99118
k8s.io/client-go v7.0.0+incompatible/go.mod h1:7vJpHMYJwNQCWgzmNV+VYUl1zCObLyodBc8nIyt8L5s=
100119
k8s.io/helm v2.11.0-rc.4+incompatible h1:+eF/aGKA9M2u2TVFyWFyMIA7lChdMdvyBFuXzZsoXRo=
101120
k8s.io/helm v2.11.0-rc.4+incompatible/go.mod h1:LZzlS4LQBHfciFOurYBFkCMTaZ0D1l+p0teMg7TSULI=
102-
sigs.k8s.io/kustomize v1.0.9-0.20180927233047-30597252c70c h1:Vo5jvg6jg33MJyq8HRyKNv6pIx4CSt8l9hIMSiOgzok=
103-
sigs.k8s.io/kustomize v1.0.9-0.20180927233047-30597252c70c/go.mod h1:MkjgH3RdOWrievjo6c9T245dYlB5QeXV4WCbnt/PEpU=
121+
sigs.k8s.io/kustomize v1.0.10 h1:KngFW4wrk7VRlvk1vJOF498rkxp088d8IHSrFsT1rz4=
122+
sigs.k8s.io/kustomize v1.0.10/go.mod h1:MkjgH3RdOWrievjo6c9T245dYlB5QeXV4WCbnt/PEpU=

pkg/generators/generators.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,12 @@ import (
99
"path"
1010
"strings"
1111

12+
"github.com/ContainerSolutions/helm-convert/pkg/types"
13+
"github.com/ContainerSolutions/helm-convert/pkg/utils"
1214
"github.com/ghodss/yaml"
1315
"github.com/golang/glog"
1416
"k8s.io/helm/pkg/proto/hapi/chart"
1517
ktypes "sigs.k8s.io/kustomize/pkg/types"
16-
17-
"github.com/ContainerSolutions/helm-convert/pkg/types"
18-
"github.com/ContainerSolutions/helm-convert/pkg/utils"
1918
)
2019

2120
const (

pkg/helm/helm.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ import (
1111
"path/filepath"
1212
"strings"
1313

14+
"github.com/ghodss/yaml"
15+
"github.com/golang/glog"
1416
"k8s.io/helm/pkg/chartutil"
1517
"k8s.io/helm/pkg/downloader"
1618
"k8s.io/helm/pkg/getter"
@@ -20,9 +22,6 @@ import (
2022
"k8s.io/helm/pkg/renderutil"
2123
"k8s.io/helm/pkg/repo"
2224
"k8s.io/helm/pkg/strvals"
23-
24-
"github.com/ghodss/yaml"
25-
"github.com/golang/glog"
2625
)
2726

2827
var defaultKubeVersion = fmt.Sprintf("%s.%s", chartutil.DefaultKubeVersion.Major, chartutil.DefaultKubeVersion.Minor)

pkg/transformers/annotations.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
package transformers
22

33
import (
4-
ktypes "sigs.k8s.io/kustomize/pkg/types"
5-
64
"github.com/ContainerSolutions/helm-convert/pkg/types"
75
"github.com/ContainerSolutions/helm-convert/pkg/utils"
6+
ktypes "sigs.k8s.io/kustomize/pkg/types"
87
)
98

109
type annotationsTransformer struct {
@@ -22,8 +21,8 @@ func NewAnnotationsTransformer(keys []string) Transformer {
2221
func (t *annotationsTransformer) Transform(config *ktypes.Kustomization, resources *types.Resources) error {
2322
// TODO: retrieve common annotations for config.CommonAnnotations
2423
RESOURCES_LOOP:
25-
for _, res := range resources.ResMap {
26-
obj := res.UnstructuredContent()
24+
for id := range resources.ResMap {
25+
obj := resources.ResMap[id].Map()
2726

2827
for _, key := range t.keys {
2928
err := utils.RecursivelyRemoveKey("annotations", key, obj)

pkg/transformers/annotations_test.go

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,16 @@ package transformers
22

33
import (
44
"fmt"
5-
"reflect"
65
"testing"
76

7+
"github.com/ContainerSolutions/helm-convert/pkg/types"
8+
"github.com/kylelemons/godebug/pretty"
9+
"sigs.k8s.io/kustomize/k8sdeps/kunstruct"
810
"sigs.k8s.io/kustomize/pkg/gvk"
11+
"sigs.k8s.io/kustomize/pkg/resid"
912
"sigs.k8s.io/kustomize/pkg/resmap"
1013
"sigs.k8s.io/kustomize/pkg/resource"
1114
ktypes "sigs.k8s.io/kustomize/pkg/types"
12-
13-
"github.com/davecgh/go-spew/spew"
14-
15-
"github.com/ContainerSolutions/helm-convert/pkg/types"
1615
)
1716

1817
type annotationsTransformerArgs struct {
@@ -23,6 +22,7 @@ type annotationsTransformerArgs struct {
2322
func TestAnnotationsRun(t *testing.T) {
2423
var ingress = gvk.Gvk{Kind: "Ingress"}
2524
var deploy = gvk.Gvk{Group: "apps", Version: "v1", Kind: "Deployment"}
25+
var rf = resource.NewFactory(kunstruct.NewKunstructuredFactoryImpl())
2626

2727
for _, test := range []struct {
2828
name string
@@ -41,7 +41,7 @@ func TestAnnotationsRun(t *testing.T) {
4141
config: &ktypes.Kustomization{},
4242
resources: &types.Resources{
4343
ResMap: resmap.ResMap{
44-
resource.NewResId(ingress, "ing1"): resource.NewResourceFromMap(
44+
resid.NewResId(ingress, "ing1"): rf.FromMap(
4545
map[string]interface{}{
4646
"apiVersion": "v1",
4747
"kind": "Ingress",
@@ -52,7 +52,7 @@ func TestAnnotationsRun(t *testing.T) {
5252
},
5353
},
5454
}),
55-
resource.NewResId(deploy, "deploy1"): resource.NewResourceFromMap(
55+
resid.NewResId(deploy, "deploy1"): rf.FromMap(
5656
map[string]interface{}{
5757
"apiVersion": "v1",
5858
"kind": "Deployment",
@@ -81,7 +81,7 @@ func TestAnnotationsRun(t *testing.T) {
8181
config: &ktypes.Kustomization{},
8282
resources: &types.Resources{
8383
ResMap: resmap.ResMap{
84-
resource.NewResId(ingress, "ing1"): resource.NewResourceFromMap(
84+
resid.NewResId(ingress, "ing1"): rf.FromMap(
8585
map[string]interface{}{
8686
"apiVersion": "v1",
8787
"kind": "Ingress",
@@ -92,7 +92,7 @@ func TestAnnotationsRun(t *testing.T) {
9292
},
9393
},
9494
}),
95-
resource.NewResId(deploy, "deploy1"): resource.NewResourceFromMap(
95+
resid.NewResId(deploy, "deploy1"): rf.FromMap(
9696
map[string]interface{}{
9797
"apiVersion": "v1",
9898
"kind": "Deployment",
@@ -122,20 +122,13 @@ func TestAnnotationsRun(t *testing.T) {
122122
if err != nil {
123123
t.Fatalf("unexpected error: %v", err)
124124
}
125-
if !reflect.DeepEqual(test.input.config, test.expected.config) {
126-
t.Fatalf(
127-
"expected: \n %v\ngot:\n %v",
128-
spew.Sdump(test.expected.config),
129-
spew.Sdump(test.input.config),
130-
)
125+
126+
if diff := pretty.Compare(test.input.config, test.expected.config); diff != "" {
127+
t.Errorf("%s, diff: (-got +want)\n%s", test.name, diff)
131128
}
132129

133-
if !reflect.DeepEqual(test.input.resources, test.expected.resources) {
134-
t.Fatalf(
135-
"expected: \n %v\ngot:\n %v",
136-
spew.Sdump(test.expected.resources),
137-
spew.Sdump(test.input.resources),
138-
)
130+
if diff := pretty.Compare(test.input.resources, test.expected.resources); diff != "" {
131+
t.Errorf("%s, diff: (-got +want)\n%s", test.name, diff)
139132
}
140133
})
141134
}

pkg/transformers/configmap.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ package transformers
33
import (
44
"fmt"
55
"regexp"
6+
"sort"
67

8+
"github.com/ContainerSolutions/helm-convert/pkg/types"
79
"github.com/golang/glog"
810
ktypes "sigs.k8s.io/kustomize/pkg/types"
9-
10-
"github.com/ContainerSolutions/helm-convert/pkg/types"
1111
)
1212

1313
type configMapTransformer struct{}
@@ -23,7 +23,7 @@ func NewConfigMapTransformer() Transformer {
2323

2424
// Transform retrieve configmap from manifests and store them as configMapGenerator in the kustomization.yaml
2525
func (t *configMapTransformer) Transform(config *ktypes.Kustomization, resources *types.Resources) error {
26-
for _, res := range resources.ResMap {
26+
for id, res := range resources.ResMap {
2727
kind, err := res.GetFieldValue("kind")
2828
if err != nil {
2929
return err
@@ -38,7 +38,7 @@ func (t *configMapTransformer) Transform(config *ktypes.Kustomization, resources
3838
return err
3939
}
4040

41-
obj := res.UnstructuredContent()
41+
obj := resources.ResMap[id].Map()
4242

4343
if _, found := obj["data"]; !found {
4444
glog.V(8).Infof("Data field from configmap '%s' was not found", name)
@@ -75,6 +75,9 @@ func (t *configMapTransformer) Transform(config *ktypes.Kustomization, resources
7575
}
7676
}
7777

78+
sort.Strings(literalSources)
79+
sort.Strings(fileSources)
80+
7881
configMapArg.DataSources = ktypes.DataSources{
7982
LiteralSources: literalSources,
8083
FileSources: fileSources,

0 commit comments

Comments
 (0)