Merge pull request #337 from TomChv/ci-kind-setup

Setup Kind cluster in CI
This commit is contained in:
Sam Alba 2021-06-03 09:08:49 -07:00 committed by GitHub
commit e328e71e6c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 45 additions and 54 deletions

View File

@ -76,6 +76,9 @@ jobs:
with: with:
go-version: 1.16 go-version: 1.16
- name: Setup Kind Kubernetes Cluster
uses: engineerd/setup-kind@v0.5.0
- name: Install Dependencies - name: Install Dependencies
run: | run: |
# SOPS # SOPS

View File

@ -14,7 +14,7 @@ import (
name: string @dagger(input) name: string @dagger(input)
// Helm chart to install from source // Helm chart to install from source
chartSource: dagger.#Artifact @dagger(input) chartSource?: dagger.#Artifact @dagger(input)
// Helm chart to install from repository // Helm chart to install from repository
chart?: string @dagger(input) chart?: string @dagger(input)
@ -84,11 +84,6 @@ import (
dest: "/entrypoint.sh" dest: "/entrypoint.sh"
content: #code content: #code
}, },
op.#WriteFile & {
dest: "/kubeconfig"
content: kubeconfig
mode: 0o600
},
if chart != _|_ { if chart != _|_ {
op.#WriteFile & { op.#WriteFile & {
dest: "/helm/chart" dest: "/helm/chart"
@ -126,6 +121,7 @@ import (
if chartSource != _|_ && chart == _|_ { if chartSource != _|_ && chart == _|_ {
"/helm/chart": from: chartSource "/helm/chart": from: chartSource
} }
"/kubeconfig": secret: kubeconfig
} }
}, },
] ]

View File

@ -59,8 +59,7 @@ import (
version: *"v1.19.9" | string @dagger(input) version: *"v1.19.9" | string @dagger(input)
// Kube config file // Kube config file
// FIXME: should be `dagger.#Secret` kubeconfig: dagger.#Secret @dagger(input)
kubeconfig: string @dagger(input)
#code: #""" #code: #"""
kubectl create namespace "$KUBE_NAMESPACE" > /dev/null 2>&1 || true kubectl create namespace "$KUBE_NAMESPACE" > /dev/null 2>&1 || true
@ -75,11 +74,7 @@ import (
dest: "/entrypoint.sh" dest: "/entrypoint.sh"
content: #code content: #code
}, },
op.#WriteFile & {
dest: "/kubeconfig"
content: kubeconfig
mode: 0o600
},
if manifest != _|_ { if manifest != _|_ {
op.#WriteFile & { op.#WriteFile & {
dest: "/source" dest: "/source"
@ -103,6 +98,7 @@ import (
if manifest == _|_ { if manifest == _|_ {
mount: "/source": from: source mount: "/source": from: source
} }
mount: "/kubeconfig": secret: kubeconfig
}, },
] ]
} }

View File

