mirror of
https://github.com/kyverno/kyverno.git
synced 2024-12-14 11:57:48 +00:00
kyverno CLI accessable through krew
(#941)
* automate kyverno-cli plugin release for krew * windows support added * revert ci changes * update plugin name * documentation added Co-authored-by: Yuvraj <yuvraj@neualto.com>
This commit is contained in:
parent
08e9c4678e
commit
7a8298419e
4 changed files with 69 additions and 39 deletions
6
.github/workflows/release.yaml
vendored
6
.github/workflows/release.yaml
vendored
|
@ -1,11 +1,9 @@
|
||||||
name: prereleaser
|
name: prereleaser
|
||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
tags:
|
tags:
|
||||||
- '*'
|
- '*'
|
||||||
|
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
releaser:
|
releaser:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
@ -36,6 +34,8 @@ jobs:
|
||||||
access-token: ${{ secrets.ACCESS_TOKEN }}
|
access-token: ${{ secrets.ACCESS_TOKEN }}
|
||||||
deploy-branch: gh-pages
|
deploy-branch: gh-pages
|
||||||
charts-folder: charts
|
charts-folder: charts
|
||||||
|
- name: Update new version in krew-index
|
||||||
|
uses: rajatjindal/krew-release-bot@v0.0.38
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -14,7 +14,6 @@ builds:
|
||||||
- windows
|
- windows
|
||||||
goarch:
|
goarch:
|
||||||
- amd64
|
- amd64
|
||||||
goarm: [6, 7]
|
|
||||||
archives:
|
archives:
|
||||||
- id: kyverno-cli-archive
|
- id: kyverno-cli-archive
|
||||||
name_template: |-
|
name_template: |-
|
||||||
|
@ -26,12 +25,12 @@ archives:
|
||||||
{{- end -}}
|
{{- end -}}
|
||||||
builds:
|
builds:
|
||||||
- kyverno-cli
|
- kyverno-cli
|
||||||
replacements:
|
|
||||||
386: i386
|
|
||||||
amd64: x86_64
|
|
||||||
format_overrides:
|
format_overrides:
|
||||||
- goos: windows
|
- goos: windows
|
||||||
format: zip
|
format: zip
|
||||||
|
replacements:
|
||||||
|
386: i386
|
||||||
|
amd64: x86_64
|
||||||
files: ["LICENSE"]
|
files: ["LICENSE"]
|
||||||
checksum:
|
checksum:
|
||||||
name_template: "checksums.txt"
|
name_template: "checksums.txt"
|
||||||
|
|
46
.krew.yaml
Normal file
46
.krew.yaml
Normal file
|
@ -0,0 +1,46 @@
|
||||||
|
apiVersion: krew.googlecontainertools.github.com/v1alpha2
|
||||||
|
kind: Plugin
|
||||||
|
metadata:
|
||||||
|
name: kyverno
|
||||||
|
spec:
|
||||||
|
version: {{ .TagName }}
|
||||||
|
homepage: https://github.com/nirmata/kyverno
|
||||||
|
platforms:
|
||||||
|
- selector:
|
||||||
|
matchLabels:
|
||||||
|
os: linux
|
||||||
|
arch: amd64
|
||||||
|
{{addURIAndSha "https://github.com/nirmata/kyverno/releases/download/{{ .TagName }}/kyverno-cli_{{ .TagName }}_linux_x86_64.tar.gz" .TagName }}
|
||||||
|
files:
|
||||||
|
- from: kyverno
|
||||||
|
to: .
|
||||||
|
- from: LICENSE
|
||||||
|
to: .
|
||||||
|
bin: kyverno
|
||||||
|
- selector:
|
||||||
|
matchLabels:
|
||||||
|
os: darwin
|
||||||
|
arch: amd64
|
||||||
|
{{addURIAndSha "https://github.com/nirmata/kyverno/releases/download/{{ .TagName }}/kyverno-cli_{{ .TagName }}_darwin_x86_64.tar.gz" .TagName }}
|
||||||
|
files:
|
||||||
|
- from: kyverno
|
||||||
|
to: .
|
||||||
|
- from: LICENSE
|
||||||
|
to: .
|
||||||
|
bin: kyverno
|
||||||
|
- selector:
|
||||||
|
matchLabels:
|
||||||
|
os: windows
|
||||||
|
arch: amd64
|
||||||
|
{{addURIAndSha "https://github.com/nirmata/kyverno/releases/download/{{ .TagName }}/kyverno-cli_{{ .TagName }}_windows_x86_64.zip" .TagName }}
|
||||||
|
files:
|
||||||
|
- from: kyverno.exe
|
||||||
|
to: .
|
||||||
|
- from: LICENSE
|
||||||
|
to: .
|
||||||
|
bin: kyverno.exe
|
||||||
|
shortDescription: Kyverno is a policy engine for kubernetes
|
||||||
|
description: |+2
|
||||||
|
Kyverno is used to test kyverno policies and apply policies to resources files
|
||||||
|
caveats: |
|
||||||
|
The plugin requires access to create Policy and CustomResources
|
|
@ -1,13 +1,10 @@
|
||||||
<small>_[documentation](/README.md#documentation) / kyverno-cli_</small>
|
<small>*[documentation](/README.md#documentation) / kyverno-cli*</small>
|
||||||
|
|
||||||
|
|
||||||
# Kyverno CLI
|
# Kyverno CLI
|
||||||
|
|
||||||
The Kyverno Command Line Interface (CLI) is designed to validate policies and test the behavior of applying policies to resources before adding the policy to a cluster. It can be used as a kubectl plugin and as a standalone CLI.
|
The Kyverno Command Line Interface (CLI) is designed to validate policies and test the behavior of applying policies to resources before adding the policy to a cluster. It can be used as a kubectl plugin and as a standalone CLI.
|
||||||
|
|
||||||
## Install the CLI
|
|
||||||
|
|
||||||
The Kyverno CLI binary is distributed with each release. You can install the CLI for your platform from the [releases](https://github.com/nirmata/kyverno/releases) site.
|
|
||||||
|
|
||||||
## Build the CLI
|
## Build the CLI
|
||||||
|
|
||||||
You can build the CLI binary locally, then move the binary into a directory in your PATH.
|
You can build the CLI binary locally, then move the binary into a directory in your PATH.
|
||||||
|
@ -19,10 +16,14 @@ make cli
|
||||||
mv ./cmd/cli/kubectl-kyverno/kyverno /usr/local/bin/kyverno
|
mv ./cmd/cli/kubectl-kyverno/kyverno /usr/local/bin/kyverno
|
||||||
```
|
```
|
||||||
|
|
||||||
You can also use curl to install kyverno-cli
|
You can also use [Krew](https://github.com/kubernetes-sigs/krew)
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
curl -L https://raw.githubusercontent.com/nirmata/kyverno/master/scripts/install-cli.sh | bash
|
# Install kyverno using krew plugin manager
|
||||||
|
kubectl krew install kyverno
|
||||||
|
|
||||||
|
#example
|
||||||
|
kuberctl kyverno version
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
## Install via AUR (archlinux)
|
## Install via AUR (archlinux)
|
||||||
|
@ -39,55 +40,39 @@ yay -S kyverno-git
|
||||||
|
|
||||||
Prints the version of kyverno used by the CLI.
|
Prints the version of kyverno used by the CLI.
|
||||||
|
|
||||||
Example:
|
Example:
|
||||||
|
|
||||||
```
|
```
|
||||||
kyverno version
|
kyverno version
|
||||||
```
|
```
|
||||||
|
|
||||||
#### Validate
|
#### Validate
|
||||||
|
Validates a policy, can validate multiple policy resource description files or even an entire folder containing policy resource description
|
||||||
Validates a policy, can validate multiple policy resource description files or even an entire folder containing policy resource description
|
files. Currently supports files with resource description in yaml.
|
||||||
files. Currently supports files with resource description in YAML.
|
|
||||||
|
|
||||||
Example:
|
Example:
|
||||||
|
|
||||||
```
|
```
|
||||||
kyverno validate /path/to/policy1.yaml /path/to/policy2.yaml /path/to/folderFullOfPolicies
|
kyverno validate /path/to/policy1.yaml /path/to/policy2.yaml /path/to/folderFullOfPolicies
|
||||||
```
|
```
|
||||||
|
|
||||||
#### Apply
|
#### Apply
|
||||||
|
|
||||||
Applies policies on resources, and supports applying multiple policies on multiple resources in a single command.
|
Applies policies on resources, and supports applying multiple policies on multiple resources in a single command.
|
||||||
Also supports applying the given policies to an entire cluster. The current kubectl context will be used to access the cluster.
|
Also supports applying the given policies to an entire cluster. The current kubectl context will be used to access the cluster.
|
||||||
Will return results to stdout.
|
Will return results to stdout.
|
||||||
|
|
||||||
Apply to a resource:
|
Apply to a resource:
|
||||||
|
```
|
||||||
```bash
|
|
||||||
kyverno apply /path/to/policy.yaml --resource /path/to/resource.yaml
|
kyverno apply /path/to/policy.yaml --resource /path/to/resource.yaml
|
||||||
```
|
```
|
||||||
|
|
||||||
Apply to all matching resources in a cluster:
|
Apply to all matching resources in a cluster:
|
||||||
|
```
|
||||||
```bash
|
|
||||||
kyverno apply /path/to/policy.yaml --cluster > policy-results.txt
|
kyverno apply /path/to/policy.yaml --cluster > policy-results.txt
|
||||||
```
|
```
|
||||||
|
|
||||||
Apply multiple policies to multiple resources:
|
Apply multiple policies to multiple resources:
|
||||||
|
```
|
||||||
```bash
|
|
||||||
kyverno apply /path/to/policy1.yaml /path/to/folderFullOfPolicies --resource /path/to/resource1.yaml --resource /path/to/resource2.yaml --cluster
|
kyverno apply /path/to/policy1.yaml /path/to/folderFullOfPolicies --resource /path/to/resource1.yaml --resource /path/to/resource2.yaml --cluster
|
||||||
```
|
```
|
||||||
|
|
||||||
##### Exit Codes
|
|
||||||
|
|
||||||
The CLI exits with diffenent exit codes:
|
<small>*Read Next >> [Sample Policies](/samples/README.md)*</small>
|
||||||
|
|
||||||
| Message | Exit Code |
|
|
||||||
| ------------------------------------- | --------- |
|
|
||||||
| executes successfully | 0 |
|
|
||||||
| one or more policy rules are violated | 1 |
|
|
||||||
| policy validation failed | 2 |
|
|
||||||
|
|
||||||
<small>_Read Next >> [Sample Policies](/samples/README.md)_</small>
|
|
||||||
|
|
Loading…
Reference in a new issue