diff --git a/README.md b/README.md index 0a0926a25b..cf9bb44d4f 100644 --- a/README.md +++ b/README.md @@ -176,3 +176,4 @@ Need help or want to contribute? Please see the links below. ## License scan details [![FOSSA Status](https://app.fossa.com/api/projects/custom%2B19155%2Fgithub.com%2Fweaveworks%2Fweave-gitops.svg?type=large)](https://app.fossa.com/reports/005da7c4-1f10-4889-9432-8b97c2084e41) + diff --git a/cmd/gitops/upgrade/cmd.go b/cmd/gitops/upgrade/cmd.go index 3e55523adb..56540de578 100644 --- a/cmd/gitops/upgrade/cmd.go +++ b/cmd/gitops/upgrade/cmd.go @@ -19,7 +19,11 @@ import ( var upgradeCmdFlags upgrade.UpgradeValues var example = fmt.Sprintf(` # Upgrade Weave GitOps in the %s namespace - gitops upgrade --version 0.0.15 --config-repo https://github.com/my-org/my-management-cluster.git`, + gitops upgrade --version 0.0.17 --config-repo https://github.com/my-org/my-management-cluster.git + + # Upgrade Weave GitOps and set the natsURL + gitops upgrade --version 0.0.17 --set "agentTemplate.natsURL=my-cluster.acme.org:4222" \ + --config-repo https://github.com/my-org/my-management-cluster.git`, wego.DefaultNamespace) var Cmd = &cobra.Command{ @@ -34,10 +38,10 @@ var Cmd = &cobra.Command{ func init() { Cmd.PersistentFlags().StringVar(&upgradeCmdFlags.ConfigRepo, "config-repo", "", "URL of external repository that will hold automation manifests") Cmd.PersistentFlags().StringVar(&upgradeCmdFlags.Version, "version", "", "Version of Weave GitOps Enterprise to be installed") - Cmd.PersistentFlags().StringVar(&upgradeCmdFlags.BaseBranch, "base", "main", "The base branch to open the pull request against") + Cmd.PersistentFlags().StringVar(&upgradeCmdFlags.BaseBranch, "base", "", "The base branch to open the pull request against") Cmd.PersistentFlags().StringVar(&upgradeCmdFlags.HeadBranch, "branch", "tier-upgrade-enterprise", "The branch to create the pull request from") Cmd.PersistentFlags().StringVar(&upgradeCmdFlags.CommitMessage, "commit-message", "Upgrade to WGE", "The commit message") - Cmd.PersistentFlags().StringArrayVar(&upgradeCmdFlags.Values, "set", []string{}, "set values on the command line (can specify multiple or separate values with commas: key1=val1,key2=val2)") + Cmd.PersistentFlags().StringArrayVar(&upgradeCmdFlags.Values, "set", []string{}, "set profile values on the command line (can specify multiple or separate values with commas: key1=val1,key2=val2)") Cmd.PersistentFlags().BoolVar(&upgradeCmdFlags.DryRun, "dry-run", false, "Output the generated profile without creating a pull request") cobra.CheckErr(Cmd.MarkPersistentFlagRequired("config-repo")) diff --git a/go.mod b/go.mod index 5e0df35f21..75825e670b 100644 --- a/go.mod +++ b/go.mod @@ -7,7 +7,7 @@ require ( github.com/benbjohnson/clock v1.1.0 github.com/coreos/go-oidc/v3 v3.1.0 github.com/deepmap/oapi-codegen v1.8.1 - github.com/fluxcd/go-git-providers v0.4.0 + github.com/fluxcd/go-git-providers v0.5.2-0.20220111143741-04eef9791373 github.com/fluxcd/helm-controller/api v0.14.1 github.com/fluxcd/kustomize-controller/api v0.18.2 github.com/fluxcd/pkg/apis/meta v0.10.1 @@ -18,8 +18,8 @@ require ( github.com/go-errors/errors v1.4.0 // indirect github.com/go-git/go-billy/v5 v5.3.1 github.com/go-git/go-git/v5 v5.4.2 - github.com/go-logr/logr v1.1.0 - github.com/go-logr/zapr v1.1.0 + github.com/go-logr/logr v1.2.2 + github.com/go-logr/zapr v1.2.2 github.com/go-resty/resty/v2 v2.6.0 github.com/golang-jwt/jwt/v4 v4.0.0 github.com/google/go-cmp v0.5.6 @@ -45,7 +45,7 @@ require ( github.com/spf13/viper v1.9.0 github.com/stretchr/testify v1.7.0 github.com/weaveworks/go-checkpoint v0.0.0-20170503165305-ebbb8b0518ab - github.com/xanzy/go-gitlab v0.51.1 + github.com/xanzy/go-gitlab v0.54.3 go.uber.org/zap v1.19.0 golang.org/x/oauth2 v0.0.0-20211104180415-d3ed0bb246c8 google.golang.org/genproto v0.0.0-20211129164237-f09f9a12af12 @@ -65,7 +65,10 @@ require ( sigs.k8s.io/yaml v1.3.0 ) -require github.com/oauth2-proxy/mockoidc v0.0.0-20210703044157-382d3faf2671 +require ( + github.com/oauth2-proxy/mockoidc v0.0.0-20210703044157-382d3faf2671 + gopkg.in/square/go-jose.v2 v2.5.1 +) require ( cloud.google.com/go v0.93.3 // indirect @@ -128,9 +131,9 @@ require ( github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect github.com/golang/protobuf v1.5.2 // indirect github.com/google/btree v1.0.1 // indirect - github.com/google/go-github/v35 v35.3.0 // indirect - github.com/google/go-querystring v1.0.0 // indirect - github.com/google/gofuzz v1.2.0 // indirect + github.com/google/go-github/v41 v41.0.0 // indirect + github.com/google/go-querystring v1.1.0 // indirect + github.com/google/gofuzz v1.1.0 // indirect github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 // indirect github.com/google/uuid v1.3.0 // indirect github.com/googleapis/gnostic v0.5.5 // indirect @@ -206,9 +209,9 @@ require ( go.starlark.net v0.0.0-20200306205701-8dd3e2ee1dd5 // indirect go.uber.org/atomic v1.7.0 // indirect go.uber.org/multierr v1.6.0 // indirect - golang.org/x/crypto v0.0.0-20210817164053-32db794688a5 // indirect + golang.org/x/crypto v0.0.0-20211215153901-e495a2d5b3d3 // indirect golang.org/x/mod v0.4.2 // indirect - golang.org/x/net v0.0.0-20210825183410-e898025ed96a // indirect + golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2 // indirect golang.org/x/sync v0.0.0-20210220032951-036812b2e83c // indirect golang.org/x/sys v0.0.0-20210903071746-97244b99971b // indirect golang.org/x/term v0.0.0-20210615171337-6886f2dfbf5b // indirect @@ -221,7 +224,6 @@ require ( gopkg.in/gorp.v1 v1.7.2 // indirect gopkg.in/inf.v0 v0.9.1 // indirect gopkg.in/ini.v1 v1.63.2 // indirect - gopkg.in/square/go-jose.v2 v2.5.1 // indirect gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 // indirect gopkg.in/warnings.v0 v0.1.2 // indirect gopkg.in/yaml.v2 v2.4.0 // indirect @@ -246,9 +248,9 @@ replace github.com/opencontainers/runc => github.com/opencontainers/runc v1.0.2 // https://github.com/gorilla/websocket/security/advisories/GHSA-jf24-p9p9-4rjh replace github.com/gorilla/websocket v0.0.0 => github.com/gorilla/websocket v1.4.1 -replace github.com/go-logr/logr v1.1.0 => github.com/go-logr/logr v0.4.0 +replace github.com/go-logr/logr v1.2.2 => github.com/go-logr/logr v0.4.0 -replace github.com/go-logr/zapr v1.1.0 => github.com/go-logr/zapr v0.4.0 +replace github.com/go-logr/zapr v1.2.2 => github.com/go-logr/zapr v0.4.0 // https://security.snyk.io/vuln/SNYK-GOLANG-GITHUBCOMOPENCONTAINERSIMAGESPECSPECSGOV1-1922832 replace github.com/opencontainers/image-spec v1.0.1 => github.com/opencontainers/image-spec v1.0.2 diff --git a/go.sum b/go.sum index a72a399339..744066a7bc 100644 --- a/go.sum +++ b/go.sum @@ -259,6 +259,7 @@ github.com/coreos/etcd v3.3.10+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc github.com/coreos/etcd v3.3.13+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE= github.com/coreos/go-etcd v2.0.0+incompatible/go.mod h1:Jez6KQU2B/sWsbdaef3ED8NzMklzPG4d5KIOhIy30Tk= github.com/coreos/go-iptables v0.5.0/go.mod h1:/mVI274lEDI2ns62jHCDnCyBF9Iwsmekav8Dbxlm1MU= +github.com/coreos/go-oidc v2.1.0+incompatible h1:sdJrfw8akMnCuUlaZU3tE/uYXFgfqom8DBE9so9EBsM= github.com/coreos/go-oidc v2.1.0+incompatible/go.mod h1:CgnwVTmzoESiwO9qyAFEMiHoZ1nMCKZlZ9V6mm3/LKc= github.com/coreos/go-oidc/v3 v3.1.0 h1:6avEvcdvTa1qYsOZ6I5PRkSYHzpTNWgKYmaJfaYbrRw= github.com/coreos/go-oidc/v3 v3.1.0/go.mod h1:rEJ/idjfUyfkBit1eI1fvyr+64/g9dcKpAm8MJMesvo= @@ -271,6 +272,7 @@ github.com/coreos/go-systemd/v22 v22.1.0/go.mod h1:xO0FLkIi5MaZafQlIrOotqXZ90ih+ github.com/coreos/go-systemd/v22 v22.3.2/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc= github.com/coreos/pkg v0.0.0-20160727233714-3ac0863d7acf/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA= github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA= +github.com/cpuguy83/go-md2man v1.0.10 h1:BSKMNlYxDvnunlTymqtgONjNnaRV1sTpcovwwjF22jk= github.com/cpuguy83/go-md2man v1.0.10/go.mod h1:SmD6nW6nTyfqj6ABTjUi3V3JVMnlJmwcJI5acqYI6dE= github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU= github.com/cpuguy83/go-md2man/v2 v2.0.0 h1:EoUDS0afbrsXAZ9YQ9jdu/mZ2sXgT1/2yyNng4PGlyM= @@ -368,8 +370,8 @@ github.com/fatih/color v1.9.0 h1:8xPHl4/q1VyqGIPif1F+1V3Y3lSmrq01EabUW3CoW5s= github.com/fatih/color v1.9.0/go.mod h1:eQcE1qtQxscV5RaZvpXrrb8Drkc3/DdQ+uUYCNjL+zU= github.com/felixge/httpsnoop v1.0.1 h1:lvB5Jl89CsZtGIWuTcDM1E/vkVs49/Ml7JJe07l8SPQ= github.com/felixge/httpsnoop v1.0.1/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U= -github.com/fluxcd/go-git-providers v0.4.0 h1:hdGGRDCNphf9FRrk297lorhwHWcST74R7cGAOZTRtSU= -github.com/fluxcd/go-git-providers v0.4.0/go.mod h1:enIPrXnSOBxahS6rngohpG3d/QZ3yjjy/w+agbp97ZI= +github.com/fluxcd/go-git-providers v0.5.2-0.20220111143741-04eef9791373 h1:d2RHYaFZrWQy3KKobyqkwToLxH8kgujnqf8/BGo8cj8= +github.com/fluxcd/go-git-providers v0.5.2-0.20220111143741-04eef9791373/go.mod h1:4jTHTmSx3rFGnG78KUVgFYeG6vWFnKwUSr2mi31tvp8= github.com/fluxcd/helm-controller/api v0.14.1 h1:aAWaYZxTI68SD1R2SpNJh8+hm9oBeIOa9nW4YX5qYjM= github.com/fluxcd/helm-controller/api v0.14.1/go.mod h1:NkfZ5ugs9EUUPSGHfAnNs295mf8sVKG0842aL6cFzMM= github.com/fluxcd/kustomize-controller/api v0.18.2 h1:rGu9R6PMFw3x0S6tVj/ZS54sJWW6/cdWe0Gga09e1AY= @@ -607,14 +609,14 @@ github.com/google/go-cmp v0.5.6 h1:BKbKCqvP6I+rmFHt06ZmyQtvB8xAkWdhFyr0ZUNZcxQ= github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-github/v32 v32.1.0 h1:GWkQOdXqviCPx7Q7Fj+KyPoGm4SwHRh8rheoPhd27II= github.com/google/go-github/v32 v32.1.0/go.mod h1:rIEpZD9CTDQwDK9GDrtMTycQNA4JU3qBsCizh3q2WCI= -github.com/google/go-github/v35 v35.3.0 h1:fU+WBzuukn0VssbayTT+Zo3/ESKX9JYWjbZTLOTEyho= -github.com/google/go-github/v35 v35.3.0/go.mod h1:yWB7uCcVWaUbUP74Aq3whuMySRMatyRmq5U9FTNlbio= -github.com/google/go-querystring v1.0.0 h1:Xkwi/a1rcvNg1PPYe5vI8GbeBY/jrVuDX5ASuANWTrk= +github.com/google/go-github/v41 v41.0.0 h1:HseJrM2JFf2vfiZJ8anY2hqBjdfY1Vlj/K27ueww4gg= +github.com/google/go-github/v41 v41.0.0/go.mod h1:XgmCA5H323A9rtgExdTcnDkcqp6S30AVACCBDOonIxg= github.com/google/go-querystring v1.0.0/go.mod h1:odCYkC5MyYFN7vkCjXpyrEuKhc/BUO6wN/zVPAxq5ck= +github.com/google/go-querystring v1.1.0 h1:AnCroh3fv4ZBgVIf1Iwtovgjaw/GiKJo8M8yD/fhyJ8= +github.com/google/go-querystring v1.1.0/go.mod h1:Kcdr2DB4koayq7X8pmAG4sNG59So17icRSOU623lUBU= github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= +github.com/google/gofuzz v1.1.0 h1:Hsa8mG0dQ46ij8Sl2AYJDUv1oA9/d6Vk+3LG99Oe02g= github.com/google/gofuzz v1.1.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= -github.com/google/gofuzz v1.2.0 h1:xRy4A+RhZaiKjJ1bPfwQ8sedCA+YS2YcCHW6ec7JMi0= -github.com/google/gofuzz v1.2.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs= github.com/google/martian/v3 v3.0.0/go.mod h1:y5Zk1BBys9G+gd6Jrk0W3cC1+ELVxBWuIGO+w/tUAp0= github.com/google/martian/v3 v3.1.0/go.mod h1:y5Zk1BBys9G+gd6Jrk0W3cC1+ELVxBWuIGO+w/tUAp0= @@ -674,6 +676,7 @@ github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0/go.mod h1:8NvIoxWQoOIhqOTXgf github.com/grpc-ecosystem/grpc-gateway v1.9.0/go.mod h1:vNeuVxBJEsws4ogUvrchl83t/GYV9WGTSLVdBhOQFDY= github.com/grpc-ecosystem/grpc-gateway v1.9.5/go.mod h1:vNeuVxBJEsws4ogUvrchl83t/GYV9WGTSLVdBhOQFDY= github.com/grpc-ecosystem/grpc-gateway v1.15.2/go.mod h1:vO11I9oWA+KsxmfFQPhLnnIb1VDE24M+pdxZFiuZcA8= +github.com/grpc-ecosystem/grpc-gateway v1.16.0 h1:gmcG1KaJ57LophUzW0Hy8NmPhnMZb4M0+kPpLofRdBo= github.com/grpc-ecosystem/grpc-gateway v1.16.0/go.mod h1:BDjrQk3hbvj6Nolgz8mAMFbcEtjT1g+wF4CSlocrBnw= github.com/grpc-ecosystem/grpc-gateway/v2 v2.7.1 h1:p5m7GOEGXyoq6QWl4/RRMsQ6tWbTpbQmAnkxXgWSprY= github.com/grpc-ecosystem/grpc-gateway/v2 v2.7.1/go.mod h1:8ZeZajTed/blCOHBbj8Fss8bPHiFKcmJJzuIbUtFCAo= @@ -801,7 +804,7 @@ github.com/kr/pty v1.1.5/go.mod h1:9r2w37qlBe7rQ6e1fg1S/9xpWHSnaqNdHD3WcMdbPDA= 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/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= -github.com/ktrysmt/go-bitbucket v0.9.28/go.mod h1:FWxy2UK7GlK5b0NSJGc5hPqnssVlkNnsChvyuOf/Xno= +github.com/ktrysmt/go-bitbucket v0.9.34/go.mod h1:FWxy2UK7GlK5b0NSJGc5hPqnssVlkNnsChvyuOf/Xno= github.com/labstack/echo/v4 v4.2.1 h1:LF5Iq7t/jrtUuSutNuiEWtB5eiHfZ5gSe2pcu5exjQw= github.com/labstack/echo/v4 v4.2.1/go.mod h1:AA49e0DZ8kk5jTOOCKNuPR6oTnBS0dYiM4FW1e6jwpg= github.com/labstack/gommon v0.3.0 h1:JEeO0bvc78PKdyHxloTKiF8BD5iGrH8T6MSeGvSgob0= @@ -1215,8 +1218,8 @@ github.com/vishvananda/netns v0.0.0-20191106174202-0a2b9b5464df/go.mod h1:JP3t17 github.com/vishvananda/netns v0.0.0-20200728191858-db3c7e526aae/go.mod h1:DD4vA1DwXk04H54A1oHXtwZmA0grkVMdPxx/VGLCah0= github.com/weaveworks/go-checkpoint v0.0.0-20170503165305-ebbb8b0518ab h1:mW+hgchD9qUUBqnuaDBj7BkcpFPk/FxeFcUFI5lvvUw= github.com/weaveworks/go-checkpoint v0.0.0-20170503165305-ebbb8b0518ab/go.mod h1:qkbvw5GPibQ/Nf7IZJL0UoLwmJ6858b4S/hUWRd+cH4= -github.com/xanzy/go-gitlab v0.51.1 h1:wWKLalwx4omxFoHh3PLs9zDgAD4GXDP/uoxwMRCSiWM= -github.com/xanzy/go-gitlab v0.51.1/go.mod h1:Q+hQhV508bDPoBijv7YjK/Lvlb4PhVhJdKqXVQrUoAE= +github.com/xanzy/go-gitlab v0.54.3 h1:fPfZ3Jcu5dPc3xyIYtAALZsEgoyKNFNuULD+TdJ7Zvk= +github.com/xanzy/go-gitlab v0.54.3/go.mod h1:F0QEXwmqiBUxCgJm8fE9S+1veX4XC9Z4cfaAbqwk4YM= github.com/xanzy/ssh-agent v0.3.0 h1:wUMzuKtKilRgBAD1sUb8gOwwRr2FGoBVumcjoOACClI= github.com/xanzy/ssh-agent v0.3.0/go.mod h1:3s9xbODqPuuhK9JV1R321M/FlMZSBvE5aY6eAcqrDh0= github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f h1:J9EGpcZtP0E/raorCMxlFGSTBrsSlaDGf3jU/qvAE2c= @@ -1337,8 +1340,9 @@ golang.org/x/crypto v0.0.0-20210220033148-5ea612d1eb83/go.mod h1:jdWPYTVW3xRLrWP golang.org/x/crypto v0.0.0-20210322153248-0c34fe9e7dc2/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4= golang.org/x/crypto v0.0.0-20210421170649-83a5a9bb288b/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4= golang.org/x/crypto v0.0.0-20210513164829-c07d793c2f9a/go.mod h1:P+XmwS30IXTQdn5tA2iutPOUgjI07+tq3H3K9MVA1s8= -golang.org/x/crypto v0.0.0-20210817164053-32db794688a5 h1:HWj/xjIHfjYU5nVXpTM0s39J9CbLn7Cc5a7IC5rwsMQ= golang.org/x/crypto v0.0.0-20210817164053-32db794688a5/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= +golang.org/x/crypto v0.0.0-20211215153901-e495a2d5b3d3 h1:0es+/5331RGQPcXlMfP+WrnIIS6dNnNRe0WB02W0F4M= +golang.org/x/crypto v0.0.0-20211215153901-e495a2d5b3d3/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8= @@ -1440,8 +1444,9 @@ golang.org/x/net v0.0.0-20210428140749-89ef3d95e781/go.mod h1:OJAsFXCWl8Ukc7SiCT golang.org/x/net v0.0.0-20210503060351-7fd8e65b6420/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.0.0-20210520170846-37e1c6afe023/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.0.0-20210525063256-abc453219eb5/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= -golang.org/x/net v0.0.0-20210825183410-e898025ed96a h1:bRuuGXV8wwSdGTB+CtJf+FjgO1APK1CoO39T4BN/XBw= golang.org/x/net v0.0.0-20210825183410-e898025ed96a/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= +golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2 h1:CIJ76btIcR3eFI5EgSo6k1qKw9KJexJuRLI9G7Hp5wE= +golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/oauth2 v0.0.0-20180227000427-d7d64896b5ff/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20181106182150-f42d05182288/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= diff --git a/pkg/git/git.go b/pkg/git/git.go index 6dad17866b..96ce1d53b9 100644 --- a/pkg/git/git.go +++ b/pkg/git/git.go @@ -82,6 +82,7 @@ type Git interface { Init(path, url, branch string) (bool, error) Clone(ctx context.Context, path, url, branch string) (bool, error) Checkout(newBranch string) error + Read(path string) ([]byte, error) Write(path string, content []byte) error Remove(path string) error Commit(message Commit, filters ...func(string) bool) (string, error) diff --git a/pkg/git/gitfakes/fake_git.go b/pkg/git/gitfakes/fake_git.go index 193497dd52..36f790d91b 100644 --- a/pkg/git/gitfakes/fake_git.go +++ b/pkg/git/gitfakes/fake_git.go @@ -116,6 +116,19 @@ type FakeGit struct { pushReturnsOnCall map[int]struct { result1 error } + ReadStub func(string) ([]byte, error) + readMutex sync.RWMutex + readArgsForCall []struct { + arg1 string + } + readReturns struct { + result1 []byte + result2 error + } + readReturnsOnCall map[int]struct { + result1 []byte + result2 error + } RemoveStub func(string) error removeMutex sync.RWMutex removeArgsForCall []struct { @@ -673,6 +686,70 @@ func (fake *FakeGit) PushReturnsOnCall(i int, result1 error) { }{result1} } +func (fake *FakeGit) Read(arg1 string) ([]byte, error) { + fake.readMutex.Lock() + ret, specificReturn := fake.readReturnsOnCall[len(fake.readArgsForCall)] + fake.readArgsForCall = append(fake.readArgsForCall, struct { + arg1 string + }{arg1}) + stub := fake.ReadStub + fakeReturns := fake.readReturns + fake.recordInvocation("Read", []interface{}{arg1}) + fake.readMutex.Unlock() + if stub != nil { + return stub(arg1) + } + if specificReturn { + return ret.result1, ret.result2 + } + return fakeReturns.result1, fakeReturns.result2 +} + +func (fake *FakeGit) ReadCallCount() int { + fake.readMutex.RLock() + defer fake.readMutex.RUnlock() + return len(fake.readArgsForCall) +} + +func (fake *FakeGit) ReadCalls(stub func(string) ([]byte, error)) { + fake.readMutex.Lock() + defer fake.readMutex.Unlock() + fake.ReadStub = stub +} + +func (fake *FakeGit) ReadArgsForCall(i int) string { + fake.readMutex.RLock() + defer fake.readMutex.RUnlock() + argsForCall := fake.readArgsForCall[i] + return argsForCall.arg1 +} + +func (fake *FakeGit) ReadReturns(result1 []byte, result2 error) { + fake.readMutex.Lock() + defer fake.readMutex.Unlock() + fake.ReadStub = nil + fake.readReturns = struct { + result1 []byte + result2 error + }{result1, result2} +} + +func (fake *FakeGit) ReadReturnsOnCall(i int, result1 []byte, result2 error) { + fake.readMutex.Lock() + defer fake.readMutex.Unlock() + fake.ReadStub = nil + if fake.readReturnsOnCall == nil { + fake.readReturnsOnCall = make(map[int]struct { + result1 []byte + result2 error + }) + } + fake.readReturnsOnCall[i] = struct { + result1 []byte + result2 error + }{result1, result2} +} + func (fake *FakeGit) Remove(arg1 string) error { fake.removeMutex.Lock() ret, specificReturn := fake.removeReturnsOnCall[len(fake.removeArgsForCall)] @@ -939,6 +1016,8 @@ func (fake *FakeGit) Invocations() map[string][][]interface{} { defer fake.openMutex.RUnlock() fake.pushMutex.RLock() defer fake.pushMutex.RUnlock() + fake.readMutex.RLock() + defer fake.readMutex.RUnlock() fake.removeMutex.RLock() defer fake.removeMutex.RUnlock() fake.statusMutex.RLock() diff --git a/pkg/git/gogit.go b/pkg/git/gogit.go index 6156471d7a..22889de9c4 100644 --- a/pkg/git/gogit.go +++ b/pkg/git/gogit.go @@ -153,6 +153,33 @@ func (g *GoGit) clone(ctx context.Context, path, url, branch string, depth int) return r, nil } +// Read reads the content from the path +func (g *GoGit) Read(path string) ([]byte, error) { + if g.repository == nil { + return nil, ErrNoGitRepository + } + + wt, err := g.repository.Worktree() + if err != nil { + return nil, fmt.Errorf("failed to open the worktree: %w", err) + } + + f, err := wt.Filesystem.Open(path) + if err != nil { + return nil, fmt.Errorf("failed to open file %s: %w", path, err) + } + defer f.Close() + + buf := bytes.NewBuffer(nil) + + _, err = buf.ReadFrom(f) + if err != nil { + return nil, fmt.Errorf("error reading bytes from buffer %s: %w", path, err) + } + + return buf.Bytes(), nil +} + // Write writes the provided content to the path, if the file exists, it will be // truncated. func (g *GoGit) Write(path string, content []byte) error { diff --git a/pkg/git/gogit_test.go b/pkg/git/gogit_test.go index 607ede9e82..7262d237c7 100644 --- a/pkg/git/gogit_test.go +++ b/pkg/git/gogit_test.go @@ -142,6 +142,63 @@ var _ = Describe("ValidateAccess", func() { }) }) +var _ = Describe("Read", func() { + It("Reads a file from a repo", func() { + _, err = gitClient.Init(dir, "https://github.com/github/gitignore", "master") + + filePath := "/test.txt" + content := []byte("testing") + Expect(gitClient.Write(filePath, content)).To(Succeed()) + + _, err = gitClient.Commit(git.Commit{ + Author: git.Author{Name: "test", Email: "test@example.com"}, + Message: "test commit", + }) + Expect(err).ShouldNot(HaveOccurred()) + + fileContent, err := gitClient.Read(filePath) + Expect(err).ShouldNot(HaveOccurred()) + Expect(content).To(Equal(fileContent)) + }) + + It("Reads a file from a repo even if not commited", func() { + _, err = gitClient.Init(dir, "https://github.com/github/gitignore", "master") + filePath := "/test.txt" + content := []byte("testing") + err := ioutil.WriteFile(dir+filePath, content, 0644) + Expect(err).ShouldNot(HaveOccurred()) + fileContent, err := gitClient.Read(filePath) + Expect(err).ShouldNot(HaveOccurred()) + Expect(content).To(Equal(fileContent)) + }) + + It("gives a nice error when file not present", func() { + _, err = gitClient.Init(dir, "https://github.com/github/gitignore", "master") + filePath := "/test.txt" + _, err := gitClient.Read(filePath) + Expect(fmt.Sprint(err)).To(MatchRegexp("failed to open file /test.txt")) + }) + + It("fails when the repository has not been initialized", func() { + _, err := gitClient.Init(dir, "https://github.com/github/gitignore", "master") + Expect(err).ShouldNot(HaveOccurred()) + + gc := git.New(nil, wrapper.NewGoGit()) + _, err = gc.Read("testing.txt") + Expect(err).To(MatchError("no git repository")) + }) + + It("returns an error if the repository is bare", func() { + _, err = gogit.PlainInit(dir, true) + Expect(err).ShouldNot(HaveOccurred()) + _, err = gitClient.Open(dir) + Expect(err).ShouldNot(HaveOccurred()) + + _, err := gitClient.Read("testing.txt") + Expect(err).Should(MatchError("failed to open the worktree: worktree not available in a bare repository")) + }) +}) + var _ = Describe("Write", func() { It("writes a file into a given repository", func() { _, err = gitClient.Init(dir, "https://github.com/github/gitignore", "master") diff --git a/pkg/server/profiles.go b/pkg/server/profiles.go index e11eaae419..81c3154baf 100644 --- a/pkg/server/profiles.go +++ b/pkg/server/profiles.go @@ -109,7 +109,7 @@ func (s *ProfilesServer) GetProfiles(ctx context.Context, msg *pb.GetProfilesReq } } - return nil, fmt.Errorf("failed to get HelmRepository %q/%q", s.HelmRepoNamespace, s.HelmRepoName) + return nil, fmt.Errorf("failed to get HelmRepository %q/%q: %w", s.HelmRepoNamespace, s.HelmRepoName, err) } ps, err := s.HelmChartManager.GetCharts(ctx, helmRepo, helm.Profiles) diff --git a/pkg/services/automation/automation_test.go b/pkg/services/automation/automation_test.go index e814e6b649..e1517de456 100644 --- a/pkg/services/automation/automation_test.go +++ b/pkg/services/automation/automation_test.go @@ -424,7 +424,7 @@ var _ = Describe("Generate cluster manifests", func() { configBranch, err := gitProviders.GetDefaultBranch(ctx, url) Expect(err).ShouldNot(HaveOccurred()) - sourceName := createClusterSourceName(url) + sourceName := CreateClusterSourceName(url) sourceManifest, err := realFlux.CreateSourceGit(sourceName, url, configBranch, secretStr, namespace) Expect(err).ShouldNot(HaveOccurred()) Expect(clusterAutomation.SourceManifest.Content).To(Equal(sourceManifest)) diff --git a/pkg/services/automation/cluster_generator.go b/pkg/services/automation/cluster_generator.go index dfba656ac0..c6e731348c 100644 --- a/pkg/services/automation/cluster_generator.go +++ b/pkg/services/automation/cluster_generator.go @@ -46,7 +46,7 @@ const ( WegoConfigMapName = "weave-gitops-config" ) -func createClusterSourceName(gitSourceURL gitproviders.RepoURL) string { +func CreateClusterSourceName(gitSourceURL gitproviders.RepoURL) string { provider := string(gitSourceURL.Provider()) cleanRepoName := replaceUnderscores(gitSourceURL.RepositoryName()) qualifiedName := fmt.Sprintf("wego-auto-%s-%s", provider, cleanRepoName) @@ -87,7 +87,7 @@ func (a *AutomationGen) GenerateClusterAutomation(ctx context.Context, cluster m wegoAppManifest := bytes.Join(m, []byte("---\n")) - sourceName := createClusterSourceName(configURL) + sourceName := CreateClusterSourceName(configURL) sourceManifest, err := a.Flux.CreateSourceGit(sourceName, configURL, configBranch, secretStr, namespace) if err != nil { diff --git a/pkg/upgrade/upgrade.go b/pkg/upgrade/upgrade.go index 9284ec65b3..18542be471 100644 --- a/pkg/upgrade/upgrade.go +++ b/pkg/upgrade/upgrade.go @@ -11,7 +11,6 @@ import ( "strconv" "time" - "github.com/fluxcd/go-git-providers/gitprovider" helmv2 "github.com/fluxcd/helm-controller/api/v2beta1" kustomizev2 "github.com/fluxcd/kustomize-controller/api/v1beta2" "github.com/fluxcd/pkg/apis/meta" @@ -22,9 +21,11 @@ import ( "github.com/weaveworks/weave-gitops/pkg/kube" "github.com/weaveworks/weave-gitops/pkg/logger" "github.com/weaveworks/weave-gitops/pkg/services/automation" + "github.com/weaveworks/weave-gitops/pkg/services/gitrepo" corev1 "k8s.io/api/core/v1" v1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "sigs.k8s.io/kustomize/api/types" "sigs.k8s.io/yaml" "k8s.io/apimachinery/pkg/runtime" @@ -95,27 +96,42 @@ func upgrade(ctx context.Context, uv UpgradeValues, kube kube.Kube, gitClient gi return fmt.Errorf("failed to normalize URL %q: %w", uv.ConfigRepo, err) } - // Create pull request - path := filepath.Join(git.WegoRoot, git.WegoClusterDir, cname, git.WegoClusterOSWorkloadDir, WegoEnterpriseName) - capiKeepPath := filepath.Join(git.WegoRoot, git.WegoAppDir, "capi", "templates", ".keep") - capiKeepContents := string(strconv.AppendQuote(nil, "# keep")) + configBranch := uv.BaseBranch + if configBranch == "" { + configBranch, err = gitProvider.GetDefaultBranch(ctx, normalizedURL) + if err != nil { + return fmt.Errorf("could not determine default branch for config repository: %q %w", uv.ConfigRepo, err) + } + } + + remover, _, err := gitrepo.CloneRepo(ctx, gitClient, normalizedURL, configBranch) + if err != nil { + return fmt.Errorf("failed to clone configuration repo: %w", err) + } + + defer remover() + + err = gitClient.Checkout(uv.HeadBranch) + if err != nil { + return fmt.Errorf("failed to create new branch %s: %w", uv.HeadBranch, err) + } + + err = upgradeGitManifests(gitClient, cname, stringOut, logger) + if err != nil { + return fmt.Errorf("failed to write update manifest in clone repo: %w", err) + } + + err = gitrepo.CommitAndPush(ctx, gitClient, uv.CommitMessage, logger) + if err != nil { + return fmt.Errorf("failed to commit and push: %w", err) + } pri := gitproviders.PullRequestInfo{ - Title: "Gitops upgrade", - Description: "Pull request to upgrade to Weave GitOps Enterprise", - CommitMessage: uv.CommitMessage, - TargetBranch: uv.BaseBranch, - NewBranch: uv.HeadBranch, - Files: []gitprovider.CommitFile{ - { - Path: &path, - Content: &stringOut, - }, - { - Path: &capiKeepPath, - Content: &capiKeepContents, - }, - }, + Title: uv.CommitMessage, + Description: "Pull request to upgrade to Weave GitOps Enterprise", + SkipAddingFilesOnCreation: true, + TargetBranch: configBranch, + NewBranch: uv.HeadBranch, } pr, err := gitProvider.CreatePullRequest(ctx, normalizedURL, pri) @@ -123,9 +139,9 @@ func upgrade(ctx context.Context, uv UpgradeValues, kube kube.Kube, gitClient gi return err } - _, err = w.Write([]byte(fmt.Sprintf("Pull Request created: %s\n", pr.Get().WebURL))) + logger.Successf("Pull Request created: %s", pr.Get().WebURL) - return err + return nil } func marshalToYamlStream(objects []runtime.Object) ([]byte, error) { @@ -149,7 +165,7 @@ func makeAppsCapiKustomization(namespace, repoURL string) ([]runtime.Object, err return nil, fmt.Errorf("failed to normalize URL %q: %w", repoURL, err) } - gitRepositoryName := automation.CreateRepoSecretName(normalizedURL).String() + gitRepositoryName := automation.CreateClusterSourceName(normalizedURL) appsCapiKustomization := &kustomizev2.Kustomization{ ObjectMeta: metav1.ObjectMeta{ @@ -246,6 +262,62 @@ func makeHelmResources(namespace, version, clusterName, repoURL string, values [ return []runtime.Object{helmRepository, helmRelease}, nil } +func upgradeGitManifests(gitClient git.Git, cname, wegoEnterpriseManifests string, logger logger.Logger) error { + capiKeepPath := filepath.Join(git.WegoRoot, git.WegoAppDir, "capi", "templates", ".keep") + capiKeepContents := string(strconv.AppendQuote(nil, "# keep")) + kustomizationPath := git.GetSystemQualifiedPath(cname, automation.SystemKustomizationPath) + wegoAppPath := git.GetSystemQualifiedPath(cname, automation.WegoAppPath) + wegoEnterprisePath := git.GetSystemQualifiedPath(cname, WegoEnterpriseName) + + newKustomizationBytes, err := updateKustomization(gitClient, kustomizationPath, wegoAppPath, wegoEnterprisePath) + if err != nil { + return fmt.Errorf("Failed to update kustomization: %w", err) + } + + manifests := map[string]string{ + wegoEnterprisePath: wegoEnterpriseManifests, + capiKeepPath: capiKeepContents, + kustomizationPath: string(newKustomizationBytes), + } + + for path, content := range manifests { + if err := gitClient.Write(path, []byte(content)); err != nil { + return fmt.Errorf("failed to write out manifest to %s: %w", path, err) + } + } + + err = gitClient.Remove(wegoAppPath) + if err != nil { + logger.Warningf("Failed to remove existing %s deployment, skipping.\n", wegoAppPath) + } + + return nil +} + +func updateKustomization(gitClient git.Git, kustomizationPath, wegoAppPath, wegoEnterprisePath string) ([]byte, error) { + kustomizationBytes, err := gitClient.Read(kustomizationPath) + if err != nil { + return nil, fmt.Errorf("Failed to read existing kustomization %s: %w", kustomizationPath, err) + } + + var k types.Kustomization + if err := yaml.Unmarshal(kustomizationBytes, &k); err != nil { + return nil, fmt.Errorf("failed to unmarshal kustomization file %s: %w", kustomizationPath, err) + } + + newResources := []string{WegoEnterpriseName} + + for _, resource := range k.Resources { + if resource != automation.WegoAppPath { + newResources = append(newResources, resource) + } + } + + k.Resources = newResources + + return yaml.Marshal(&k) +} + func getBasicAuth(ctx context.Context, kubeClient client.Client, ns string) error { deployKeySecret := &corev1.Secret{}