Skip to content

Commit

Permalink
add: starting the project.
Browse files Browse the repository at this point in the history
  • Loading branch information
nataliagranato committed Jan 24, 2024
1 parent 732a19a commit db8422c
Show file tree
Hide file tree
Showing 11 changed files with 436 additions and 0 deletions.
18 changes: 18 additions & 0 deletions .chainsaw.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# yaml-language-server: $schema=https://raw.githubusercontent.com/kyverno/chainsaw/main/.schemas/json/configuration-chainsaw-v1alpha1.json
apiVersion: chainsaw.kyverno.io/v1alpha1
kind: Configuration
metadata:
creationTimestamp: null
name: configuration
spec:
parallel: 1
timeouts:
apply: 1m30s
assert: 1m30s
cleanup: 1m30s
delete: 1m30s
error: 1m30s
exec: 1m30s
fullName: true
forceTerminationGracePeriod: 5s
delayBeforeCleanup: 3s
24 changes: 24 additions & 0 deletions .github/workflows/check-actions.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: Check actions

permissions: {}

on:
push:
branches:
- '*'
pull_request:
branches:
- 'main'
- 'release*'

jobs:
check:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
- name: Ensure SHA pinned actions
uses: zgosalvez/github-actions-ensure-sha-pinned-actions@ba37328d4ea95eaf8b3bd6c6cef308f709a5f2ec # v3.0.3
with:
allowlist: |
kyverno/chainsaw
75 changes: 75 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
name: Policy Test

permissions: {}

on:
push:
branches:
- '*'
pull_request:
branches:
- main
- release*

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
with:
path: policies
- name: Validate all policies
run: ./.hack/verify-files-structure.sh
working-directory: policies
- name: Clone Kyverno
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
with:
repository: kyverno/kyverno
path: kyverno
# The target branch of a pull request or the branch/tag of a push
ref: ${{ github.base_ref || github.ref_name }}
- name: Set up Go
uses: actions/setup-go@0c52d547c9bc32b1aa3301fd7a9cb496313a4491 # v5.0.0
with:
go-version: ~1.21.1
- name: Test Policy
run: go run ./cmd/cli/kubectl-kyverno test ../policies
working-directory: kyverno

lint:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
with:
path: policies
- name: Checkout Kyverno
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
with:
repository: kyverno/kyverno
path: kyverno
# The target branch of a pull request or the branch/tag of a push
ref: ${{ github.base_ref || github.ref_name }}
- name: Set up Go
uses: actions/setup-go@0c52d547c9bc32b1aa3301fd7a9cb496313a4491 # v5.0.0
with:
go-version: ~1.21.1
- name: Lint policies
run: |
set -e
KYVERNO_EXPERIMENTAL=true go run ./cmd/cli/kubectl-kyverno fix test . --save
working-directory: kyverno
- name: Check artifacthub-pkg digests
run: ./.hack/update-artifacthub-pkg.sh
working-directory: policies
- name: Check diff
run: |
set -e
git --no-pager diff .
git diff --quiet --exit-code .
working-directory: policies
6 changes: 6 additions & 0 deletions .github/workflows/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
version: 2
updates:
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "daily"
36 changes: 36 additions & 0 deletions .github/workflows/kind.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
kubeadmConfigPatches:
- |-
kind: ClusterConfiguration
controllerManager:
extraArgs:
bind-address: 0.0.0.0
etcd:
local:
extraArgs:
listen-metrics-urls: http://0.0.0.0:2382
scheduler:
extraArgs:
bind-address: 0.0.0.0
- |-
kind: KubeProxyConfiguration
metricsBindAddress: 0.0.0.0
nodes:
- role: control-plane
kubeadmConfigPatches:
- |-
kind: InitConfiguration
nodeRegistration:
kubeletExtraArgs:
node-labels: "ingress-ready=true"
extraPortMappings:
- containerPort: 80
hostPort: 80
protocol: TCP
- containerPort: 443
hostPort: 443
protocol: TCP
- role: worker
- role: worker
- role: worker
112 changes: 112 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
name: E2E Tests

permissions: {}

