Skip to content

Commit

Permalink
fix(local-k8s): ensure correct nginx status when getting env status (#…
Browse files Browse the repository at this point in the history
…6696)

We use the `clusterType` config field to determine
the status of the nginx ingress controller when applicable for the
`local-kubernetes` provider.

Before this fix however, we'd set the `clusterType` on the provider
config (if needed) in the `prepareEnvironment` handler and not the
`getEnvironmentStatus` handler.

This basically resulted in the `getEnvironmentStatus` handler always
returning that nginx wasn't ready, then the `clusterType` would be
set in the `prepareEnvironment` and the status checked again, this time
correctly.
  • Loading branch information
eysi09 authored Dec 10, 2024
1 parent 86602c6 commit 3c65e49
Showing 1 changed file with 21 additions and 9 deletions.
30 changes: 21 additions & 9 deletions core/src/plugins/kubernetes/local/local.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,16 @@ import type {
PrepareEnvironmentResult,
} from "../../../plugin/handlers/Provider/prepareEnvironment.js"
import type { KubernetesPluginContext } from "../config.js"
import { prepareEnvironment as _prepareEnvironmentBase } from "../init.js"
import {
prepareEnvironment as _prepareEnvironmentBase,
getEnvironmentStatus as _getEnviornmentStatusBase,
} from "../init.js"
import type { Log } from "../../../logger/log-entry.js"
import { setMinikubeDockerEnv } from "./minikube.js"
import { isKindCluster } from "./kind.js"
import { configureMicrok8sAddons } from "./microk8s.js"
import { isK3sFamilyCluster } from "./k3s.js"
import type { GetEnvironmentStatusParams } from "../../../plugin/handlers/Provider/getEnvironmentStatus.js"

const providerUrl = "./kubernetes.md"

Expand All @@ -40,26 +44,34 @@ export const gardenPlugin = () =>
handlers: {
configureProvider,
prepareEnvironment,
getEnvironmentStatus,
},
})

async function getEnvironmentStatus(params: GetEnvironmentStatusParams<LocalKubernetesConfig>) {
const { ctx, log } = params
const provider = ctx.provider

// This should be set in the configureProvider handler but we need the
// plugin context to get the cluster type
if (!provider.config.clusterType) {
provider.config.clusterType = await getClusterType(ctx, log)
}

return await _getEnviornmentStatusBase(params)
}

async function prepareEnvironment(
params: PrepareEnvironmentParams<LocalKubernetesConfig>
): Promise<PrepareEnvironmentResult> {
const { ctx, log } = params
const provider = ctx.provider

let clusterType = provider.config.clusterType
if (!clusterType) {
clusterType = await getClusterType(ctx, log)
provider.config.clusterType = clusterType
}

const result = await _prepareEnvironmentBase(params)

if (clusterType === "minikube") {
if (provider.config.clusterType === "minikube") {
await setMinikubeDockerEnv()
} else if (clusterType === "microk8s") {
} else if (provider.config.clusterType === "microk8s") {
const microk8sAddons = ["dns", "registry", "storage"]
await configureMicrok8sAddons(log, microk8sAddons)
}
Expand Down

0 comments on commit 3c65e49

Please sign in to comment.