Skip to content

Commit

Permalink
fix(k8s): helm returned deprecated manifest version for tiller
Browse files Browse the repository at this point in the history
Fixes #1166
  • Loading branch information
edvald committed Sep 11, 2019
1 parent c99b6e4 commit b4ff21c
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
2 changes: 2 additions & 0 deletions garden-service/src/plugins/kubernetes/helm/tiller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { combineStates } from "../../../types/service"
import { apply } from "../kubectl"
import { KubernetesProvider, KubernetesPluginContext } from "../config"
import chalk from "chalk"
import { convertDeprecatedManifestVersion } from "../util"

const serviceAccountName = "garden-tiller"

Expand Down Expand Up @@ -84,6 +85,7 @@ async function getTillerResources(
})

const resources = safeLoadAll(tillerManifests)
.map(convertDeprecatedManifestVersion)

return resources
}
Expand Down
35 changes: 35 additions & 0 deletions garden-service/src/plugins/kubernetes/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -288,3 +288,38 @@ export function prepareEnvVars(env: ContainerEnvVars): V1EnvVar[] {
}
})
}

/**
* Makes sure a Kubernetes manifest has an up-to-date API version.
* See https://kubernetes.io/blog/2019/07/18/api-deprecations-in-1-16/
*
* @param manifest any Kubernetes manifest
*/
export function convertDeprecatedManifestVersion(manifest: KubernetesResource): KubernetesResource {
const { apiVersion, kind } = manifest

if (workloadTypes.includes(kind)) {
manifest.apiVersion = "apps/v1"
} else if (apiVersion === "extensions/v1beta1") {
switch (kind) {
case "NetworkPolicy":
manifest.apiVersion = "networking.k8s.io/v1"
break

case "PodSecurityPolicy":
manifest.apiVersion = "policy/v1beta1"
break
}
}

// apps/v1/Deployment requires spec.selector to be set
if (kind === "Deployment") {
if (manifest.spec && !manifest.spec.selector) {
manifest.spec.selector = {
...{ matchLabels: manifest.spec.template.metadata.labels || manifest.metadata.labels },
}
}
}

return manifest
}

0 comments on commit b4ff21c

Please sign in to comment.