├── .circleci ├── config.yml └── test-deploy.yml ├── .github ├── CODEOWNERS ├── ISSUE_TEMPLATE │ ├── BUG.md │ ├── config.yml │ └── feature_request.md └── PULL_REQUEST_TEMPLATE │ └── PULL_REQUEST.md ├── .gitignore ├── LICENSE ├── README.md ├── publish-alpha.sh ├── src ├── @orb.yml ├── commands │ ├── create_or_update_resource.yml │ ├── delete_resource.yml │ ├── get_rollout_status.yml │ ├── install.yml │ ├── install_kops.yml │ ├── install_kubeconfig.yml │ ├── install_kubectl.yml │ ├── rollback.yml │ └── update_container_image.yml ├── examples │ ├── delete.yml │ ├── deployment.yml │ ├── deployment_update.yml │ ├── install.yml │ ├── install_kops.yml │ ├── install_kubeconfig.yml │ └── install_kubectl.yml └── scripts │ ├── create_or_update_resource.sh │ ├── delete_resource.sh │ ├── describe.sh │ ├── get_rollout_status.sh │ ├── install_kops.sh │ ├── install_kubeconfig.sh │ ├── install_kubectl.sh │ ├── rollback.sh │ └── update_container_image.sh └── tests ├── kustomize ├── base │ ├── deployment.yaml │ └── kustomization.yaml └── overlays │ └── staging │ └── kustomization.yaml └── nginx-deployment └── deployment.yaml /.circleci/config.yml: -------------------------------------------------------------------------------- 1 | version: 2.1 2 | setup: true 3 | orbs: 4 | orb-tools: circleci/orb-tools@12.3 5 | shellcheck: circleci/shellcheck@3.3 6 | 7 | filters: &filters 8 | tags: 9 | only: /.*/ 10 | 11 | workflows: 12 | lint-pack: 13 | jobs: 14 | - orb-tools/lint: 15 | filters: *filters 16 | - orb-tools/pack: 17 | filters: *filters 18 | - orb-tools/review: 19 | filters: *filters 20 | - shellcheck/check: 21 | filters: *filters 22 | - orb-tools/continue: 23 | orb_name: kubernetes 24 | pipeline_number: << pipeline.number >> 25 | vcs_type: << pipeline.project.type >> 26 | requires: [orb-tools/lint, orb-tools/review, orb-tools/pack, shellcheck/check] 27 | filters: *filters -------------------------------------------------------------------------------- /.circleci/test-deploy.yml: -------------------------------------------------------------------------------- 1 | version: 2.1 2 | 3 | orbs: 4 | orb-tools: circleci/orb-tools@12.3 5 | kubernetes: {} 6 | filters: &filters 7 | tags: 8 | only: /.*/ 9 | release-filters: &release-filters 10 | branches: 11 | ignore: /.*/ 12 | tags: 13 | only: /^v[0-9]+\.[0-9]+\.[0-9]+$/ 14 | # Pipeline parameters 15 | executors: 16 | docker-base: 17 | docker: 18 | - image: cimg/base:current 19 | 20 | minikube: 21 | machine: 22 | image: ubuntu-2204:2024.11.1 23 | environment: 24 | CHANGE_MINIKUBE_NONE_USER=true 25 | 26 | arm: 27 | machine: 28 | image: ubuntu-2204:2024.11.1 29 | resource_class: arm.medium 30 | 31 | machine: 32 | machine: 33 | image: ubuntu-2204:2024.11.1 34 | 35 | macos: 36 | macos: 37 | xcode: 15.3.0 38 | 39 | commands: 40 | start-minikube: 41 | steps: 42 | - run: 43 | name: Install cricli for minikube 44 | command: | 45 | VERSION="v1.24.1" 46 | wget https://github.com/kubernetes-sigs/cri-tools/releases/download/$VERSION/crictl-$VERSION-linux-amd64.tar.gz 47 | sudo tar zxvf crictl-$VERSION-linux-amd64.tar.gz -C /usr/local/bin 48 | rm -f crictl-$VERSION-linux-amd64.tar.gz 49 | - run: 50 | name: Start minikube 51 | command: | 52 | curl -Lo minikube https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64 \ 53 | && chmod +x minikube 54 | sudo mkdir -p /usr/local/bin/ 55 | sudo install minikube /usr/local/bin/ 56 | # Start minikube with Docker driver 57 | sudo -u circleci minikube start --driver=docker 58 | 59 | integration-tests: 60 | steps: 61 | - checkout 62 | - kubernetes/install 63 | - run: 64 | name: Test kops 65 | command: kops version 66 | - run: 67 | name: Test kubectl 68 | command: kubectl 69 | - kubernetes/install_kubeconfig: 70 | kubeconfig: MY_KUBECONFIG_DATA 71 | - run: 72 | name: Test kubeconfig output 73 | command: | 74 | set -x 75 | [[ -f $HOME/.kube/config && ! -z $HOME/.kube/config && $(<$HOME/.kube/config) == "test" ]] 76 | set +x 77 | integration-tests-specific-version: 78 | steps: 79 | - checkout 80 | - kubernetes/install: 81 | kubectl_version: "v1.15.2" 82 | kops_version: 1.12.2 83 | max_time: true 84 | - run: 85 | name: Test kops version 86 | command: kops version | grep "1.12.2" 87 | - run: 88 | name: Test kubectl version 89 | command: | 90 | set +e 91 | # ignore connection refused error 92 | KUBECTL_VERSION=$(kubectl version) 93 | set -e 94 | echo $KUBECTL_VERSION | grep "v1.15.2" 95 | - kubernetes/install_kubeconfig 96 | - run: 97 | name: Test kubeconfig output 98 | command: | 99 | [[ -f $HOME/.kube/config && ! -z $HOME/.kube/config && $(<$HOME/.kube/config) == "test" ]] 100 | 101 | jobs: 102 | integration-test-docker: 103 | executor: docker-base 104 | environment: 105 | # For testing the install_kubeconfig command 106 | MY_KUBECONFIG_DATA: dGVzdA== 107 | steps: 108 | - integration-tests 109 | 110 | integration-test-machine: 111 | executor: machine 112 | environment: 113 | # For testing the install_kubeconfig command 114 | KUBECONFIG_DATA: dGVzdA== 115 | steps: 116 | - integration-tests-specific-version 117 | 118 | integration-test-macos: 119 | executor: macos 120 | environment: 121 | # For testing the install_kubeconfig command 122 | MY_KUBECONFIG_DATA: dGVzdA== 123 | steps: 124 | - integration-tests 125 | 126 | integration-test-arm: 127 | executor: arm 128 | environment: 129 | # For testing the install_kubeconfig command 130 | MY_KUBECONFIG_DATA: dGVzdA== 131 | steps: 132 | - integration-tests 133 | 134 | integration-test-kubectl: 135 | executor: minikube 136 | steps: 137 | - checkout 138 | - kubernetes/install_kubectl 139 | - start-minikube 140 | - kubernetes/create_or_update_resource: 141 | resource_file_path: "tests/nginx-deployment/deployment.yaml" 142 | resource_name: "deployment/nginx-deployment" 143 | get_rollout_status: true 144 | watch_timeout: 2m 145 | show_kubectl_command: true 146 | envsubst: true 147 | - kubernetes/update_container_image: 148 | resource_name: "deployment/nginx-deployment" 149 | container_image_updates: "nginx=nginx:1.27-alpine-slim redis=redis:5-buster" 150 | show_kubectl_command: true 151 | watch_timeout: 2m 152 | - kubernetes/get_rollout_status: 153 | resource_file_path: "tests/nginx-deployment/deployment.yaml" 154 | watch_rollout_status: true 155 | watch_timeout: 2m 156 | - kubernetes/rollback: 157 | resource_name: "deployment/nginx-deployment" 158 | get_rollout_status: true 159 | - kubernetes/delete_resource: 160 | resource_types: "deployments" 161 | resource_names: "nginx-deployment" 162 | now: true 163 | wait: true 164 | - kubernetes/create_or_update_resource: 165 | resource_file_path: "tests/kustomize/overlays/staging" 166 | resource_name: "deployment/staging-hello" 167 | kustomize: true 168 | get_rollout_status: true 169 | watch_timeout: 2m 170 | show_kubectl_command: true 171 | - kubernetes/delete_resource: 172 | resource_file_path: "tests/kustomize/overlays/staging" 173 | kustomize: true 174 | now: true 175 | wait: true 176 | 177 | workflows: 178 | test-deploy: 179 | jobs: 180 | - integration-test-arm: 181 | filters: *filters 182 | - integration-test-docker: 183 | filters: *filters 184 | - integration-test-machine: 185 | filters: *filters 186 | - integration-test-macos: 187 | filters: *filters 188 | - integration-test-kubectl: 189 | filters: *filters 190 | - orb-tools/pack: 191 | filters: *release-filters 192 | - orb-tools/publish: 193 | orb_name: circleci/kubernetes 194 | vcs_type: << pipeline.project.type >> 195 | pub_type: production 196 | enable_pr_comment: true 197 | context: orb-publisher 198 | requires: [ orb-tools/pack, integration-test-docker, integration-test-machine, integration-test-macos, integration-test-kubectl ] 199 | filters: *release-filters 200 | -------------------------------------------------------------------------------- /.github/CODEOWNERS: -------------------------------------------------------------------------------- 1 | # Ping these folks when changes are made to this repository 2 | * @CircleCI-Public/orb-publishers 3 | 4 | # We can also add orb-specifc codeowners at some point if desirable 5 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/BUG.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: "\U0001F41E Bug report" 3 | about: Report any bugs encountered while using this orb. 4 | title: '' 5 | labels: bug 6 | assignees: '' 7 | 8 | --- 9 | 10 | ## Orb version: 11 | 12 | 19 | 20 | ## What happened: 21 | 22 | 26 | 27 | ## Expected behavior: 28 | 29 | 30 | 31 | ## Additional Information: 32 | 33 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/config.yml: -------------------------------------------------------------------------------- 1 | blank_issues_enabled: false 2 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: "\U0001F680 Feature Request" 3 | about: Propose changes to the orb. 4 | title: '' 5 | labels: feature_request 6 | assignees: '' 7 | --- 8 | 9 | ## Describe Request: 10 | 11 | ## Examples: 12 | 13 | ## Supporting Documentation Links: 14 | 15 | -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE/PULL_REQUEST.md: -------------------------------------------------------------------------------- 1 | 2 | **SEMVER Update Type:** 3 | - [ ] Major 4 | - [ ] Minor 5 | - [ ] Patch 6 | 7 | ## Description: 8 | 9 | 13 | 14 | ## Motivation: 15 | 16 | 19 | 20 | **Closes Issues:** 21 | - ISSUE URL 22 | 23 | ## Checklist: 24 | 25 | 30 | 31 | - [ ] All new jobs, commands, executors, parameters have descriptions. 32 | - [ ] Usage Example version numbers have been updated. 33 | - [ ] Changelog has been updated. -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /workspace 2 | *.DS_Store 3 | orb.yml -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 CircleCI Public 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Kubernetes Orb [![CircleCI status](https://circleci.com/gh/CircleCI-Public/kubernetes-orb.svg?style=shield "CircleCI status")](https://circleci.com/gh/CircleCI-Public/kubernetes-orb) [![CircleCI Orb Version](https://img.shields.io/badge/endpoint.svg?url=https://badges.circleci.io/orb/circleci/kubernetes)](https://circleci.com/orbs/registry/orb/circleci/kubernetes) [![MIT licensed](https://img.shields.io/badge/license-MIT-blue.svg)](https://raw.githubusercontent.com/circleci-public/kubernetes-orb/master/LICENSE) [![CircleCI Community](https://img.shields.io/badge/community-CircleCI%20Discuss-343434.svg)](https://discuss.circleci.com/c/ecosystem/orbs) 2 | 3 | Tools for working with Kubernetes on CircleCI. The orb currently supports installing the `kubectl` and `kops` CLI tools and using `kubectl` for resource deployments. Separate orbs for working with Google Kubernetes Engine and other cloud providers' Kubernetes solutions also exist. 4 | 5 | ## Usage 6 | 7 | See the [orb registry listing](http://circleci.com/orbs/registry/orb/circleci/kubernetes) for usage guidelines. 8 | 9 | ## Contributing 10 | 11 | We welcome [issues](https://github.com/CircleCI-Public/kubernetes-orb/issues) to and [pull requests](https://github.com/CircleCI-Public/kubernetes-orb/pulls) against this repository! 12 | 13 | For further questions/comments about this or other orbs, visit [CircleCI's orbs discussion forum](https://discuss.circleci.com/c/orbs). 14 | -------------------------------------------------------------------------------- /publish-alpha.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | circleci config pack src > orb.yml 4 | circleci orb publish orb.yml circleci/kubernetes@dev:alpha 5 | rm -rf orb.yml 6 | -------------------------------------------------------------------------------- /src/@orb.yml: -------------------------------------------------------------------------------- 1 | version: 2.1 2 | 3 | description: | 4 | A collection of tools for working with Kubernetes on CircleCI 5 | View this orb's source: https://github.com/CircleCI-Public/kubernetes-orb 6 | 7 | display: 8 | source_url: https://github.com/CircleCI-Public/kubernetes-orb 9 | home_url: https://kubernetes.io/ 10 | 11 | 12 | # notes for dev: 13 | # existing kube-related orbs: 14 | 15 | # https://circleci.com/orbs/registry/orb/tiendanube/eks 16 | # https://circleci.com/orbs/registry/orb/circleci/helm 17 | # https://circleci.com/orbs/registry/orb/airswap/kubectl 18 | -------------------------------------------------------------------------------- /src/commands/create_or_update_resource.yml: -------------------------------------------------------------------------------- 1 | description: | 2 | Create or update a kubernetes resource. 3 | Requirements: kubeconfig should be configured to connect to the cluster. 4 | 5 | parameters: 6 | resource_file_path: 7 | description: | 8 | Path to file used to create/update the resource. 9 | type: string 10 | action_type: 11 | description: | 12 | Specify whether to use `kubectl create` or `kubectl apply` 13 | to create/update the resource. 14 | default: "apply" 15 | type: enum 16 | enum: ["create", "apply"] 17 | namespace: 18 | description: | 19 | The kubernetes namespace that should be used. 20 | type: string 21 | default: "" 22 | get_rollout_status: 23 | description: | 24 | Get the status of the rollout. 25 | This can only be used for resource types that are valid 26 | for usage with `kubectl rollout` subcommands. 27 | type: boolean 28 | default: false 29 | resource_name: 30 | description: | 31 | Resource name in the format TYPE/NAME e.g. deployment/nginx-deployment 32 | This is required if get_rollout_status is set to true. 33 | type: string 34 | default: "" 35 | watch_rollout_status: 36 | description: | 37 | Whether to watch the status of the latest rollout until it's done. 38 | Only effective if get_rollout_status is set to true. 39 | type: boolean 40 | default: true 41 | pinned_revision_to_watch: 42 | description: | 43 | Pin a specific revision to be watched and abort watching if it is rolled 44 | over by another revision. 45 | Only effective if get_rollout_status is set to true. 46 | type: string 47 | default: "" 48 | watch_timeout: 49 | description: | 50 | The length of time to wait before ending the watch, zero means never. 51 | Any other values should contain corresponding time unit (e.g 1s, 2m, 3h). 52 | Only effective if get_rollout_status is set to true. 53 | type: string 54 | default: "" 55 | dry_run: 56 | description: | 57 | Whether the kubectl command will be executed in dry_run mode. 58 | Must be "none", "server", or "client" 59 | type: enum 60 | default: "" 61 | enum: ["", "server", "client"] 62 | kustomize: 63 | description: | 64 | Enable it to run the kubectl command with the option -k for kustomize. 65 | type: boolean 66 | default: false 67 | show_kubectl_command: 68 | description: | 69 | Whether to show the kubectl command used. 70 | type: boolean 71 | default: false 72 | server_side_apply: 73 | description: | 74 | Whether to run apply in the server instead of the client. 75 | Only effective if action_type is set to `apply`. 76 | type: boolean 77 | default: false 78 | envsubst: 79 | description: | 80 | Whether to run envsubst to substitute environment variables inside 81 | the deployment.yml finalizers. 82 | type: boolean 83 | default: false 84 | 85 | steps: 86 | - run: 87 | name: Create/update k8s resource from <> 88 | environment: 89 | K8_STR_RESOURCE_FILE_PATH: << parameters.resource_file_path >> 90 | K8_STR_ACTION_TYPE: << parameters.action_type >> 91 | K8_STR_NAMESPACE: << parameters.namespace >> 92 | K8_STR_DRY_RUN: << parameters.dry_run >> 93 | K8_STR_KUSTOMIZE: << parameters.kustomize >> 94 | K8_BOOL_SERVER_SIDE_APPLY: << parameters.server_side_apply >> 95 | K8_BOOL_ENVSUBST: << parameters.envsubst >> 96 | K8_BOOL_SHOW_KUBECTL_COMMAND: <> 97 | command: <> 98 | - when: 99 | condition: << parameters.get_rollout_status >> 100 | steps: 101 | - get_rollout_status: 102 | resource_name: << parameters.resource_name >> 103 | namespace: << parameters.namespace >> 104 | watch_rollout_status: << parameters.watch_rollout_status >> 105 | pinned_revision_to_watch: << parameters.pinned_revision_to_watch >> 106 | watch_timeout: << parameters.watch_timeout >> 107 | -------------------------------------------------------------------------------- /src/commands/delete_resource.yml: -------------------------------------------------------------------------------- 1 | description: | 2 | Delete kubernetes resource(s). 3 | Requirements: kubeconfig should be configured to connect to the cluster. 4 | 5 | parameters: 6 | resource_file_path: 7 | description: | 8 | Path to file used to describe the resource. 9 | Should not be set when the "resource_types" parameter is specified. 10 | type: string 11 | default: "" 12 | resource_types: 13 | description: | 14 | Specify what is to be deleted in the form of resource types. 15 | This parameter is meant to be combined with either the 16 | "resource_names" or the "label_selector" parameter. 17 | e.g. use the value "pods,services" for "resource_types" and 18 | the value "name=myLabel" for "label_selector" to delete pods and services 19 | with the label name=myLabel. 20 | e.g. use the value "pods,services" for "resource_types" and 21 | the value "baz foo" for "resource_names" to delete pods and services 22 | the match the names "baz" and "foo". 23 | 24 | Should not be set when the "resource_file_path" parameter is specified. 25 | type: string 26 | default: "" 27 | resource_names: 28 | description: | 29 | Specifies the names of resource(s) to be deleted. 30 | Effective only when the resource_types parameter is specified. 31 | Cannot be used together with the label_selector parameter. 32 | type: string 33 | default: "" 34 | label_selector: 35 | description: | 36 | Use a label selector on the resource(s) to be deleted. 37 | Effective only when the resource_types parameter is specified. 38 | Cannot be used together with the resource_names parameter. 39 | type: string 40 | default: "" 41 | all: 42 | description: | 43 | If true, deletes all resources including uninitialized ones, in the 44 | namespace of the specified resource types. 45 | type: boolean 46 | default: false 47 | cascade: 48 | description: | 49 | If true, cascades the deletion of the resources managed by this resource. 50 | (e.g. Pods created by a ReplicationController) 51 | Must be "background" or "foreground" 52 | type: enum 53 | default: "background" 54 | enum: ["background", "foreground"] 55 | force: 56 | description: | 57 | Only used when "0" is specified for grace_period. If true, remove 58 | resources from API and bypass graceful deletion. Note that immediate 59 | deletion of some resources may result in inconsistency or data 60 | loss and requires confirmation. 61 | type: boolean 62 | default: false 63 | grace_period: 64 | description: | 65 | Period of time in seconds given to the resource to terminate gracefully. 66 | A value of "-1" will be ignored. 67 | type: integer 68 | default: -1 69 | ignore_not_found: 70 | description: | 71 | If true, treats "resource not found" as a successful delete. 72 | (Note: unlike the kubectl command, this does not default to true 73 | when the "all" parameter value is set to true) 74 | type: boolean 75 | default: false 76 | now: 77 | description: | 78 | If true, resources are signaled for immediate shutdown. 79 | type: boolean 80 | default: false 81 | wait: 82 | description: | 83 | If true, wait for resources to be gone before returning. 84 | This waits for finalizers. 85 | type: boolean 86 | default: true 87 | namespace: 88 | description: | 89 | The kubernetes namespace that should be used. 90 | type: string 91 | default: "" 92 | dry_run: 93 | description: | 94 | Whether the kubectl command will be executed in dry_run mode. 95 | Must be "none", "server", or "client" 96 | type: enum 97 | default: "" 98 | enum: ["", "server", "client"] 99 | kustomize: 100 | description: | 101 | Enable it to run the kubectl command with the option -k for kustomize. 102 | type: boolean 103 | default: false 104 | show_kubectl_command: 105 | description: | 106 | Whether to show the kubectl command used. 107 | type: boolean 108 | default: false 109 | 110 | steps: 111 | - run: 112 | name: Delete the k8s resource(s) 113 | environment: 114 | K8_STR_RESOURCE_FILE_PATH: << parameters.resource_file_path >> 115 | K8_STR_RESOURCE_TYPES: << parameters.resource_types >> 116 | K8_STR_RESOURCE_NAMES: << parameters.resource_names >> 117 | K8_STR_LABEL_SELECTOR: << parameters.label_selector >> 118 | K8_BOOL_ALL: << parameters.all >> 119 | K8_STR_CASCADE: << parameters.cascade >> 120 | K8_BOOL_FORCE: << parameters.force >> 121 | K8_INT_GRACE_PERIOD: << parameters.grace_period >> 122 | K8_BOOL_IGNORE_NOT_FOUND: << parameters.ignore_not_found >> 123 | K8_BOOL_NOW: << parameters.now >> 124 | K8_BOOL_WAIT: << parameters.wait >> 125 | K8_STR_NAMESPACE: << parameters.namespace >> 126 | K8_STR_DRY_RUN: << parameters.dry_run >> 127 | K8_STR_KUSTOMIZE: << parameters.kustomize >> 128 | command: <> 129 | -------------------------------------------------------------------------------- /src/commands/get_rollout_status.yml: -------------------------------------------------------------------------------- 1 | description: | 2 | Gets the rollout status of a resource. 3 | This command is only valid for resource types that are valid 4 | for usage with `kubectl rollout` subcommands. 5 | Requirements: kubeconfig should be configured to connect to the cluster. 6 | 7 | parameters: 8 | resource_name: 9 | description: | 10 | Resource name in the format TYPE/NAME e.g. deployment/nginx-deployment 11 | type: string 12 | default: "" 13 | namespace: 14 | description: | 15 | The kubernetes namespace that should be used. 16 | type: string 17 | default: "" 18 | watch_rollout_status: 19 | description: | 20 | Whether to watch the status of the latest rollout until it's done. 21 | type: boolean 22 | default: true 23 | pinned_revision_to_watch: 24 | description: | 25 | Pin a specific revision to be watched and abort watching if it is rolled 26 | over by another revision. 27 | type: string 28 | default: "" 29 | watch_timeout: 30 | description: | 31 | The length of time to wait before ending the watch, zero means never. 32 | Any other values should contain a corresponding 33 | time unit (e.g. 1s, 2m, 3h). 34 | type: string 35 | default: "" 36 | show_kubectl_command: 37 | description: | 38 | Whether to show the kubectl command used. 39 | type: boolean 40 | default: false 41 | resource_file_path: 42 | description: | 43 | Path to file used to get the status of the resource. 44 | type: string 45 | default: "" 46 | 47 | steps: 48 | - run: 49 | name: Show the resource rollout status 50 | environment: 51 | K8_STR_RESOURCE_NAME: << parameters.resource_name >> 52 | K8_STR_NAMESPACE: << parameters.namespace >> 53 | PARAM_WATCH_ROLLOUT_STATUS: << parameters.watch_rollout_status >> 54 | PARAM_PINNED_REVISION_TO_WATCH: <> 55 | PARAM_WATCH_TIMEOUT: << parameters.watch_timeout >> 56 | K8_STR_RESOURCE_FILE_PATH: << parameters.resource_file_path >> 57 | command: <> 58 | - run: 59 | name: Get a description of the resource 60 | environment: 61 | K8_STR_RESOURCE_NAME: << parameters.resource_name >> 62 | K8_STR_NAMESPACE: << parameters.namespace >> 63 | K8_STR_RESOURCE_FILE_PATH: << parameters.resource_file_path >> 64 | command: <> 65 | -------------------------------------------------------------------------------- /src/commands/install.yml: -------------------------------------------------------------------------------- 1 | description: | 2 | Installs kubectl and kops (latest releases, by default) 3 | Requirements: curl 4 | 5 | parameters: 6 | kops_version: 7 | type: string 8 | default: "latest" 9 | kubectl_version: 10 | description: | 11 | specify version using vX.Y.Z (e.g., v1.29.0) format. 12 | type: string 13 | default: "latest" 14 | max_time: 15 | description: | 16 | This parameter will enable the curl command to not timeout for 600 seconds 17 | type: boolean 18 | default: false 19 | 20 | steps: 21 | - install_kops: 22 | kops_version: << parameters.kops_version >> 23 | - install_kubectl: 24 | kubectl_version: << parameters.kubectl_version >> 25 | max_time: << parameters.max_time >> 26 | -------------------------------------------------------------------------------- /src/commands/install_kops.yml: -------------------------------------------------------------------------------- 1 | description: | 2 | Installs kops (latest release, by default) 3 | Requirements: curl 4 | 5 | parameters: 6 | kops_version: 7 | type: string 8 | default: "latest" 9 | 10 | steps: 11 | - run: 12 | name: Install kops 13 | environment: 14 | K8_STR_KOPS_VERSION: <> 15 | command: <> 16 | -------------------------------------------------------------------------------- /src/commands/install_kubeconfig.yml: -------------------------------------------------------------------------------- 1 | description: | 2 | Install kubeconfig file with the contents taken from the value of an 3 | environment variable, which should be base64-encoded. 4 | 5 | parameters: 6 | kubeconfig: 7 | type: env_var_name 8 | description: Environment variable containing base64-encoded kubeconfig data 9 | default: KUBECONFIG_DATA 10 | 11 | steps: 12 | - run: 13 | name: Install kubeconfig 14 | environment: 15 | K8_ENV_KUBECONFIG: <> 16 | command: <> 17 | -------------------------------------------------------------------------------- /src/commands/install_kubectl.yml: -------------------------------------------------------------------------------- 1 | description: | 2 | Installs kubectl (latest release, by default) 3 | Requirements: curl 4 | 5 | parameters: 6 | kubectl_version: 7 | description: | 8 | specify version using vX.Y.Z (e.g., v1.29.0) format. 9 | type: string 10 | default: "latest" 11 | max_time: 12 | description: | 13 | This parameter will enable the curl command to not timeout for 600 seconds 14 | type: boolean 15 | default: false 16 | 17 | steps: 18 | - run: 19 | name: Install kubectl 20 | environment: 21 | K8_STR_KUBECTL_VERSION: <> 22 | K8_BOOL_MAX_TIME: <> 23 | command: <> 24 | -------------------------------------------------------------------------------- /src/commands/rollback.yml: -------------------------------------------------------------------------------- 1 | description: | 2 | Rollback a deployment or daemonset resource. 3 | Requirements: kubeconfig should be configured to connect to the cluster. 4 | 5 | parameters: 6 | resource_name: 7 | description: | 8 | Resource name in the format TYPE/NAME e.g. deployment/nginx-deployment 9 | type: string 10 | namespace: 11 | description: | 12 | The kubernetes namespace that should be used. 13 | type: string 14 | default: "" 15 | get_rollout_status: 16 | description: | 17 | Get the status of the rollout. 18 | This can only be used for resource types that are valid 19 | for usage with `kubectl rollout` subcommands. 20 | type: boolean 21 | default: false 22 | watch_rollout_status: 23 | description: | 24 | Whether to watch the status of the latest rollout until it's done. 25 | type: boolean 26 | default: true 27 | watch_timeout: 28 | description: | 29 | The length of time to wait before ending the watch, zero means never. 30 | Any other values should contain a corresponding 31 | time unit (e.g. 1s, 2m, 3h). 32 | type: string 33 | default: "" 34 | show_kubectl_command: 35 | description: | 36 | Whether to show the kubectl command used. 37 | type: boolean 38 | default: false 39 | 40 | steps: 41 | - run: 42 | name: Rollback the resource 43 | environment: 44 | K8_STR_RESOURCE_NAME: << parameters.resource_name >> 45 | K8_STR_NAMESPACE: << parameters.namespace >> 46 | command: <> 47 | - when: 48 | condition: << parameters.get_rollout_status >> 49 | steps: 50 | - get_rollout_status: 51 | resource_name: << parameters.resource_name >> 52 | namespace: << parameters.namespace >> 53 | watch_rollout_status: << parameters.watch_rollout_status >> 54 | watch_timeout: << parameters.watch_timeout >> 55 | -------------------------------------------------------------------------------- /src/commands/update_container_image.yml: -------------------------------------------------------------------------------- 1 | description: | 2 | Updates existing container image(s) of resources on the cluster using the 3 | `kubectl set image` command. 4 | Requirements: kubeconfig should be configured to connect to the cluster. 5 | 6 | parameters: 7 | resource_file_path: 8 | description: | 9 | Path to file used to update the resource. 10 | Either resource_file_path or resource_name need to be specified. 11 | type: string 12 | default: "" 13 | resource_name: 14 | description: | 15 | Resource name in the format TYPE/NAME e.g. deployment/nginx-deployment 16 | Either resource_file_path or resource_name need to be specified. 17 | This is required if get_rollout_status is set to true. 18 | type: string 19 | default: "" 20 | container_image_updates: 21 | description: | 22 | Specify a list of container image updates 23 | (space-delimited name value pairs in the form 24 | CONTAINER_NAME_1=CONTAINER_IMAGE_1 ... CONTAINER_NAME_N=CONTAINER_IMAGE_N) 25 | to be applied to the resource via `kubectl set image`. 26 | e.g. "busybox=busybox nginx=nginx:1.9.1" 27 | type: string 28 | namespace: 29 | description: | 30 | The kubernetes namespace that should be used. 31 | type: string 32 | default: "" 33 | get_rollout_status: 34 | description: | 35 | Get the status of the rollout. 36 | This can only be used for resource types that are valid 37 | for usage with `kubectl rollout` subcommands. 38 | type: boolean 39 | default: false 40 | watch_rollout_status: 41 | description: | 42 | Whether to watch the status of the latest rollout until it's done. 43 | Only effective if get_rollout_status is set to true. 44 | type: boolean 45 | default: true 46 | pinned_revision_to_watch: 47 | description: | 48 | Pin a specific revision to be watched and abort watching if it is rolled 49 | over by another revision. 50 | Only effective if get_rollout_status is set to true. 51 | type: string 52 | default: "" 53 | watch_timeout: 54 | description: | 55 | The length of time to wait before ending the watch, zero means never. 56 | Any other values should contain a corresponding 57 | time unit (e.g. 1s, 2m, 3h). Only effective if 58 | get_rollout_status is set to true. 59 | type: string 60 | default: "" 61 | dry_run: 62 | description: | 63 | Whether the kubectl command will be executed in dry_run mode. 64 | type: enum 65 | default: "" 66 | enum: ["", "server", "client"] 67 | show_kubectl_command: 68 | description: | 69 | Whether to show the kubectl command used. 70 | type: boolean 71 | default: false 72 | 73 | steps: 74 | - run: 75 | name: Update the container image(s) for the resource 76 | environment: 77 | K8_STR_RESOURCE_FILE_PATH: << parameters.resource_file_path >> 78 | K8_STR_RESOURCE_NAME: << parameters.resource_name >> 79 | K8_STR_CONTAINER_IMAGE_UPDATES: << parameters.container_image_updates >> 80 | K8_STR_NAMESPACE: << parameters.namespace >> 81 | K8_BOOL_SHOW_KUBECTL_COMMAND: << parameters.show_kubectl_command >> 82 | command: <> 83 | - when: 84 | condition: << parameters.get_rollout_status >> 85 | steps: 86 | - get_rollout_status: 87 | resource_name: << parameters.resource_name >> 88 | namespace: << parameters.namespace >> 89 | watch_rollout_status: << parameters.watch_rollout_status >> 90 | pinned_revision_to_watch: << parameters.pinned_revision_to_watch >> 91 | watch_timeout: << parameters.watch_timeout >> 92 | -------------------------------------------------------------------------------- /src/examples/delete.yml: -------------------------------------------------------------------------------- 1 | description: | 2 | Delete kubernetes resource. 3 | 4 | usage: 5 | version: 2.1 6 | 7 | orbs: 8 | kubernetes: circleci/kubernetes@x.y.z 9 | 10 | jobs: 11 | delete: 12 | docker: 13 | - image: cimg/base:stable 14 | steps: 15 | - kubernetes/install_kubectl 16 | - kubernetes/delete_resource: 17 | resource_types: "deployments" 18 | resource_names: "nginx-deployment" 19 | now: true 20 | wait: true 21 | -------------------------------------------------------------------------------- /src/examples/deployment.yml: -------------------------------------------------------------------------------- 1 | description: | 2 | Deploying kubernetes resources. 3 | 4 | usage: 5 | version: 2.1 6 | 7 | orbs: 8 | kubernetes: circleci/kubernetes@x.y.z 9 | 10 | jobs: 11 | create-update: 12 | docker: 13 | - image: cimg/base:stable 14 | steps: 15 | - checkout 16 | - kubernetes/install_kubectl 17 | - kubernetes/create_or_update_resource: 18 | resource_file_path: "tests/nginx-deployment/deployment.yaml" 19 | resource_name: "deployment/nginx-deployment" 20 | get_rollout_status: true 21 | show_kubectl_command: true 22 | -------------------------------------------------------------------------------- /src/examples/deployment_update.yml: -------------------------------------------------------------------------------- 1 | description: | 2 | Update kubernetes resource. 3 | 4 | usage: 5 | version: 2.1 6 | 7 | orbs: 8 | kubernetes: circleci/kubernetes@x.y.z 9 | 10 | jobs: 11 | update: 12 | docker: 13 | - image: cimg/base:stable 14 | steps: 15 | - checkout 16 | - kubernetes/install_kubectl 17 | - kubernetes/update_container_image: 18 | resource_name: "deployment/nginx-deployment" 19 | container_image_updates: "nginx=nginx:1.9.1" 20 | get_rollout_status: true 21 | -------------------------------------------------------------------------------- /src/examples/install.yml: -------------------------------------------------------------------------------- 1 | description: | 2 | Install kops and kubectl 3 | 4 | usage: 5 | version: 2.1 6 | 7 | orbs: 8 | kubernetes: circleci/kubernetes@x.y.z 9 | 10 | jobs: 11 | build: 12 | macos: 13 | xcode: "13.2" 14 | steps: 15 | - checkout 16 | - kubernetes/install 17 | -------------------------------------------------------------------------------- /src/examples/install_kops.yml: -------------------------------------------------------------------------------- 1 | description: | 2 | Install kops 3 | 4 | usage: 5 | version: 2.1 6 | 7 | orbs: 8 | kubernetes: circleci/kubernetes@x.y.z 9 | 10 | jobs: 11 | build: 12 | macos: 13 | xcode: "13.2" 14 | steps: 15 | - checkout 16 | - kubernetes/install_kops 17 | -------------------------------------------------------------------------------- /src/examples/install_kubeconfig.yml: -------------------------------------------------------------------------------- 1 | description: | 2 | Install kubeconfig 3 | 4 | usage: 5 | version: 2.1 6 | 7 | orbs: 8 | kubernetes: circleci/kubernetes@1.0.0 9 | 10 | jobs: 11 | build: 12 | macos: 13 | xcode: "13.2" 14 | steps: 15 | - checkout 16 | - kubernetes/install_kubeconfig: 17 | kubeconfig: KUBECONFIG_DATA 18 | -------------------------------------------------------------------------------- /src/examples/install_kubectl.yml: -------------------------------------------------------------------------------- 1 | description: | 2 | Install kubectl 3 | 4 | usage: 5 | version: 2.1 6 | 7 | orbs: 8 | kubernetes: circleci/kubernetes@x.y.z 9 | 10 | jobs: 11 | build: 12 | macos: 13 | xcode: "13.2" 14 | steps: 15 | - checkout 16 | - kubernetes/install_kubectl 17 | -------------------------------------------------------------------------------- /src/scripts/create_or_update_resource.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | RESOURCE_FILE_PATH=$(eval echo "$K8_STR_RESOURCE_FILE_PATH") 3 | ACTION_TYPE=$(eval echo "$K8_STR_ACTION_TYPE") 4 | NAMESPACE=$(eval echo "$K8_STR_NAMESPACE") 5 | DRY_RUN=$(eval echo "$K8_STR_DRY_RUN") 6 | KUSTOMIZE=$(eval echo "$K8_STR_KUSTOMIZE") 7 | SERVER_SIDE_APPLY=$(eval echo "$K8_BOOL_SERVER_SIDE_APPLY") 8 | ENVSUBST=$(eval echo "$K8_BOOL_ENVSUBST") 9 | 10 | [ -w /usr/local/bin ] && SUDO="" || SUDO=sudo 11 | 12 | if [ -n "${ACTION_TYPE}" ]; then 13 | set -- "$@" "${ACTION_TYPE}" 14 | 15 | if [ "${ACTION_TYPE}" == "apply" ] && [ "$SERVER_SIDE_APPLY" == "1" ]; then 16 | set -- "$@" --server-side 17 | fi 18 | fi 19 | if [ -n "$RESOURCE_FILE_PATH" ]; then 20 | if [ "$ENVSUBST" == "1" ]; then 21 | $SUDO apt-get update && $SUDO apt-get install -y gettext-base 22 | FILENAME="$(basename "$RESOURCE_FILE_PATH")" 23 | envsubst < "$RESOURCE_FILE_PATH" > /tmp/"$FILENAME"; mv /tmp/"$FILENAME" "$RESOURCE_FILE_PATH" 24 | fi 25 | if [ "$KUSTOMIZE" == "1" ]; then 26 | set -- "$@" -k 27 | else 28 | set -- "$@" -f 29 | fi 30 | set -- "$@" "$RESOURCE_FILE_PATH" 31 | fi 32 | if [ -n "${NAMESPACE}" ]; then 33 | set -- "$@" --namespace="${NAMESPACE}" 34 | fi 35 | if [ -n "${DRY_RUN}" ]; then 36 | set -- "$@" --dry-run="${DRY_RUN}" 37 | fi 38 | if [ "$K8_BOOL_SHOW_KUBECTL_COMMAND" == "1" ]; then 39 | set -x 40 | fi 41 | 42 | kubectl "$@" 43 | 44 | if [ "$K8_BOOL_SHOW_KUBECTL_COMMAND" == "1" ]; then 45 | set +x 46 | fi 47 | -------------------------------------------------------------------------------- /src/scripts/delete_resource.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | RESOURCE_FILE_PATH=$(eval echo "$K8_STR_RESOURCE_FILE_PATH") 3 | RESOURCE_TYPES=$(eval echo "$K8_STR_RESOURCE_TYPES") 4 | RESOURCE_NAMES=$(eval echo "$K8_STR_RESOURCE_NAMES") 5 | LABEL_SELECTOR=$(eval echo "$K8_STR_LABEL_SELECTOR") 6 | ALL=$(eval echo "$K8_BOOL_ALL") 7 | CASCADE=$(eval echo "$K8_STR_CASCADE") 8 | FORCE=$(eval echo "$K8_BOOL_FORCE") 9 | GRACE_PERIOD=$(eval echo "$K8_INT_GRACE_PERIOD") 10 | IGNORE_NOT_FOUND=$(eval echo "$K8_BOOL_IGNORE_NOT_FOUND") 11 | NOW=$(eval echo "$K8_BOOL_NOW") 12 | WAIT=$(eval echo "$K8_BOOL_WAIT") 13 | NAMESPACE=$(eval echo "$K8_STR_NAMESPACE") 14 | DRY_RUN=$(eval echo "$K8_STR_DRY_RUN") 15 | KUSTOMIZE=$(eval echo "$K8_STR_KUSTOMIZE") 16 | if [ -n "${RESOURCE_FILE_PATH}" ]; then 17 | if [ "${KUSTOMIZE}" == "1" ]; then 18 | set -- "$@" -k 19 | else 20 | set -- "$@" -f 21 | fi 22 | set -- "$@" "${RESOURCE_FILE_PATH}" 23 | elif [ -n "${RESOURCE_TYPES}" ]; then 24 | set -- "$@" "${RESOURCE_TYPES}" 25 | if [ -n "${RESOURCE_NAMES}" ]; then 26 | set -- "$@" "${RESOURCE_NAMES}" 27 | elif [ -n "${LABEL_SELECTOR}" ]; then 28 | set -- "$@" -l 29 | set -- "$@" "${LABEL_SELECTOR}" 30 | fi 31 | fi 32 | if [ "${ALL}" == "true" ]; then 33 | set -- "$@" --all=true 34 | fi 35 | if [ "${FORCE}" == "true" ]; then 36 | set -- "$@" --force=true 37 | fi 38 | if [ "${GRACE_PERIOD}" != "-1" ]; then 39 | set -- "$@" --grace-period="${GRACE_PERIOD}" 40 | fi 41 | if [ "${IGNORE_NOT_FOUND}" == "true" ]; then 42 | set -- "$@" --ignore-not-found=true 43 | fi 44 | if [ "${NOW}" == "true" ]; then 45 | set -- "$@" --now=true 46 | fi 47 | if [ -n "${NAMESPACE}" ]; then 48 | set -- "$@" --namespace="${NAMESPACE}" 49 | fi 50 | if [ -n "${DRY_RUN}" ]; then 51 | set -- "$@" --dry-run="${DRY_RUN}" 52 | fi 53 | set -- "$@" --wait="${WAIT}" 54 | set -- "$@" --cascade="${CASCADE}" 55 | if [ "$SHOW_EKSCTL_COMMAND" == "1" ]; then 56 | set -x 57 | fi 58 | kubectl delete "$@" 59 | if [ "$SHOW_EKSCTL_COMMAND" == "1" ]; then 60 | set +x 61 | fi 62 | -------------------------------------------------------------------------------- /src/scripts/describe.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | RESOURCE_NAME=$(eval echo "$K8_STR_RESOURCE_NAME") 3 | NAMESPACE=$(eval echo "$K8_STR_NAMESPACE") 4 | RESOURCE_FILE_PATH=$(eval echo "$K8_STR_RESOURCE_FILE_PATH") 5 | if [ -n "${RESOURCE_FILE_PATH}" ]; then 6 | if [ "$SHOW_EKSCTL_COMMAND" == "1" ]; then 7 | set -x 8 | fi 9 | kubectl describe -f "${RESOURCE_FILE_PATH}" 10 | if [ "$SHOW_EKSCTL_COMMAND" == "1" ]; then 11 | set +x 12 | fi 13 | else 14 | if [ -n "${NAMESPACE}" ]; then 15 | set -- "$@" "--namespace=${NAMESPACE}" 16 | fi 17 | if [ "$SHOW_EKSCTL_COMMAND" == "1" ]; then 18 | set -x 19 | fi 20 | kubectl describe "${RESOURCE_NAME}" "$@" 21 | if [ "$SHOW_EKSCTL_COMMAND" == "1" ]; then 22 | set +x 23 | fi 24 | fi 25 | 26 | 27 | -------------------------------------------------------------------------------- /src/scripts/get_rollout_status.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | RESOURCE_NAME=$(eval echo "$K8_STR_RESOURCE_NAME") 3 | NAMESPACE=$(eval echo "$K8_STR_NAMESPACE") 4 | WATCH_ROLLOUT_STATUS=$(eval echo "$PARAM_WATCH_ROLLOUT_STATUS") 5 | PINNED_REVISION_TO_WATCH=$(eval echo "$PARAM_PINNED_REVISION_TO_WATCH") 6 | WATCH_TIMEOUT=$(eval echo "$PARAM_WATCH_TIMEOUT") 7 | RESOURCE_FILE_PATH=$(eval echo "$K8_STR_RESOURCE_FILE_PATH") 8 | if [ "$SHOW_EKSCTL_COMMAND" == "1" ]; then 9 | set +x 10 | fi 11 | if [ -n "${RESOURCE_NAME}" ]; then 12 | set -- "$@" "${RESOURCE_NAME}" 13 | fi 14 | if [ -n "${NAMESPACE}" ]; then 15 | set -- "$@" "--namespace=${NAMESPACE}" 16 | fi 17 | if [ "${WATCH_ROLLOUT_STATUS}" == "true" ]; then 18 | set -- "$@" --watch=true 19 | if [ -n "${PINNED_REVISION_TO_WATCH}" ]; then 20 | set -- "$@" "--revision=${PINNED_REVISION_TO_WATCH}" 21 | fi 22 | if [ -n "${WATCH_TIMEOUT}" ]; then 23 | set -- "$@" "--timeout=${WATCH_TIMEOUT}" 24 | fi 25 | fi 26 | set -x 27 | if [ -n "$RESOURCE_FILE_PATH" ]; then 28 | kubectl rollout status -f "$RESOURCE_FILE_PATH" "$@" 29 | else 30 | kubectl rollout status "$@" 31 | fi 32 | set +x -------------------------------------------------------------------------------- /src/scripts/install_kops.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | KOPS_VERSION=$(eval echo "$K8_STR_KOPS_VERSION") 3 | if [[ "$KOPS_VERSION" == "latest" ]]; then 4 | # get latest kops release 5 | KOPS_VERSION=$(curl -s https://api.github.com/repos/kubernetes/kops/releases/latest | grep tag_name | cut -d '"' -f 4) 6 | fi 7 | 8 | PLATFORM="linux" 9 | if uname | grep "Darwin"; then 10 | PLATFORM="darwin" 11 | fi 12 | 13 | ARCH="arm64" 14 | if uname -m | grep "x86_64"; then 15 | ARCH="amd64" 16 | fi 17 | # download kops 18 | curl -Lo kops https://github.com/kubernetes/kops/releases/download/"${KOPS_VERSION}"/kops-"${PLATFORM}"-"${ARCH}" 19 | 20 | [ -w /usr/local/bin ] && SUDO="" || SUDO=sudo 21 | 22 | $SUDO chmod +x kops 23 | $SUDO mv kops /usr/local/bin/kops 24 | -------------------------------------------------------------------------------- /src/scripts/install_kubeconfig.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -x 3 | KUBECONFIG=$(eval echo "\$$K8_ENV_KUBECONFIG") 4 | if [ -n "${KUBECONFIG}" ]; then 5 | mkdir -p "$HOME"/.kube 6 | echo -n "$KUBECONFIG" | base64 --decode > "$HOME"/.kube/config 7 | fi 8 | set +x 9 | -------------------------------------------------------------------------------- /src/scripts/install_kubectl.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | KUBECTL_VERSION=$(eval echo "$K8_STR_KUBECTL_VERSION") 3 | MAX_TIME=$(eval echo "$K8_BOOL_MAX_TIME") 4 | if [ "$KUBECTL_VERSION" == "latest" ]; then 5 | # get latest kubectl release 6 | KUBECTL_VERSION=$(curl -sL https://dl.k8s.io/release/stable.txt) 7 | fi 8 | 9 | if [[ "$KUBECTL_VERSION" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then 10 | echo "Valid version format." 11 | else 12 | echo "Invalid version format: ${KUBECTL_VERSION}" 13 | echo "Please use the format vX.Y.Z (e.g., v1.29.0)." 14 | exit 1 15 | fi 16 | 17 | PLATFORM="linux" 18 | if uname | grep "Darwin"; then 19 | PLATFORM="darwin" 20 | fi 21 | 22 | ARCH="arm64" 23 | if uname -m | grep "x86_64"; then 24 | ARCH="amd64" 25 | fi 26 | 27 | # download kubectl 28 | if [ "$MAX_TIME" == "1" ]; then 29 | curl --max-time 300 -LO https://dl.k8s.io/release/"${KUBECTL_VERSION}"/bin/"${PLATFORM}"/"${ARCH}"/kubectl 30 | else 31 | curl -LO https://dl.k8s.io/release/"${KUBECTL_VERSION}"/bin/"${PLATFORM}"/"${ARCH}"/kubectl 32 | fi 33 | 34 | [ -w /usr/local/bin ] && SUDO="" || SUDO=sudo 35 | 36 | $SUDO chmod +x ./kubectl 37 | 38 | $SUDO mv ./kubectl /usr/local/bin 39 | -------------------------------------------------------------------------------- /src/scripts/rollback.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | RESOURCE_NAME=$(eval echo "$K8_STR_RESOURCE_NAME") 3 | NAMESPACE=$(eval echo "$K8_STR_NAMESPACE") 4 | if [ -n "${RESOURCE_NAME}" ]; then 5 | set -- "$@" "${RESOURCE_NAME}" 6 | fi 7 | if [ -n "${NAMESPACE}" ]; then 8 | set -- "$@" "--namespace=${NAMESPACE}" 9 | fi 10 | if [ "$SHOW_EKSCTL_COMMAND" == "1" ]; then 11 | set -x 12 | fi 13 | kubectl rollout undo "$@" 14 | if [ "$SHOW_EKSCTL_COMMAND" == "1" ]; then 15 | set +x 16 | fi 17 | -------------------------------------------------------------------------------- /src/scripts/update_container_image.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | RESOURCE_FILE_PATH=$(eval echo "$K8_STR_RESOURCE_FILE_PATH") 3 | RESOURCE_NAME=$(eval echo "$K8_STR_RESOURCE_NAME") 4 | CONTAINER_IMAGE_UPDATES=$(eval echo "$K8_STR_CONTAINER_IMAGE_UPDATES") 5 | NAMESPACE=$(eval echo "$K8_STR_NAMESPACE") 6 | DRY_RUN=$(eval echo "$K8_STR_DRY_RUN") 7 | 8 | if [ -n "${RESOURCE_FILE_PATH}" ]; then 9 | set -- "$@" -f 10 | set -- "$@" "${RESOURCE_FILE_PATH}" 11 | elif [ -n "${RESOURCE_NAME}" ]; then 12 | set -- "$@" "${RESOURCE_NAME}" 13 | else 14 | echo "Error: The update-container-image command requires either resource-file-path or resource-name to be specified." 15 | exit 1 16 | fi 17 | 18 | if [ -n "${CONTAINER_IMAGE_UPDATES}" ]; then 19 | IFS=" " read -a args -r <<< "${CONTAINER_IMAGE_UPDATES[@]}" 20 | for arg in "${args[@]}"; do 21 | set -- "$@" "$arg" 22 | done 23 | fi 24 | 25 | if [ -n "${NAMESPACE}" ]; then 26 | set -- "$@" --namespace="${NAMESPACE}" 27 | fi 28 | if [ -n "${DRY_RUN}" ]; then 29 | set -- "$@" --dry-run "${DRY_RUN}" 30 | fi 31 | if [ "$K8_BOOL_SHOW_KUBECTL_COMMAND" == "1" ]; then 32 | set -x 33 | fi 34 | 35 | kubectl set image "$@" 36 | 37 | if [ "$K8_BOOL_SHOW_KUBECTL_COMMAND" == "1" ]; then 38 | set +x 39 | fi 40 | -------------------------------------------------------------------------------- /tests/kustomize/base/deployment.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: apps/v1 2 | kind: Deployment 3 | metadata: 4 | name: hello 5 | spec: 6 | replicas: 3 7 | template: 8 | metadata: 9 | labels: 10 | deployment: hello 11 | spec: 12 | containers: 13 | - name: nginx 14 | image: nginx:1.26-alpine-slim 15 | ports: 16 | - containerPort: 80 17 | -------------------------------------------------------------------------------- /tests/kustomize/base/kustomization.yaml: -------------------------------------------------------------------------------- 1 | commonLabels: 2 | app: hello 3 | 4 | resources: 5 | - deployment.yaml 6 | -------------------------------------------------------------------------------- /tests/kustomize/overlays/staging/kustomization.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: kustomize.config.k8s.io/v1beta1 2 | kind: Kustomization 3 | namePrefix: staging- 4 | commonLabels: 5 | variant: staging 6 | org: acmeCorporation 7 | commonAnnotations: 8 | note: Hello, I am staging! 9 | bases: 10 | - ../../base 11 | -------------------------------------------------------------------------------- /tests/nginx-deployment/deployment.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: apps/v1 # for versions before 1.9.0 use apps/v1beta2 2 | kind: Deployment 3 | metadata: 4 | name: nginx-deployment 5 | spec: 6 | selector: 7 | matchLabels: 8 | app: nginx 9 | replicas: $REPLICAS # tells deployment to run 2 pods matching the template 10 | template: 11 | metadata: 12 | labels: 13 | app: ${APP} 14 | spec: 15 | containers: 16 | - name: nginx 17 | image: nginx:1.26-alpine-slim 18 | ports: 19 | - containerPort: 80 20 | # For multi-image update testing purposes 21 | - name: redis 22 | image: redis:latest 23 | ports: 24 | - containerPort: 6379 25 | --------------------------------------------------------------------------------