Merge pull request #949 from TomChv/feat/improve-kube-pkg
Improve kubernetes package to deploy config from yaml
This commit is contained in:
commit
5fa6a2adb2
@ -16,7 +16,9 @@ Kubectl client
|
|||||||
|
|
||||||
### kubernetes.#Kubectl Inputs
|
### kubernetes.#Kubectl Inputs
|
||||||
|
|
||||||
_No input._
|
| Name | Type | Description |
|
||||||
|
| ------------- |:-------------: |:-------------: |
|
||||||
|
|*version* | `*"v1.19.9" \| string` |Kubectl version |
|
||||||
|
|
||||||
### kubernetes.#Kubectl Outputs
|
### kubernetes.#Kubectl Outputs
|
||||||
|
|
||||||
@ -30,6 +32,9 @@ Apply Kubernetes resources
|
|||||||
|
|
||||||
| Name | Type | Description |
|
| Name | Type | Description |
|
||||||
| ------------- |:-------------: |:-------------: |
|
| ------------- |:-------------: |:-------------: |
|
||||||
|
|*source* | `dagger.#Artifact` |Kubernetes config to deploy |
|
||||||
|
|*manifest* | `*null \| string` |Kubernetes manifest to deploy inlined in a string |
|
||||||
|
|*url* | `*null \| string` |Kubernetes manifest url to deploy remote configuration |
|
||||||
|*namespace* | `*"default" \| string` |Kubernetes Namespace to deploy to |
|
|*namespace* | `*"default" \| string` |Kubernetes Namespace to deploy to |
|
||||||
|*version* | `*"v1.19.9" \| string` |Version of kubectl client |
|
|*version* | `*"v1.19.9" \| string` |Version of kubectl client |
|
||||||
|*kubeconfig* | `string` |Kube config file |
|
|*kubeconfig* | `string` |Kube config file |
|
||||||
|
@ -11,7 +11,7 @@ import (
|
|||||||
#Kubectl: {
|
#Kubectl: {
|
||||||
|
|
||||||
// Kubectl version
|
// Kubectl version
|
||||||
version: *"v1.19.9" | string
|
version: dagger.#Input & {*"v1.19.9" | string}
|
||||||
|
|
||||||
#code: #"""
|
#code: #"""
|
||||||
[ -e /usr/local/bin/kubectl ] || {
|
[ -e /usr/local/bin/kubectl ] || {
|
||||||
@ -50,23 +50,35 @@ import (
|
|||||||
#Resources: {
|
#Resources: {
|
||||||
|
|
||||||
// Kubernetes config to deploy
|
// Kubernetes config to deploy
|
||||||
source?: dagger.#Artifact @dagger(input)
|
source: dagger.#Input & {*null | dagger.#Artifact}
|
||||||
|
|
||||||
// Kubernetes manifest to deploy inlined in a string
|
// Kubernetes manifest to deploy inlined in a string
|
||||||
manifest?: string @dagger(input)
|
manifest: dagger.#Input & {*null | string}
|
||||||
|
|
||||||
|
// Kubernetes manifest url to deploy remote configuration
|
||||||
|
url: dagger.#Input & {*null | string}
|
||||||
|
|
||||||
// Kubernetes Namespace to deploy to
|
// Kubernetes Namespace to deploy to
|
||||||
namespace: *"default" | string @dagger(input)
|
namespace: dagger.#Input & {*"default" | string}
|
||||||
|
|
||||||
// Version of kubectl client
|
// Version of kubectl client
|
||||||
version: *"v1.19.9" | string @dagger(input)
|
version: dagger.#Input & {*"v1.19.9" | string}
|
||||||
|
|
||||||
// Kube config file
|
// Kube config file
|
||||||
kubeconfig: string @dagger(input)
|
kubeconfig: dagger.#Input & {string}
|
||||||
|
|
||||||
#code: #"""
|
#code: #"""
|
||||||
kubectl create namespace "$KUBE_NAMESPACE" > /dev/null 2>&1 || true
|
kubectl create namespace "$KUBE_NAMESPACE" > /dev/null 2>&1 || true
|
||||||
|
|
||||||
|
if [ -d /source ] || [ -f /source ]; then
|
||||||
kubectl --namespace "$KUBE_NAMESPACE" apply -R -f /source
|
kubectl --namespace "$KUBE_NAMESPACE" apply -R -f /source
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -n "$DEPLOYMENT_URL" ]; then
|
||||||
|
kubectl --namespace "$KUBE_NAMESPACE" apply -R -f "$DEPLOYMENT_URL"
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
"""#
|
"""#
|
||||||
|
|
||||||
#up: [
|
#up: [
|
||||||
@ -82,7 +94,7 @@ import (
|
|||||||
content: kubeconfig
|
content: kubeconfig
|
||||||
mode: 0o600
|
mode: 0o600
|
||||||
},
|
},
|
||||||
if manifest != _|_ {
|
if manifest != null {
|
||||||
op.#WriteFile & {
|
op.#WriteFile & {
|
||||||
dest: "/source"
|
dest: "/source"
|
||||||
content: manifest
|
content: manifest
|
||||||
@ -101,8 +113,11 @@ import (
|
|||||||
env: {
|
env: {
|
||||||
KUBECONFIG: "/kubeconfig"
|
KUBECONFIG: "/kubeconfig"
|
||||||
KUBE_NAMESPACE: namespace
|
KUBE_NAMESPACE: namespace
|
||||||
|
if url != null {
|
||||||
|
DEPLOYMENT_URL: url
|
||||||
}
|
}
|
||||||
if manifest == _|_ {
|
}
|
||||||
|
if manifest == null && source != null {
|
||||||
mount: "/source": from: source
|
mount: "/source": from: source
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -29,7 +29,7 @@ TestKubeApply: {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Apply deployment
|
// Apply deployment
|
||||||
apply: #Resources & {
|
resources: #Resources & {
|
||||||
kubeconfig: TestKubeconfig
|
kubeconfig: TestKubeconfig
|
||||||
namespace: "dagger-test"
|
namespace: "dagger-test"
|
||||||
manifest: yaml.Marshal(kubeSrc)
|
manifest: yaml.Marshal(kubeSrc)
|
||||||
@ -38,6 +38,24 @@ TestKubeApply: {
|
|||||||
// Verify deployment
|
// Verify deployment
|
||||||
verify: #VerifyApply & {
|
verify: #VerifyApply & {
|
||||||
podname: kubeSrc.metadata.name
|
podname: kubeSrc.metadata.name
|
||||||
namespace: apply.namespace
|
namespace: resources.namespace
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
TestLinkApply: {
|
||||||
|
// Podname from hello-world-pod
|
||||||
|
_podname: "hello-world"
|
||||||
|
|
||||||
|
// Apply deployment
|
||||||
|
resources: #Resources & {
|
||||||
|
kubeconfig: TestKubeconfig
|
||||||
|
namespace: "dagger-test"
|
||||||
|
url: "https://raw.githubusercontent.com/mstrzele/intro-to-k8s/master/hello-world-pod.yaml"
|
||||||
|
}
|
||||||
|
|
||||||
|
// Verify deployment
|
||||||
|
verify: #VerifyApply & {
|
||||||
|
podname: _podname
|
||||||
|
namespace: resources.namespace
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user