Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improvement(logger): various tweaks to log lines #5452

Merged
merged 1 commit into from
Nov 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
23 changes: 12 additions & 11 deletions core/src/plugins/kubernetes/container/build/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -346,11 +346,11 @@ export async function ensureUtilDeployment({
})

return deployLock.acquire(namespace, async () => {
const deployLog = log.createLog()
const buildUtilLog = log.createLog({ origin: "build-util" })

const { authSecret, updated: secretUpdated } = await ensureBuilderSecret({
provider,
log,
log: buildUtilLog,
api,
namespace,
})
Expand All @@ -364,13 +364,13 @@ export async function ensureUtilDeployment({
api,
namespace,
manifests: [deployment, service],
log: deployLog,
log: buildUtilLog,
})

// if the service account changed, all pods part of the deployment must be restarted
// so that they receive new credentials (e.g. for IRSA)
if (status.remoteResources.length > 0 && serviceAccountChanged) {
await cycleDeployment({ ctx, provider, deployment, api, namespace, deployLog })
await cycleDeployment({ ctx, provider, deployment, api, namespace, deployLog: buildUtilLog })
}

if (status.state === "ready") {
Expand All @@ -382,24 +382,24 @@ export async function ensureUtilDeployment({
}

// Deploy the service
deployLog.info(
styles.primary(`-> Deploying ${utilDeploymentName} service in ${namespace} namespace (was ${status.state})`)
buildUtilLog.info(
`Deploying ${utilDeploymentName} service in ${styles.highlight(namespace)} namespace (was ${status.state})`
)

await api.upsert({ kind: "Deployment", namespace, log: deployLog, obj: deployment })
await api.upsert({ kind: "Service", namespace, log: deployLog, obj: service })
await api.upsert({ kind: "Deployment", namespace, log: buildUtilLog, obj: deployment })
await api.upsert({ kind: "Service", namespace, log: buildUtilLog, obj: service })

await waitForResources({
namespace,
ctx,
provider,
actionName: "garden-util",
resources: [deployment, service],
log: deployLog,
log: buildUtilLog,
timeoutSec: 600,
})

deployLog.info("Done!")
buildUtilLog.success("Done")

return { authSecret, updated: true }
})
Expand Down Expand Up @@ -490,7 +490,8 @@ export async function ensureBuilderSecret({
const existingSecret = await api.readBySpecOrNull({ log, namespace, manifest: authSecret })

if (!existingSecret || authSecret.data?.[dockerAuthSecretKey] !== existingSecret.data?.[dockerAuthSecretKey]) {
log.info(styles.primary(`-> Updating Docker auth secret in namespace ${namespace}`))
const reason = !existingSecret ? "was missing" : "has changed"
log.info(`Updating Docker auth secret in namespace ${styles.highlight(namespace)} (${reason})`)
await api.upsert({ kind: "Secret", namespace, log, obj: authSecret })
updated = true
}
Expand Down
24 changes: 12 additions & 12 deletions core/src/plugins/kubernetes/ephemeral/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,10 @@ export const configSchema = () =>
.description(`The provider configuration for the ${EPHEMERAL_KUBERNETES_PROVIDER_NAME} plugin.`)

export async function configureProvider(params: ConfigureProviderParams<KubernetesConfig>) {
const { base, log, projectName, ctx, config: baseConfig } = params
const { base, log, ctx, config: baseConfig } = params

const providerLog = log.createLog({ name: ctx.provider.name }).info("Configuring provider...")

log.info(`Configuring ${EPHEMERAL_KUBERNETES_PROVIDER_NAME} provider for project ${projectName}`)
if (!ctx.cloudApi) {
throw new ConfigurationError({
message: `You are not logged in. You must be logged into Garden Cloud in order to use ${EPHEMERAL_KUBERNETES_PROVIDER_NAME} provider.`,
Expand All @@ -63,32 +64,31 @@ export async function configureProvider(params: ConfigureProviderParams<Kubernet
const ephemeralClusterDirPath = join(ctx.gardenDirPath, "ephemeral-kubernetes")
await mkdirp(ephemeralClusterDirPath)

log.info("Retrieving ephemeral Kubernetes cluster")
providerLog.info("Getting cluster info...")
const createEphemeralClusterResponse = await ctx.cloudApi.createEphemeralCluster()
const clusterId = createEphemeralClusterResponse.instanceMetadata.instanceId
log.info(`Ephemeral Kubernetes cluster retrieved successfully`)

const deadlineDateTime = moment(createEphemeralClusterResponse.instanceMetadata.deadline)
const diffInNowAndDeadline = moment.duration(deadlineDateTime.diff(moment())).asMinutes().toFixed(1)
log.info(
styles.accent(
`Ephemeral cluster will be destroyed in ${diffInNowAndDeadline} minutes, at ${deadlineDateTime.format(
"YYYY-MM-DD HH:mm:ss"
)}`
)
providerLog.info(
`Cluster will be destroyed in ${styles.highlight(diffInNowAndDeadline)} minutes (at ${deadlineDateTime.format(
"YYYY-MM-DD HH:mm:ss"
)})`
)

log.info("Fetching kubeconfig for the ephemeral cluster")
providerLog.info("Getting kubeconfig...")
const kubeConfig = await ctx.cloudApi.getKubeConfigForCluster(clusterId)
const kubeconfigFileName = `${clusterId}-kubeconfig.yaml`
const kubeConfigPath = join(ctx.gardenDirPath, "ephemeral-kubernetes", kubeconfigFileName)
await writeFile(kubeConfigPath, kubeConfig)
log.info(`Kubeconfig for ephemeral cluster saved at path: ${styles.underline(kubeConfigPath)}`)
providerLog.info(`Kubeconfig saved at local path: ${styles.highlight(kubeConfigPath)}`)

const parsedKubeConfig: any = load(kubeConfig)
baseConfig.context = parsedKubeConfig["current-context"]
baseConfig.kubeconfig = kubeConfigPath

providerLog.success("Done")

// set deployment registry
baseConfig.deploymentRegistry = {
hostname: createEphemeralClusterResponse.registry.endpointAddress,
Expand Down
1 change: 1 addition & 0 deletions core/src/plugins/kubernetes/status/status.ts
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,7 @@ export async function waitForResources({
.createLog({
// TODO: Avoid setting fallback, the action name should be known
name: actionName || "<kubernetes>",
origin: "kubernetes",
})
.info(waitingMsg)
emitLog(waitingMsg)
Expand Down