Skip to content
This repository has been archived by the owner on Apr 27, 2020. It is now read-only.

Add 'kubeconfig_file' param into the out params #18

Merged
merged 1 commit into from
Jan 26, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ Control the Kubernetes cluster like `kubectl apply`, `kubectl delete`, `kubectl
- `wait_until_ready`: *Optional.* The number of seconds that waits until all pods are ready. 0 means don't wait. Defaults to `30`.
- `wait_until_ready_interval`: *Optional.* The interval (sec) on which to check whether all pods are ready. Defaults to `3`.
- `wait_until_ready_selector`: *Optional.* [A label selector](https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/#label-selectors) to identify a set of pods which to check whether those are ready. Defaults to every pods in the namespace.
- `kubeconfig_file`: *Optional.* The path of kubeconfig file. This param has priority over the `kubeconfig` of source configuration.

## Example

Expand Down Expand Up @@ -104,6 +105,40 @@ jobs:
wait_until_ready_selector: run=nginx
```

### Use a remote kubeconfig file fetched by s3-resource

```yaml
resources:
- name: k8s-prod
type: kubernetes

- name: kubeconfig-file
type: s3
source:
bucket: mybucket
versioned_file: config
access_key_id: ((s3-access-key))
secret_access_key: ((s3-secret))

- name: my-app
type: git
source:
...

jobs:
- name: k8s-deploy-prod
plan:
- aggregate:
- get: my-app
trigger: true
- get: kubeconfig-file
- put: k8s-prod
params:
kubectl: apply -f my-app/k8s -f my-app/k8s/production
wait_until_ready_selector: app=myapp
kubeconfig_file: kubeconfig-file/config
```

## License

This software is released under the MIT License.
24 changes: 17 additions & 7 deletions assets/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,20 @@ setup_kubectl() {

export KUBECONFIG=$(mktemp $TMPDIR/kubernetes-resource-kubeconfig.XXXXXX)

# Optional. A kubeconfig file.
# Optional. The path of kubeconfig file
local kubeconfig_file="$(jq -r '.params.kubeconfig_file // ""' < $payload)"
# Optional. The content of kubeconfig
local kubeconfig="$(jq -r '.source.kubeconfig // ""' < $payload)"
if [[ -n "$kubeconfig" ]]; then
echo "$kubeconfig" > $KUBECONFIG

# Optional. The name of the kubeconfig context to use.
local context="$(jq -r '.source.context // ""' < $payload)"
if [[ -n "$context" ]]; then
exe kubectl config use-context $context
if [[ -n "$kubeconfig_file" ]]; then
if [[ ! -f "$kubeconfig_file" ]]; then
echoerr "kubeconfig file '$kubeconfig_file' does not exist"
exit 1
fi

cat "$kubeconfig_file" > $KUBECONFIG
elif [[ -n "$kubeconfig" ]]; then
echo "$kubeconfig" > $KUBECONFIG
else
# Optional. The address and port of the API server. Requires token.
local server="$(jq -r '.source.server // ""' < $payload)"
Expand Down Expand Up @@ -73,6 +77,12 @@ setup_kubectl() {
exe kubectl config use-context $CONTEXT_NAME
fi

# Optional. The name of the kubeconfig context to use.
local context="$(jq -r '.source.context // ""' < $payload)"
if [[ -n "$context" ]]; then
exe kubectl config use-context $context
fi

# Print information
exe kubectl version
exe kubectl cluster-info
Expand Down