Skip to content

Commit

Permalink
add helm mapkubeapis command (#320)
Browse files Browse the repository at this point in the history
  • Loading branch information
zreigz authored Sep 5, 2023
1 parent 32a8f88 commit 0735b5b
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 15 deletions.
16 changes: 16 additions & 0 deletions cmd/plural/workspace.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@ func (p *Plural) workspaceCommands() []cli.Command {
ArgsUsage: "NAME",
Action: latestVersion(requireArgs(p.templateHelm, []string{"NAME"})),
},
{
Name: "helm-mapkubeapis",
Usage: "updates in-place Helm release metadata that contains deprecated or removed Kubernetes APIs to a new instance with supported Kubernetes APIs",
ArgsUsage: "NAME",
Action: latestVersion(requireArgs(p.mapkubeapis, []string{"NAME"})),
},
}
}

Expand Down Expand Up @@ -170,3 +176,13 @@ func (p *Plural) templateHelm(c *cli.Context) error {

return minimal.TemplateHelm()
}

func (p *Plural) mapkubeapis(c *cli.Context) error {
name := c.Args().Get(0)
minimal, err := wkspace.Minimal(name, p.HelmConfiguration)
if err != nil {
return err
}

return minimal.MapKubeApis()
}
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ require (
github.com/hashicorp/go-retryablehttp v0.7.1
github.com/hashicorp/hcl v1.0.0
github.com/hashicorp/terraform-plugin-sdk/v2 v2.20.0
github.com/helm/helm-mapkubeapis v0.4.1
github.com/imdario/mergo v0.3.13
github.com/inancgumus/screen v0.0.0-20190314163918-06e984b86ed3
github.com/ktrysmt/go-bitbucket v0.9.55
Expand Down Expand Up @@ -154,7 +155,7 @@ require (
github.com/chai2010/gettext-go v1.0.2 // indirect
github.com/cli/browser v1.0.0 // indirect
github.com/cli/safeexec v1.0.0 // indirect
github.com/containerd/containerd v1.6.15 // indirect
github.com/containerd/containerd v1.6.18 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect
github.com/cyphar/filepath-securejoin v0.2.3 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
Expand Down
20 changes: 6 additions & 14 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -275,8 +275,8 @@ github.com/cncf/udpa/go v0.0.0-20200629203442-efcf912fb354/go.mod h1:WmhPx2Nbnht
github.com/cncf/udpa/go v0.0.0-20201120205902-5459f2c99403/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk=
github.com/cockroachdb/datadriven v0.0.0-20190809214429-80d97fb3cbaa/go.mod h1:zn76sxSg3SzpJ0PPJaLDCu+Bu0Lg3sKTORVIj19EIF8=
github.com/containerd/cgroups v1.0.4 h1:jN/mbWBEaz+T1pi5OFtnkQ+8qnmEbAr1Oo1FRm5B0dA=
github.com/containerd/containerd v1.6.15 h1:4wWexxzLNHNE46aIETc6ge4TofO550v+BlLoANrbses=
github.com/containerd/containerd v1.6.15/go.mod h1:U2NnBPIhzJDm59xF7xB2MMHnKtggpZ+phKg8o2TKj2c=
github.com/containerd/containerd v1.6.18 h1:qZbsLvmyu+Vlty0/Ex5xc0z2YtKpIsb5n45mAMI+2Ns=
github.com/containerd/containerd v1.6.18/go.mod h1:1RdCUu95+gc2v9t3IL+zIlpClSmew7/0YS8O5eQZrOw=
github.com/coreos/bbolt v1.3.1-coreos.6/go.mod h1:iRUV2dpdMOn7Bo10OQBFzIJO9kkE559Wcmn+qkEiiKk=
github.com/coreos/bbolt v1.3.2/go.mod h1:iRUV2dpdMOn7Bo10OQBFzIJO9kkE559Wcmn+qkEiiKk=
github.com/coreos/etcd v3.3.10+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE=
Expand Down Expand Up @@ -662,6 +662,8 @@ github.com/hashicorp/terraform-plugin-log v0.7.0 h1:SDxJUyT8TwN4l5b5/VkiTIaQgY6R
github.com/hashicorp/terraform-plugin-log v0.7.0/go.mod h1:p4R1jWBXRTvL4odmEkFfDdhUjHf9zcs/BCoNHAc7IK4=
github.com/hashicorp/terraform-plugin-sdk/v2 v2.20.0 h1:+KxZULPsbjpAVoP0WNj/8aVW6EqpcX5JcUcQ5wl7Da4=
github.com/hashicorp/terraform-plugin-sdk/v2 v2.20.0/go.mod h1:DwGJG3KNxIPluVk6hexvDfYR/MS/eKGpiztJoT3Bbbw=
github.com/helm/helm-mapkubeapis v0.4.1 h1:Xu03dMzVv/zqp+Vw1+2ZHufnDQRqoGa8Ml4N/GBgqME=
github.com/helm/helm-mapkubeapis v0.4.1/go.mod h1:o2qnBCfz2cbUod9QlbPjjXtsQI/X7QQjwU/rk7m1T2M=
github.com/hinshun/vt10x v0.0.0-20220119200601-820417d04eec h1:qv2VnGeEQHchGaZ/u7lxST/RaJw+cv273q79D81Xbog=
github.com/hinshun/vt10x v0.0.0-20220119200601-820417d04eec/go.mod h1:Q48J4R4DvxnHolD5P8pOtXigYlRuPLGl6moFx3ulM68=
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
Expand Down Expand Up @@ -890,12 +892,12 @@ github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+W
github.com/onsi/ginkgo v1.8.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
github.com/onsi/ginkgo v1.10.1/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
github.com/onsi/ginkgo v1.16.5 h1:8xi0RTUf59SOSfEtZMvwTvXYMzG4gV23XVHOZiXNtnE=
github.com/onsi/ginkgo/v2 v2.4.0 h1:+Ig9nvqgS5OBSACXNk15PLdp0U9XPYROt9CFzVdFGIs=
github.com/onsi/ginkgo/v2 v2.6.1 h1:1xQPCjcqYw/J5LchOcp4/2q/jzJFjiAOc25chhnDw+Q=
github.com/onsi/gomega v0.0.0-20170829124025-dcabb60a477c/go.mod h1:C1qb7wdrVGGVU+Z6iS04AVkA3Q65CEZX59MT0QO5uiA=
github.com/onsi/gomega v1.3.0/go.mod h1:C1qb7wdrVGGVU+Z6iS04AVkA3Q65CEZX59MT0QO5uiA=
github.com/onsi/gomega v1.5.0/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY=
github.com/onsi/gomega v1.7.0/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY=
github.com/onsi/gomega v1.23.0 h1:/oxKu9c2HVap+F3PfKort2Hw5DEU+HGlW8n+tguWsys=
github.com/onsi/gomega v1.24.2 h1:J/tulyYK6JwBldPViHJReihxxZ+22FHs0piGjQAvoUE=
github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8Oi/yOhh5U=
github.com/opencontainers/go-digest v1.0.0/go.mod h1:0JzlMkj0TRzQZfJkVvzbP0HBR3IKzErnv2BNG4W4MAM=
github.com/opencontainers/image-spec v1.1.0-rc2 h1:2zx/Stx4Wc5pIPDvIxHXvXtQFW/7XWJGmnM7r3wg034=
Expand All @@ -922,16 +924,6 @@ github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINE
github.com/pkg/sftp v1.10.1/go.mod h1:lYOWFsE0bwd1+KfKJaKeuokY15vzFx25BLbzYYoAxZI=
github.com/pluralsh/controller-reconcile-helper v0.0.4 h1:1o+7qYSyoeqKFjx+WgQTxDz4Q2VMpzprJIIKShxqG0E=
github.com/pluralsh/controller-reconcile-helper v0.0.4/go.mod h1:AfY0gtteD6veBjmB6jiRx/aR4yevEf6K0M13/pGan/s=
github.com/pluralsh/gqlclient v1.6.0 h1:7R0H98XrZdBdl8rQQGVGKkCY9iMStyrX+0lZ3zuArqo=
github.com/pluralsh/gqlclient v1.6.0/go.mod h1:qSXKUlio1F2DRPy8el4oFYsmpKbkUYspgPB87T4it5I=
github.com/pluralsh/gqlclient v1.6.1 h1:E2VTJYwoEc6X3Nfm30lKDlPw+N+6l9NiPHJcRQqJ0Ng=
github.com/pluralsh/gqlclient v1.6.1/go.mod h1:qSXKUlio1F2DRPy8el4oFYsmpKbkUYspgPB87T4it5I=
github.com/pluralsh/gqlclient v1.7.0 h1:QUNVxAwu0CrkZAo9sYPav+nGxlCyvGypmDqxY2HBgoA=
github.com/pluralsh/gqlclient v1.7.0/go.mod h1:qSXKUlio1F2DRPy8el4oFYsmpKbkUYspgPB87T4it5I=
github.com/pluralsh/gqlclient v1.8.0 h1:0KCgfjmeOXYmlExXRsxyvdkb7WEL03vu4g17u8fL5Js=
github.com/pluralsh/gqlclient v1.8.0/go.mod h1:qSXKUlio1F2DRPy8el4oFYsmpKbkUYspgPB87T4it5I=
github.com/pluralsh/gqlclient v1.9.0 h1:ERQovQEs1/IFcYQLi7S4SmWcMo0Fl4sz/UTmpcyMgoc=
github.com/pluralsh/gqlclient v1.9.0/go.mod h1:qSXKUlio1F2DRPy8el4oFYsmpKbkUYspgPB87T4it5I=
github.com/pluralsh/gqlclient v1.10.0 h1:ccYB+A0JbPYkEeVzdfajd29l65N6x/buSKPMMxM8OIA=
github.com/pluralsh/gqlclient v1.10.0/go.mod h1:qSXKUlio1F2DRPy8el4oFYsmpKbkUYspgPB87T4it5I=
github.com/pluralsh/oauth v0.9.2 h1:tM9hBK4tCnJUeCOgX0ctxBBCS3hiCDPoxkJLODtedmQ=
Expand Down
31 changes: 31 additions & 0 deletions pkg/wkspace/minimal.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ import (

helmdiff "github.com/databus23/helm-diff/v3/diff"
diffmanifest "github.com/databus23/helm-diff/v3/manifest"
"github.com/helm/helm-mapkubeapis/pkg/common"
release "github.com/helm/helm-mapkubeapis/pkg/v3"
"github.com/imdario/mergo"
"github.com/mitchellh/go-homedir"
"github.com/pkg/errors"
"github.com/pluralsh/plural/pkg/config"
"github.com/pluralsh/plural/pkg/diff"
Expand Down Expand Up @@ -254,6 +257,12 @@ func (m *MinimalWorkspace) DiffTerraform() error {
return m.runDiff("terraform", "plan")
}

func (m *MinimalWorkspace) MapKubeApis() error {
namespace := m.Config.Namespace(m.Name)
utils.Warn("helm mapkubeapis %s --namespace %s\n", m.Name, namespace)
return mapKubeApis(m.Name, namespace)
}

func (m *MinimalWorkspace) runDiff(command string, args ...string) error {
diffFolder, err := m.constructDiffFolder()
if err != nil {
Expand Down Expand Up @@ -350,3 +359,25 @@ func getHelmPath(name string) (string, error) {
}
return filepath.Abs(pathing.SanitizeFilepath(filepath.Join(root, name, "helm", name)))
}

func mapKubeApis(name, namespace string) error {
p, err := homedir.Expand("~/.plural")
if err != nil {
return err
}
mapFile := filepath.Join(p, "Map.yaml")
if !utils.Exists(mapFile) {
err := utils.DownloadFile(mapFile, "https://raw.githubusercontent.com/helm/helm-mapkubeapis/main/config/Map.yaml")
if err != nil {
return err
}
}
options := common.MapOptions{
DryRun: false,
KubeConfig: common.KubeConfig{},
MapFile: mapFile,
ReleaseName: name,
ReleaseNamespace: namespace,
}
return release.MapReleaseWithUnSupportedAPIs(options)
}

0 comments on commit 0735b5b

Please sign in to comment.