Skip to content

Commit

Permalink
fix(k8s): warn instead of error when cluster services are outdated
Browse files Browse the repository at this point in the history
  • Loading branch information
edvald committed Jun 5, 2019
1 parent 83d9efb commit fbc4cb5
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 7 deletions.
25 changes: 22 additions & 3 deletions garden-service/src/plugins/kubernetes/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { KubernetesPluginContext, KubernetesConfig } from "./config"
import { checkTillerStatus, installTiller } from "./helm/tiller"
import {
prepareSystemServices,
getSystemServiceStatuses,
getSystemServiceStatus,
getSystemGarden,
systemNamespaceUpToDate,
systemNamespace,
Expand All @@ -22,6 +22,7 @@ import { GetEnvironmentStatusParams, EnvironmentStatus } from "../../types/plugi
import { PrepareEnvironmentParams } from "../../types/plugin/provider/prepareEnvironment"
import { CleanupEnvironmentParams } from "../../types/plugin/provider/cleanupEnvironment"
import { millicpuToString, megabytesToString } from "./util"
import chalk from "chalk"

/**
* Performs the following actions to check environment status:
Expand Down Expand Up @@ -68,17 +69,35 @@ export async function getEnvironmentStatus({ ctx, log }: GetEnvironmentStatusPar
const sysNamespaceUpToDate = await systemNamespaceUpToDate(api, log, namespace, contextForLog)

// Get system service statuses
const systemServiceStatuses = await getSystemServiceStatuses({
const systemServiceStatuses = await getSystemServiceStatus({
ctx: k8sCtx,
log,
namespace,
serviceNames: systemServiceNames,
variables: variables || {},
})

systemReady = systemTillerReady && systemServiceStatuses.ready && sysNamespaceUpToDate
systemReady = systemTillerReady && sysNamespaceUpToDate && (
systemServiceStatuses.state === "ready"
||
(needManualInit && systemServiceStatuses.state === "outdated")
)

dashboardPages = systemServiceStatuses.dashboardPages

if (needManualInit && systemServiceStatuses.state === "outdated") {
// If we require manual init and system services are outdated (as opposed to unhealthy, missing etc.), we warn
// instead of aborting. This avoids blocking users where there's variance in configuration between users of the
// same cluster, that most likely shouldn't affect usage.
log.warn({
symbol: "warning",
msg: chalk.yellow(
"One or more cluster-wide services are outdated or their configuration does not match your current " +
"configuration. You may want to run \`garden init\` to update them, or contact your cluster admin.",
),
})
}

// We always require manual init if we're installing any system services to remote clusters, to avoid conflicts
// between users or unnecessary work.
needManualInit = ctx.provider.name !== "local-kubernetes"
Expand Down
9 changes: 5 additions & 4 deletions garden-service/src/plugins/kubernetes/system.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/

import { join } from "path"
import { every, values, find } from "lodash"
import { values, find } from "lodash"
import { V1Namespace } from "@kubernetes/client-node"
import * as semver from "semver"

Expand All @@ -23,6 +23,7 @@ import { deleteNamespaces } from "./namespace"
import { PluginError } from "../../exceptions"
import { DashboardPage } from "../../config/dashboard"
import { PrimitiveMap } from "../../config/common"
import { combineStates } from "../../types/service"

const GARDEN_VERSION = getPackageVersion()
const SYSTEM_NAMESPACE_MIN_VERSION = "0.9.0"
Expand Down Expand Up @@ -132,15 +133,15 @@ interface GetSystemServicesStatusParams {
variables: PrimitiveMap,
}

export async function getSystemServiceStatuses(
export async function getSystemServiceStatus(
{ ctx, log, namespace, serviceNames, variables }: GetSystemServicesStatusParams,
) {
let dashboardPages: DashboardPage[] = []

const sysGarden = await getSystemGarden(ctx.provider, variables)

const serviceStatuses = await sysGarden.actions.getServiceStatuses({ log, serviceNames })
const ready = every(values(serviceStatuses).map(s => s.state === "ready"))
const state = combineStates(values(serviceStatuses).map(s => s.state || "unknown"))

// Add the Kubernetes dashboard to the Garden dashboard
if (serviceNames.includes("kubernetes-dashboard")) {
Expand All @@ -167,7 +168,7 @@ export async function getSystemServiceStatuses(
}

return {
ready,
state,
dashboardPages,
}
}
Expand Down

0 comments on commit fbc4cb5

Please sign in to comment.