Skip to content

Commit

Permalink
feat: add chart
Browse files Browse the repository at this point in the history
Signed-off-by: Charles-Edouard Brétéché <[email protected]>
  • Loading branch information
eddycharly committed Jan 23, 2024
1 parent 9854955 commit 37c54d9
Show file tree
Hide file tree
Showing 17 changed files with 604 additions and 6 deletions.
29 changes: 29 additions & 0 deletions .github/workflows/ah-lint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# yaml-language-server: $schema=https://json.schemastore.org/github-workflow.json

name: ArtifactHub Lint

# permissions: {}

on:
pull_request:
branches:
- '*'

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

jobs:
required:
runs-on: ubuntu-latest
container:
image: artifacthub/ah
options: --user root
steps:
- name: Checkout
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
- name: Run ah lint
working-directory: ./charts/
run: |
set -e
ah lint
35 changes: 35 additions & 0 deletions .github/workflows/ct-lint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# yaml-language-server: $schema=https://json.schemastore.org/github-workflow.json

name: CT Lint

# permissions: {}

on:
pull_request:
branches:
- '*'

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

jobs:
required:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
with:
fetch-depth: 0
- name: Set up Helm
uses: azure/setup-helm@5119fcb9089d432beecbf79bb2c7915207344b78 # v3.5
- name: Setup python
uses: actions/setup-python@0a5c61591373683505ea898e09a3ea4f39ef2b9c # v5.0.0
with:
python-version: 3.7
- name: Set up chart-testing
uses: helm/chart-testing-action@e6669bcd63d7cb57cb4380c33043eebe5d111992 # v2.6.1
- name: Run chart-testing (lint)
run: |
set -e
ct lint --target-branch=main --check-version-increment=false
34 changes: 34 additions & 0 deletions .github/workflows/helm-install.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# yaml-language-server: $schema=https://json.schemastore.org/github-workflow.json

name: Helm install

# permissions: {}

on:
pull_request:
branches:
- '*'

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

jobs:
required:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
- name: Set up Go
uses: actions/setup-go@0c52d547c9bc32b1aa3301fd7a9cb496313a4491 # v5.0.0
with:
go-version-file: go.mod
cache-dependency-path: go.sum
- name: Create cluster
run: |
set -e
make kind-create
- name: Install chart
run: |
set -e
make kind-install
4 changes: 2 additions & 2 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ builds:
binary: policy-reports
flags:
- -trimpath
# ldflags:
# - -s -w -X github.com/kyverno/policy-reports/pkg/version.BuildVersion={{ .Version }}
ldflags:
- -s -w

kos:
- build: policy-reports
Expand Down
66 changes: 62 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -335,19 +335,45 @@ test-version: test-image-all
clean:
rm -rf $(OUTPUT_DIR)


ORG ?= kyverno
PACKAGE ?= github.com/$(ORG)/policy-reports
GIT_SHA := $(shell git rev-parse HEAD)
GOOS ?= $(shell go env GOOS)
GOARCH ?= $(shell go env GOARCH)
REGISTRY ?= ghcr.io
REPO ?= policy-reports
LOCAL_PLATFORM := linux/$(GOARCH)
KO_REGISTRY := ko.local
KO_PLATFORMS := all
KO_TAGS := $(GIT_SHA)
KO_CACHE ?= /tmp/ko-cache

#########
# TOOLS #
#########

TOOLS_DIR := $(PWD)/.tools
KIND := $(TOOLS_DIR)/kind
KIND_VERSION := v0.20.0
TOOLS := $(KIND)
KO := $(TOOLS_DIR)/ko
KO_VERSION := v0.14.1
HELM := $(TOOLS_DIR)/helm
HELM_VERSION := v3.10.1
TOOLS := $(KIND) $(KO) $(HELM)

$(KIND):
@echo Install kind... >&2
@GOBIN=$(TOOLS_DIR) go install sigs.k8s.io/kind@$(KIND_VERSION)

$(KO):
@echo Install ko... >&2
@GOBIN=$(TOOLS_DIR) go install github.com/google/ko@$(KO_VERSION)

$(HELM):
@echo Install helm... >&2
@GOBIN=$(TOOLS_DIR) go install helm.sh/helm/v3/cmd/helm@$(HELM_VERSION)

.PHONY: install-tools
install-tools: $(TOOLS) ## Install tools

Expand All @@ -356,16 +382,48 @@ clean-tools: ## Remove installed tools
@echo Clean tools... >&2
@rm -rf $(TOOLS_DIR)

#########
# BUILD #
#########

CGO_ENABLED ?= 0
LD_FLAGS := "-s -w"

.PHONY: ko-build
ko-build: $(KO) ## Build image (with ko)
@echo Build image with ko... >&2
@LDFLAGS=$(LD_FLAGS) KOCACHE=$(KO_CACHE) KO_DOCKER_REPO=$(KO_REGISTRY) \
$(KO) build . --preserve-import-paths --tags=$(KO_TAGS) --platform=$(LOCAL_PLATFORM)

########
# KIND #
########

KIND_IMAGE ?= kindest/node:v1.28.0
KIND_NAME ?= kind

.PHONY: kind-cluster
kind-cluster: $(KIND) ## Create kind cluster
.PHONY: kind-create
kind-create: $(KIND) ## Create kind cluster
@echo Create kind cluster... >&2
@$(KIND) create cluster --image $(KIND_IMAGE) --wait 1m
@$(KIND) create cluster --name $(KIND_NAME) --image $(KIND_IMAGE) --wait 1m

