Update helm and kubernetes tests to use new dagger.#Secret definition

Signed-off-by: Tom Chauveau <tom.chauveau@epitech.eu>
This commit is contained in:
Tom Chauveau 2021-06-03 16:28:03 +02:00
parent ce65a65ede
commit 2c6e67cb7d
7 changed files with 42 additions and 54 deletions

View File

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

View File

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

View File

@ -27,7 +27,14 @@ setup() {
@test "stdlib: kubernetes" {
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" {
@ -37,7 +44,18 @@ setup() {
@test "stdlib: helm" {
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" {

View File

@ -2,19 +2,12 @@ package helm
import (
"dagger.io/dagger"
"dagger.io/file"
"dagger.io/kubernetes/helm"
)
// 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/
kubeconfig: dagger.#Artifact
// Retrive kubeconfig
config: file.#Read & {
filename: "config"
from: kubeconfig
}
kubeconfig: dagger.#Secret @dagger(input)
// Deploy user local chart
TestHelmSimpleChart: {
@ -22,7 +15,7 @@ TestHelmSimpleChart: {
deploy: helm.#Chart & {
name: "dagger-test-helm-simple-chart-\(random)"
namespace: "dagger-test"
kubeconfig: config.contents
"kubeconfig": kubeconfig
chartSource: dagger.#Artifact
}
@ -39,7 +32,7 @@ TestHelmRepoChart: {
deploy: helm.#Chart & {
name: "dagger-test-helm-repository-\(random)"
namespace: "dagger-test"
kubeconfig: config.contents
"kubeconfig": kubeconfig
chart: "redis"
}

View File

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

View File

@ -3,19 +3,12 @@ package kubernetes
import (
"encoding/yaml"
"dagger.io/dagger"
"dagger.io/file"
"dagger.io/kubernetes"
)
// 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/
kubeconfig: dagger.#Artifact
// Retrive kubeconfig
config: file.#Read & {
filename: "config"
from: kubeconfig
}
kubeconfig: dagger.#Secret @dagger(input)
TestKubeApply: {
// Pod spec
@ -34,7 +27,7 @@ TestKubeApply: {
// Apply deployment
apply: kubernetes.#Apply & {
kubeconfig: config.contents
"kubeconfig": kubeconfig
namespace: "dagger-test"
manifest: yaml.Marshal(kubeSrc)
}

View File

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