From 91f6492de3a01cb661b570e2b80445526cf4444d Mon Sep 17 00:00:00 2001 From: Etienne Tremel Date: Tue, 12 Mar 2019 22:10:10 +0100 Subject: [PATCH 1/5] Initial migration to kustomize v2.x --- cmd/convert.go | 2 +- go.mod | 20 ++----- go.sum | 44 +++------------ pkg/generators/comments.go | 2 +- pkg/transformers/configmap.go | 6 ++- pkg/transformers/configmap_test.go | 14 ++--- pkg/transformers/{imagetag.go => image.go} | 53 ++++++++++--------- .../{imagetag_test.go => image_test.go} | 23 ++++---- pkg/transformers/secret.go | 13 +++-- pkg/transformers/secret_test.go | 34 +++++++----- 10 files changed, 93 insertions(+), 118 deletions(-) rename pkg/transformers/{imagetag.go => image.go} (53%) rename pkg/transformers/{imagetag_test.go => image_test.go} (89%) diff --git a/cmd/convert.go b/cmd/convert.go index f5ed53b..584b1e5 100644 --- a/cmd/convert.go +++ b/cmd/convert.go @@ -225,7 +225,7 @@ func (k *convertCmd) run() error { hooks.HookWeightAnno, hooks.HookDeleteAnno, }), - transformers.NewImageTagTransformer(), + transformers.NewImageTransformer(), transformers.NewConfigMapTransformer(), transformers.NewSecretTransformer(), transformers.NewNamePrefixTransformer(), diff --git a/go.mod b/go.mod index fa0ba17..7f8f3d9 100644 --- a/go.mod +++ b/go.mod @@ -5,8 +5,7 @@ require ( github.com/Masterminds/semver v1.4.2 // indirect github.com/Masterminds/sprig v2.16.0+incompatible // indirect github.com/aokoli/goutils v1.0.1 // indirect - github.com/aws/aws-sdk-go v1.15.44 // indirect - github.com/bgentry/go-netrc v0.0.0-20140422174119-9fd32a8b3d3d // indirect + github.com/cyphar/filepath-securejoin v0.2.2 // indirect github.com/davecgh/go-spew v1.1.1 // indirect github.com/ghodss/yaml v1.0.0 github.com/gobwas/glob v0.2.3 // indirect @@ -14,29 +13,18 @@ require ( github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b github.com/google/gofuzz v0.0.0-20170612174753-24818f796faf // indirect github.com/google/uuid v1.0.0 // indirect - github.com/gopherjs/gopherjs v0.0.0-20181004151105-1babbf986f6f // indirect - github.com/hashicorp/go-cleanhttp v0.5.0 // indirect - github.com/hashicorp/go-getter v0.0.0-20180809191950-4bda8fa99001 // indirect - github.com/hashicorp/go-safetemp v1.0.0 // indirect - github.com/hashicorp/go-version v1.0.0 // indirect github.com/huandu/xstrings v1.2.0 // indirect github.com/imdario/mergo v0.0.0-20141206190957-6633656539c1 // indirect github.com/inconshreveable/mousetrap v1.0.0 // indirect github.com/json-iterator/go v1.1.5 // indirect - github.com/jtolds/gls v4.2.1+incompatible // indirect github.com/kylelemons/godebug v0.0.0-20170820004349-d65d576e9348 - github.com/mitchellh/go-homedir v1.0.0 // indirect - github.com/mitchellh/go-testing-interface v1.0.0 // indirect github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect github.com/modern-go/reflect2 v1.0.1 // indirect github.com/pkg/errors v0.8.0 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect - github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d // indirect - github.com/smartystreets/goconvey v0.0.0-20180222194500-ef6db91d284a // indirect github.com/spf13/cobra v0.0.3 github.com/spf13/pflag v1.0.2 // indirect github.com/stretchr/testify v1.2.2 // indirect - github.com/ulikunitz/xz v0.5.4 // indirect golang.org/x/crypto v0.0.0-20181009213950-7c1a557ab941 // indirect golang.org/x/net v0.0.0-20181005035420-146acd28ed58 // indirect google.golang.org/grpc v1.15.0 @@ -45,7 +33,7 @@ require ( gopkg.in/yaml.v2 v2.2.1 // indirect k8s.io/api v0.0.0-20180628040859-072894a440bd k8s.io/apimachinery v0.0.0-20180621070125-103fd098999d - k8s.io/client-go v7.0.0+incompatible // indirect - k8s.io/helm v2.11.0-rc.4+incompatible - sigs.k8s.io/kustomize v1.0.10 + k8s.io/client-go v10.0.0+incompatible // indirect + k8s.io/helm v2.13.0+incompatible + sigs.k8s.io/kustomize v2.0.3+incompatible ) diff --git a/go.sum b/go.sum index 79ffd99..6a5f0b3 100644 --- a/go.sum +++ b/go.sum @@ -7,17 +7,13 @@ github.com/Masterminds/sprig v2.16.0+incompatible h1:QZbMUPxRQ50EKAq3LFMnxddMu88 github.com/Masterminds/sprig v2.16.0+incompatible/go.mod h1:y6hNFY5UBTIWBxnzTeuNhlNS5hqE0NB0E6fgfo2Br3o= github.com/aokoli/goutils v1.0.1 h1:7fpzNGoJ3VA8qcrm++XEE1QUe0mIwNeLa02Nwq7RDkg= github.com/aokoli/goutils v1.0.1/go.mod h1:SijmP0QR8LtwsmDs8Yii5Z/S4trXFGFC2oO5g9DP+DQ= -github.com/aws/aws-sdk-go v1.15.44 h1:XIhmST75fI9XXOdRQKw2czRLiT7abSjKLXdhD9jC4Fk= -github.com/aws/aws-sdk-go v1.15.44/go.mod h1:mFuSZ37Z9YOHbQEwBWztmVzqXrEkub65tZoCYDt7FT0= -github.com/bgentry/go-netrc v0.0.0-20140422174119-9fd32a8b3d3d h1:xDfNPAt8lFiC1UJrqV3uuy861HCTo708pDMbjHHdCas= -github.com/bgentry/go-netrc v0.0.0-20140422174119-9fd32a8b3d3d/go.mod h1:6QX/PXZ00z/TKoufEY6K/a0k6AhaJrQKdFe6OfVXsa4= github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= +github.com/cyphar/filepath-securejoin v0.2.2 h1:jCwT2GTP+PY5nBz3c/YL5PAIbusElVrPujOBSCj8xRg= +github.com/cyphar/filepath-securejoin v0.2.2/go.mod h1:FpkQEhXnPnOthhzymB7CGsFk2G9VLXONKD9G7QGMM+4= 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/ghodss/yaml v1.0.0 h1:wQHKEahhL6wmXdzwWG11gIVCkOv05bNOh+Rxn0yngAk= github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= -github.com/go-ini/ini v1.25.4 h1:Mujh4R/dH6YL8bxuISne3xX2+qcQ9p0IxKAP6ExWoUo= -github.com/go-ini/ini v1.25.4/go.mod h1:ByCAeIL28uOIIG0E3PJtZPDL8WnHpFKFOtgjp+3Ies8= github.com/gobwas/glob v0.2.3 h1:A4xDbljILXROh+kObIiy5kIaPYD8e96x1tgBhUI5J+Y= github.com/gobwas/glob v0.2.3/go.mod h1:d3Ez4x06l9bZtSvzIay5+Yzi0fmZzPgnTbPcKjJAkT8= github.com/gogo/protobuf v1.1.1 h1:72R+M5VuhED/KujmZVcIquuo8mBgX4oVda//DQb3PXo= @@ -32,35 +28,17 @@ github.com/google/gofuzz v0.0.0-20170612174753-24818f796faf h1:+RRA9JqSOZFfKrOeq github.com/google/gofuzz v0.0.0-20170612174753-24818f796faf/go.mod h1:HP5RmnzzSNb993RKQDq4+1A4ia9nllfqcQFTQJedwGI= github.com/google/uuid v1.0.0 h1:b4Gk+7WdP/d3HZH8EJsZpvV7EtDOgaZLtnaNGIu1adA= github.com/google/uuid v1.0.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= -github.com/gopherjs/gopherjs v0.0.0-20181004151105-1babbf986f6f h1:JJ2EP5vV3LAD2U1CxQtD7PTOO15Y96kXmKDz7TjxGHs= -github.com/gopherjs/gopherjs v0.0.0-20181004151105-1babbf986f6f/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY= -github.com/hashicorp/go-cleanhttp v0.5.0 h1:wvCrVc9TjDls6+YGAF2hAifE1E5U1+b4tH6KdvN3Gig= -github.com/hashicorp/go-cleanhttp v0.5.0/go.mod h1:JpRdi6/HCYpAwUzNwuwqhbovhLtngrth3wmdIIUrZ80= -github.com/hashicorp/go-getter v0.0.0-20180809191950-4bda8fa99001 h1:MFPzqpPED05pFyGjNPJEC2sXM6EHTzFyvX+0s0JoZ48= -github.com/hashicorp/go-getter v0.0.0-20180809191950-4bda8fa99001/go.mod h1:6rdJFnhkXnzGOJbvkrdv4t9nLwKcVA+tmbQeUlkIzrU= -github.com/hashicorp/go-safetemp v1.0.0 h1:2HR189eFNrjHQyENnQMMpCiBAsRxzbTMIgBhEyExpmo= -github.com/hashicorp/go-safetemp v1.0.0/go.mod h1:oaerMy3BhqiTbVye6QuFhFtIceqFoDHxNAB65b+Rj1I= -github.com/hashicorp/go-version v1.0.0 h1:21MVWPKDphxa7ineQQTrCU5brh7OuVVAzGOCnnCPtE8= -github.com/hashicorp/go-version v1.0.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA= github.com/huandu/xstrings v1.2.0 h1:yPeWdRnmynF7p+lLYz0H2tthW9lqhMJrQV/U7yy4wX0= github.com/huandu/xstrings v1.2.0/go.mod h1:DvyZB1rfVYsBIigL8HwpZgxHwXozlTgGqn63UyNX5k4= github.com/imdario/mergo v0.0.0-20141206190957-6633656539c1 h1:FeeCi0I2Fu8kA8IXrdVPtGzym+mW9bzfj9f26EaES9k= github.com/imdario/mergo v0.0.0-20141206190957-6633656539c1/go.mod h1:2EnlNZ0deacrJVfApfmtdGgDfMuh/nq6Ok1EcJh5FfA= github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NHg9XEKhtSvM= github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8= -github.com/jmespath/go-jmespath v0.0.0-20160202185014-0b12d6b521d8 h1:12VvqtR6Aowv3l/EQUlocDHW2Cp4G9WJVH7uyH8QFJE= -github.com/jmespath/go-jmespath v0.0.0-20160202185014-0b12d6b521d8/go.mod h1:Nht3zPeWKUH0NzdCt2Blrr5ys8VGpn0CEB0cQHVjt7k= github.com/json-iterator/go v1.1.5 h1:gL2yXlmiIo4+t+y32d4WGwOjKGYcGOuyrg46vadswDE= github.com/json-iterator/go v1.1.5/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU= -github.com/jtolds/gls v4.2.1+incompatible h1:fSuqC+Gmlu6l/ZYAoZzx2pyucC8Xza35fpRVWLVmUEE= -github.com/jtolds/gls v4.2.1+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU= github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= github.com/kylelemons/godebug v0.0.0-20170820004349-d65d576e9348 h1:MtvEpTB6LX3vkb4ax0b5D2DHbNAUsen0Gx5wZoq3lV4= github.com/kylelemons/godebug v0.0.0-20170820004349-d65d576e9348/go.mod h1:B69LEHPfb2qLo0BaaOLcbitczOKLWTsrBG9LczfCD4k= -github.com/mitchellh/go-homedir v1.0.0 h1:vKb8ShqSby24Yrqr/yDYkuFz8d0WUjys40rvnGC8aR0= -github.com/mitchellh/go-homedir v1.0.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= -github.com/mitchellh/go-testing-interface v1.0.0 h1:fzU/JVNcaqHQEcVFAKeR41fkiLdIPrefOvVG1VZ96U0= -github.com/mitchellh/go-testing-interface v1.0.0/go.mod h1:kRemZodwjscx+RGhAo8eIhFbs2+BFgRtFPeD/KE+zxI= github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg= github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= github.com/modern-go/reflect2 v1.0.1 h1:9f412s+6RmYXLWZSEzVVgPGK7C2PphHj5RJrvfx9AWI= @@ -69,18 +47,12 @@ github.com/pkg/errors v0.8.0 h1:WdK/asTD0HN+q6hsWO3/vpuAkAr+tw6aNJNDFFf0+qw= github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d h1:zE9ykElWQ6/NYmHa3jpm/yHnI4xSofP+UP6SpjHcSeM= -github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc= -github.com/smartystreets/goconvey v0.0.0-20180222194500-ef6db91d284a h1:JSvGDIbmil4Ui/dDdFBExb7/cmkNjyX5F97oglmvCDo= -github.com/smartystreets/goconvey v0.0.0-20180222194500-ef6db91d284a/go.mod h1:XDJAKZRPZ1CvBcN2aX5YOUTYGHki24fSF0Iv48Ibg0s= github.com/spf13/cobra v0.0.3 h1:ZlrZ4XsMRm04Fr5pSFxBgfND2EBVa1nLpiy1stUsX/8= github.com/spf13/cobra v0.0.3/go.mod h1:1l0Ry5zgKvJasoi3XT1TypsSe7PqH0Sj9dhYf7v3XqQ= github.com/spf13/pflag v1.0.2 h1:Fy0orTDgHdbnzHcsOgfCN4LtHf0ec3wwtiwJqwvf3Gc= github.com/spf13/pflag v1.0.2/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4= github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1w= github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= -github.com/ulikunitz/xz v0.5.4 h1:zATC2OoZ8H1TZll3FpbX+ikwmadbO699PE06cIkm9oU= -github.com/ulikunitz/xz v0.5.4/go.mod h1:2bypXElzHzzJZwzH67Y6wb67pO62Rzfn7BSiF4ABRW8= golang.org/x/crypto v0.0.0-20181009213950-7c1a557ab941 h1:qBTHLajHecfu+xzRI9PqVDcqx7SdHj9d4B+EzSn3tAc= golang.org/x/crypto v0.0.0-20181009213950-7c1a557ab941/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/lint v0.0.0-20180702182130-06c8688daad7/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= @@ -114,9 +86,9 @@ k8s.io/api v0.0.0-20180628040859-072894a440bd h1:HzgYeLDS1jLxw8DGr68KJh9cdQ5iZJi k8s.io/api v0.0.0-20180628040859-072894a440bd/go.mod h1:iuAfoD4hCxJ8Onx9kaTIt30j7jUFS00AXQi6QMi99vA= k8s.io/apimachinery v0.0.0-20180621070125-103fd098999d h1:MZjlsu9igBoVPZkXpIGoxI6EonqNsXXZU7hhvfQLkd4= k8s.io/apimachinery v0.0.0-20180621070125-103fd098999d/go.mod h1:ccL7Eh7zubPUSh9A3USN90/OzHNSVN6zxzde07TDCL0= -k8s.io/client-go v7.0.0+incompatible h1:kiH+Y6hn+pc78QS/mtBfMJAMIIaWevHi++JvOGEEQp4= -k8s.io/client-go v7.0.0+incompatible/go.mod h1:7vJpHMYJwNQCWgzmNV+VYUl1zCObLyodBc8nIyt8L5s= -k8s.io/helm v2.11.0-rc.4+incompatible h1:GAfCHQGqACuv1juOmFDQkrpmzRKL9sKtMa4KRhdlwoQ= -k8s.io/helm v2.11.0-rc.4+incompatible/go.mod h1:LZzlS4LQBHfciFOurYBFkCMTaZ0D1l+p0teMg7TSULI= -sigs.k8s.io/kustomize v1.0.10 h1:KngFW4wrk7VRlvk1vJOF498rkxp088d8IHSrFsT1rz4= -sigs.k8s.io/kustomize v1.0.10/go.mod h1:MkjgH3RdOWrievjo6c9T245dYlB5QeXV4WCbnt/PEpU= +k8s.io/client-go v10.0.0+incompatible h1:F1IqCqw7oMBzDkqlcBymRq1450wD0eNqLE9jzUrIi34= +k8s.io/client-go v10.0.0+incompatible/go.mod h1:7vJpHMYJwNQCWgzmNV+VYUl1zCObLyodBc8nIyt8L5s= +k8s.io/helm v2.13.0+incompatible h1:d1WBmGGoVb5VZcmQbysDbXGR0Kh/IXPe1SXldrdu19U= +k8s.io/helm v2.13.0+incompatible/go.mod h1:LZzlS4LQBHfciFOurYBFkCMTaZ0D1l+p0teMg7TSULI= +sigs.k8s.io/kustomize v2.0.3+incompatible h1:JUufWFNlI44MdtnjUqVnvh29rR37PQFzPbLXqhyOyX0= +sigs.k8s.io/kustomize v2.0.3+incompatible/go.mod h1:MkjgH3RdOWrievjo6c9T245dYlB5QeXV4WCbnt/PEpU= diff --git a/pkg/generators/comments.go b/pkg/generators/comments.go index b24fc09..4cd8a3e 100644 --- a/pkg/generators/comments.go +++ b/pkg/generators/comments.go @@ -25,6 +25,6 @@ var commentsMapping = map[string]string{ "# a file for custom resource definition(CRD).", "vars": "# Vars are used to insert values from resources that cannot\n" + "# be referenced otherwise.", - "imageTags": "# ImageTags modify the tags for images without\n" + + "images": "# Images modify the tags for images without\n" + "# creating patches.", } diff --git a/pkg/transformers/configmap.go b/pkg/transformers/configmap.go index b18a174..0b2e856 100644 --- a/pkg/transformers/configmap.go +++ b/pkg/transformers/configmap.go @@ -53,7 +53,9 @@ func (t *configMapTransformer) Transform(config *ktypes.Kustomization, resources data := obj["data"].(map[string]interface{}) configMapArg := ktypes.ConfigMapArgs{ - Name: name, + GeneratorArgs: ktypes.GeneratorArgs{ + Name: name, + }, } var fileSources []string @@ -78,7 +80,7 @@ func (t *configMapTransformer) Transform(config *ktypes.Kustomization, resources sort.Strings(literalSources) sort.Strings(fileSources) - configMapArg.DataSources = ktypes.DataSources{ + configMapArg.GeneratorArgs.DataSources = ktypes.DataSources{ LiteralSources: literalSources, FileSources: fileSources, } diff --git a/pkg/transformers/configmap_test.go b/pkg/transformers/configmap_test.go index 54bc7bb..f6c75c2 100644 --- a/pkg/transformers/configmap_test.go +++ b/pkg/transformers/configmap_test.go @@ -61,13 +61,15 @@ spring.datasource.password=pass123 config: &ktypes.Kustomization{ ConfigMapGenerator: []ktypes.ConfigMapArgs{ ktypes.ConfigMapArgs{ - Name: "configmap1", - DataSources: ktypes.DataSources{ - LiteralSources: []string{ - "SOME_ENV=\"development\"", - "somekey=\"not a file\"", + GeneratorArgs: ktypes.GeneratorArgs{ + Name: "configmap1", + DataSources: ktypes.DataSources{ + LiteralSources: []string{ + "SOME_ENV=\"development\"", + "somekey=\"not a file\"", + }, + FileSources: []string{"configmap1-application.properties"}, }, - FileSources: []string{"configmap1-application.properties"}, }, }, }, diff --git a/pkg/transformers/imagetag.go b/pkg/transformers/image.go similarity index 53% rename from pkg/transformers/imagetag.go rename to pkg/transformers/image.go index d2535dd..dbd131e 100644 --- a/pkg/transformers/imagetag.go +++ b/pkg/transformers/image.go @@ -5,23 +5,24 @@ import ( "strings" "github.com/ContainerSolutions/helm-convert/pkg/types" + kimage "sigs.k8s.io/kustomize/pkg/image" ktypes "sigs.k8s.io/kustomize/pkg/types" ) -// imageTagTransformer replace image tags -type imageTagTransformer struct { - imageTags []ktypes.ImageTag +// imageTransformer replace images +type imageTransformer struct { + images []kimage.Image } -var _ Transformer = &imageTagTransformer{} +var _ Transformer = &imageTransformer{} -// NewImageTagTransformer constructs a imageTagTransformer. -func NewImageTagTransformer() Transformer { - return &imageTagTransformer{} +// NewImageTransformer constructs a imageTransformer. +func NewImageTransformer() Transformer { + return &imageTransformer{} } // Transform finds all images and store them in the kustomization.yaml file -func (pt *imageTagTransformer) Transform(config *ktypes.Kustomization, resources *types.Resources) error { +func (pt *imageTransformer) Transform(config *ktypes.Kustomization, resources *types.Resources) error { for id := range resources.ResMap { obj := resources.ResMap[id].Map() err := pt.findImage(config, obj) @@ -30,14 +31,14 @@ func (pt *imageTagTransformer) Transform(config *ktypes.Kustomization, resources } } - sort.Slice(config.ImageTags, func(i, j int) bool { - return imageTagString(config.ImageTags[i]) < imageTagString(config.ImageTags[j]) + sort.Slice(config.Images, func(i, j int) bool { + return imageString(config.Images[i]) < imageString(config.Images[j]) }) return nil } -func (pt *imageTagTransformer) findImage(config *ktypes.Kustomization, obj map[string]interface{}) error { +func (pt *imageTransformer) findImage(config *ktypes.Kustomization, obj map[string]interface{}) error { paths := []string{"containers", "initContainers"} found := false for _, path := range paths { @@ -55,7 +56,7 @@ func (pt *imageTagTransformer) findImage(config *ktypes.Kustomization, obj map[s return nil } -func (pt *imageTagTransformer) getImageTag(config *ktypes.Kustomization, obj map[string]interface{}, path string) error { +func (pt *imageTransformer) getImageTag(config *ktypes.Kustomization, obj map[string]interface{}, path string) error { containers := obj[path].([]interface{}) LOOP_CONTAINERS: for i := range containers { @@ -66,42 +67,42 @@ LOOP_CONTAINERS: continue } - image := imagePath.(string) + imagePathStr := imagePath.(string) - hasDigest := strings.Contains(image, "@") + hasDigest := strings.Contains(imagePathStr, "@") separator := ":" if hasDigest { separator = "@" } - s := strings.Split(image, separator) + s := strings.Split(imagePathStr, separator) - imageTag := ktypes.ImageTag{ + image := kimage.Image{ Name: s[0], } // doesn't add image if already in the list - for _, v := range config.ImageTags { - if v.Name == imageTag.Name { + for _, v := range config.Images { + if v.Name == image.Name { continue LOOP_CONTAINERS } } if len(s) > 1 { if hasDigest { - imageTag.Digest = s[1] + image.Digest = s[1] } else { - imageTag.NewTag = s[1] + image.NewTag = s[1] } } - config.ImageTags = append(config.ImageTags, imageTag) + config.Images = append(config.Images, image) } return nil } -func (pt *imageTagTransformer) findContainers(config *ktypes.Kustomization, obj map[string]interface{}) error { +func (pt *imageTransformer) findContainers(config *ktypes.Kustomization, obj map[string]interface{}) error { for key := range obj { switch typedV := obj[key].(type) { case map[string]interface{}: @@ -125,9 +126,9 @@ func (pt *imageTagTransformer) findContainers(config *ktypes.Kustomization, obj return nil } -func imageTagString(imageTag ktypes.ImageTag) string { - if imageTag.Digest != "" { - return imageTag.Name + "@" + imageTag.Digest +func imageString(image kimage.Image) string { + if image.Digest != "" { + return image.Name + "@" + image.Digest } - return imageTag.Name + ":" + imageTag.NewTag + return image.Name + ":" + image.NewTag } diff --git a/pkg/transformers/imagetag_test.go b/pkg/transformers/image_test.go similarity index 89% rename from pkg/transformers/imagetag_test.go rename to pkg/transformers/image_test.go index e378897..47ecadf 100644 --- a/pkg/transformers/imagetag_test.go +++ b/pkg/transformers/image_test.go @@ -8,29 +8,30 @@ import ( "github.com/kylelemons/godebug/pretty" "sigs.k8s.io/kustomize/k8sdeps/kunstruct" "sigs.k8s.io/kustomize/pkg/gvk" + kimage "sigs.k8s.io/kustomize/pkg/image" "sigs.k8s.io/kustomize/pkg/resid" "sigs.k8s.io/kustomize/pkg/resmap" "sigs.k8s.io/kustomize/pkg/resource" ktypes "sigs.k8s.io/kustomize/pkg/types" ) -type imageTagTransformerArgs struct { +type imageTransformerArgs struct { config *ktypes.Kustomization resources *types.Resources } -func TestImageTagRun(t *testing.T) { +func TestImageRun(t *testing.T) { var deploy = gvk.Gvk{Group: "apps", Version: "v1", Kind: "Deployment"} var rf = resource.NewFactory(kunstruct.NewKunstructuredFactoryImpl()) for _, test := range []struct { name string - input *imageTagTransformerArgs - expected *imageTagTransformerArgs + input *imageTransformerArgs + expected *imageTransformerArgs }{ { name: "it should retrieve images", - input: &imageTagTransformerArgs{ + input: &imageTransformerArgs{ config: &ktypes.Kustomization{}, resources: &types.Resources{ ResMap: resmap.ResMap{ @@ -87,12 +88,12 @@ func TestImageTagRun(t *testing.T) { }, }, }, - expected: &imageTagTransformerArgs{ + expected: &imageTransformerArgs{ config: &ktypes.Kustomization{ - ImageTags: []ktypes.ImageTag{ - ktypes.ImageTag{Name: "alpine", Digest: "sha256:24a0c4b4a4c0eb97a1aabb8e29f18e917d05abfe1b7a7c07857230879ce7d3d3"}, - ktypes.ImageTag{Name: "busybox"}, - ktypes.ImageTag{Name: "nginx", NewTag: "1.7.9"}, + Images: []kimage.Image{ + kimage.Image{Name: "alpine", Digest: "sha256:24a0c4b4a4c0eb97a1aabb8e29f18e917d05abfe1b7a7c07857230879ce7d3d3"}, + kimage.Image{Name: "busybox"}, + kimage.Image{Name: "nginx", NewTag: "1.7.9"}, }, }, resources: &types.Resources{ @@ -153,7 +154,7 @@ func TestImageTagRun(t *testing.T) { }, } { t.Run(fmt.Sprintf("%s", test.name), func(t *testing.T) { - lt := NewImageTagTransformer() + lt := NewImageTransformer() err := lt.Transform(test.input.config, test.input.resources) if err != nil { diff --git a/pkg/transformers/secret.go b/pkg/transformers/secret.go index d1c13ae..0b2e14e 100644 --- a/pkg/transformers/secret.go +++ b/pkg/transformers/secret.go @@ -48,21 +48,24 @@ func (t *secretTransformer) Transform(config *ktypes.Kustomization, resources *t } secretArg := ktypes.SecretArgs{ - Name: name, + GeneratorArgs: ktypes.GeneratorArgs{ + Name: name, + }, Type: secretType, } - commands := make(map[string]string) + // TODO: handle envSource and fileSources + literalSources := []string{} for key, value := range data { decoded, err := base64.StdEncoding.DecodeString(value.(string)) if err != nil { return fmt.Errorf("couldn't base64 decode the secret key '%s' with value '%v'", key, value) } - commands[string(key)] = fmt.Sprintf("printf \\\"%s\\\"", string(decoded)) + literalSources = append(literalSources, fmt.Sprintf("%s=%s", string(key), string(decoded))) } - secretArg.CommandSources = ktypes.CommandSources{ - Commands: commands, + secretArg.GeneratorArgs.DataSources = ktypes.DataSources{ + LiteralSources: literalSources, } config.SecretGenerator = append(config.SecretGenerator, secretArg) diff --git a/pkg/transformers/secret_test.go b/pkg/transformers/secret_test.go index beb262a..73d3910 100644 --- a/pkg/transformers/secret_test.go +++ b/pkg/transformers/secret_test.go @@ -90,34 +90,40 @@ func TestSecretRun(t *testing.T) { config: &ktypes.Kustomization{ SecretGenerator: []ktypes.SecretArgs{ ktypes.SecretArgs{ - Name: "secret1", - CommandSources: ktypes.CommandSources{ - Commands: map[string]string{ - "DB_USERNAME": "printf \\\"admin\\\"", - "DB_PASSWORD": "printf \\\"password\\\"", + GeneratorArgs: ktypes.GeneratorArgs{ + Name: "secret1", + DataSources: ktypes.DataSources{ + LiteralSources: []string{ + "DB_USERNAME=admin", + "DB_PASSWORD=password", + }, }, }, Type: string(corev1.SecretTypeOpaque), }, ktypes.SecretArgs{ - Name: "secret2", - CommandSources: ktypes.CommandSources{ - Commands: map[string]string{ - "tls.cert": "printf \\\"" + string(cert) + "\\\"", - "tls.key": "printf \\\"" + string(key) + "\\\"", + GeneratorArgs: ktypes.GeneratorArgs{ + Name: "secret2", + DataSources: ktypes.DataSources{ + LiteralSources: []string{ + "tls.cert": string(cert), + "tls.key": string(key), + }, }, }, Type: string(corev1.SecretTypeTLS), }, ktypes.SecretArgs{ - Name: "secret3", - CommandSources: ktypes.CommandSources{ - Commands: map[string]string{}, + GeneratorArgs: ktypes.GeneratorArgs{ + Name: "secret3", + DataSources: ktypes.DataSources{ + LiteralSources: []string{}, + }, }, Type: string(corev1.SecretTypeOpaque), }, }, - }, + , resources: &types.Resources{ ResMap: resmap.ResMap{}, }, From 515f92bdb779335521073c13e76cca1f0bd22873 Mon Sep 17 00:00:00 2001 From: Etienne Tremel Date: Sun, 17 Mar 2019 13:39:35 +0100 Subject: [PATCH 2/5] Handle datasources (literal, env and source files) --- README.md | 1 + pkg/generators/generators.go | 9 ++- pkg/transformers/configmap.go | 33 ++------ pkg/transformers/configmap_test.go | 15 ++-- pkg/transformers/datasources.go | 115 +++++++++++++++++++++++++++ pkg/transformers/datasources_test.go | 72 +++++++++++++++++ pkg/transformers/secret.go | 9 +-- pkg/transformers/secret_test.go | 25 +++--- pkg/types/resources.go | 8 +- 9 files changed, 230 insertions(+), 57 deletions(-) create mode 100644 pkg/transformers/datasources.go create mode 100644 pkg/transformers/datasources_test.go diff --git a/README.md b/README.md index 7d6030b..f0b70ff 100644 --- a/README.md +++ b/README.md @@ -81,3 +81,4 @@ The conversion is currently quite basic and has the following features: - create secretGenerator based on secret resources (type Opaque and TLS) - create secretGenerator based on secret type TLS - create configGenerator from multiline files +- handle datasources type literal, env files and source files diff --git a/pkg/generators/generators.go b/pkg/generators/generators.go index 5a5640b..9851f97 100644 --- a/pkg/generators/generators.go +++ b/pkg/generators/generators.go @@ -33,7 +33,8 @@ func NewGenerator(force bool) *Generator { } // Render to disk the kustomization.yaml, Kube-descriptor.yaml and associated resources -func (g *Generator) Render(destination string, config *ktypes.Kustomization, metadata *chart.Metadata, resources *types.Resources, addConfigComments bool) error { +func (g *Generator) Render(destination string, config *ktypes.Kustomization, + metadata *chart.Metadata, resources *types.Resources, addConfigComments bool) error { var err error // chech if destination path already exist, prompt user to confirm override @@ -65,8 +66,10 @@ func (g *Generator) Render(destination string, config *ktypes.Kustomization, met } } - // render all config files - for filename, data := range resources.ConfigFiles { + // render all config and env files + for filename, data := range resources.SourceFiles { + // TODO: prevent overwriting of file, filename can be similar from one + // resource to another err = writeFile(path.Join(destination, filename), []byte(data), 0644) if err != nil { return err diff --git a/pkg/transformers/configmap.go b/pkg/transformers/configmap.go index 0b2e856..e043c10 100644 --- a/pkg/transformers/configmap.go +++ b/pkg/transformers/configmap.go @@ -1,9 +1,7 @@ package transformers import ( - "fmt" "regexp" - "sort" "github.com/ContainerSolutions/helm-convert/pkg/types" "github.com/golang/glog" @@ -51,6 +49,10 @@ func (t *configMapTransformer) Transform(config *ktypes.Kustomization, resources } data := obj["data"].(map[string]interface{}) + dataMap := make(map[string]string, len(data)) + for key, value := range data { + dataMap[key] = value.(string) + } configMapArg := ktypes.ConfigMapArgs{ GeneratorArgs: ktypes.GeneratorArgs{ @@ -58,32 +60,7 @@ func (t *configMapTransformer) Transform(config *ktypes.Kustomization, resources }, } - var fileSources []string - var literalSources []string - - for key, value := range data { - // if multiline, store as external file otherwise literal - // TODO: detect if key/value file, ie: .env, .ini and set DataSources.EnvSource - if v, ok := value.(string); ok { - if regexpMultiline.MatchString(v) { - glog.V(8).Infof("Converting '%s' as external file from configmap '%s'", key, name) - filename := fmt.Sprintf("%s-%s", name, key) - fileSources = append(fileSources, filename) - resources.ConfigFiles[filename] = v - } else { - glog.V(8).Infof("Converting '%s' as literal value from configmap '%s'", key, name) - literalSources = append(literalSources, fmt.Sprintf("%s=\"%s\"", key, value)) - } - } - } - - sort.Strings(literalSources) - sort.Strings(fileSources) - - configMapArg.GeneratorArgs.DataSources = ktypes.DataSources{ - LiteralSources: literalSources, - FileSources: fileSources, - } + configMapArg.GeneratorArgs.DataSources = TransformDataSource(name, dataMap, resources.SourceFiles) config.ConfigMapGenerator = append(config.ConfigMapGenerator, configMapArg) delete(resources.ResMap, res.Id()) diff --git a/pkg/transformers/configmap_test.go b/pkg/transformers/configmap_test.go index f6c75c2..5fdc359 100644 --- a/pkg/transformers/configmap_test.go +++ b/pkg/transformers/configmap_test.go @@ -54,7 +54,7 @@ spring.datasource.password=pass123 }, }), }, - ConfigFiles: map[string]string{}, + SourceFiles: map[string]string{}, }, }, expected: &configMapTransformerArgs{ @@ -65,8 +65,8 @@ spring.datasource.password=pass123 Name: "configmap1", DataSources: ktypes.DataSources{ LiteralSources: []string{ - "SOME_ENV=\"development\"", - "somekey=\"not a file\"", + "SOME_ENV=development", + "somekey=not a file", }, FileSources: []string{"configmap1-application.properties"}, }, @@ -76,7 +76,7 @@ spring.datasource.password=pass123 }, resources: &types.Resources{ ResMap: resmap.ResMap{}, - ConfigFiles: map[string]string{ + SourceFiles: map[string]string{ "configmap1-application.properties": ` app.name=My app spring.jpa.hibernate.ddl-auto=update @@ -90,8 +90,11 @@ spring.datasource.password=pass123 }, } { t.Run(fmt.Sprintf("%s", test.name), func(t *testing.T) { + res := types.NewResources() + res.ResMap = test.input.resources.ResMap + lt := NewConfigMapTransformer() - err := lt.Transform(test.input.config, test.input.resources) + err := lt.Transform(test.input.config, res) if err != nil { t.Fatalf("unexpected error: %v", err) @@ -101,7 +104,7 @@ spring.datasource.password=pass123 t.Errorf("%s, diff: (-got +want)\n%s", test.name, diff) } - if diff := pretty.Compare(test.input.resources, test.expected.resources); diff != "" { + if diff := pretty.Compare(res, test.expected.resources); diff != "" { t.Errorf("%s, diff: (-got +want)\n%s", test.name, diff) } }) diff --git a/pkg/transformers/datasources.go b/pkg/transformers/datasources.go new file mode 100644 index 0000000..c9e4a71 --- /dev/null +++ b/pkg/transformers/datasources.go @@ -0,0 +1,115 @@ +package transformers + +import ( + "fmt" + "regexp" + "sort" + "strings" + + "github.com/golang/glog" + ktypes "sigs.k8s.io/kustomize/pkg/types" +) + +var regexpEnv = regexp.MustCompile("^[A-Z0-9_]+$") + +// TransformDataSource return a Kustomize DataSource from a given ConfigMap.Data or +// Secret.Data. If all keys from the resource matches an environment variable +// format, the resource is converted as EnvFile. If keys contains a file +// extension and the value is multiline then the file is stored as FileSources, +// otherwise LiteralSources. +func TransformDataSource(resourceName string, input map[string]string, + sourceFiles map[string]string) (dataSources ktypes.DataSources) { + + if len(input) == 0 { + return + } + + if isEnvFile(input) { + envFilename := fmt.Sprintf("%s.env", resourceName) + envFile := TransformEnvDataSource(input) + sourceFiles[envFilename] = envFile + dataSources.EnvSource = envFilename + + glog.V(8).Infof("Converting '%s' as environment file with filename '%s'", + resourceName, envFilename) + } else { + for key, value := range TransformFileDataSource(input) { + filename := fmt.Sprintf("%s-%s", resourceName, key) + sourceFiles[filename] = value + dataSources.FileSources = append(dataSources.FileSources, filename) + } + dataSources.LiteralSources = TransformLiteralDataSource(input) + + sort.Strings(dataSources.FileSources) + sort.Strings(dataSources.LiteralSources) + + glog.V(8).Infof("Converting %d file(s) as external file and %d literal(s) "+ + "from resource '%s'", len(dataSources.FileSources), + len(dataSources.LiteralSources), resourceName) + } + + return +} + +// TransformEnvDataSource return an environment file from a given map +func TransformEnvDataSource(input map[string]string) (envFile string) { + var envList []string + for key, value := range input { + if isEnvVariable(key) { + envList = append(envList, fmt.Sprintf("%s=%s", key, value)) + } + } + sort.Strings(envList) + envFile = strings.Join(envList, "\n") + return +} + +// TransformFileDataSource return a list of files from a given map +func TransformFileDataSource(input map[string]string) (files map[string]string) { + files = make(map[string]string) + for key, value := range input { + if isFileExtension(key) && isMultiline(value) { + files[key] = value + } + } + return +} + +// TransformLiteralDataSource return a list of literals (key=value) from a +// given map +func TransformLiteralDataSource(input map[string]string) (literal []string) { + for key, value := range input { + if !isFileExtension(key) && !isMultiline(value) { + literal = append(literal, fmt.Sprintf("%s=%s", key, value)) + } + } + return +} + +// isEnvFile return true if all the keys provided from a map match an +// environment variable pattern (uppercase, underscore separated words and value +// isn't multiline) +func isEnvFile(input map[string]string) bool { + for key, value := range input { + if !isEnvVariable(key) || isMultiline(value) { + return false + } + } + return true +} + +// isMultiline return true if the provided value contains one of more line break +func isMultiline(s string) bool { + return strings.Contains(s, "\n") +} + +// isFileExtension return true if the provided string contains a dot +func isFileExtension(s string) bool { + return strings.Contains(s, ".") +} + +// isEnvVariable return true if the provided string match an environment +// variable pattern (uppercase, underscore separated words) +func isEnvVariable(key string) bool { + return regexpEnv.MatchString(key) +} diff --git a/pkg/transformers/datasources_test.go b/pkg/transformers/datasources_test.go new file mode 100644 index 0000000..d73dc51 --- /dev/null +++ b/pkg/transformers/datasources_test.go @@ -0,0 +1,72 @@ +package transformers + +import ( + "fmt" + "testing" + + "github.com/kylelemons/godebug/pretty" + ktypes "sigs.k8s.io/kustomize/pkg/types" +) + +func TestTransformDataSource(t *testing.T) { + for _, test := range []struct { + name string + resourceName string + input map[string]string + sourceFiles map[string]string + expectedSourceFile map[string]string + expectedOutput ktypes.DataSources + }{ + { + name: "it should detect file source and literal", + resourceName: "my-configmap", + input: map[string]string{ + "somevar": "single line", + "name.txt": "multi\nline", + }, + sourceFiles: map[string]string{ + "file1.yaml": "content", + }, + expectedSourceFile: map[string]string{ + "file1.yaml": "content", + "my-configmap-name.txt": "multi\nline", + }, + expectedOutput: ktypes.DataSources{ + LiteralSources: []string{ + "somevar=single line", + }, + FileSources: []string{ + "my-configmap-name.txt", + }, + }, + }, + { + name: "it should detect env file", + resourceName: "my-configmap", + input: map[string]string{ + "NODE_ENV": "production", + "SOMEENV": "blop", + }, + sourceFiles: map[string]string{ + "file1.yaml": "content", + }, + expectedSourceFile: map[string]string{ + "file1.yaml": "content", + "my-configmap.env": "NODE_ENV=production\nSOMEENV=blop", + }, + expectedOutput: ktypes.DataSources{ + EnvSource: "my-configmap.env", + }, + }, + } { + t.Run(fmt.Sprintf("%s", test.name), func(t *testing.T) { + output := TransformDataSource(test.resourceName, test.input, test.sourceFiles) + if diff := pretty.Compare(output, test.expectedOutput); diff != "" { + t.Errorf("%s, diff: (-got +want)\n%s", test.name, diff) + } + if diff := pretty.Compare(test.sourceFiles, test.expectedSourceFile); diff != "" { + t.Errorf("%s, diff: (-got +want)\n%s", test.name, diff) + } + }) + } +} diff --git a/pkg/transformers/secret.go b/pkg/transformers/secret.go index 0b2e14e..181deed 100644 --- a/pkg/transformers/secret.go +++ b/pkg/transformers/secret.go @@ -54,19 +54,16 @@ func (t *secretTransformer) Transform(config *ktypes.Kustomization, resources *t Type: secretType, } - // TODO: handle envSource and fileSources - literalSources := []string{} + dataDecoded := make(map[string]string, len(data)) for key, value := range data { decoded, err := base64.StdEncoding.DecodeString(value.(string)) if err != nil { return fmt.Errorf("couldn't base64 decode the secret key '%s' with value '%v'", key, value) } - literalSources = append(literalSources, fmt.Sprintf("%s=%s", string(key), string(decoded))) + dataDecoded[key] = string(decoded) } - secretArg.GeneratorArgs.DataSources = ktypes.DataSources{ - LiteralSources: literalSources, - } + secretArg.GeneratorArgs.DataSources = TransformDataSource(name, dataDecoded, resources.SourceFiles) config.SecretGenerator = append(config.SecretGenerator, secretArg) delete(resources.ResMap, res.Id()) diff --git a/pkg/transformers/secret_test.go b/pkg/transformers/secret_test.go index 73d3910..81199d2 100644 --- a/pkg/transformers/secret_test.go +++ b/pkg/transformers/secret_test.go @@ -93,10 +93,7 @@ func TestSecretRun(t *testing.T) { GeneratorArgs: ktypes.GeneratorArgs{ Name: "secret1", DataSources: ktypes.DataSources{ - LiteralSources: []string{ - "DB_USERNAME=admin", - "DB_PASSWORD=password", - }, + EnvSource: "secret1.env", }, }, Type: string(corev1.SecretTypeOpaque), @@ -105,9 +102,9 @@ func TestSecretRun(t *testing.T) { GeneratorArgs: ktypes.GeneratorArgs{ Name: "secret2", DataSources: ktypes.DataSources{ - LiteralSources: []string{ - "tls.cert": string(cert), - "tls.key": string(key), + FileSources: []string{ + "secret2-tls.cert", + "secret2-tls.key", }, }, }, @@ -123,16 +120,24 @@ func TestSecretRun(t *testing.T) { Type: string(corev1.SecretTypeOpaque), }, }, - , + }, resources: &types.Resources{ ResMap: resmap.ResMap{}, + SourceFiles: map[string]string{ + "secret1.env": "DB_PASSWORD=password\nDB_USERNAME=admin", + "secret2-tls.cert": string(cert), + "secret2-tls.key": string(key), + }, }, }, }, } { t.Run(fmt.Sprintf("%s", test.name), func(t *testing.T) { + res := types.NewResources() + res.ResMap = test.input.resources.ResMap + lt := NewSecretTransformer() - err := lt.Transform(test.input.config, test.input.resources) + err := lt.Transform(test.input.config, res) if err != nil { t.Fatalf("unexpected error: %v", err) @@ -142,7 +147,7 @@ func TestSecretRun(t *testing.T) { t.Errorf("%s, diff: (-got +want)\n%s", test.name, diff) } - if diff := pretty.Compare(test.input.resources, test.expected.resources); diff != "" { + if diff := pretty.Compare(res, test.expected.resources); diff != "" { t.Errorf("%s, diff: (-got +want)\n%s", test.name, diff) } }) diff --git a/pkg/types/resources.go b/pkg/types/resources.go index a12ddb9..3c147dc 100644 --- a/pkg/types/resources.go +++ b/pkg/types/resources.go @@ -9,15 +9,15 @@ type Resources struct { // ResMap contains a list of Kustomize resources ResMap resmap.ResMap - // ConfigFiles contains a list of external configuration file retrieved from - // configmaps resources, ie: a multiline application.properties - ConfigFiles map[string]string + // SourceFiles contains a list of file retrieved from either configmaps or + // secret resources. The key being the filename, and the value its content + SourceFiles map[string]string } // NewResources constructs a new Resources func NewResources() *Resources { return &Resources{ ResMap: resmap.ResMap{}, - ConfigFiles: make(map[string]string), + SourceFiles: make(map[string]string), } } From 83749e416be29432cc625ec4567f3bd59ee8b887 Mon Sep 17 00:00:00 2001 From: Etienne Tremel Date: Mon, 18 Mar 2019 19:22:49 +0100 Subject: [PATCH 3/5] Update go dependencies --- go.mod | 7 +++---- go.sum | 14 ++++++-------- 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/go.mod b/go.mod index 7f8f3d9..34faace 100644 --- a/go.mod +++ b/go.mod @@ -2,9 +2,9 @@ module github.com/ContainerSolutions/helm-convert require ( github.com/BurntSushi/toml v0.3.1 // indirect + github.com/Masterminds/goutils v1.1.0 // indirect github.com/Masterminds/semver v1.4.2 // indirect - github.com/Masterminds/sprig v2.16.0+incompatible // indirect - github.com/aokoli/goutils v1.0.1 // indirect + github.com/Masterminds/sprig v2.18.1-0.20190301161902-9f8fceff796f+incompatible // indirect github.com/cyphar/filepath-securejoin v0.2.2 // indirect github.com/davecgh/go-spew v1.1.1 // indirect github.com/ghodss/yaml v1.0.0 @@ -14,7 +14,7 @@ require ( github.com/google/gofuzz v0.0.0-20170612174753-24818f796faf // indirect github.com/google/uuid v1.0.0 // indirect github.com/huandu/xstrings v1.2.0 // indirect - github.com/imdario/mergo v0.0.0-20141206190957-6633656539c1 // indirect + github.com/imdario/mergo v0.3.7 // indirect github.com/inconshreveable/mousetrap v1.0.0 // indirect github.com/json-iterator/go v1.1.5 // indirect github.com/kylelemons/godebug v0.0.0-20170820004349-d65d576e9348 @@ -29,7 +29,6 @@ require ( golang.org/x/net v0.0.0-20181005035420-146acd28ed58 // indirect google.golang.org/grpc v1.15.0 gopkg.in/inf.v0 v0.9.1 // indirect - gopkg.in/yaml.v1 v1.0.0-20140924161607-9f9df34309c0 // indirect gopkg.in/yaml.v2 v2.2.1 // indirect k8s.io/api v0.0.0-20180628040859-072894a440bd k8s.io/apimachinery v0.0.0-20180621070125-103fd098999d diff --git a/go.sum b/go.sum index 6a5f0b3..7bd6f27 100644 --- a/go.sum +++ b/go.sum @@ -1,12 +1,12 @@ cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= +github.com/Masterminds/goutils v1.1.0 h1:zukEsf/1JZwCMgHiK3GZftabmxiCw4apj3a28RPBiVg= +github.com/Masterminds/goutils v1.1.0/go.mod h1:8cTjp+g8YejhMuvIA5y2vz3BpJxksy863GQaJW2MFNU= github.com/Masterminds/semver v1.4.2 h1:WBLTQ37jOCzSLtXNdoo8bNM8876KhNqOKvrlGITgsTc= github.com/Masterminds/semver v1.4.2/go.mod h1:MB6lktGJrhw8PrUyiEoblNEGEQ+RzHPF078ddwwvV3Y= -github.com/Masterminds/sprig v2.16.0+incompatible h1:QZbMUPxRQ50EKAq3LFMnxddMu88/EUUG3qmxwtDmPsY= -github.com/Masterminds/sprig v2.16.0+incompatible/go.mod h1:y6hNFY5UBTIWBxnzTeuNhlNS5hqE0NB0E6fgfo2Br3o= -github.com/aokoli/goutils v1.0.1 h1:7fpzNGoJ3VA8qcrm++XEE1QUe0mIwNeLa02Nwq7RDkg= -github.com/aokoli/goutils v1.0.1/go.mod h1:SijmP0QR8LtwsmDs8Yii5Z/S4trXFGFC2oO5g9DP+DQ= +github.com/Masterminds/sprig v2.18.1-0.20190301161902-9f8fceff796f+incompatible h1:i3KaRauSAi1fdIRAWtYgF1zTHlL1SScJ0DZBGzzeHyA= +github.com/Masterminds/sprig v2.18.1-0.20190301161902-9f8fceff796f+incompatible/go.mod h1:y6hNFY5UBTIWBxnzTeuNhlNS5hqE0NB0E6fgfo2Br3o= github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= github.com/cyphar/filepath-securejoin v0.2.2 h1:jCwT2GTP+PY5nBz3c/YL5PAIbusElVrPujOBSCj8xRg= github.com/cyphar/filepath-securejoin v0.2.2/go.mod h1:FpkQEhXnPnOthhzymB7CGsFk2G9VLXONKD9G7QGMM+4= @@ -30,8 +30,8 @@ github.com/google/uuid v1.0.0 h1:b4Gk+7WdP/d3HZH8EJsZpvV7EtDOgaZLtnaNGIu1adA= github.com/google/uuid v1.0.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/huandu/xstrings v1.2.0 h1:yPeWdRnmynF7p+lLYz0H2tthW9lqhMJrQV/U7yy4wX0= github.com/huandu/xstrings v1.2.0/go.mod h1:DvyZB1rfVYsBIigL8HwpZgxHwXozlTgGqn63UyNX5k4= -github.com/imdario/mergo v0.0.0-20141206190957-6633656539c1 h1:FeeCi0I2Fu8kA8IXrdVPtGzym+mW9bzfj9f26EaES9k= -github.com/imdario/mergo v0.0.0-20141206190957-6633656539c1/go.mod h1:2EnlNZ0deacrJVfApfmtdGgDfMuh/nq6Ok1EcJh5FfA= +github.com/imdario/mergo v0.3.7 h1:Y+UAYTZ7gDEuOfhxKWy+dvb5dRQ6rJjFSdX2HZY1/gI= +github.com/imdario/mergo v0.3.7/go.mod h1:2EnlNZ0deacrJVfApfmtdGgDfMuh/nq6Ok1EcJh5FfA= github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NHg9XEKhtSvM= github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8= github.com/json-iterator/go v1.1.5 h1:gL2yXlmiIo4+t+y32d4WGwOjKGYcGOuyrg46vadswDE= @@ -77,8 +77,6 @@ gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+ gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/inf.v0 v0.9.1 h1:73M5CoZyi3ZLMOyDlQh031Cx6N9NDJ2Vvfl76EDAgDc= gopkg.in/inf.v0 v0.9.1/go.mod h1:cWUDdTG/fYaXco+Dcufb5Vnc6Gp2YChqWtbxRZE0mXw= -gopkg.in/yaml.v1 v1.0.0-20140924161607-9f9df34309c0 h1:POO/ycCATvegFmVuPpQzZFJ+pGZeX22Ufu6fibxDVjU= -gopkg.in/yaml.v1 v1.0.0-20140924161607-9f9df34309c0/go.mod h1:WDnlLJ4WF5VGsH/HVa3CI79GS0ol3YnhVnKP89i0kNg= gopkg.in/yaml.v2 v2.2.1 h1:mUhvW9EsL+naU5Q3cakzfE91YhliOondGd6ZrsDBHQE= gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= honnef.co/go/tools v0.0.0-20180728063816-88497007e858/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= From 74311240c096f6ee7ebccbfbc144e53ecfa75530 Mon Sep 17 00:00:00 2001 From: Etienne Tremel Date: Mon, 18 Mar 2019 19:50:36 +0100 Subject: [PATCH 4/5] Upgrade Go to 1.12 --- .travis.yml | 2 +- Dockerfile | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index f9500bf..4b6cd47 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,7 @@ language: go go: - - master + - 1.12.x script: - make test-all diff --git a/Dockerfile b/Dockerfile index 1ba1641..e7c5dda 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM golang:1.11 AS build +FROM golang:1.12 AS build ENV GOPATH="" ARG LDFLAGS COPY go.sum . @@ -8,7 +8,7 @@ COPY . . RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o helm-convert -ldflags "$LDFLAGS" main.go FROM alpine AS helm -ENV HELM_VERSION=v2.10.0 +ENV HELM_VERSION=v2.13.0 ENV HELM_TMP_FILE=helm-${HELM_VERSION}-linux-amd64.tar.gz RUN wget https://storage.googleapis.com/kubernetes-helm/${HELM_TMP_FILE} && \ wget https://storage.googleapis.com/kubernetes-helm/${HELM_TMP_FILE}.sha256 From 4b3e22cf2b9288cf96ea350023500e1300a07d7b Mon Sep 17 00:00:00 2001 From: Etienne Tremel Date: Mon, 18 Mar 2019 22:37:26 +0100 Subject: [PATCH 5/5] Bump v0.5.0 --- plugin.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin.yaml b/plugin.yaml index 3b84d12..6d66924 100644 --- a/plugin.yaml +++ b/plugin.yaml @@ -1,6 +1,6 @@ --- name: "convert" -version: "0.4.5" +version: "0.5.0" usage: "convert" description: |- Convert Helm charts into Kustomize compatible package