This repository has been archived on 2024-04-08. You can view files and clone it, but cannot push or open issues or pull requests.
dagger/stdlib/kubernetes/kubernetes.cue
Andrea Luzzardi a5e9ac8a0f stdlib: kubernetes: rename #Apply to #Resources
Code convention: use nouns instead of verbs whenever possible.

Reasoning: One can apply just about anything to Kubernetes via this:
deployment, load balancer, RBAC policy, a custom CRD resource, etc.

Upstream those are called resources: You give `kubectl apply` one or more
manifests and it will create the corresponding resources.

Signed-off-by: Andrea Luzzardi <aluzzardi@gmail.com>
2021-06-04 14:03:35 -07:00

105 lines
1.9 KiB
CUE

package kubernetes
import (
"dagger.io/dagger/op"
"dagger.io/dagger"
"dagger.io/alpine"
)
#Kubectl: {
version: *"v1.19.9" | string
#code: #"""
[ -e /usr/local/bin/kubectl ] || {
curl -sfL https://dl.k8s.io/${KUBECTL_VERSION}/bin/linux/amd64/kubectl -o /usr/local/bin/kubectl \
&& chmod +x /usr/local/bin/kubectl
}
"""#
#up: [
op.#Load & {
from: alpine.#Image & {
package: bash: "=~5.1"
package: jq: "=~1.6"
package: curl: true
}
},
op.#WriteFile & {
dest: "/entrypoint.sh"
content: #code
},
op.#Exec & {
args: [
"/bin/bash",
"--noprofile",
"--norc",
"-eo",
"pipefail",
"/entrypoint.sh",
]
env: KUBECTL_VERSION: version
},
]
}
// Apply Kubernetes resources
#Resources: {
// Kubernetes config to deploy
source?: dagger.#Artifact @dagger(input)
// Kubernetes manifest to deploy inlined in a string
manifest?: string @dagger(input)
// Kubernetes Namespace to deploy to
namespace: *"default" | string @dagger(input)
// Version of kubectl client
version: *"v1.19.9" | string @dagger(input)
// Kube config file
kubeconfig: dagger.#Secret @dagger(input)
#code: #"""
kubectl create namespace "$KUBE_NAMESPACE" > /dev/null 2>&1 || true
kubectl --namespace "$KUBE_NAMESPACE" apply -R -f /source
"""#
#up: [
op.#Load & {
from: #Kubectl & {"version": version}
},
op.#WriteFile & {
dest: "/entrypoint.sh"
content: #code
},
if manifest != _|_ {
op.#WriteFile & {
dest: "/source"
content: manifest
}
},
op.#Exec & {
always: true
args: [
"/bin/bash",
"--noprofile",
"--norc",
"-eo",
"pipefail",
"/entrypoint.sh",
]
env: {
KUBECONFIG: "/kubeconfig"
KUBE_NAMESPACE: namespace
}
if manifest == _|_ {
mount: "/source": from: source
}
mount: "/kubeconfig": secret: kubeconfig
},
]
}