on:
workflow_dispatch: {}
pull_request:
branches:
- 'main'

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
chainsaw:
strategy:
fail-fast: false
matrix:
k8s-version:
- name: v1.25
version: v1.25.11
- name: v1.26
version: v1.26.6
- name: v1.27
version: v1.27.3
- name: v1.28
version: v1.28.0
tests:
- ^argo$
- ^aws$
- ^best-practices$
- ^castai$
- ^cert-manager$
- ^consul$
- ^external-secret-operator$
- ^flux$
- ^istio$
- ^karpenter$
- ^kasten$
- ^kubecost$
- ^kubeops$
- ^kubevirt$
- ^linkerd$
- ^nginx-ingress$
- ^openshift$
- ^other$/^a
- ^other$/^[b-d]
- ^other$/^[e-l]
- ^other$/^[m-q]
- ^other$/^re[c-q]
- ^other$/^res
- ^other$/^[s-z]
- ^pod-security$
- ^pod-security-cel$
- ^psa$
- ^psp-migration$
# - ^tekton
# - ^traefik
# - ^velero
runs-on: ubuntu-latest
name: ${{ matrix.k8s-version.name }} - ${{ matrix.tests }}
steps:
- name: Checkout
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
- name: Setup Go
uses: actions/setup-go@0c52d547c9bc32b1aa3301fd7a9cb496313a4491 # v5.0.0
with:
go-version: ~1.21.1
- name: Install Tools
run: |
set -e
curl -LO "https://dl.k8s.io/release/${{ matrix.k8s-version.version }}/bin/linux/amd64/kubectl"
sudo install -o root -g root -m 0755 kubectl /usr/local/bin/kubectl
- name: Install kind
shell: bash
run: |
set -e
# For AMD64 / x86_64
[ $(uname -m) = x86_64 ] && curl -Lo ./kind https://kind.sigs.k8s.io/dl/v0.20.0/kind-linux-amd64
# For ARM64
[ $(uname -m) = aarch64 ] && curl -Lo ./kind https://kind.sigs.k8s.io/dl/v0.20.0/kind-linux-arm64
chmod +x ./kind
sudo mv ./kind /usr/local/bin/kind
- name: Install latest Kyverno CLI
uses: kyverno/action-install-cli@fcee92fca5c883169ef9927acf543e0b5fc58289 # v0.2.0
- name: Create kind cluster
run: |
set -e
kind create cluster --image kindest/node:${{ matrix.k8s-version.version }} --config ./.github/kind.yml
- name: Install latest kyverno
run: |
set -e
kubectl create -f https://github.com/kyverno/kyverno/raw/main/config/install-latest-testing.yaml
- name: Wait for kyverno ready
run: |
set -e
kubectl wait --namespace kyverno --for=condition=ready pod --selector '!job-name' --timeout=60s
- name: Install CRDs
run: |
set -e
kubectl apply -f ./.chainsaw/crds
- name: Install Chainsaw
uses: kyverno/action-install-chainsaw@56be3cb4ec65a987b6ef4d7ab3a55ee17760a57c # v0.1.2
with:
release: v0.0.9
- name: Test with Chainsaw
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
set -e
chainsaw test --config .chainsaw.yaml --include-test-regex '^chainsaw$/${{ matrix.tests }}' --no-color=false
2 changes: 2 additions & 0 deletions docs/policies-validade.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Tipo audit
Tipo enforce
22 changes: 22 additions & 0 deletions policies/require-resources-limits.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
apiVersion: kyverno.io/v1
kind: ClusterPolicy
metadata:
name: require-resources-limits
spec:
validationFailureAction: Enforce
rules:
- name: validate-resources-limits
match:
resources:
kinds:
- Pod
validate:
message: "Pod {{request.object.metadata.name}} does not have resource limits set"
pattern:
spec:
containers:
- name: "*"
resources:
limits:
memory: "?*"
cpu: "?*"
24 changes: 24 additions & 0 deletions tests/kyverno-test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
apiVersion: cli.kyverno.io/v1alpha1
kind: Test
metadata:
name: require-requests-limits
policies:
- ../require-pod-requests-limits.yaml
resources:
- resource.yaml
results:
- kind: Pod
policy: require-requests-limits
resources:
- badpod01
- badpod02
- badpod03
result: fail
rule: validate-resources
- kind: Pod
policy: require-requests-limits
resources:
- goodpod01
- goodpod02
result: pass
rule: validate-resources
31 changes: 31 additions & 0 deletions tests/require_labels.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
apiVersion: kyverno.io/v1
kind: ClusterPolicy
metadata:
name: require-labels
annotations:
policies.kyverno.io/title: Require Labels
policies.kyverno.io/category: Best Practices
policies.kyverno.io/minversion: 1.6.0
policies.kyverno.io/severity: medium
policies.kyverno.io/subject: Pod, Label
policies.kyverno.io/description: >-
Define and use labels that identify semantic attributes of your application or Deployment.
A common set of labels allows tools to work collaboratively, describing objects in a common manner that
all tools can understand. The recommended labels describe applications in a way that can be
queried. This policy validates that the label `app.kubernetes.io/name` is specified with some value.
spec:
validationFailureAction: audit
background: true
rules:
- name: check-for-labels
match:
any:
- resources:
kinds:
- Pod
validate:
message: "The label `app.kubernetes.io/name` is required."
pattern:
metadata:
labels:
app: "?*"
Loading

0 comments on commit db8422c

Please sign in to comment.