-
Notifications
You must be signed in to change notification settings - Fork 273
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(k8s): don't match on version label when getting workload pods
This fixes an issue where Garden wouldn't find pods because the version in the cluster didn't match the version Garden expected after a hot reload event. This would e.g. cause issues for the 'logs' and 'exec' commands.
- Loading branch information
Showing
11 changed files
with
316 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
garden-service/test/data/test-projects/container/simple-service/Dockerfile
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
FROM busybox | ||
|
||
COPY main . | ||
|
||
ENTRYPOINT ./main | ||
|
||
EXPOSE 8080 |
9 changes: 9 additions & 0 deletions
9
garden-service/test/data/test-projects/container/simple-service/garden.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
kind: Module | ||
name: simple-service | ||
description: Test module for a simple service | ||
type: container | ||
services: | ||
- name: simple-service | ||
ports: | ||
- name: http | ||
containerPort: 8080 |
Binary file not shown.
17 changes: 17 additions & 0 deletions
17
garden-service/test/data/test-projects/container/simple-service/main.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"net/http" | ||
) | ||
|
||
func handler(w http.ResponseWriter, r *http.Request) { | ||
fmt.Fprint(w, "Hello from Go!") | ||
} | ||
|
||
func main() { | ||
http.HandleFunc("/hello-backend", handler) | ||
fmt.Println("Server running...") | ||
|
||
http.ListenAndServe(":8080", nil) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
garden-service/test/integ/src/plugins/kubernetes/container/logs.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import { expect } from "chai" | ||
import { Garden } from "../../../../../../src/garden" | ||
import { getDataDir, makeTestGarden } from "../../../../../helpers" | ||
import { ConfigGraph } from "../../../../../../src/config-graph" | ||
import { Provider } from "../../../../../../src/config/provider" | ||
import { DeployTask } from "../../../../../../src/tasks/deploy" | ||
import { getServiceLogs } from "../../../../../../src/plugins/kubernetes/container/logs" | ||
import { Stream } from "ts-stream" | ||
import { ServiceLogEntry } from "../../../../../../src/types/plugin/service/getServiceLogs" | ||
import { PluginContext } from "../../../../../../src/plugin-context" | ||
|
||
describe("kubernetes", () => { | ||
describe("getServiceLogs", () => { | ||
let garden: Garden | ||
let graph: ConfigGraph | ||
let provider: Provider | ||
let ctx: PluginContext | ||
|
||
before(async () => { | ||
const root = getDataDir("test-projects", "container") | ||
garden = await makeTestGarden(root) | ||
graph = await garden.getConfigGraph() | ||
provider = await garden.resolveProvider("local-kubernetes") | ||
ctx = garden.getPluginContext(provider) | ||
}) | ||
|
||
after(async () => { | ||
await garden.close() | ||
}) | ||
|
||
it("should write service logs to stream", async () => { | ||
const module = await graph.getModule("simple-service") | ||
const service = await graph.getService("simple-service") | ||
|
||
const entries: ServiceLogEntry[] = [] | ||
|
||
const deployTask = new DeployTask({ | ||
force: true, | ||
forceBuild: true, | ||
garden, | ||
graph, | ||
log: garden.log, | ||
service, | ||
}) | ||
|
||
await garden.processTasks([deployTask], { throwOnError: true }) | ||
const stream = new Stream<ServiceLogEntry>() | ||
|
||
void stream.forEach((entry) => { | ||
entries.push(entry) | ||
}) | ||
|
||
await getServiceLogs({ | ||
ctx, | ||
module, | ||
service, | ||
log: garden.log, | ||
stream, | ||
follow: false, | ||
tail: -1, | ||
}) | ||
|
||
expect(entries[0].msg).to.include("Server running...") | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import { expect } from "chai" | ||
import { flatten } from "lodash" | ||
import { Garden } from "../../../../../src/garden" | ||
import { getDataDir, makeTestGarden } from "../../../../helpers" | ||
import { ConfigGraph } from "../../../../../src/config-graph" | ||
import { Provider } from "../../../../../src/config/provider" | ||
import { DeployTask } from "../../../../../src/tasks/deploy" | ||
import { KubeApi } from "../../../../../src/plugins/kubernetes/api" | ||
import { KubernetesConfig } from "../../../../../src/plugins/kubernetes/config" | ||
import { getWorkloadPods } from "../../../../../src/plugins/kubernetes/util" | ||
import { createWorkloadResource } from "../../../../../src/plugins/kubernetes/container/deployment" | ||
import { emptyRuntimeContext } from "../../../../../src/runtime-context" | ||
|
||
describe("util", () => { | ||
// TODO: Add more test cases | ||
describe("getWorkloadPods", () => { | ||
let garden: Garden | ||
let graph: ConfigGraph | ||
let provider: Provider<KubernetesConfig> | ||
let api: KubeApi | ||
|
||
before(async () => { | ||
const root = getDataDir("test-projects", "container") | ||
garden = await makeTestGarden(root) | ||
graph = await garden.getConfigGraph() | ||
provider = (await garden.resolveProvider("local-kubernetes")) as Provider<KubernetesConfig> | ||
api = await KubeApi.factory(garden.log, provider) | ||
}) | ||
|
||
after(async () => { | ||
await garden.close() | ||
}) | ||
|
||
it("should return workload pods", async () => { | ||
const service = await graph.getService("simple-service") | ||
|
||
const deployTask = new DeployTask({ | ||
force: false, | ||
forceBuild: false, | ||
garden, | ||
graph, | ||
log: garden.log, | ||
service, | ||
}) | ||
|
||
const resource = await createWorkloadResource({ | ||
provider, | ||
service, | ||
runtimeContext: emptyRuntimeContext, | ||
namespace: "container-artifacts", | ||
enableHotReload: false, | ||
log: garden.log, | ||
}) | ||
await garden.processTasks([deployTask], { throwOnError: true }) | ||
|
||
const pods = await getWorkloadPods(api, "container-artifacts", resource) | ||
const services = flatten(pods.map((pod) => pod.spec.containers.map((container) => container.name))) | ||
expect(services).to.eql(["simple-service"]) | ||
}) | ||
}) | ||
}) |
Oops, something went wrong.