1
0
Fork 0
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:
Yuvraj 2020-07-08 09:05:55 -07:00 committed by GitHub
parent 08e9c4678e
commit 7a8298419e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 69 additions and 39 deletions

View file

@ -1,11 +1,9 @@
name: prereleaser
on:
push:
tags:
- '*'
- '*'
jobs:
releaser:
runs-on: ubuntu-latest
@ -36,6 +34,8 @@ jobs:
access-token: ${{ secrets.ACCESS_TOKEN }}
deploy-branch: gh-pages
charts-folder: charts
- name: Update new version in krew-index
uses: rajatjindal/krew-release-bot@v0.0.38

View file

@ -14,7 +14,6 @@ builds:
- windows
goarch:
- amd64
goarm: [6, 7]
archives:
- id: kyverno-cli-archive
name_template: |-
@ -26,12 +25,12 @@ archives:
{{- end -}}
builds:
- kyverno-cli
replacements:
386: i386
amd64: x86_64
format_overrides:
- goos: windows
format: zip
replacements:
386: i386
amd64: x86_64
files: ["LICENSE"]
checksum:
name_template: "checksums.txt"

46
.krew.yaml Normal file
View 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

View file

@ -1,13 +1,10 @@
<small>_[documentation](/README.md#documentation) / kyverno-cli_</small>
<small>*[documentation](/README.md#documentation) / kyverno-cli*</small>
# 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.
## 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
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
```
You can also use curl to install kyverno-cli
You can also use [Krew](https://github.com/kubernetes-sigs/krew)
```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)
@ -39,55 +40,39 @@ yay -S kyverno-git
Prints the version of kyverno used by the CLI.
Example:
Example:
```
kyverno version
```
#### Validate
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.
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.
Example:
```
kyverno validate /path/to/policy1.yaml /path/to/policy2.yaml /path/to/folderFullOfPolicies
```
#### Apply
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.
Will return results to stdout.
Will return results to stdout.
Apply to a resource:
```bash
```
kyverno apply /path/to/policy.yaml --resource /path/to/resource.yaml
```
Apply to all matching resources in a cluster:
```bash
```
kyverno apply /path/to/policy.yaml --cluster > policy-results.txt
```
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
```
##### Exit Codes
The CLI exits with diffenent exit codes:
| 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>
<small>*Read Next >> [Sample Policies](/samples/README.md)*</small>