From 0aff683e3d72f98f5a1c86b3dacf5969044a8cb1 Mon Sep 17 00:00:00 2001 From: Jon Edvald Date: Mon, 6 Jan 2020 16:33:57 +0100 Subject: [PATCH] fix(k8s): don't throw init error if garden-system services are modified This narrows the condition for throwing an error on init (when using remote clusters). We now only throw an error if any of the expected services are unhealthy, deploying or missing. Also made the warning message a bit less intrusive, since it's to be expected in some cases that configuration is out of sync between users, as well as when users make modifications of their own. --- garden-service/src/plugins/kubernetes/init.ts | 50 +++++++++++-------- 1 file changed, 28 insertions(+), 22 deletions(-) diff --git a/garden-service/src/plugins/kubernetes/init.ts b/garden-service/src/plugins/kubernetes/init.ts index 91e09b4a85..51ba7e8232 100644 --- a/garden-service/src/plugins/kubernetes/init.ts +++ b/garden-service/src/plugins/kubernetes/init.ts @@ -277,17 +277,38 @@ export async function prepareSystem({ return {} } - // If we require manual init and system services are ready OR outdated but none are *missing*, we warn - // in the prepareEnvironment handler, instead of flagging as not ready here. This avoids blocking users where - // there's variance in configuration between users of the same cluster, that often doesn't affect usage. + // We require manual init if we're installing any system services to remote clusters, to avoid conflicts + // between users or unnecessary work. if (!clusterInit && remoteCluster) { - if (combinedState === "outdated" && !serviceStates.includes("missing")) { + const initCommand = chalk.white.bold(`garden --env=${ctx.environmentName} plugins kubernetes cluster-init`) + + if (combinedState === "ready") { + return {} + } else if ( + combinedState === "deploying" || + combinedState === "unhealthy" || + serviceStates.includes("missing") || + serviceStates.includes("unknown") + ) { + // If any of the services are not ready or missing, we throw, since builds and deployments are likely to fail. + throw new KubernetesError( + deline` + One or more cluster-wide system services are missing or not ready. You need to run ${initCommand} + to initialize them, or contact a cluster admin to do so, before deploying services to this cluster. + `, + { + status, + } + ) + } else { + // If system services are outdated but none are *missing*, we warn instead of flagging as not ready here. + // This avoids blocking users where there's variance in configuration between users of the same cluster, + // that often doesn't affect usage. log.warn({ symbol: "warning", - msg: chalk.yellow(deline` + msg: chalk.gray(deline` One or more cluster-wide system services are outdated or their configuration does not match your current - configuration. You may want to run \`garden --env=${ctx.environmentName} plugins kubernetes cluster-init\` - to update them, or contact a cluster admin to do so. + configuration. You may want to run ${initCommand} to update them, or contact a cluster admin to do so. `), }) @@ -295,21 +316,6 @@ export async function prepareSystem({ } } - // We require manual init if we're installing any system services to remote clusters, to avoid conflicts - // between users or unnecessary work. - if (!clusterInit && remoteCluster && !systemReady) { - throw new KubernetesError( - deline` - One or more cluster-wide system services are missing or not ready. You need to run - \`garden --env=${ctx.environmentName} plugins kubernetes cluster-init\` - to initialize them, or contact a cluster admin to do so, before deploying services to this cluster. - `, - { - status, - } - ) - } - const sysGarden = await getSystemGarden(k8sCtx, variables || {}, log) const sysProvider = await sysGarden.resolveProvider(provider.name) const sysCtx = sysGarden.getPluginContext(sysProvider)