-
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.
improvement(k8s): add default tolerations to system services
- Loading branch information
Showing
17 changed files
with
182 additions
and
20 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
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
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 |
---|---|---|
|
@@ -23,3 +23,4 @@ values: | |
buildSync: | ||
volume: | ||
name: ${var.sync-volume-name} | ||
tolerations: ${var.system-tolerations} |
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
31 changes: 31 additions & 0 deletions
31
garden-service/static/kubernetes/system/policy/base_test.rego
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,31 @@ | ||
package main | ||
|
||
empty(value) { | ||
count(value) == 0 | ||
} | ||
|
||
no_violations { | ||
empty(deny) | ||
} | ||
|
||
no_warnings { | ||
empty(warn) | ||
} | ||
|
||
test_deployment_without_security_context { | ||
deny["Containers must not run as root in Deployment sample"] with input as {"kind": "Deployment", "metadata": { "name": "sample" }} | ||
} | ||
|
||
test_deployment_with_security_context { | ||
no_violations with input as {"kind": "Deployment", "metadata": {"name": "sample"}, "spec": { | ||
"selector": { "matchLabels": { "app": "something", "release": "something" }}, | ||
"template": { "spec": { "securityContext": { "runAsNonRoot": true }}}}} | ||
} | ||
|
||
test_services_not_denied { | ||
no_violations with input as {"kind": "Service", "metadata": { "name": "sample" }} | ||
} | ||
|
||
test_services_issue_warning { | ||
warn["Found service sample but services are not allowed"] with input as {"kind": "Service", "metadata": { "name": "sample" }} | ||
} |
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,18 @@ | ||
package main | ||
|
||
import data.kubernetes | ||
|
||
name = input.metadata.name | ||
|
||
deny[msg] { | ||
kubernetes.is_deployment | ||
toleration := { | ||
"key": "garden-system", | ||
"operator": "Equal", | ||
"value": "true", | ||
"effect": "NoSchedule", | ||
} | ||
input.spec.template.spec.tolerations[_] != toleration | ||
|
||
msg = sprintf("Deployment %s is missing toleration of kind %v", [name, toleration]) | ||
} |
9 changes: 9 additions & 0 deletions
9
garden-service/static/kubernetes/system/policy/kubernetes.rego
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 @@ | ||
package kubernetes | ||
|
||
is_service { | ||
input.kind = "Service" | ||
} | ||
|
||
is_deployment { | ||
input.kind = "Deployment" | ||
} |
21 changes: 21 additions & 0 deletions
21
garden-service/static/kubernetes/system/policy/labels.rego
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,21 @@ | ||
package main | ||
|
||
import data.kubernetes | ||
|
||
name = input.metadata.name | ||
|
||
# TODO: Re-enable this policy (or some version thereof) | ||
# labels { | ||
# input.metadata.labels["app.kubernetes.io/name"] | ||
# input.metadata.labels["app.kubernetes.io/instance"] | ||
# input.metadata.labels["app.kubernetes.io/version"] | ||
# input.metadata.labels["app.kubernetes.io/component"] | ||
# input.metadata.labels["app.kubernetes.io/part-of"] | ||
# input.metadata.labels["app.kubernetes.io/managed-by"] | ||
# } | ||
# | ||
# deny[msg] { | ||
# kubernetes.is_deployment | ||
# not labels | ||
# msg = sprintf("%s must include Kubernetes recommended labels: https://kubernetes.io/docs/concepts/overview/working-with-objects/common-labels/#labels ", [name]) | ||
# } |
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,6 @@ | ||
package main | ||
|
||
import data.kubernetes | ||
|
||
name = input.metadata.name | ||
|
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
58 changes: 58 additions & 0 deletions
58
garden-service/test/integ/src/plugins/kubernetes/system.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,58 @@ | ||
/* | ||
* Copyright (C) 2018-2020 Garden Technologies, Inc. <[email protected]> | ||
* | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
*/ | ||
|
||
import { Garden } from "../../../../../src/garden" | ||
import { Provider } from "../../../../../src/config/provider" | ||
import { KubernetesConfig, KubernetesPluginContext } from "../../../../../src/plugins/kubernetes/config" | ||
import { getDataDir, makeTestGarden } from "../../../../helpers" | ||
import { expect } from "chai" | ||
import { TestTask } from "../../../../../src/tasks/test" | ||
import { getSystemGarden } from "../../../../../src/plugins/kubernetes/system" | ||
import { getKubernetesSystemVariables } from "../../../../../src/plugins/kubernetes/init" | ||
import Bluebird = require("bluebird") | ||
|
||
describe("System services", () => { | ||
let garden: Garden | ||
let provider: Provider<KubernetesConfig> | ||
|
||
before(async () => { | ||
const root = getDataDir("test-projects", "container") | ||
garden = await makeTestGarden(root) | ||
provider = (await garden.resolveProvider("local-kubernetes")) as Provider<KubernetesConfig> | ||
}) | ||
|
||
after(async () => { | ||
await garden.close() | ||
}) | ||
|
||
it("should use conftest to check whether system services have a valid config", async () => { | ||
const ctx = <KubernetesPluginContext>garden.getPluginContext(provider) | ||
const variables = getKubernetesSystemVariables(provider.config) | ||
const systemGarden = await getSystemGarden(ctx, variables, garden.log) | ||
const graph = await systemGarden.getConfigGraph(garden.log) | ||
const modules = (await graph.getModules()).filter((module) => module.name.startsWith("conftest-")) | ||
|
||
await Bluebird.map(modules, async (module) => { | ||
const testTask = new TestTask({ | ||
garden: systemGarden, | ||
module, | ||
log: garden.log, | ||
graph, | ||
testConfig: module.testConfigs[0] || {}, | ||
force: true, | ||
forceBuild: true, | ||
version: module.version, | ||
_guard: true, | ||
}) | ||
const key = testTask.getKey() | ||
const result = await systemGarden.processTasks([testTask]) | ||
expect(result[key]).to.exist | ||
expect(result[key]?.error).to.not.exist | ||
}) | ||
}) | ||
}) |