Skip to content

Commit 2d268f5

Browse files
authored
Merge pull request #61 from hickeyma/chore/remove-helm2-support
chore: Remove Helm v2 support
2 parents 6b80213 + e81d264 commit 2d268f5

File tree

10 files changed

+1417
-646
lines changed

10 files changed

+1417
-646
lines changed

.circleci/config.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@ jobs:
1212
shellcheck -x scripts/install_plugin.sh
1313
untagged-build:
1414
docker:
15-
- image: circleci/golang:1.16
15+
- image: circleci/golang:1.17
1616
working_directory: /go/src/github.com/helm/helm-mapkubeapis
1717
steps:
1818
- checkout
1919
- run: make build
2020
tagged-build:
2121
docker:
22-
- image: circleci/golang:1.16
22+
- image: circleci/golang:1.17
2323
working_directory: /go/src/github.com/helm/helm-mapkubeapis
2424
steps:
2525
- checkout

README.md

+37-33
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,17 @@
55
[![CircleCI](https://circleci.com/gh/helm/helm-mapkubeapis/tree/master.svg?style=svg)](https://circleci.com/gh/helm/helm-mapkubeapis/tree/master)
66
[![Release](https://img.shields.io/github/release/helm/helm-mapkubeapis.svg?style=flat-square)](https://github.com/helm/helm-mapkubeapis/releases/latest)
77

8-
`mapkubeapis` is a Helm v2/v3 plugin which updates in-place Helm release metadata that contains deprecated or removed Kubernetes APIs to a new instance with supported Kubernetes APIs. Jump to [background to the issue](#background-to-the-issue) for more details on the problem space that the plugin solves.
8+
`mapkubeapis` is a Helm v3 plugin which updates in-place Helm release metadata that contains deprecated or removed Kubernetes APIs to a new instance with supported Kubernetes APIs. Jump to [background to the issue](#background-to-the-issue) for more details on the problem space that the plugin solves.
99

10-
> Note: Charts need to be updated also to supported Kubernetes APIs to avoid failure during deployment in a Kubernetes version. This is a separate task to the plugin.
10+
> Note: Charts need to be updated also to supported Kubernetes APIs to avoid failure during deployment in a Kubernetes version. This is a separate task to the plugin.
1111
1212
## Prerequisite
1313

1414
- Helm client with `mapkubeapis` plugin installed on the same system
1515
- Access to the cluster(s) that Helm manages. This access is similar to `kubectl` access using [kubeconfig files](https://kubernetes.io/docs/concepts/configuration/organize-cluster-access-kubeconfig/).
1616
The `--kubeconfig`, `--kube-context` and `--namespace` flags can be used to set the kubeconfig path, kube context and namespace context to override the environment configuration.
17-
- If you try and upgrade a release with unsupported APIs then the upgrade will fail. This is ok in Helm v3 as it will not generate a failed release for Helm. However, Helm v2 does produce a failed release. This needs to be removed before running the plugin on the release. The command to remove the failed release version is: `kubectl delete configmap/secret <release_name>.v<latest_version_number> --namespace <tiller_namespace>`
17+
- If you try and upgrade a release with unsupported APIs then the upgrade will fail. This is ok in Helm v3 as it will not generate a failed release for Helm.
1818
- The plugin updates the lastest release version. The latest release version should be in a `deployed` state as you want to update a successful deployment. If it is not then you need to delete the latest release version. The command to remove a release version is:
19-
- Helm v2: `kubectl delete configmap/secret <release_name>.v<latest_version_number> --namespace <tiller_namespace>`
2019
- Helm v3: `kubectl delete configmap/secret sh.helm.release.v1.<release_name>.v<latest_version_number> --namespace <release_namespace>`
2120

2221
## Install
@@ -54,40 +53,42 @@ Flags:
5453
--kube-context string name of the kubeconfig context to use
5554
--kubeconfig string path to the kubeconfig file
5655
--mapfile string path to the API mapping file (default "config/Map.yaml")
57-
--namespace string namespace scope of the release. For Helm v2, this is the Tiller namespace (e.g. kube-system)
58-
-s, --release-storage string for Helm v2 only - release storage type/object. It can be 'secrets' or 'configmaps'. This is only used with the 'tiller-out-cluster' flag (default "secrets")
59-
--tiller-out-cluster for Helm v2 only - when Tiller is not running in the cluster e.g. Tillerless
60-
--v2 run for Helm v2 release (default is Helm v3)
56+
--namespace string namespace scope of the release
6157
```
6258

6359
Example output:
6460

6561
```console
66-
$ helm mapkubeapis v2-oldapi --namespace kube-system --v2
67-
2020/04/17 13:05:45 Release 'v2-oldapi' will be checked for deprecated or removed Kubernetes APIs and will be updated if necessary to supported API versions.
68-
2020/04/17 13:05:45 Get release 'v2-oldapi' latest version.
69-
2020/04/17 13:05:45 Check release 'v2-oldapi' for deprecated or removed APIs...
70-
2020/04/17 13:05:45 Found deprecated or removed Kubernetes API:
71-
"apiVersion: apps/v1beta1
72-
kind: Deployment"
62+
$ helm mapkubeapis cluster-role-example --namespace test-cluster-role-example
63+
2022/02/07 18:48:49 Release 'cluster-role-example' will be checked for deprecated or removed Kubernetes APIs and will be updated if necessary to supported API versions.
64+
2022/02/07 18:48:49 Get release 'cluster-role-example' latest version.
65+
2022/02/07 18:48:49 Check release 'cluster-role-example' for deprecated or removed APIs...
66+
2022/02/07 18:48:49 Found 1 instances of deprecated or removed Kubernetes API:
67+
"apiVersion: rbac.authorization.k8s.io/v1beta1
68+
kind: ClusterRole
69+
"
7370
Supported API equivalent:
74-
"apiVersion: apps/v1
75-
kind: Deployment"
76-
2020/04/17 13:05:45 Found deprecated or removed Kubernetes API:
77-
"apiVersion: extensions/v1beta1
78-
kind: Ingress"
71+
"apiVersion: rbac.authorization.k8s.io/v1
72+
kind: ClusterRole
73+
"
74+
2022/02/07 18:48:49 Found 1 instances of deprecated or removed Kubernetes API:
75+
"apiVersion: rbac.authorization.k8s.io/v1beta1
76+
kind: ClusterRoleBinding
77+
"
7978
Supported API equivalent:
80-
"apiVersion: networking.k8s.io/v1beta1
81-
kind: Ingress"
82-
2020/04/17 13:05:45 Finished checking release 'v2-oldapi' for deprecated or removed APIs.
83-
2020/04/17 13:05:45 Deprecated or removed APIs exist, updating release: v2-oldapi.
84-
2020/04/17 13:05:45 Set status of release version 'v2-oldapi.v1' to 'superseded'.
85-
2020/04/17 13:05:45 Release version 'v2-oldapi.v1' updated successfully.
86-
2020/04/17 13:05:45 Add release version 'v2-oldapi.v2' with updated supported APIs.
87-
2020/04/17 13:05:45 Release version 'v2-oldapi.v2' added successfully.
88-
2020/04/17 13:05:45 Release 'v2-oldapi' with deprecated or removed APIs updated successfully to new version.
89-
2020/04/17 13:05:45 Map of release 'v2-oldapi' deprecated or removed APIs to supported versions, completed successfully.
79+
"apiVersion: rbac.authorization.k8s.io/v1
80+
kind: ClusterRoleBinding
81+
"
82+
2022/02/07 18:48:49 Finished checking release 'cluster-role-example' for deprecated or removed APIs.
83+
2022/02/07 18:48:49 Deprecated or removed APIs exist, updating release: cluster-role-example.
84+
2022/02/07 18:48:49 Set status of release version 'cluster-role-example.v1' to 'superseded'.
85+
2022/02/07 18:48:49 Release version 'cluster-role-example.v1' updated successfully.
86+
2022/02/07 18:48:49 Add release version 'cluster-role-example.v2' with updated supported APIs.
87+
2022/02/07 18:48:49 Release version 'cluster-role-example.v2' added successfully.
88+
2022/02/07 18:48:49 Release 'cluster-role-example' with deprecated or removed APIs updated successfully to new version.
89+
2022/02/07 18:48:49 Map of release 'cluster-role-example' deprecated or removed APIs to supported versions, completed successfully.
9090
```
91+
9192
## API Mapping
9293

9394
The mapping information of deprecated or removed APIs to supported APIs is configured in the [Map.yaml](https://github.com/helm/helm-mapkubeapis/blob/master/config/Map.yaml) file. The file is a list of entries similar to the following:
@@ -102,29 +103,32 @@ The mapping information of deprecated or removed APIs to supported APIs is confi
102103
The plugin when performing update of a Helm release metadata first loads the map file from the `config` directory where the plugin is run from. If the map file is a different name or in a different location, you can use the `--mapfile` flag to specify the different mapping file.
103104

104105
The OOTB mapping file is configured as follows:
106+
105107
- The search and replace strings are in order with `apiVersion` first and then `kind`. This should be changed if the Helm release metadata is rendered with different search/replace string.
106108
- The strings contain UNIX/Linux line feeds. This means that `\n` is used to signify line separation between properties in the strings. This should be changed if the Helm release metadata is rendered in Windows or Mac.
107109
- Each mapping contains the Kubernetes version that the API is deprecated and removed in. This information is important as the plugin checks that the deprecated version (uses removed if deprecated unset) is later than the Kubernetes version that it is running against. If it is then no mapping occurs for this API as it not yet deprecated in this Kubernetes version and hence the new API is not yet supported. Otherwise, the mapping can proceed.
108110

109111
> Note: The Helm release metadata can be checked by following the steps in:
110-
- Helm v2: [Updating API Versions of a Release Manifest](https://github.com/helm/helm/blob/dev-v2/docs/kubernetes_apis.md#updating-api-versions-of-a-release-manifest)
111112
- Helm v3: [Updating API Versions of a Release Manifest](https://helm.sh/docs/topics/kubernetes_apis/#updating-api-versions-of-a-release-manifest)
112113

113114
## Background to the issue
114115

115116
For details on the background to this issue, it is recommended to read the docs appropriate to your Helm version. The docs can be accessed as follows:
116-
- Helm v2: [Deprecated Kubernetes APIs](https://github.com/helm/helm/blob/dev-v2/docs/kubernetes_apis.md)
117117
- Helm v3: [Deprecated Kubernetes APIs](https://helm.sh/docs/topics/kubernetes_apis)
118118

119119
The Helm documentation describes the problem when Helm releases that are already deployed with APIs that are no longer supported. If the Kubernetes cluster (containing such releases) is updated to a version where the APIs are removed, then Helm becomes unable to manage such releases anymore. It does not matter if the chart being passed in the upgrade contains the supported API versions or not.
120120

121121
This is what the `mapkubeapis` plugin resolves. It fixes the issue by mapping releases which contain deprecated or removed Kubernetes APIs to supported APIs. This is performed inline in the release metadata where the existing release is `superseded` and a new release (metadata only) is added. The deployed Kubernetes resources are updated automatically by Kubernetes during upgrade of its version. Once this operation is completed, you can then upgrade using the chart with supported APIs.
122122

123+
## Helm v2 Support
124+
125+
Helm [v2.17.0](https://github.com/helm/helm/releases/tag/v2.17.0) was the final release of Helm v2 in October 2020. Helm v2 is unsupported since November 2020, as detailed in [Helm 2 and the Charts Project Are Now Unsupported](https://helm.sh/blog/helm-2-becomes-unsupported/). `mapkubeapis` Helm v2 support finished in [release v0.2.0](https://github.com/helm/helm-mapkubeapis/releases/tag/v0.2.0).
126+
123127
## Developer (From Source) Install
124128

125129
If you would like to handle the build yourself, this is the recommended way to do it.
126130

127-
You must first have [Go v1.13+](http://golang.org) installed, and then you run:
131+
You must first have [Go v1.17+](http://golang.org) installed, and then you run:
128132

129133
```console
130134
$ mkdir -p ${GOPATH}/src/github.com

cmd/mapkubeapis/environment.go

+6-12
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,11 @@ import (
2222

2323
// EnvSettings defined settings
2424
type EnvSettings struct {
25-
DryRun bool
26-
KubeConfigFile string
27-
KubeContext string
28-
MapFile string
29-
Namespace string
30-
RunV2 bool
31-
StorageType string
32-
TillerOutCluster bool
25+
DryRun bool
26+
KubeConfigFile string
27+
KubeContext string
28+
MapFile string
29+
Namespace string
3330
}
3431

3532
// New returns default env settings
@@ -49,8 +46,5 @@ func (s *EnvSettings) AddFlags(fs *pflag.FlagSet) {
4946
fs.StringVar(&s.KubeConfigFile, "kubeconfig", "", "path to the kubeconfig file")
5047
fs.StringVar(&s.KubeContext, "kube-context", s.KubeContext, "name of the kubeconfig context to use")
5148
fs.StringVar(&s.MapFile, "mapfile", s.MapFile, "path to the API mapping file")
52-
fs.StringVar(&s.Namespace, "namespace", s.Namespace, "namespace scope of the release. For Helm v2, this is the Tiller namespace e.g. kube-system")
53-
fs.BoolVar(&s.RunV2, "v2", false, "run for Helm v2 release. The default is Helm v3.")
54-
fs.BoolVar(&s.TillerOutCluster, "tiller-out-cluster", false, "for Helm v2 only - when Tiller is not running in the cluster e.g. Tillerless")
55-
fs.StringVarP(&s.StorageType, "release-storage", "s", "secrets", "for Helm v2 only - release storage type/object. It can be 'secrets' or 'configmaps'. This is only used with the 'tiller-out-cluster' flag")
49+
fs.StringVar(&s.Namespace, "namespace", s.Namespace, "namespace scope of the release")
5650
}

cmd/mapkubeapis/map.go

+2-21
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ import (
2626
"github.com/spf13/cobra"
2727

2828
"github.com/helm/helm-mapkubeapis/pkg/common"
29-
v2 "github.com/helm/helm-mapkubeapis/pkg/v2"
3029
v3 "github.com/helm/helm-mapkubeapis/pkg/v3"
3130
)
3231

@@ -36,9 +35,6 @@ type MapOptions struct {
3635
MapFile string
3736
ReleaseName string
3837
ReleaseNamespace string
39-
RunV2 bool
40-
StorageType string
41-
TillerOutCluster bool
4238
}
4339

4440
var (
@@ -99,9 +95,6 @@ func runMap(cmd *cobra.Command, args []string) error {
9995
MapFile: settings.MapFile,
10096
ReleaseName: releaseName,
10197
ReleaseNamespace: settings.Namespace,
102-
RunV2: settings.RunV2,
103-
StorageType: settings.StorageType,
104-
TillerOutCluster: settings.TillerOutCluster,
10598
}
10699
kubeConfig := common.KubeConfig{
107100
Context: settings.KubeContext,
@@ -129,22 +122,10 @@ func Map(mapOptions MapOptions, kubeConfig common.KubeConfig) error {
129122
MapFile: mapOptions.MapFile,
130123
ReleaseName: mapOptions.ReleaseName,
131124
ReleaseNamespace: mapOptions.ReleaseNamespace,
132-
StorageType: mapOptions.StorageType,
133-
TillerOutCluster: mapOptions.TillerOutCluster,
134125
}
135126

136-
if mapOptions.RunV2 {
137-
// default namespace to the Tiller default namespace
138-
if options.ReleaseNamespace == "" {
139-
options.ReleaseNamespace = "kube-system"
140-
}
141-
if err := v2.MapReleaseWithUnSupportedAPIs(options); err != nil {
142-
return err
143-
}
144-
} else {
145-
if err := v3.MapReleaseWithUnSupportedAPIs(options); err != nil {
146-
return err
147-
}
127+
if err := v3.MapReleaseWithUnSupportedAPIs(options); err != nil {
128+
return err
148129
}
149130

150131
log.Printf("Map of release '%s' deprecated or removed APIs to supported versions, completed successfully.\n", mapOptions.ReleaseName)

0 commit comments

Comments
 (0)