Skip to content

Commit

Permalink
improvement(k8s): always require manual init for remote clusters
Browse files Browse the repository at this point in the history
  • Loading branch information
edvald committed May 31, 2019
1 parent dba8982 commit 4201dc5
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 14 deletions.
12 changes: 6 additions & 6 deletions garden-service/src/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ export class ActionHelper implements TypeGuard {
/**
* Checks environment status and calls prepareEnvironment for each provider that isn't flagged as ready.
*
* If any of the getEnvironmentStatus handlers returns needUserInput=true, this throws and guides the user to
* If any of the getEnvironmentStatus handlers returns needManualInit=true, this throws and guides the user to
* run `garden init`
*/
async prepareEnvironment(
Expand All @@ -151,13 +151,13 @@ export class ActionHelper implements TypeGuard {
const entry = log.info({ section: "providers", msg: "Getting status...", status: "active" })
const statuses = await this.getEnvironmentStatus({ pluginName, log: entry })

const needUserInput = Object.entries(statuses)
const needManualInit = Object.entries(statuses)
.map(([name, status]) => ({ ...status, name }))
.filter(status => status.needUserInput === true)
.filter(status => status.needManualInit === true)

if (!allowUserInput && needUserInput.length > 0) {
const names = needUserInput.map(s => s.name).join(", ")
const msgPrefix = needUserInput.length === 1
if (!allowUserInput && needManualInit.length > 0) {
const names = needManualInit.map(s => s.name).join(", ")
const msgPrefix = needManualInit.length === 1
? `Plugin ${names} has been updated or hasn't been configured, and requires user input.`
: `Plugins ${names} have been updated or haven't been configured, and require user input.`

Expand Down
6 changes: 6 additions & 0 deletions garden-service/src/plugins/kubernetes/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ export async function getEnvironmentStatus(
}

const systemServiceNames = k8sCtx.provider.config._systemServices
let needManualInit = false

if (systemServiceNames.length > 0) {
// Check Tiller status in system namespace
Expand All @@ -80,6 +81,10 @@ export async function getEnvironmentStatus(

systemReady = systemTillerReady && systemServiceStatuses.ready && sysNamespaceUpToDate
dashboardPages = systemServiceStatuses.dashboardPages

// We always require manual init if we're installing any system services to remote clusters, to avoid conflicts
// between users or unnecessary work.
needManualInit = true
}

const detail = { systemReady, projectReady }
Expand All @@ -88,6 +93,7 @@ export async function getEnvironmentStatus(
ready: projectReady && systemReady,
detail,
dashboardPages,
needManualInit,
}
}

Expand Down
11 changes: 5 additions & 6 deletions garden-service/src/types/plugin/provider/getEnvironmentStatus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export interface GetEnvironmentStatusParams extends PluginActionParamsBase { }

export interface EnvironmentStatus {
ready: boolean
needUserInput?: boolean
needManualInit?: boolean
dashboardPages?: DashboardPage[]
detail?: any
}
Expand All @@ -30,7 +30,7 @@ export const environmentStatusSchema = Joi.object()
ready: Joi.boolean()
.required()
.description("Set to true if the environment is fully configured for a provider."),
needUserInput: Joi.boolean()
needManualInit: Joi.boolean()
.description(
"Set to true if the environment needs user input to be initialized, " +
"and thus needs to be initialized via `garden init`.",
Expand All @@ -50,10 +50,9 @@ export const getEnvironmentStatus = {
Called before \`prepareEnvironment\`. If this returns \`ready: true\`, the
\`prepareEnvironment\` action is not called.
If this returns \`needUserInput: true\`, the process may throw an error and guide the user to
run \`garden init\`, so that \`prepareEnvironment\` can safely ask for user input. Otherwise the
\`prepareEnvironment\` handler may be run implicitly ahead of actions like \`deployService\`,
\`runModule\` etc.
If this returns \`needManualInit: true\`, the process may throw an error and guide the user to
run \`garden init\`. Otherwise the \`prepareEnvironment\` handler may be run implicitly ahead of
actions like \`deployService\`, \`runModule\` etc.
`,
paramsSchema: actionParamsSchema,
resultSchema: environmentStatusSchema,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ export const prepareEnvironment = {
Called ahead of any service runtime actions (such as \`deployService\`,
\`runModule\` and \`testModule\`), unless \`getEnvironmentStatus\` returns \`ready: true\` or
\`needUserInput: true\`.
\`needManualInit: true\`.
Important: If your handler does require user input, please be sure to indicate that via the
\`getEnvironmentStatus\` handler. If this provider's \`getEnvironmentStatus\` returns \`needUserInput: true\`,
\`getEnvironmentStatus\` handler. If this provider's \`getEnvironmentStatus\` returns \`needManualInit: true\`,
this is only called via the \`garden init\` command, so that the handler can safely request user input via
the CLI.
`,
Expand Down

0 comments on commit 4201dc5

Please sign in to comment.