├── .github ├── dependabot.yml └── workflows │ ├── golangci-lint.yml │ └── release.yml ├── .gitignore ├── .golangci.yml ├── .goreleaser.yaml ├── .krew.yaml ├── .mockery.yaml ├── Dockerfile ├── LICENSE ├── README.md ├── cmd └── kubectl-conditioner.go ├── go.mod ├── go.sum ├── logo └── conditioner.png └── pkg ├── cmd ├── conditioner.go └── conditioner_test.go ├── config ├── config.go ├── config_test.go └── filesystem.go ├── jsonpatch ├── jsonpatch.go └── jsonpatch_test.go └── mocks └── mock_Filesystem.go /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | updates: 3 | - package-ecosystem: gomod 4 | directory: "/" 5 | schedule: 6 | interval: daily 7 | 8 | - package-ecosystem: docker 9 | directory: "/" 10 | schedule: 11 | interval: daily 12 | 13 | - package-ecosystem: github-actions 14 | directory: "/" 15 | schedule: 16 | interval: daily 17 | -------------------------------------------------------------------------------- /.github/workflows/golangci-lint.yml: -------------------------------------------------------------------------------- 1 | name: golangci-lint 2 | on: 3 | push: 4 | branches: 5 | - main 6 | pull_request: 7 | 8 | permissions: 9 | contents: read 10 | 11 | jobs: 12 | golangci: 13 | name: lint 14 | runs-on: ubuntu-latest 15 | steps: 16 | - uses: actions/checkout@v4 17 | - uses: actions/setup-go@v5 18 | with: 19 | go-version-file: 'go.mod' 20 | check-latest: true 21 | cache: false 22 | - name: golangci-lint 23 | uses: golangci/golangci-lint-action@v8 24 | with: 25 | version: v2.1.2 26 | args: --timeout=10m 27 | -------------------------------------------------------------------------------- /.github/workflows/release.yml: -------------------------------------------------------------------------------- 1 | # .github/workflows/release.yml 2 | name: goreleaser 3 | 4 | on: 5 | push: 6 | tags: 7 | - "*" 8 | 9 | permissions: 10 | contents: write 11 | packages: write 12 | 13 | jobs: 14 | goreleaser: 15 | runs-on: ubuntu-latest 16 | steps: 17 | - name: Checkout 18 | uses: actions/checkout@v4 19 | with: 20 | fetch-depth: 0 21 | - uses: docker/setup-qemu-action@v3 22 | - uses: docker/setup-buildx-action@v3 23 | - name: Login to GitHub Container Registry 24 | uses: docker/login-action@v3 25 | with: 26 | registry: ghcr.io 27 | username: ${{ github.repository_owner }} 28 | password: ${{ secrets.GITHUB_TOKEN }} 29 | - name: Login to Docker Hub 30 | uses: docker/login-action@v3 31 | with: 32 | username: ${{ secrets.DOCKERHUB_USERNAME }} 33 | password: ${{ secrets.DOCKERHUB_TOKEN }} 34 | - name: Set up Go 35 | uses: actions/setup-go@v5 36 | with: 37 | go-version-file: 'go.mod' 38 | check-latest: true 39 | - name: Run GoReleaser 40 | uses: goreleaser/goreleaser-action@v6 41 | with: 42 | distribution: goreleaser 43 | version: latest 44 | args: release --clean 45 | env: 46 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 47 | GORELEASER_AUTH_TOKEN: ${{ secrets.GORELEASER_AUTH_TOKEN}} 48 | - name: Upload conditioner.yaml artifact 49 | uses: actions/upload-artifact@v4 50 | with: 51 | name: conditioner-yaml 52 | path: dist/krew/conditioner.yaml 53 | - name: Update new version in krew-index 54 | uses: rajatjindal/krew-release-bot@v0.0.47 55 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # If you prefer the allow list template instead of the deny list, see community template: 2 | # https://github.com/github/gitignore/blob/main/community/Golang/Go.AllowList.gitignore 3 | # 4 | # Binaries for programs and plugins 5 | *.exe 6 | *.exe~ 7 | *.dll 8 | *.so 9 | *.dylib 10 | 11 | # Test binary, built with `go test -c` 12 | *.test 13 | 14 | # Output of the go coverage tool, specifically when used with LiteIDE 15 | *.out 16 | 17 | # Dependency directories (remove the comment below to include it) 18 | # vendor/ 19 | 20 | # Go workspace file 21 | go.work 22 | 23 | dist/ 24 | -------------------------------------------------------------------------------- /.golangci.yml: -------------------------------------------------------------------------------- 1 | # https://golangci-lint.run/usage/configuration/ 2 | # https://golangci-lint.run/usage/linters/ 3 | version: "2" 4 | linters: 5 | enable: 6 | - gocyclo 7 | 8 | formatters: 9 | enable: 10 | - gofumpt 11 | - goimports 12 | -------------------------------------------------------------------------------- /.goreleaser.yaml: -------------------------------------------------------------------------------- 1 | version: 2 2 | 3 | before: 4 | hooks: 5 | - go mod tidy 6 | 7 | 8 | builds: 9 | - id: "conditioner" 10 | main: "./cmd/" 11 | binary: "kubectl-conditioner" 12 | 13 | env: 14 | - CGO_ENABLED=0 15 | goos: 16 | - linux 17 | - windows 18 | - darwin 19 | goarch: 20 | - amd64 21 | - arm64 22 | - arm 23 | 24 | flags: 25 | - -trimpath 26 | 27 | archives: 28 | - format: tar.gz 29 | # this name template makes the OS and Arch compatible with the results of `uname`. 30 | name_template: >- 31 | {{ .ProjectName }}_ 32 | {{- title .Os }}_ 33 | {{- if eq .Arch "amd64" }}x86_64 34 | {{- else if eq .Arch "386" }}i386 35 | {{- else }}{{ .Arch }}{{ end }} 36 | {{- if .Arm }}v{{ .Arm }}{{ end }} 37 | # use zip for windows archives 38 | format_overrides: 39 | - goos: windows 40 | format: zip 41 | 42 | changelog: 43 | sort: asc 44 | filters: 45 | exclude: 46 | - "^docs:" 47 | - "^test:" 48 | 49 | release: 50 | github: 51 | owner: devbytes-cloud 52 | name: conditioner 53 | 54 | dockers: 55 | - image_templates: 56 | - "devbytescloud/conditioner:{{ .Tag }}-amd64" 57 | - "ghcr.io/devbytes-cloud/conditioner:{{ .Tag }}-amd64" 58 | use: buildx 59 | dockerfile: Dockerfile 60 | build_flag_templates: 61 | - "--platform=linux/amd64" 62 | - "--label=org.opencontainers.image.created={{ .Date }}" 63 | - "--label=org.opencontainers.image.name={{ .ProjectName }}" 64 | - "--label=org.opencontainers.image.revision={{ .FullCommit }}" 65 | - "--label=org.opencontainers.image.version={{ .Version }}" 66 | - "--label=org.opencontainers.image.source={{ .GitURL }}" 67 | 68 | - image_templates: 69 | - "devbytescloud/conditioner:{{ .Tag }}-arm64v8" 70 | - "ghcr.io/devbytes-cloud/conditioner:{{ .Tag }}-arm64v8" 71 | use: buildx 72 | goarch: arm64 73 | dockerfile: Dockerfile 74 | build_flag_templates: 75 | - "--platform=linux/arm64/v8" 76 | - "--label=org.opencontainers.image.created={{ .Date }}" 77 | - "--label=org.opencontainers.image.name={{ .ProjectName }}" 78 | - "--label=org.opencontainers.image.revision={{ .FullCommit }}" 79 | - "--label=org.opencontainers.image.version={{ .Version }}" 80 | - "--label=org.opencontainers.image.source={{ .GitURL }}" 81 | 82 | docker_manifests: 83 | - id: conditioner-docker 84 | name_template: "devbytescloud/conditioner:{{ .Tag }}" 85 | image_templates: 86 | - "devbytescloud/conditioner:{{ .Tag }}-amd64" 87 | - "devbytescloud/conditioner:{{ .Tag }}-arm64v8" 88 | - id: conditioner-ghcr 89 | name_template: "ghcr.io/devbytes-cloud/conditioner:{{ .Tag }}" 90 | image_templates: 91 | - "ghcr.io/devbytes-cloud/conditioner:{{ .Tag }}-amd64" 92 | - "ghcr.io/devbytes-cloud/conditioner:{{ .Tag }}-arm64v8" 93 | 94 | brews: 95 | - name: conditioner 96 | 97 | commit_author: 98 | name: David Dymko 99 | email: dymkod@gmail.com 100 | 101 | directory: Formula 102 | homepage: "https://github.com/devbytes-cloud/conditioner" 103 | description: "Conditioner plugin allows you to add, update, or remove conditions on Kubernetes nodes" 104 | license: "Apache-2.0 license" 105 | install: | 106 | bin.install "kubectl-conditioner" => "conditioner" 107 | 108 | repository: 109 | owner: devbytes-cloud 110 | name: homebrew-tap 111 | branch: main 112 | token: "{{ .Env.GORELEASER_AUTH_TOKEN }}" 113 | 114 | krews: 115 | - name: conditioner 116 | url_template: "https://github.com/devbytes-cloud/conditioner/releases/download/{{ .Tag }}/{{ .ArtifactName }}" 117 | commit_author: 118 | name: goreleaserbot 119 | email: bot@goreleaser.com 120 | commit_msg_template: "Krew plugin update for {{ .ProjectName }} version {{ .Tag }}" 121 | homepage: "https://github.com/devbytes-cloud/conditioner" 122 | description: "Conditioner allows you to add, update, or remove conditions on Kubernetes nodes. It's a handy tool for cluster administrators to manage node status conditions effectively." 123 | short_description: "Add, update, or remove conditions on Kubernetes nodes" 124 | skip_upload: true 125 | -------------------------------------------------------------------------------- /.krew.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: krew.googlecontainertools.github.com/v1alpha2 2 | kind: Plugin 3 | metadata: 4 | name: conditioner 5 | spec: 6 | version: {{ .TagName }} 7 | platforms: 8 | - bin: kubectl-conditioner.exe 9 | {{addURIAndSha "https://github.com/devbytes-cloud/conditioner/releases/download/{{ .TagName }}/conditioner_Windows_x86_64.zip" .TagName | indent 6 }} 10 | selector: 11 | matchLabels: 12 | os: windows 13 | arch: amd64 14 | - bin: kubectl-conditioner.exe 15 | {{addURIAndSha "https://github.com/devbytes-cloud/conditioner/releases/download/{{ .TagName }}/conditioner_Windows_arm64.zip" .TagName | indent 6 }} 16 | selector: 17 | matchLabels: 18 | os: windows 19 | arch: arm64 20 | - bin: kubectl-conditioner 21 | {{addURIAndSha "https://github.com/devbytes-cloud/conditioner/releases/download/{{ .TagName }}/conditioner_Linux_x86_64.tar.gz" .TagName | indent 6 }} 22 | selector: 23 | matchLabels: 24 | os: linux 25 | arch: amd64 26 | - bin: kubectl-conditioner 27 | {{addURIAndSha "https://github.com/devbytes-cloud/conditioner/releases/download/{{ .TagName }}/conditioner_Linux_arm64.tar.gz" .TagName | indent 6 }} 28 | selector: 29 | matchLabels: 30 | os: linux 31 | arch: arm64 32 | - bin: kubectl-conditioner 33 | {{addURIAndSha "https://github.com/devbytes-cloud/conditioner/releases/download/{{ .TagName }}/conditioner_Darwin_x86_64.tar.gz" .TagName | indent 6 }} 34 | selector: 35 | matchLabels: 36 | os: darwin 37 | arch: amd64 38 | - bin: kubectl-conditioner 39 | {{addURIAndSha "https://github.com/devbytes-cloud/conditioner/releases/download/{{ .TagName }}/conditioner_Darwin_arm64.tar.gz" .TagName | indent 6 }} 40 | selector: 41 | matchLabels: 42 | os: darwin 43 | arch: arm64 44 | shortDescription: Add, update, or remove conditions on Kubernetes nodes 45 | homepage: https://github.com/devbytes-cloud/conditioner 46 | description: Conditioner allows you to add, update, or remove conditions on Kubernetes nodes. It's a handy tool for cluster administrators to manage node status conditions effectively. 47 | -------------------------------------------------------------------------------- /.mockery.yaml: -------------------------------------------------------------------------------- 1 | dir: "pkg/mocks" 2 | outpkg: "mocks" 3 | with-expecter: true 4 | packages: 5 | github.com/devbytes-cloud/conditioner/pkg/config: 6 | interfaces: 7 | Filesystem: 8 | 9 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM bitnami/kubectl:1.33.1 2 | COPY kubectl-conditioner /opt/bitnami/kubectl/bin/kubectl-conditioner 3 | ENTRYPOINT ["kubectl"] 4 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Conditioner 2 | 3 | conditioner.png 4 | 5 | This `kubectl` plugin allows you to add, update, or remove conditions on Kubernetes nodes. It's a handy tool for cluster administrators to manage node status conditions effectively. 6 | 7 | ## Features 8 | 9 | - **Add a new condition** to a node with specific details. 10 | - **Update an existing condition** on a node, including status, reason, and message. 11 | - **Remove a condition** from a node. 12 | 13 | ## Prerequisites 14 | 15 | - Kubernetes cluster 16 | - `kubectl` installed and configured to communicate with your cluster 17 | 18 | ## Installation 19 | 20 | ### Manual 21 | To install the plugin, download the binary and make it executable: 22 | 23 | ```bash 24 | curl -LO https://github.com/devbytse-cloud/conditioner/releases/download/{{ .Tag }}/{{ .ArtifactName }} 25 | chmod +x ./kubectl-conditioner 26 | mv ./kubectl-conditioner /usr/local/bin 27 | ``` 28 | 29 | ### Homebrew 30 | 31 | To install conditioner via homebrew you can use our tap. 32 | 33 | ```bash 34 | brew tap devbytes-cloud/tap 35 | brew install conditioner 36 | ``` 37 | 38 | or 39 | 40 | ```bash 41 | brew install devbytes-cloud/tap/conditioner 42 | ``` 43 | 44 | ### Docker 45 | 46 | The docker image uses bitnami kubectl as its base. This means you have full access to kubectl and conditioner. 47 | To yous the conditioner you just need to supply `conditioner` as your first input into the docker container 48 | 49 | ```bash 50 | docker run devbytescloud/conditioner conditioner 51 | ``` 52 | 53 | The images can be found https://hub.docker.com/repository/docker/devbytescloud/conditioner 54 | 55 | ## Installation via Krew 56 | 57 | Krew is a plugin manager for `kubectl`, which allows you to install `conditioner` easily. Follow these steps to install `conditioner` using Krew: 58 | 59 | 1. Ensure you have Krew installed. If not, follow the [Krew installation instructions](https://krew.sigs.k8s.io/docs/user-guide/setup/install/). 60 | 61 | 2. Run the following command to install `conditioner`: 62 | 63 | ```shell 64 | kubectl krew install conditioner 65 | ``` 66 | 67 | ## Usage 68 | 69 | The general syntax for using the plugin is as follows: 70 | 71 | ``` 72 | kubectl conditioner [NODE_NAME] [FLAGS] 73 | ``` 74 | 75 | ```shell 76 | kubectl conditioner -h 77 | The 'condition' command allows you to add, update, or remove status conditions on nodes. 78 | You need to provide the node name as an argument and use flags to specify the details of the condition. 79 | The '--type' flag is required and it specifies the type of condition you wish to interact with. 80 | The '--status' flag sets the status for the specific status condition and it can be 'true', 'false', or left blank for 'unknown'. 81 | The '--reason' flag sets the reason for the specific status condition. 82 | The '--message' flag sets the message for the specific status condition. 83 | If you wish to remove the condition from the node entirely, use the '--remove' flag. 84 | 85 | Usage: 86 | conditioner [node name] [flags] 87 | 88 | Examples: 89 | 90 | # Add a new condition to a node 91 | kubectl conditioner my-node --type Ready --status true --reason KubeletReady --message "kubelet is posting ready status" 92 | 93 | # Update an existing condition on a node 94 | kubectl conditioner my-node --type DiskPressure --status false --reason KubeletHasNoDiskPressure --message "kubelet has sufficient disk space available" 95 | 96 | # Remove a condition from a node 97 | kubectl conditioner my-node --type NetworkUnavailable --remove 98 | 99 | 100 | Flags: 101 | --as string Username to impersonate for the operation. User could be a regular user or a service account in a namespace. 102 | --as-group stringArray Group to impersonate for the operation, this flag can be repeated to specify multiple groups. 103 | --as-uid string UID to impersonate for the operation. 104 | --cache-dir string Default cache directory (default "/Users/ddymko/.kube/cache") 105 | --certificate-authority string Path to a cert file for the certificate authority 106 | --client-certificate string Path to a client certificate file for TLS 107 | --client-key string Path to a client key file for TLS 108 | --cluster string The name of the kubeconfig cluster to use 109 | --context string The name of the kubeconfig context to use 110 | --disable-compression If true, opt-out of response compression for all requests to the server 111 | -h, --help help for condition 112 | --insecure-skip-tls-verify If true, the server's certificate will not be checked for validity. This will make your HTTPS connections insecure 113 | --kubeconfig string Path to the kubeconfig file to use for CLI requests. 114 | --message string Message for the specific status condition 115 | -n, --namespace string If present, the namespace scope for this CLI request 116 | -r, --reason string Reason for the specific status condition 117 | -x, --remove If you wish to remove the condition from the node entirely 118 | --request-timeout string The length of time to wait before giving up on a single server request. Non-zero values should contain a corresponding time unit (e.g. 1s, 2m, 3h). A value of zero means don't timeout requests. (default "0") 119 | -s, --server string The address and port of the Kubernetes API server 120 | --status string Status for the specific status condition [true, false] 121 | --tls-server-name string Server name to use for server certificate validation. If it is not provided, the hostname used to contact the server is used 122 | --token string Bearer token for authentication to the API server 123 | --type string (required): type of condition you wish to interact with 124 | --user string The name of the kubeconfig user to use 125 | ``` 126 | 127 | ## Configuration 128 | 129 | The application uses a configuration file named `.conditioner.json` located in the user's home directory. This file is automatically created if it does not exist. 130 | 131 | The configuration file is in JSON format and contains the following fields: 132 | 133 | - `prepend-whoami`: A boolean value that indicates whether to prepend the user's identity to the output. Default value is `false`. 134 | - `allow-list`: An array of strings that represents a list of allowed conditions that can be used with conditioner. Default value is an empty array `[]`. 135 | 136 | Here is an example of a configuration file: 137 | 138 | ```json 139 | { 140 | "prepend-whoami": true, 141 | "allow-list": ["allowed-condition-1"] 142 | } 143 | ``` 144 | 145 | This json configuration will only allowed `allowed-condition-1` to be used. 146 | ```sh 147 | ☁ ~ conditioner np-vm-02 --type random-condition --status false --reason conditionerExample --message "readme example" 148 | Error: condition random-condition is not in allow-list [allowed-condition-1] 149 | 150 | ☁ ~ conditioner np-vm-02 --type allowed-condition-1 --status false --reason conditionerExample --message "readme example" 151 | condition status allowed-condition-1 has been added on node np-vm-02 152 | ```` 153 | 154 | The `prepend-whoami` will append the current user to the `message` 155 | 156 | ```sh 157 | allowed-condition-1 False Sun, 01 Sep 2024 07:21:47 -0400 Sun, 01 Sep 2024 07:21:47 -0400 conditionerExample ddymko: readme example 158 | ``` 159 | 160 | ### Examples 161 | 162 | - **Add a new condition** to a node: 163 | 164 | ``` 165 | kubectl conditioner my-node --type Ready --status true --reason KubeletReady --message "kubelet is posting ready status" 166 | ``` 167 | 168 | - **Update an existing condition** on a node: 169 | 170 | ``` 171 | kubectl conditioner my-node --type DiskPressure --status false --reason KubeletHasNoDiskPressure --message "kubelet has sufficient disk space available" 172 | ``` 173 | 174 | - **Remove a condition** from a node: 175 | 176 | ``` 177 | kubectl conditioner my-node --type NetworkUnavailable --remove 178 | ``` 179 | 180 | ### Flags 181 | 182 | - `--type` (required): The type of condition (e.g., Ready, DiskPressure). 183 | - `--status`: The status of the condition (`true`, `false`, or leave blank for `unknown`). 184 | - `--reason`: A machine-readable, camel-case reason for the condition's last transition. 185 | - `--message`: A human-readable message indicating details about the last transition. 186 | - `--remove`: If set, the specified condition will be removed from the node. 187 | 188 | ## Building From Source 189 | 190 | To build the plugin from source, you'll need Go installed. Clone the repository and run: 191 | 192 | ```bash 193 | go build -o kubectl-conditioner ./cmd 194 | ``` 195 | 196 | This command will create a binary named `kubectl-conditioner` in your current directory. 197 | 198 | ## Contributing 199 | 200 | Contributions are welcome! Please feel free to submit issues, pull requests, or suggest features. 201 | 202 | ## License 203 | 204 | This project is open source and available under the [Apache License](LICENSE). 205 | -------------------------------------------------------------------------------- /cmd/kubectl-conditioner.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "os" 6 | 7 | "github.com/devbytes-cloud/conditioner/pkg/cmd" 8 | "github.com/devbytes-cloud/conditioner/pkg/config" 9 | "github.com/spf13/pflag" 10 | 11 | "k8s.io/cli-runtime/pkg/genericiooptions" 12 | ) 13 | 14 | func init() { 15 | fs := config.FS{} 16 | exists, err := config.Exists(fs) 17 | if err != nil { 18 | fmt.Println(err.Error()) 19 | os.Exit(1) 20 | } 21 | 22 | if !exists { 23 | if err := config.Write(); err != nil { 24 | fmt.Println(err.Error()) 25 | os.Exit(1) 26 | } 27 | } 28 | } 29 | 30 | func main() { 31 | flags := pflag.NewFlagSet("kubectl-conditioner", pflag.ExitOnError) 32 | pflag.CommandLine = flags 33 | 34 | root := cmd.NewCmdCondition(genericiooptions.IOStreams{In: os.Stdin, Out: os.Stdout, ErrOut: os.Stderr}) 35 | if err := root.Execute(); err != nil { 36 | os.Exit(1) 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /go.mod: -------------------------------------------------------------------------------- 1 | module github.com/devbytes-cloud/conditioner 2 | 3 | go 1.24.2 4 | 5 | require ( 6 | github.com/mitchellh/go-homedir v1.1.0 7 | github.com/spf13/cobra v1.9.1 8 | github.com/spf13/pflag v1.0.6 9 | github.com/stretchr/testify v1.10.0 10 | k8s.io/api v0.33.1 11 | k8s.io/apimachinery v0.33.1 12 | k8s.io/cli-runtime v0.33.1 13 | k8s.io/client-go v0.33.1 14 | ) 15 | 16 | require ( 17 | github.com/Azure/go-ansiterm v0.0.0-20230124172434-306776ec8161 // indirect 18 | github.com/blang/semver/v4 v4.0.0 // indirect 19 | github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect 20 | github.com/emicklei/go-restful/v3 v3.11.0 // indirect 21 | github.com/fxamacker/cbor/v2 v2.7.0 // indirect 22 | github.com/go-errors/errors v1.4.2 // indirect 23 | github.com/go-logr/logr v1.4.2 // indirect 24 | github.com/go-openapi/jsonpointer v0.21.0 // indirect 25 | github.com/go-openapi/jsonreference v0.20.2 // indirect 26 | github.com/go-openapi/swag v0.23.0 // indirect 27 | github.com/gogo/protobuf v1.3.2 // indirect 28 | github.com/google/btree v1.1.3 // indirect 29 | github.com/google/gnostic-models v0.6.9 // indirect 30 | github.com/google/go-cmp v0.7.0 // indirect 31 | github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 // indirect 32 | github.com/google/uuid v1.6.0 // indirect 33 | github.com/gregjones/httpcache v0.0.0-20190611155906-901d90724c79 // indirect 34 | github.com/inconshreveable/mousetrap v1.1.0 // indirect 35 | github.com/josharian/intern v1.0.0 // indirect 36 | github.com/json-iterator/go v1.1.12 // indirect 37 | github.com/liggitt/tabwriter v0.0.0-20181228230101-89fcab3d43de // indirect 38 | github.com/mailru/easyjson v0.7.7 // indirect 39 | github.com/moby/term v0.5.0 // indirect 40 | github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect 41 | github.com/modern-go/reflect2 v1.0.2 // indirect 42 | github.com/monochromegane/go-gitignore v0.0.0-20200626010858-205db1a8cc00 // indirect 43 | github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect 44 | github.com/peterbourgon/diskv v2.0.1+incompatible // indirect 45 | github.com/pkg/errors v0.9.1 // indirect 46 | github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect 47 | github.com/stretchr/objx v0.5.2 // indirect 48 | github.com/x448/float16 v0.8.4 // indirect 49 | github.com/xlab/treeprint v1.2.0 // indirect 50 | golang.org/x/net v0.38.0 // indirect 51 | golang.org/x/oauth2 v0.27.0 // indirect 52 | golang.org/x/sync v0.12.0 // indirect 53 | golang.org/x/sys v0.31.0 // indirect 54 | golang.org/x/term v0.30.0 // indirect 55 | golang.org/x/text v0.23.0 // indirect 56 | golang.org/x/time v0.9.0 // indirect 57 | google.golang.org/protobuf v1.36.5 // indirect 58 | gopkg.in/evanphx/json-patch.v4 v4.12.0 // indirect 59 | gopkg.in/inf.v0 v0.9.1 // indirect 60 | gopkg.in/yaml.v3 v3.0.1 // indirect 61 | k8s.io/klog/v2 v2.130.1 // indirect 62 | k8s.io/kube-openapi v0.0.0-20250318190949-c8a335a9a2ff // indirect 63 | k8s.io/utils v0.0.0-20241104100929-3ea5e8cea738 // indirect 64 | sigs.k8s.io/json v0.0.0-20241010143419-9aa6b5e7a4b3 // indirect 65 | sigs.k8s.io/kustomize/api v0.19.0 // indirect 66 | sigs.k8s.io/kustomize/kyaml v0.19.0 // indirect 67 | sigs.k8s.io/randfill v1.0.0 // indirect 68 | sigs.k8s.io/structured-merge-diff/v4 v4.6.0 // indirect 69 | sigs.k8s.io/yaml v1.4.0 // indirect 70 | ) 71 | -------------------------------------------------------------------------------- /go.sum: -------------------------------------------------------------------------------- 1 | github.com/Azure/go-ansiterm v0.0.0-20230124172434-306776ec8161 h1:L/gRVlceqvL25UVaW/CKtUDjefjrs0SPonmDGUVOYP0= 2 | github.com/Azure/go-ansiterm v0.0.0-20230124172434-306776ec8161/go.mod h1:xomTg63KZ2rFqZQzSB4Vz2SUXa1BpHTVz9L5PTmPC4E= 3 | github.com/blang/semver/v4 v4.0.0 h1:1PFHFE6yCCTv8C1TeyNNarDzntLi7wMI5i/pzqYIsAM= 4 | github.com/blang/semver/v4 v4.0.0/go.mod h1:IbckMUScFkM3pff0VJDNKRiT6TG/YpiHIM2yvyW5YoQ= 5 | github.com/cpuguy83/go-md2man/v2 v2.0.6/go.mod h1:oOW0eioCTA6cOiMLiUPZOpcVxMig6NIQQ7OS05n1F4g= 6 | github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= 7 | github.com/creack/pty v1.1.18 h1:n56/Zwd5o6whRC5PMGretI4IdRLlmBXYNjScPaBgsbY= 8 | github.com/creack/pty v1.1.18/go.mod h1:MOBLtS5ELjhRRrroQr9kyvTxUAFNvYEK993ew/Vr4O4= 9 | github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 10 | github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 11 | github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM= 12 | github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 13 | github.com/emicklei/go-restful/v3 v3.11.0 h1:rAQeMHw1c7zTmncogyy8VvRZwtkmkZ4FxERmMY4rD+g= 14 | github.com/emicklei/go-restful/v3 v3.11.0/go.mod h1:6n3XBCmQQb25CM2LCACGz8ukIrRry+4bhvbpWn3mrbc= 15 | github.com/fxamacker/cbor/v2 v2.7.0 h1:iM5WgngdRBanHcxugY4JySA0nk1wZorNOpTgCMedv5E= 16 | github.com/fxamacker/cbor/v2 v2.7.0/go.mod h1:pxXPTn3joSm21Gbwsv0w9OSA2y1HFR9qXEeXQVeNoDQ= 17 | github.com/go-errors/errors v1.4.2 h1:J6MZopCL4uSllY1OfXM374weqZFFItUbrImctkmUxIA= 18 | github.com/go-errors/errors v1.4.2/go.mod h1:sIVyrIiJhuEF+Pj9Ebtd6P/rEYROXFi3BopGUQ5a5Og= 19 | github.com/go-logr/logr v1.4.2 h1:6pFjapn8bFcIbiKo3XT4j/BhANplGihG6tvd+8rYgrY= 20 | github.com/go-logr/logr v1.4.2/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY= 21 | github.com/go-openapi/jsonpointer v0.19.6/go.mod h1:osyAmYz/mB/C3I+WsTTSgw1ONzaLJoLCyoi6/zppojs= 22 | github.com/go-openapi/jsonpointer v0.21.0 h1:YgdVicSA9vH5RiHs9TZW5oyafXZFc6+2Vc1rr/O9oNQ= 23 | github.com/go-openapi/jsonpointer v0.21.0/go.mod h1:IUyH9l/+uyhIYQ/PXVA41Rexl+kOkAPDdXEYns6fzUY= 24 | github.com/go-openapi/jsonreference v0.20.2 h1:3sVjiK66+uXK/6oQ8xgcRKcFgQ5KXa2KvnJRumpMGbE= 25 | github.com/go-openapi/jsonreference v0.20.2/go.mod h1:Bl1zwGIM8/wsvqjsOQLJ/SH+En5Ap4rVB5KVcIDZG2k= 26 | github.com/go-openapi/swag v0.22.3/go.mod h1:UzaqsxGiab7freDnrUUra0MwWfN/q7tE4j+VcZ0yl14= 27 | github.com/go-openapi/swag v0.23.0 h1:vsEVJDUo2hPJ2tu0/Xc+4noaxyEffXNIs3cOULZ+GrE= 28 | github.com/go-openapi/swag v0.23.0/go.mod h1:esZ8ITTYEsH1V2trKHjAN8Ai7xHb8RV+YSZ577vPjgQ= 29 | github.com/go-task/slim-sprig/v3 v3.0.0 h1:sUs3vkvUymDpBKi3qH1YSqBQk9+9D/8M2mN1vB6EwHI= 30 | github.com/go-task/slim-sprig/v3 v3.0.0/go.mod h1:W848ghGpv3Qj3dhTPRyJypKRiqCdHZiAzKg9hl15HA8= 31 | github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q= 32 | github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q= 33 | github.com/google/btree v1.1.3 h1:CVpQJjYgC4VbzxeGVHfvZrv1ctoYCAI8vbl07Fcxlyg= 34 | github.com/google/btree v1.1.3/go.mod h1:qOPhT0dTNdNzV6Z/lhRX0YXUafgPLFUh+gZMl761Gm4= 35 | github.com/google/gnostic-models v0.6.9 h1:MU/8wDLif2qCXZmzncUQ/BOfxWfthHi63KqpoNbWqVw= 36 | github.com/google/gnostic-models v0.6.9/go.mod h1:CiWsm0s6BSQd1hRn8/QmxqB6BesYcbSZxsz9b0KuDBw= 37 | github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= 38 | github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8= 39 | github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU= 40 | github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= 41 | github.com/google/pprof v0.0.0-20241029153458-d1b30febd7db h1:097atOisP2aRj7vFgYQBbFN4U4JNXUNYpxael3UzMyo= 42 | github.com/google/pprof v0.0.0-20241029153458-d1b30febd7db/go.mod h1:vavhavw2zAxS5dIdcRluK6cSGGPlZynqzFM8NdvU144= 43 | github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 h1:El6M4kTTCOh6aBiKaUGG7oYTSPP8MxqL4YI3kZKwcP4= 44 | github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510/go.mod h1:pupxD2MaaD3pAXIBCelhxNneeOaAeabZDe5s4K6zSpQ= 45 | github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= 46 | github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= 47 | github.com/gregjones/httpcache v0.0.0-20190611155906-901d90724c79 h1:+ngKgrYPPJrOjhax5N+uePQ0Fh1Z7PheYoUI/0nzkPA= 48 | github.com/gregjones/httpcache v0.0.0-20190611155906-901d90724c79/go.mod h1:FecbI9+v66THATjSRHfNgh1IVFe/9kFxbXtjV0ctIMA= 49 | github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8= 50 | github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw= 51 | github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY= 52 | github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y= 53 | github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM= 54 | github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo= 55 | github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8= 56 | github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= 57 | github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= 58 | github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= 59 | github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= 60 | github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= 61 | github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= 62 | github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= 63 | github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= 64 | github.com/liggitt/tabwriter v0.0.0-20181228230101-89fcab3d43de h1:9TO3cAIGXtEhnIaL+V+BEER86oLrvS+kWobKpbJuye0= 65 | github.com/liggitt/tabwriter v0.0.0-20181228230101-89fcab3d43de/go.mod h1:zAbeS9B/r2mtpb6U+EI2rYA5OAXxsYw6wTamcNW+zcE= 66 | github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0= 67 | github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc= 68 | github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y= 69 | github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= 70 | github.com/moby/term v0.5.0 h1:xt8Q1nalod/v7BqbG21f8mQPqH+xAaC9C3N3wfWbVP0= 71 | github.com/moby/term v0.5.0/go.mod h1:8FzsFHVUBGZdbDsJw/ot+X+d5HLUbvklYLJ9uGfcI3Y= 72 | github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= 73 | github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg= 74 | github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= 75 | github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M= 76 | github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk= 77 | github.com/monochromegane/go-gitignore v0.0.0-20200626010858-205db1a8cc00 h1:n6/2gBQ3RWajuToeY6ZtZTIKv2v7ThUy5KKusIT0yc0= 78 | github.com/monochromegane/go-gitignore v0.0.0-20200626010858-205db1a8cc00/go.mod h1:Pm3mSP3c5uWn86xMLZ5Sa7JB9GsEZySvHYXCTK4E9q4= 79 | github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq1c1nUAm88MOHcQC9l5mIlSMApZMrHA= 80 | github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ= 81 | github.com/onsi/ginkgo/v2 v2.21.0 h1:7rg/4f3rB88pb5obDgNZrNHrQ4e6WpjonchcpuBRnZM= 82 | github.com/onsi/ginkgo/v2 v2.21.0/go.mod h1:7Du3c42kxCUegi0IImZ1wUQzMBVecgIHjR1C+NkhLQo= 83 | github.com/onsi/gomega v1.35.1 h1:Cwbd75ZBPxFSuZ6T+rN/WCb/gOc6YgFBXLlZLhC7Ds4= 84 | github.com/onsi/gomega v1.35.1/go.mod h1:PvZbdDc8J6XJEpDK4HCuRBm8a6Fzp9/DmhC9C7yFlog= 85 | github.com/peterbourgon/diskv v2.0.1+incompatible h1:UBdAOUP5p4RWqPBg048CAvpKN+vxiaj6gdUUzhl4XmI= 86 | github.com/peterbourgon/diskv v2.0.1+incompatible/go.mod h1:uqqh8zWWbv1HBMNONnaR/tNboyR3/BZd58JJSHlUSCU= 87 | github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= 88 | github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= 89 | github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= 90 | github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U= 91 | github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= 92 | github.com/rogpeppe/go-internal v1.13.1 h1:KvO1DLK/DRN07sQ1LQKScxyZJuNnedQ5/wKSR38lUII= 93 | github.com/rogpeppe/go-internal v1.13.1/go.mod h1:uMEvuHeurkdAXX61udpOXGD/AzZDWNMNyH2VO9fmH0o= 94 | github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= 95 | github.com/sergi/go-diff v1.2.0 h1:XU+rvMAioB0UC3q1MFrIQy4Vo5/4VsRDQQXHsEya6xQ= 96 | github.com/sergi/go-diff v1.2.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM= 97 | github.com/spf13/cobra v1.9.1 h1:CXSaggrXdbHK9CF+8ywj8Amf7PBRmPCOJugH954Nnlo= 98 | github.com/spf13/cobra v1.9.1/go.mod h1:nDyEzZ8ogv936Cinf6g1RU9MRY64Ir93oCnqb9wxYW0= 99 | github.com/spf13/pflag v1.0.6 h1:jFzHGLGAlb3ruxLB8MhbI6A8+AQX/2eW4qeyNZXNp2o= 100 | github.com/spf13/pflag v1.0.6/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= 101 | github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= 102 | github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= 103 | github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= 104 | github.com/stretchr/objx v0.5.2 h1:xuMeJ0Sdp5ZMRXx/aWO6RZxdr3beISkG5/G/aIRr3pY= 105 | github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA= 106 | github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= 107 | github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= 108 | github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= 109 | github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= 110 | github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= 111 | github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA= 112 | github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= 113 | github.com/x448/float16 v0.8.4 h1:qLwI1I70+NjRFUR3zs1JPUCgaCXSh3SW62uAKT1mSBM= 114 | github.com/x448/float16 v0.8.4/go.mod h1:14CWIYCyZA/cWjXOioeEpHeN/83MdbZDRQHoFcYsOfg= 115 | github.com/xlab/treeprint v1.2.0 h1:HzHnuAF1plUN2zGlAFHbSQP2qJ0ZAD3XF5XD7OesXRQ= 116 | github.com/xlab/treeprint v1.2.0/go.mod h1:gj5Gd3gPdKtR1ikdDK6fnFLdmIS0X30kTTuNd/WEJu0= 117 | github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= 118 | github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= 119 | go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto= 120 | go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE= 121 | golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= 122 | golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= 123 | golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= 124 | golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= 125 | golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= 126 | golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= 127 | golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= 128 | golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= 129 | golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= 130 | golang.org/x/net v0.38.0 h1:vRMAPTMaeGqVhG5QyLJHqNDwecKTomGeqbnfZyKlBI8= 131 | golang.org/x/net v0.38.0/go.mod h1:ivrbrMbzFq5J41QOQh0siUuly180yBYtLp+CKbEaFx8= 132 | golang.org/x/oauth2 v0.27.0 h1:da9Vo7/tDv5RH/7nZDz1eMGS/q1Vv1N/7FCrBhI9I3M= 133 | golang.org/x/oauth2 v0.27.0/go.mod h1:onh5ek6nERTohokkhCD/y2cV4Do3fxFHFuAejCkRWT8= 134 | golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= 135 | golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= 136 | golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= 137 | golang.org/x/sync v0.12.0 h1:MHc5BpPuC30uJk597Ri8TV3CNZcTLu6B6z4lJy+g6Jw= 138 | golang.org/x/sync v0.12.0/go.mod h1:1dzgHSNfp02xaA81J2MS99Qcpr2w7fw1gpm99rleRqA= 139 | golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= 140 | golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 141 | golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 142 | golang.org/x/sys v0.0.0-20210616094352-59db8d763f22/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= 143 | golang.org/x/sys v0.31.0 h1:ioabZlmFYtWhL+TRYpcnNlLwhyxaM9kWTDEmfnprqik= 144 | golang.org/x/sys v0.31.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k= 145 | golang.org/x/term v0.30.0 h1:PQ39fJZ+mfadBm0y5WlL4vlM7Sx1Hgf13sMIY2+QS9Y= 146 | golang.org/x/term v0.30.0/go.mod h1:NYYFdzHoI5wRh/h5tDMdMqCqPJZEuNqVR5xJLd/n67g= 147 | golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= 148 | golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= 149 | golang.org/x/text v0.23.0 h1:D71I7dUrlY+VX0gQShAThNGHFxZ13dGLBHQLVl1mJlY= 150 | golang.org/x/text v0.23.0/go.mod h1:/BLNzu4aZCJ1+kcD0DNRotWKage4q2rGVAg4o22unh4= 151 | golang.org/x/time v0.9.0 h1:EsRrnYcQiGH+5FfbgvV4AP7qEZstoyrHB0DzarOQ4ZY= 152 | golang.org/x/time v0.9.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM= 153 | golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= 154 | golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= 155 | golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= 156 | golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= 157 | golang.org/x/tools v0.26.0 h1:v/60pFQmzmT9ExmjDv2gGIfi3OqfKoEP6I5+umXlbnQ= 158 | golang.org/x/tools v0.26.0/go.mod h1:TPVVj70c7JJ3WCazhD8OdXcZg/og+b9+tH/KxylGwH0= 159 | golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= 160 | golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= 161 | golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= 162 | golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= 163 | google.golang.org/protobuf v1.36.5 h1:tPhr+woSbjfYvY6/GPufUoYizxw1cF/yFoxJ2fmpwlM= 164 | google.golang.org/protobuf v1.36.5/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE= 165 | gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= 166 | gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= 167 | gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= 168 | gopkg.in/evanphx/json-patch.v4 v4.12.0 h1:n6jtcsulIzXPJaxegRbvFNNrZDjbij7ny3gmSPG+6V4= 169 | gopkg.in/evanphx/json-patch.v4 v4.12.0/go.mod h1:p8EYWUEYMpynmqDbY58zCKCFZw8pRWMG4EsWvDvM72M= 170 | gopkg.in/inf.v0 v0.9.1 h1:73M5CoZyi3ZLMOyDlQh031Cx6N9NDJ2Vvfl76EDAgDc= 171 | gopkg.in/inf.v0 v0.9.1/go.mod h1:cWUDdTG/fYaXco+Dcufb5Vnc6Gp2YChqWtbxRZE0mXw= 172 | gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= 173 | gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= 174 | gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= 175 | k8s.io/api v0.33.1 h1:tA6Cf3bHnLIrUK4IqEgb2v++/GYUtqiu9sRVk3iBXyw= 176 | k8s.io/api v0.33.1/go.mod h1:87esjTn9DRSRTD4fWMXamiXxJhpOIREjWOSjsW1kEHw= 177 | k8s.io/apimachinery v0.33.1 h1:mzqXWV8tW9Rw4VeW9rEkqvnxj59k1ezDUl20tFK/oM4= 178 | k8s.io/apimachinery v0.33.1/go.mod h1:BHW0YOu7n22fFv/JkYOEfkUYNRN0fj0BlvMFWA7b+SM= 179 | k8s.io/cli-runtime v0.33.1 h1:TvpjEtF71ViFmPeYMj1baZMJR4iWUEplklsUQ7D3quA= 180 | k8s.io/cli-runtime v0.33.1/go.mod h1:9dz5Q4Uh8io4OWCLiEf/217DXwqNgiTS/IOuza99VZE= 181 | k8s.io/client-go v0.33.1 h1:ZZV/Ks2g92cyxWkRRnfUDsnhNn28eFpt26aGc8KbXF4= 182 | k8s.io/client-go v0.33.1/go.mod h1:JAsUrl1ArO7uRVFWfcj6kOomSlCv+JpvIsp6usAGefA= 183 | k8s.io/klog/v2 v2.130.1 h1:n9Xl7H1Xvksem4KFG4PYbdQCQxqc/tTUyrgXaOhHSzk= 184 | k8s.io/klog/v2 v2.130.1/go.mod h1:3Jpz1GvMt720eyJH1ckRHK1EDfpxISzJ7I9OYgaDtPE= 185 | k8s.io/kube-openapi v0.0.0-20250318190949-c8a335a9a2ff h1:/usPimJzUKKu+m+TE36gUyGcf03XZEP0ZIKgKj35LS4= 186 | k8s.io/kube-openapi v0.0.0-20250318190949-c8a335a9a2ff/go.mod h1:5jIi+8yX4RIb8wk3XwBo5Pq2ccx4FP10ohkbSKCZoK8= 187 | k8s.io/utils v0.0.0-20241104100929-3ea5e8cea738 h1:M3sRQVHv7vB20Xc2ybTt7ODCeFj6JSWYFzOFnYeS6Ro= 188 | k8s.io/utils v0.0.0-20241104100929-3ea5e8cea738/go.mod h1:OLgZIPagt7ERELqWJFomSt595RzquPNLL48iOWgYOg0= 189 | sigs.k8s.io/json v0.0.0-20241010143419-9aa6b5e7a4b3 h1:/Rv+M11QRah1itp8VhT6HoVx1Ray9eB4DBr+K+/sCJ8= 190 | sigs.k8s.io/json v0.0.0-20241010143419-9aa6b5e7a4b3/go.mod h1:18nIHnGi6636UCz6m8i4DhaJ65T6EruyzmoQqI2BVDo= 191 | sigs.k8s.io/kustomize/api v0.19.0 h1:F+2HB2mU1MSiR9Hp1NEgoU2q9ItNOaBJl0I4Dlus5SQ= 192 | sigs.k8s.io/kustomize/api v0.19.0/go.mod h1:/BbwnivGVcBh1r+8m3tH1VNxJmHSk1PzP5fkP6lbL1o= 193 | sigs.k8s.io/kustomize/kyaml v0.19.0 h1:RFge5qsO1uHhwJsu3ipV7RNolC7Uozc0jUBC/61XSlA= 194 | sigs.k8s.io/kustomize/kyaml v0.19.0/go.mod h1:FeKD5jEOH+FbZPpqUghBP8mrLjJ3+zD3/rf9NNu1cwY= 195 | sigs.k8s.io/randfill v0.0.0-20250304075658-069ef1bbf016/go.mod h1:XeLlZ/jmk4i1HRopwe7/aU3H5n1zNUcX6TM94b3QxOY= 196 | sigs.k8s.io/randfill v1.0.0 h1:JfjMILfT8A6RbawdsK2JXGBR5AQVfd+9TbzrlneTyrU= 197 | sigs.k8s.io/randfill v1.0.0/go.mod h1:XeLlZ/jmk4i1HRopwe7/aU3H5n1zNUcX6TM94b3QxOY= 198 | sigs.k8s.io/structured-merge-diff/v4 v4.6.0 h1:IUA9nvMmnKWcj5jl84xn+T5MnlZKThmUW1TdblaLVAc= 199 | sigs.k8s.io/structured-merge-diff/v4 v4.6.0/go.mod h1:dDy58f92j70zLsuZVuUX5Wp9vtxXpaZnkPGWeqDfCps= 200 | sigs.k8s.io/yaml v1.4.0 h1:Mk1wCc2gy/F0THH0TAp1QYyJNzRm2KCLy3o5ASXVI5E= 201 | sigs.k8s.io/yaml v1.4.0/go.mod h1:Ejl7/uTz7PSA4eKMyQCUTnhZYNmLIl+5c2lQPGR2BPY= 202 | -------------------------------------------------------------------------------- /logo/conditioner.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/devbytes-cloud/conditioner/85c839e0a4b052c8cc7d0f8ea29e31ca28baab6a/logo/conditioner.png -------------------------------------------------------------------------------- /pkg/cmd/conditioner.go: -------------------------------------------------------------------------------- 1 | package cmd 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | "os/user" 7 | 8 | "github.com/devbytes-cloud/conditioner/pkg/config" 9 | "github.com/devbytes-cloud/conditioner/pkg/jsonpatch" 10 | "github.com/spf13/cobra" 11 | 12 | corev1 "k8s.io/api/core/v1" 13 | metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 14 | "k8s.io/apimachinery/pkg/types" 15 | "k8s.io/apimachinery/pkg/util/json" 16 | "k8s.io/cli-runtime/pkg/genericclioptions" 17 | "k8s.io/cli-runtime/pkg/genericiooptions" 18 | "k8s.io/client-go/kubernetes" 19 | ) 20 | 21 | var ( 22 | example = ` 23 | # Add a new condition to a node 24 | kubectl conditioner my-node --type Ready --status true --reason KubeletReady --message "kubelet is posting ready status" 25 | 26 | # Update an existing condition on a node 27 | kubectl conditioner my-node --type DiskPressure --status false --reason KubeletHasNoDiskPressure --message "kubelet has sufficient disk space available" 28 | 29 | # Remove a condition from a node 30 | kubectl conditioner my-node --type NetworkUnavailable --remove 31 | ` 32 | 33 | long = `The 'conditioner' command allows you to add, update, or remove status conditions on nodes. 34 | You need to provide the node name as an argument and use flags to specify the details of the condition. 35 | The '--type' flag is required and it specifies the type of condition you wish to interact with. 36 | The '--status' flag sets the status for the specific status condition and it can be 'true', 'false', or left blank for 'unknown'. 37 | The '--reason' flag sets the reason for the specific status condition. 38 | The '--message' flag sets the message for the specific status condition. 39 | If you wish to remove the condition from the node entirely, use the '--remove' flag.` 40 | ) 41 | 42 | // ConditionOptions is a struct that holds the configuration for the condition command. 43 | type ConditionOptions struct { 44 | // client is a pointer to a Clientset object that is used to interact with the Kubernetes API. 45 | client *kubernetes.Clientset 46 | 47 | // configFlags holds the configuration flags for the command. 48 | configFlags *genericclioptions.ConfigFlags 49 | 50 | // IOStreams provides the standard names for iostreams. This is useful for embedding and for unit testing. 51 | genericiooptions.IOStreams 52 | 53 | // nodeName is the name of the node that the command is being run against. 54 | nodeName string 55 | 56 | // remove is a boolean that indicates whether the condition should be removed. 57 | remove bool 58 | 59 | // condition is a pointer to a NodeCondition object that represents the condition to be added or updated. 60 | condition *corev1.NodeCondition 61 | 62 | // args is a slice of strings that contains the arguments that were passed to the command. 63 | args []string 64 | } 65 | 66 | // NewConditionOptions is a function that creates a new ConditionOptions. 67 | func NewConditionOptions(streams genericiooptions.IOStreams) *ConditionOptions { 68 | return &ConditionOptions{ 69 | configFlags: genericclioptions.NewConfigFlags(true), 70 | IOStreams: streams, 71 | } 72 | } 73 | 74 | func NewCmdCondition(streams genericiooptions.IOStreams) *cobra.Command { 75 | o := NewConditionOptions(streams) 76 | 77 | cmd := &cobra.Command{ 78 | Use: "conditioner [node name] [flags]", 79 | Short: "Manipulate status conditions on a specified node.", 80 | Long: long, 81 | Example: example, 82 | SilenceUsage: true, 83 | PreRunE: func(cmd *cobra.Command, args []string) error { 84 | o.args = args 85 | if len(o.args) != 1 { 86 | return fmt.Errorf("must provide a node to be conditioned") 87 | } 88 | 89 | o.nodeName = o.args[0] 90 | return nil 91 | }, 92 | RunE: func(c *cobra.Command, args []string) error { 93 | fs := config.FS{} 94 | conf, err := config.Read(fs) 95 | if err != nil { 96 | return err 97 | } 98 | 99 | if err := o.Complete(c, args, conf); err != nil { 100 | return err 101 | } 102 | 103 | if err := o.Run(); err != nil { 104 | return err 105 | } 106 | 107 | return nil 108 | }, 109 | } 110 | 111 | cmd.Flags().StringP("status", "", "", "Status for the specific status condition [true, false]") 112 | cmd.Flags().StringP("reason", "r", "", "Reason for the specific status condition") 113 | cmd.Flags().StringP("message", "", "", "Message for the specific status condition") 114 | cmd.Flags().StringP("type", "", "", "(required): type of condition you wish to interact with") 115 | cmd.Flags().BoolP("remove", "x", false, "If you wish to remove the condition from the node entirely") 116 | 117 | if err := cmd.MarkFlagRequired("type"); err != nil { 118 | panic(fmt.Sprintf("failed to mark %s flag required: %s", "message", err.Error())) 119 | } 120 | 121 | o.configFlags.AddFlags(cmd.Flags()) 122 | 123 | return cmd 124 | } 125 | 126 | // Complete sets all information required for updating the current context 127 | // It retrieves the restConfig from the configFlags and creates a new Kubernetes client. 128 | // It also sets the condition status, reason, message, type, and remove flag from the command flags. 129 | func (o *ConditionOptions) Complete(cmd *cobra.Command, _ []string, config *config.Config) error { 130 | // Get the restConfig from the configFlags 131 | restConfig, err := o.configFlags.ToRawKubeConfigLoader().ClientConfig() 132 | if err != nil { 133 | return err 134 | } 135 | 136 | // Create a new Kubernetes client 137 | o.client, err = kubernetes.NewForConfig(restConfig) 138 | if err != nil { 139 | return err 140 | } 141 | 142 | o.condition = &corev1.NodeCondition{} 143 | 144 | status, err := cmd.Flags().GetString("status") 145 | if err != nil { 146 | return err 147 | } 148 | 149 | switch status { 150 | case "true": 151 | o.condition.Status = corev1.ConditionTrue 152 | case "false": 153 | o.condition.Status = corev1.ConditionFalse 154 | default: 155 | o.condition.Status = corev1.ConditionUnknown 156 | 157 | } 158 | 159 | o.condition.Reason, err = cmd.Flags().GetString("reason") 160 | if err != nil { 161 | return err 162 | } 163 | 164 | o.condition.Message, err = cmd.Flags().GetString("message") 165 | if err != nil { 166 | return err 167 | } 168 | 169 | if config.WhoAmI { 170 | u, err := user.Current() 171 | if err != nil { 172 | return err 173 | } 174 | 175 | o.condition.Message = fmt.Sprintf("%s: %s", u.Username, o.condition.Message) 176 | } 177 | 178 | // Get the type from the command flags and set the condition type 179 | conditionType, err := cmd.Flags().GetString("type") 180 | if err != nil { 181 | return err 182 | } 183 | 184 | if len(config.AllowList) != 0 { 185 | if ok := allowedType(conditionType, config.AllowList); !ok { 186 | return fmt.Errorf("condition %s is not in allow-list %v", conditionType, config.AllowList) 187 | } 188 | } 189 | 190 | o.condition.Type = corev1.NodeConditionType(conditionType) 191 | 192 | o.remove, err = cmd.Flags().GetBool("remove") 193 | if err != nil { 194 | return err 195 | } 196 | 197 | return nil 198 | } 199 | 200 | // Run handles the condition applying or removal on nodes. 201 | func (o *ConditionOptions) Run() error { 202 | node, err := o.client.CoreV1().Nodes().Get(context.Background(), o.nodeName, metav1.GetOptions{}) 203 | if err != nil { 204 | return err 205 | } 206 | 207 | oldConditions, index := findConditionType(node.Status.Conditions, o.condition.Type) 208 | 209 | if index == -1 && o.remove { 210 | return fmt.Errorf("condition type of %s does not exist", o.condition.Type) 211 | } 212 | 213 | patch := jsonpatch.GenerateJsonPath(index, o.remove, oldConditions, o.condition) 214 | 215 | jsonPath := []interface{}{patch} 216 | bytePatch, err := json.Marshal(jsonPath) 217 | if err != nil { 218 | return err 219 | } 220 | 221 | if _, err := o.client.CoreV1().Nodes().Patch(context.Background(), node.Name, types.JSONPatchType, bytePatch, metav1.PatchOptions{}, "status"); err != nil { 222 | return err 223 | } 224 | 225 | fmt.Printf("condition status %s has been %sed on node %s\n", o.condition.Type, patch.OP, node.Name) 226 | 227 | return nil 228 | } 229 | 230 | // findConditionType is a function that searches for a specific condition type in a slice of NodeCondition objects. 231 | // If a match is found, the function returns a pointer to the matching NodeCondition object and its index in the slice. 232 | // If no match is found, the function returns nil and -1. 233 | func findConditionType(conditions []corev1.NodeCondition, conditionType corev1.NodeConditionType) (*corev1.NodeCondition, int) { 234 | for k, v := range conditions { 235 | if v.Type == conditionType { 236 | return &v, k 237 | } 238 | } 239 | 240 | return nil, -1 241 | } 242 | 243 | // allowedType checks if a given condition type is in the list of allowed types. 244 | func allowedType(conditionType string, allowedTypes []string) bool { 245 | for _, v := range allowedTypes { 246 | if v == conditionType { 247 | return true 248 | } 249 | } 250 | return false 251 | } 252 | -------------------------------------------------------------------------------- /pkg/cmd/conditioner_test.go: -------------------------------------------------------------------------------- 1 | package cmd 2 | 3 | import ( 4 | "testing" 5 | 6 | "github.com/devbytes-cloud/conditioner/pkg/config" 7 | "github.com/spf13/cobra" 8 | "github.com/stretchr/testify/assert" 9 | 10 | corev1 "k8s.io/api/core/v1" 11 | "k8s.io/cli-runtime/pkg/genericiooptions" 12 | ) 13 | 14 | func TestComplete(t *testing.T) { 15 | streams := genericiooptions.IOStreams{} 16 | o := NewConditionOptions(streams) 17 | 18 | // Setup Cobra command with flags 19 | c := &cobra.Command{} 20 | c.Flags().String("type", "Ready", "") 21 | c.Flags().String("status", "true", "") 22 | c.Flags().String("reason", "KubeletReady", "") 23 | c.Flags().String("message", "kubelet is posting ready status", "") 24 | c.Flags().Bool("remove", false, "remove the condition") // Make sure to define the 'remove' flag 25 | 26 | err := o.Complete(c, []string{"test-node"}, &config.Config{}) 27 | assert.NoError(t, err) 28 | 29 | // Assert the fields are set correctly 30 | assert.Equal(t, "Ready", string(o.condition.Type)) 31 | assert.Equal(t, corev1.ConditionTrue, o.condition.Status) 32 | assert.Equal(t, "KubeletReady", o.condition.Reason) 33 | assert.Equal(t, "kubelet is posting ready status", o.condition.Message) 34 | } 35 | -------------------------------------------------------------------------------- /pkg/config/config.go: -------------------------------------------------------------------------------- 1 | package config 2 | 3 | import ( 4 | "encoding/json" 5 | "errors" 6 | "os" 7 | 8 | "github.com/mitchellh/go-homedir" 9 | ) 10 | 11 | // ConfigName is the name of the configuration file. 12 | const configName string = "~/.conditioner.json" 13 | 14 | // Config represents the conditioners configuration. 15 | // It includes fields for user preferences and settings. 16 | type Config struct { 17 | // WhoAmI indicates whether to prepend the user's identity to the output. 18 | WhoAmI bool `json:"prepend-whoami"` 19 | // AllowList is a list of allowed entities for the application. 20 | AllowList []string `json:"allow-list"` 21 | } 22 | 23 | // Exists checks if the configuration file exists. 24 | // It returns a boolean indicating the existence of the file and any error encountered. 25 | func Exists(fs Filesystem) (bool, error) { 26 | path, err := getPath() 27 | if err != nil { 28 | return false, err 29 | } 30 | 31 | if _, err := fs.Stat(path); err == nil { 32 | return true, nil 33 | } else if errors.Is(err, os.ErrNotExist) { 34 | return false, nil 35 | } else { 36 | return false, err 37 | } 38 | } 39 | 40 | // Write writes the default configuration to the configuration file. 41 | // It returns any error encountered during the operation. 42 | func Write() error { 43 | conf := &Config{ 44 | WhoAmI: false, 45 | AllowList: []string{}, 46 | } 47 | 48 | confJson, err := json.MarshalIndent(conf, "", "\t") 49 | if err != nil { 50 | return err 51 | } 52 | 53 | fileName, err := getPath() 54 | if err != nil { 55 | return err 56 | } 57 | 58 | return os.WriteFile(fileName, confJson, 0o644) 59 | } 60 | 61 | // Read is a placeholder function for reading the configuration file. 62 | func Read(fs Filesystem) (*Config, error) { 63 | path, err := getPath() 64 | if err != nil { 65 | return nil, err 66 | } 67 | 68 | byteConfig, err := fs.ReadFile(path) 69 | if err != nil { 70 | return nil, err 71 | } 72 | 73 | config := &Config{} 74 | if err := json.Unmarshal(byteConfig, config); err != nil { 75 | return nil, err 76 | } 77 | return config, nil 78 | } 79 | 80 | // getPath expands the configuration file name to its full path. 81 | // It returns the full path and any error encountered. 82 | func getPath() (string, error) { 83 | return homedir.Expand(configName) 84 | } 85 | -------------------------------------------------------------------------------- /pkg/config/config_test.go: -------------------------------------------------------------------------------- 1 | package config 2 | 3 | import ( 4 | "encoding/json" 5 | "errors" 6 | "fmt" 7 | "os" 8 | "testing" 9 | 10 | "github.com/devbytes-cloud/conditioner/pkg/mocks" 11 | "github.com/stretchr/testify/assert" 12 | ) 13 | 14 | func TestExists(t *testing.T) { 15 | mockFS := new(mocks.MockFilesystem) 16 | path, err := getPath() 17 | assert.NoError(t, err) 18 | 19 | t.Run("File Exists", func(t *testing.T) { 20 | mockFS.On("Stat", path).Return(nil, nil).Once() 21 | 22 | exists, err := Exists(mockFS) 23 | assert.NoError(t, err) 24 | assert.True(t, exists) 25 | }) 26 | 27 | t.Run("Random Error", func(t *testing.T) { 28 | expectedError := errors.New("random error") 29 | mockFS.On("Stat", path).Return(nil, expectedError).Once() 30 | 31 | exists, err := Exists(mockFS) 32 | assert.Error(t, err, expectedError) 33 | assert.False(t, exists) 34 | }) 35 | 36 | t.Run("File does not exist", func(t *testing.T) { 37 | mockFS.On("Stat", path).Return(nil, fmt.Errorf("%w", os.ErrNotExist)).Once() 38 | 39 | exists, err := Exists(mockFS) 40 | assert.Nil(t, err) 41 | assert.False(t, exists) 42 | }) 43 | } 44 | 45 | func TestRead(t *testing.T) { 46 | mockFS := new(mocks.MockFilesystem) 47 | 48 | path, err := getPath() 49 | assert.NoError(t, err) 50 | 51 | t.Run("Error: reading config", func(t *testing.T) { 52 | expectedError := errors.New("not found") 53 | mockFS.On("ReadFile", path).Return(nil, expectedError).Once() 54 | 55 | cfg, err := Read(mockFS) 56 | 57 | assert.Error(t, err, expectedError) 58 | assert.Nil(t, cfg) 59 | }) 60 | 61 | t.Run("Error: json unmarshall", func(t *testing.T) { 62 | mockFS.On("ReadFile", path).Return(nil, nil).Once() 63 | 64 | cfg, err := Read(mockFS) 65 | 66 | assert.Error(t, err) 67 | assert.Nil(t, cfg) 68 | }) 69 | 70 | t.Run("Success: json unmarshall", func(t *testing.T) { 71 | expectedConfig := &Config{ 72 | WhoAmI: false, 73 | AllowList: []string{"unit-test"}, 74 | } 75 | 76 | byteArray, err := json.Marshal(expectedConfig) 77 | assert.NoError(t, err) 78 | 79 | mockFS.On("ReadFile", path).Return(byteArray, nil).Once() 80 | 81 | cfg, err := Read(mockFS) 82 | 83 | assert.NoError(t, err) 84 | assert.Equal(t, cfg, expectedConfig) 85 | }) 86 | } 87 | -------------------------------------------------------------------------------- /pkg/config/filesystem.go: -------------------------------------------------------------------------------- 1 | package config 2 | 3 | import "os" 4 | 5 | // Filesystem defines the operations available for interacting with the filesystem. 6 | // It provides an abstraction over the standard file operations, allowing for easier testing and mocking. 7 | type Filesystem interface { 8 | // ReadFile reads the file named by `name` and returns the contents. 9 | // It returns the file contents as a byte slice and any error encountered. 10 | ReadFile(name string) ([]byte, error) 11 | 12 | // Stat returns the FileInfo structure describing the file. 13 | // If there is an error, it will be of type *PathError. 14 | Stat(name string) (os.FileInfo, error) 15 | 16 | // WriteFile writes data to a file named by `name`. 17 | // If the file does not exist, WriteFile creates it with permissions `perm`; 18 | // otherwise WriteFile truncates it before writing. 19 | WriteFile(name string, data []byte, perm os.FileMode) error 20 | } 21 | 22 | // FS implements the Filesystem interface using the os package. 23 | type FS struct{} 24 | 25 | // ReadFile reads the file named by `name` and returns the contents. 26 | // It leverages os.ReadFile to read the file and return its contents along with any error encountered. 27 | func (f FS) ReadFile(name string) ([]byte, error) { 28 | return os.ReadFile(name) 29 | } 30 | 31 | // Stat returns the FileInfo structure describing the file. 32 | // It uses os.Stat to obtain the FileInfo of the specified file, returning any errors encountered. 33 | func (f FS) Stat(name string) (os.FileInfo, error) { 34 | return os.Stat(name) 35 | } 36 | 37 | // WriteFile writes data to a file named by `name`. 38 | // It creates or truncates the file named by `name`, writing the provided data with the specified permissions. 39 | // It uses os.WriteFile to perform the operation, returning any errors encountered. 40 | func (f FS) WriteFile(name string, data []byte, perm os.FileMode) error { 41 | return os.WriteFile(name, data, perm) 42 | } 43 | -------------------------------------------------------------------------------- /pkg/jsonpatch/jsonpatch.go: -------------------------------------------------------------------------------- 1 | package jsonpatch 2 | 3 | import ( 4 | "fmt" 5 | "time" 6 | 7 | corev1 "k8s.io/api/core/v1" 8 | metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 9 | ) 10 | 11 | // basePath is a constant string that represents the base path in the JSON document where the operations are performed. 12 | // It is used in the formation of the path for the JSON Patch operation. 13 | const ( 14 | basePath string = "/status/conditions" 15 | ) 16 | 17 | // JsonPatch represents a JSON Patch operation. 18 | // JSON Patch is a format (identified by the media type "application/json-patch+json") 19 | // for expressing a sequence of operations to apply to a JavaScript Object Notation (JSON) document. 20 | // It is suitable for use with HTTP PATCH requests. 21 | type JsonPatch struct { 22 | // OP is the operation to be performed. It's a string and can be one of "add", "remove", or "replace". 23 | OP string `json:"op"` 24 | // Path is the string that contains the location in the JSON document where the operation is performed. 25 | Path string `json:"path"` 26 | // Value is the actual value that is used by the operation. 27 | // It's a pointer to a NodeCondition object from the "k8s.io/api/core/v1" package. 28 | Value *corev1.NodeCondition `json:"value"` 29 | } 30 | 31 | // GenerateJsonPath is a function that generates a JSON Patch operation based on the provided parameters. 32 | // It takes four parameters: 33 | // - index: an integer that represents the index of the condition in the conditions array. 34 | // - remove: a boolean that indicates whether the operation is a remove operation. 35 | // - oldConditions: a pointer to a NodeCondition object that represents the old conditions. 36 | // - newConditions: a pointer to a NodeCondition object that represents the new conditions. 37 | func GenerateJsonPath(index int, remove bool, oldConditions, newConditions *corev1.NodeCondition) JsonPatch { 38 | jsonPatch := JsonPatch{ 39 | OP: opType(index, remove), 40 | Path: pathType(index), 41 | } 42 | 43 | // If the operation is a remove operation, return the JsonPatch object. 44 | if remove { 45 | return jsonPatch 46 | } 47 | 48 | jsonPatch.Value = &corev1.NodeCondition{ 49 | Type: newConditions.Type, 50 | Status: newConditions.Status, 51 | LastHeartbeatTime: metav1.Time{Time: time.Now()}, 52 | LastTransitionTime: metav1.Time{Time: time.Now()}, 53 | Reason: newConditions.Reason, 54 | Message: newConditions.Message, 55 | } 56 | 57 | // If the index is not -1, update the value of the JsonPatch object based on the oldConditions parameter. 58 | if index != -1 { 59 | if newConditions.Message == "" { 60 | jsonPatch.Value.Message = oldConditions.Reason 61 | } 62 | 63 | if newConditions.Reason == "" { 64 | jsonPatch.Value.Reason = oldConditions.Reason 65 | } 66 | 67 | if newConditions.Status == "" { 68 | jsonPatch.Value.Status = oldConditions.Status 69 | } 70 | 71 | } 72 | 73 | // Return the JsonPatch object. 74 | return jsonPatch 75 | } 76 | 77 | // opType is a function that determines the operation type for a JSON Patch operation. 78 | // The function returns a string that represents the operation type. 79 | // If the remove parameter is true, the function returns "remove". 80 | // If the index parameter is -1, the function returns "add". 81 | func opType(index int, remove bool) string { 82 | if remove { 83 | return "remove" 84 | } 85 | if index == -1 { 86 | return "add" 87 | } 88 | 89 | return "replace" 90 | } 91 | 92 | // pathType is a function that generates the path for a JSON Patch operation. 93 | // If the index parameter is -1, the function returns a string that ends with "/-". 94 | // This is due to adding elements to the end of the array is denoted with "/-" 95 | // Otherwise, the function returns a string that ends with the index. 96 | func pathType(index int) string { 97 | if index == -1 { 98 | return fmt.Sprintf("%s/-", basePath) 99 | } 100 | 101 | return fmt.Sprintf("%s/%d", basePath, index) 102 | } 103 | -------------------------------------------------------------------------------- /pkg/jsonpatch/jsonpatch_test.go: -------------------------------------------------------------------------------- 1 | package jsonpatch 2 | 3 | import ( 4 | "testing" 5 | "time" 6 | 7 | "github.com/stretchr/testify/assert" 8 | corev1 "k8s.io/api/core/v1" 9 | metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 10 | ) 11 | 12 | func TestOpType(t *testing.T) { 13 | assert := assert.New(t) 14 | 15 | tests := []struct { 16 | index int 17 | remove bool 18 | want string 19 | }{ 20 | {-1, false, "add"}, 21 | {0, false, "replace"}, 22 | {1, false, "replace"}, 23 | {0, true, "remove"}, 24 | } 25 | 26 | for _, tt := range tests { 27 | t.Run(tt.want, func(t *testing.T) { 28 | assert.Equal(tt.want, opType(tt.index, tt.remove)) 29 | }) 30 | } 31 | } 32 | 33 | func TestPathType(t *testing.T) { 34 | assert := assert.New(t) 35 | 36 | tests := []struct { 37 | index int 38 | want string 39 | }{ 40 | {-1, basePath + "/-"}, 41 | {0, basePath + "/0"}, 42 | {1, basePath + "/1"}, 43 | } 44 | 45 | for _, tt := range tests { 46 | t.Run(tt.want, func(t *testing.T) { 47 | assert.Equal(tt.want, pathType(tt.index)) 48 | }) 49 | } 50 | } 51 | 52 | func TestGenerateJsonPath(t *testing.T) { 53 | assert := assert.New(t) 54 | 55 | // Use a fixed time for testing 56 | now := metav1.Time{Time: time.Now()} 57 | 58 | tests := []struct { 59 | name string 60 | index int 61 | remove bool 62 | oldConditions corev1.NodeCondition 63 | newConditions corev1.NodeCondition 64 | want JsonPatch 65 | }{ 66 | { 67 | name: "Add condition", 68 | index: -1, 69 | remove: false, 70 | oldConditions: corev1.NodeCondition{}, 71 | newConditions: corev1.NodeCondition{Type: "Ready", Status: "True", Reason: "NodeReady", Message: "Node is ready"}, 72 | want: JsonPatch{ 73 | OP: "add", 74 | Path: basePath + "/-", 75 | Value: &corev1.NodeCondition{ 76 | Type: "Ready", 77 | Status: "True", 78 | LastHeartbeatTime: now, 79 | LastTransitionTime: now, 80 | Reason: "NodeReady", 81 | Message: "Node is ready", 82 | }, 83 | }, 84 | }, 85 | { 86 | name: "Update condition", 87 | index: 1, 88 | remove: false, 89 | oldConditions: corev1.NodeCondition{Type: "Ready", Status: "False", Reason: "NodeNotReady", Message: "Node is not ready"}, 90 | newConditions: corev1.NodeCondition{Type: "Ready", Status: "True", Reason: "NodeReady", Message: "Node is now ready"}, 91 | want: JsonPatch{ 92 | OP: "replace", 93 | Path: basePath + "/1", 94 | Value: &corev1.NodeCondition{ 95 | Type: "Ready", 96 | Status: "True", 97 | LastHeartbeatTime: now, 98 | LastTransitionTime: now, 99 | Reason: "NodeReady", 100 | Message: "Node is now ready", 101 | }, 102 | }, 103 | }, 104 | { 105 | name: "Remove condition", 106 | index: 0, 107 | remove: true, 108 | oldConditions: corev1.NodeCondition{Type: "DiskPressure", Status: "False", Reason: "DiskOK", Message: "Disk has sufficient space"}, 109 | newConditions: corev1.NodeCondition{}, 110 | want: JsonPatch{ 111 | OP: "remove", 112 | Path: basePath + "/0", 113 | Value: nil, 114 | }, 115 | }, 116 | } 117 | 118 | for _, tt := range tests { 119 | t.Run(tt.name, func(t *testing.T) { 120 | got := GenerateJsonPath(tt.index, tt.remove, &tt.oldConditions, &tt.newConditions) 121 | assert.Equal(tt.want.OP, got.OP) 122 | assert.Equal(tt.want.Path, got.Path) 123 | if tt.want.Value != nil { 124 | assert.Equal(tt.want.Value.Type, got.Value.Type) 125 | assert.Equal(tt.want.Value.Status, got.Value.Status) 126 | assert.Equal(tt.want.Value.Reason, got.Value.Reason) 127 | assert.Equal(tt.want.Value.Message, got.Value.Message) 128 | } else { 129 | assert.Nil(got.Value) 130 | } 131 | }) 132 | } 133 | } 134 | -------------------------------------------------------------------------------- /pkg/mocks/mock_Filesystem.go: -------------------------------------------------------------------------------- 1 | // Code generated by mockery v2.43.2. DO NOT EDIT. 2 | 3 | package mocks 4 | 5 | import ( 6 | fs "io/fs" 7 | 8 | mock "github.com/stretchr/testify/mock" 9 | ) 10 | 11 | // MockFilesystem is an autogenerated mock type for the Filesystem type 12 | type MockFilesystem struct { 13 | mock.Mock 14 | } 15 | 16 | type MockFilesystem_Expecter struct { 17 | mock *mock.Mock 18 | } 19 | 20 | func (_m *MockFilesystem) EXPECT() *MockFilesystem_Expecter { 21 | return &MockFilesystem_Expecter{mock: &_m.Mock} 22 | } 23 | 24 | // ReadFile provides a mock function with given fields: name 25 | func (_m *MockFilesystem) ReadFile(name string) ([]byte, error) { 26 | ret := _m.Called(name) 27 | 28 | if len(ret) == 0 { 29 | panic("no return value specified for ReadFile") 30 | } 31 | 32 | var r0 []byte 33 | var r1 error 34 | if rf, ok := ret.Get(0).(func(string) ([]byte, error)); ok { 35 | return rf(name) 36 | } 37 | if rf, ok := ret.Get(0).(func(string) []byte); ok { 38 | r0 = rf(name) 39 | } else { 40 | if ret.Get(0) != nil { 41 | r0 = ret.Get(0).([]byte) 42 | } 43 | } 44 | 45 | if rf, ok := ret.Get(1).(func(string) error); ok { 46 | r1 = rf(name) 47 | } else { 48 | r1 = ret.Error(1) 49 | } 50 | 51 | return r0, r1 52 | } 53 | 54 | // MockFilesystem_ReadFile_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'ReadFile' 55 | type MockFilesystem_ReadFile_Call struct { 56 | *mock.Call 57 | } 58 | 59 | // ReadFile is a helper method to define mock.On call 60 | // - name string 61 | func (_e *MockFilesystem_Expecter) ReadFile(name interface{}) *MockFilesystem_ReadFile_Call { 62 | return &MockFilesystem_ReadFile_Call{Call: _e.mock.On("ReadFile", name)} 63 | } 64 | 65 | func (_c *MockFilesystem_ReadFile_Call) Run(run func(name string)) *MockFilesystem_ReadFile_Call { 66 | _c.Call.Run(func(args mock.Arguments) { 67 | run(args[0].(string)) 68 | }) 69 | return _c 70 | } 71 | 72 | func (_c *MockFilesystem_ReadFile_Call) Return(_a0 []byte, _a1 error) *MockFilesystem_ReadFile_Call { 73 | _c.Call.Return(_a0, _a1) 74 | return _c 75 | } 76 | 77 | func (_c *MockFilesystem_ReadFile_Call) RunAndReturn(run func(string) ([]byte, error)) *MockFilesystem_ReadFile_Call { 78 | _c.Call.Return(run) 79 | return _c 80 | } 81 | 82 | // Stat provides a mock function with given fields: name 83 | func (_m *MockFilesystem) Stat(name string) (fs.FileInfo, error) { 84 | ret := _m.Called(name) 85 | 86 | if len(ret) == 0 { 87 | panic("no return value specified for Stat") 88 | } 89 | 90 | var r0 fs.FileInfo 91 | var r1 error 92 | if rf, ok := ret.Get(0).(func(string) (fs.FileInfo, error)); ok { 93 | return rf(name) 94 | } 95 | if rf, ok := ret.Get(0).(func(string) fs.FileInfo); ok { 96 | r0 = rf(name) 97 | } else { 98 | if ret.Get(0) != nil { 99 | r0 = ret.Get(0).(fs.FileInfo) 100 | } 101 | } 102 | 103 | if rf, ok := ret.Get(1).(func(string) error); ok { 104 | r1 = rf(name) 105 | } else { 106 | r1 = ret.Error(1) 107 | } 108 | 109 | return r0, r1 110 | } 111 | 112 | // MockFilesystem_Stat_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Stat' 113 | type MockFilesystem_Stat_Call struct { 114 | *mock.Call 115 | } 116 | 117 | // Stat is a helper method to define mock.On call 118 | // - name string 119 | func (_e *MockFilesystem_Expecter) Stat(name interface{}) *MockFilesystem_Stat_Call { 120 | return &MockFilesystem_Stat_Call{Call: _e.mock.On("Stat", name)} 121 | } 122 | 123 | func (_c *MockFilesystem_Stat_Call) Run(run func(name string)) *MockFilesystem_Stat_Call { 124 | _c.Call.Run(func(args mock.Arguments) { 125 | run(args[0].(string)) 126 | }) 127 | return _c 128 | } 129 | 130 | func (_c *MockFilesystem_Stat_Call) Return(_a0 fs.FileInfo, _a1 error) *MockFilesystem_Stat_Call { 131 | _c.Call.Return(_a0, _a1) 132 | return _c 133 | } 134 | 135 | func (_c *MockFilesystem_Stat_Call) RunAndReturn(run func(string) (fs.FileInfo, error)) *MockFilesystem_Stat_Call { 136 | _c.Call.Return(run) 137 | return _c 138 | } 139 | 140 | // WriteFile provides a mock function with given fields: name, data, perm 141 | func (_m *MockFilesystem) WriteFile(name string, data []byte, perm fs.FileMode) error { 142 | ret := _m.Called(name, data, perm) 143 | 144 | if len(ret) == 0 { 145 | panic("no return value specified for WriteFile") 146 | } 147 | 148 | var r0 error 149 | if rf, ok := ret.Get(0).(func(string, []byte, fs.FileMode) error); ok { 150 | r0 = rf(name, data, perm) 151 | } else { 152 | r0 = ret.Error(0) 153 | } 154 | 155 | return r0 156 | } 157 | 158 | // MockFilesystem_WriteFile_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WriteFile' 159 | type MockFilesystem_WriteFile_Call struct { 160 | *mock.Call 161 | } 162 | 163 | // WriteFile is a helper method to define mock.On call 164 | // - name string 165 | // - data []byte 166 | // - perm fs.FileMode 167 | func (_e *MockFilesystem_Expecter) WriteFile(name interface{}, data interface{}, perm interface{}) *MockFilesystem_WriteFile_Call { 168 | return &MockFilesystem_WriteFile_Call{Call: _e.mock.On("WriteFile", name, data, perm)} 169 | } 170 | 171 | func (_c *MockFilesystem_WriteFile_Call) Run(run func(name string, data []byte, perm fs.FileMode)) *MockFilesystem_WriteFile_Call { 172 | _c.Call.Run(func(args mock.Arguments) { 173 | run(args[0].(string), args[1].([]byte), args[2].(fs.FileMode)) 174 | }) 175 | return _c 176 | } 177 | 178 | func (_c *MockFilesystem_WriteFile_Call) Return(_a0 error) *MockFilesystem_WriteFile_Call { 179 | _c.Call.Return(_a0) 180 | return _c 181 | } 182 | 183 | func (_c *MockFilesystem_WriteFile_Call) RunAndReturn(run func(string, []byte, fs.FileMode) error) *MockFilesystem_WriteFile_Call { 184 | _c.Call.Return(run) 185 | return _c 186 | } 187 | 188 | // NewMockFilesystem creates a new instance of MockFilesystem. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. 189 | // The first argument is typically a *testing.T value. 190 | func NewMockFilesystem(t interface { 191 | mock.TestingT 192 | Cleanup(func()) 193 | }) *MockFilesystem { 194 | mock := &MockFilesystem{} 195 | mock.Mock.Test(t) 196 | 197 | t.Cleanup(func() { mock.AssertExpectations(t) }) 198 | 199 | return mock 200 | } 201 | --------------------------------------------------------------------------------