diff --git a/garden-service/src/commands/logs.ts b/garden-service/src/commands/logs.ts index a02a73100d..1b38758cff 100644 --- a/garden-service/src/commands/logs.ts +++ b/garden-service/src/commands/logs.ts @@ -84,10 +84,17 @@ export class LogsCommand extends Command { } }) - // NOTE: This will work differently when we have Elasticsearch set up for logging, but is - // quite servicable for now. await Bluebird.map(services, async (service: Service) => { - await garden.actions.getServiceLogs({ service, stream, tail }) + const status = await garden.actions.getServiceStatus({ service }) + if (status.state === "ready" || status.state === "outdated") { + await garden.actions.getServiceLogs({ service, stream, tail }) + } else { + await stream.write({ + serviceName: service.name, + timestamp: new Date(), + msg: chalk.yellow(``), + }) + } }) return { result } diff --git a/garden-service/src/plugins/kubernetes/actions.ts b/garden-service/src/plugins/kubernetes/actions.ts index b3e29e605e..bd38f3df56 100644 --- a/garden-service/src/plugins/kubernetes/actions.ts +++ b/garden-service/src/plugins/kubernetes/actions.ts @@ -337,8 +337,6 @@ export async function getServiceLogs( void stream.write({ serviceName: service.name, timestamp, msg }) }) - proc.stderr.pipe(process.stderr) - return new Promise((resolve, reject) => { proc.on("error", reject) diff --git a/garden-service/src/plugins/kubernetes/deployment.ts b/garden-service/src/plugins/kubernetes/deployment.ts index 9a402a5de6..905e8af64b 100644 --- a/garden-service/src/plugins/kubernetes/deployment.ts +++ b/garden-service/src/plugins/kubernetes/deployment.ts @@ -76,13 +76,13 @@ export async function getContainerServiceStatus( // FIXME: [objects, matched] and ingresses can be run in parallel const objects = await createContainerObjects(ctx, service, runtimeContext, enableHotReload) - const matched = await compareDeployedObjects(ctx, objects) + const state = await compareDeployedObjects(ctx, objects) const ingresses = await getIngresses(service, api) return { ingresses, - state: matched ? "ready" : "outdated", - version: matched ? version.versionString : undefined, + state, + version: state === "ready" ? version.versionString : undefined, } } diff --git a/garden-service/src/plugins/kubernetes/helm.ts b/garden-service/src/plugins/kubernetes/helm.ts index 3a54e0355d..4a5f0355fc 100644 --- a/garden-service/src/plugins/kubernetes/helm.ts +++ b/garden-service/src/plugins/kubernetes/helm.ts @@ -314,10 +314,10 @@ async function getServiceStatus( // first check if the installed objects on the cluster match the current code const objects = await getChartObjects(ctx, service, logEntry) - const matched = await compareDeployedObjects(ctx, objects) + let state = await compareDeployedObjects(ctx, objects) - if (!matched) { - return { state: "outdated" } + if (state !== "ready") { + return { state } } // then check if the rollout is complete @@ -327,7 +327,7 @@ async function getServiceStatus( const { ready } = await checkObjectStatus(api, namespace, objects) // TODO: set state to "unhealthy" if any status is "unhealthy" - const state = ready ? "ready" : "deploying" + state = ready ? "ready" : "deploying" return { state, version: version.versionString } } diff --git a/garden-service/src/plugins/kubernetes/status.ts b/garden-service/src/plugins/kubernetes/status.ts index 9ee17ded5f..6dc619ec26 100644 --- a/garden-service/src/plugins/kubernetes/status.ts +++ b/garden-service/src/plugins/kubernetes/status.ts @@ -397,11 +397,14 @@ export async function waitForServices( /** * Check if each of the given Kubernetes objects matches what's installed in the cluster */ -export async function compareDeployedObjects(ctx: PluginContext, objects: KubernetesObject[]): Promise { +export async function compareDeployedObjects(ctx: PluginContext, objects: KubernetesObject[]): Promise { const existingObjects = await Bluebird.map(objects, obj => getDeployedObject(ctx, ctx.provider, obj)) + let missing = true for (let [obj, existingSpec] of zip(objects, existingObjects)) { if (existingSpec && obj) { + missing = false + // the API version may implicitly change when deploying existingSpec.apiVersion = obj.apiVersion @@ -436,19 +439,21 @@ export async function compareDeployedObjects(ctx: PluginContext, objects: Kubern obj = removeNull(obj) } - if (!existingSpec || !isSubset(existingSpec, obj)) { + if (existingSpec && !isSubset(existingSpec, obj)) { // console.log(JSON.stringify(obj, null, 4)) // console.log(JSON.stringify(existingSpec, null, 4)) // console.log("----------------------------------------------------") // throw new Error("bla") - return false + return "outdated" } } - return true + return missing ? "missing" : "ready" } -async function getDeployedObject(ctx: PluginContext, provider: KubernetesProvider, obj: KubernetesObject) { +async function getDeployedObject( + ctx: PluginContext, provider: KubernetesProvider, obj: KubernetesObject, +): Promise { const api = new KubeApi(provider) const namespace = obj.metadata.namespace || await getAppNamespace(ctx, provider)