.PHONY: kind-delete
kind-delete: $(KIND) ## Delete kind cluster
@echo Delete kind cluster... >&2
@$(KIND) delete cluster --name $(KIND_NAME)

.PHONY: kind-load
kind-load: $(KIND) ko-build ## Build image and load in kind cluster
@echo Load image... >&2
@$(KIND) load docker-image --name $(KIND_NAME) $(KO_REGISTRY)/$(PACKAGE):$(GIT_SHA)

.PHONY: kind-install
kind-install: $(HELM) kind-load ## Build image, load it in kind cluster and deploy helm chart
@echo Install chart... >&2
@$(HELM) upgrade --install policy-reports --namespace policy-reports --create-namespace --wait ./charts/policy-reports \
--set image.registry=$(KO_REGISTRY) \
--set image.repository=$(PACKAGE) \
--set image.tag=$(GIT_SHA)

########
# HELP #
Expand Down
23 changes: 23 additions & 0 deletions charts/policy-reports/.helmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Patterns to ignore when building packages.
# This supports shell glob matching, relative path matching, and
# negation (prefixed with !). Only one pattern per line.
.DS_Store
# Common VCS dirs
.git/
.gitignore
.bzr/
.bzrignore
.hg/
.hgignore
.svn/
# Common backup files
*.swp
*.bak
*.tmp
*.orig
*~
# Various IDEs
.project
.idea/
*.tmproj
.vscode/
6 changes: 6 additions & 0 deletions charts/policy-reports/Chart.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
dependencies:
- name: postgresql
repository: oci://registry-1.docker.io/bitnamicharts
version: 13.4.1
digest: sha256:ac38b83c061b6851340ec78ea88bc2ac4a24d705235ebeeab2edc69ceb18f598
generated: "2024-01-23T21:13:53.879046+01:00"
21 changes: 21 additions & 0 deletions charts/policy-reports/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
apiVersion: v2
name: policy-reports
type: application
version: 0.0.1
appVersion: v0.0.1
keywords:
- kubernetes
- policy reports storage
- postgresql
sources:
- https://github.com/kyverno/policy-reports
maintainers:
- name: Nirmata
url: https://kyverno.io/
email: [email protected]
kubeVersion: ">=1.16.0-0"
dependencies:
- condition: postgresql.enabled
name: postgresql
version: 13.4.1
repository: oci://registry-1.docker.io/bitnamicharts
Binary file not shown.
62 changes: 62 additions & 0 deletions charts/policy-reports/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
{{/*
Expand the name of the chart.
*/}}
{{- define "policy-reports.name" -}}
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }}
{{- end }}

{{/*
Create a default fully qualified app name.
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
If release name contains chart name it will be used as a full name.
*/}}
{{- define "policy-reports.fullname" -}}
{{- if .Values.fullnameOverride }}
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }}
{{- else }}
{{- $name := default .Chart.Name .Values.nameOverride }}
{{- if contains $name .Release.Name }}
{{- .Release.Name | trunc 63 | trimSuffix "-" }}
{{- else }}
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }}
{{- end }}
{{- end }}
{{- end }}

{{/*
Create chart name and version as used by the chart label.
*/}}
{{- define "policy-reports.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
{{- end }}

{{/*
Common labels
*/}}
{{- define "policy-reports.labels" -}}
helm.sh/chart: {{ include "policy-reports.chart" . }}
{{ include "policy-reports.selectorLabels" . }}
{{- if .Chart.AppVersion }}
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
{{- end }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- end }}

{{/*
Selector labels
*/}}
{{- define "policy-reports.selectorLabels" -}}
app.kubernetes.io/name: {{ include "policy-reports.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end }}

{{/*
Create the name of the service account to use
*/}}
{{- define "policy-reports.serviceAccountName" -}}
{{- if .Values.serviceAccount.create }}
{{- default (include "policy-reports.fullname" .) .Values.serviceAccount.name }}
{{- else }}
{{- default "default" .Values.serviceAccount.name }}
{{- end }}
{{- end }}
16 changes: 16 additions & 0 deletions charts/policy-reports/templates/api-service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
apiVersion: apiregistration.k8s.io/v1
kind: APIService
metadata:
name: v1alpha2.wgpolicyk8s.io
namespace: {{ $.Release.Namespace }}
labels:
{{- include "policy-reports.labels" . | nindent 4 }}
spec:
group: wgpolicyk8s.io
groupPriorityMinimum: 100
insecureSkipTLSVerify: true
service:
name: {{ include "policy-reports.fullname" . }}
namespace: {{ $.Release.Namespace }}
version: v1alpha2
versionPriority: 100
35 changes: 35 additions & 0 deletions charts/policy-reports/templates/cluster-roles.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
metadata:
name: {{ include "policy-reports.fullname" . }}
labels:
rbac.authorization.k8s.io/aggregate-to-admin: 'true'
rbac.authorization.k8s.io/aggregate-to-edit: 'true'
rbac.authorization.k8s.io/aggregate-to-view: 'true'
{{- include "policy-reports.labels" . | nindent 4 }}
rules:
- apiGroups:
- wgpolicyk8s.io
resources:
- policyreports
- clusterpolicyreports
verbs:
- get
- list
- watch
---
kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: {{ include "policy-reports.fullname" . }}
labels:
{{- include "policy-reports.labels" . | nindent 4 }}
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: {{ include "policy-reports.fullname" . }}
subjects:
- kind: ServiceAccount
name: {{ include "policy-reports.serviceAccountName" $ }}
namespace: {{ $.Release.Namespace }}
Loading

0 comments on commit 37c54d9

Please sign in to comment.