@ -27,7 +27,14 @@ setup() {
@test "stdlib: kubernetes" { @test "stdlib: kubernetes" {
skip_unless_local_kube skip_unless_local_kube
"$DAGGER" compute "$TESTDIR"/stdlib/kubernetes --input-dir kubeconfig=~/.kube "$DAGGER" init
dagger_new_with_plan kubernetes "$TESTDIR"/stdlib/kubernetes/
run "$DAGGER" input -e "kubernetes" secret kubeconfig -f ~/.kube/config
assert_success
run "$DAGGER" up -e "kubernetes"
assert_success
} }
@test "stdlib: kustomize" { @test "stdlib: kustomize" {
@ -37,7 +44,18 @@ setup() {
@test "stdlib: helm" { @test "stdlib: helm" {
skip_unless_local_kube skip_unless_local_kube
"$DAGGER" compute "$TESTDIR"/stdlib/kubernetes/helm --input-dir kubeconfig=~/.kube --input-dir TestHelmSimpleChart.deploy.chartSource="$TESTDIR"/stdlib/kubernetes/helm/testdata/mychart "$DAGGER" init
dagger_new_with_plan helm "$TESTDIR"/stdlib/kubernetes/helm
run "$DAGGER" input -e "helm" secret kubeconfig -f ~/.kube/config
assert_success
cp -R "$TESTDIR"/stdlib/kubernetes/helm/testdata/mychart "$DAGGER_WORKSPACE"/testdata
run "$DAGGER" input -e "helm" dir TestHelmSimpleChart.deploy.chartSource "$DAGGER_WORKSPACE"/testdata
assert_success
run "$DAGGER" up -e "helm"
assert_success
} }
@test "stdlib: aws: s3" { @test "stdlib: aws: s3" {

View File

@ -2,19 +2,12 @@ package helm
import ( import (
"dagger.io/dagger" "dagger.io/dagger"
"dagger.io/file"
"dagger.io/kubernetes/helm" "dagger.io/kubernetes/helm"
) )
// We assume that a kinD cluster is running locally // We assume that a kinD cluster is running locally
// To deploy a local KinD cluster, follow this link : https://kind.sigs.k8s.io/docs/user/quick-start/ // To deploy a local KinD cluster, follow this link : https://kind.sigs.k8s.io/docs/user/quick-start/
kubeconfig: dagger.#Artifact kubeconfig: dagger.#Secret @dagger(input)
// Retrive kubeconfig
config: file.#Read & {
filename: "config"
from: kubeconfig
}
// Deploy user local chart // Deploy user local chart
TestHelmSimpleChart: { TestHelmSimpleChart: {
@ -22,7 +15,7 @@ TestHelmSimpleChart: {
deploy: helm.#Chart & { deploy: helm.#Chart & {
name: "dagger-test-helm-simple-chart-\(random)" name: "dagger-test-helm-simple-chart-\(random)"
namespace: "dagger-test" namespace: "dagger-test"
kubeconfig: config.contents "kubeconfig": kubeconfig
chartSource: dagger.#Artifact chartSource: dagger.#Artifact
} }
@ -39,7 +32,7 @@ TestHelmRepoChart: {
deploy: helm.#Chart & { deploy: helm.#Chart & {
name: "dagger-test-helm-repository-\(random)" name: "dagger-test-helm-repository-\(random)"
namespace: "dagger-test" namespace: "dagger-test"
kubeconfig: config.contents "kubeconfig": kubeconfig
chart: "redis" chart: "redis"
} }

View File

@ -21,12 +21,6 @@ import (
from: kubernetes.#Kubectl from: kubernetes.#Kubectl
}, },
op.#WriteFile & {
dest: "/kubeconfig"
content: config.contents
mode: 0o600
},
op.#WriteFile & { op.#WriteFile & {
dest: "/getHelmPods.sh" dest: "/getHelmPods.sh"
content: #getHelmPods content: #getHelmPods
@ -46,6 +40,7 @@ import (
KUBECONFIG: "/kubeconfig" KUBECONFIG: "/kubeconfig"
KUBE_NAMESPACE: namespace KUBE_NAMESPACE: namespace
} }
mount: "/kubeconfig": secret: kubeconfig
}, },
] ]
} }

View File

@ -3,19 +3,12 @@ package kubernetes
import ( import (
"encoding/yaml" "encoding/yaml"
"dagger.io/dagger" "dagger.io/dagger"
"dagger.io/file"
"dagger.io/kubernetes" "dagger.io/kubernetes"
) )
// We assume that a kinD cluster is running locally // We assume that a kinD cluster is running locally
// To deploy a local KinD cluster, follow this link : https://kind.sigs.k8s.io/docs/user/quick-start/ // To deploy a local KinD cluster, follow this link : https://kind.sigs.k8s.io/docs/user/quick-start/
kubeconfig: dagger.#Artifact kubeconfig: dagger.#Secret @dagger(input)
// Retrive kubeconfig
config: file.#Read & {
filename: "config"
from: kubeconfig
}
TestKubeApply: { TestKubeApply: {
// Pod spec // Pod spec
@ -34,7 +27,7 @@ TestKubeApply: {
// Apply deployment // Apply deployment
apply: kubernetes.#Apply & { apply: kubernetes.#Apply & {
kubeconfig: config.contents "kubeconfig": kubeconfig
namespace: "dagger-test" namespace: "dagger-test"
manifest: yaml.Marshal(kubeSrc) manifest: yaml.Marshal(kubeSrc)
} }

View File

@ -27,17 +27,12 @@ import (
from: kubernetes.#Kubectl from: kubernetes.#Kubectl
}, },
op.#WriteFile & {
dest: "/kubeconfig"
content: config.contents
mode: 0o600
},
op.#WriteFile & { op.#WriteFile & {
dest: "/getPods.sh" dest: "/getPods.sh"
content: #GetPods content: #GetPods
}, },
// Check pods
op.#Exec & { op.#Exec & {
always: true always: true
args: [ args: [
@ -52,6 +47,7 @@ import (
KUBECONFIG: "/kubeconfig" KUBECONFIG: "/kubeconfig"
KUBE_NAMESPACE: namespace KUBE_NAMESPACE: namespace
} }
mount: "/kubeconfig": secret: kubeconfig
}, },
op.#WriteFile & { op.#WriteFile & {
@ -73,6 +69,7 @@ import (
KUBECONFIG: "/kubeconfig" KUBECONFIG: "/kubeconfig"
KUBE_NAMESPACE: namespace KUBE_NAMESPACE: namespace
} }
mount: "/kubeconfig": secret: kubeconfig
}, },
] ]
} }