Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add helm chart #40

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 20 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,14 @@

<!-- toc -->

- [Artifactory cleanup](#artifactory-cleanup)
- [Tables of Contents](#tables-of-contents)
- [Installation](#installation)
- [Usage](#usage)
* [Commands](#commands)
* [Available Rules](#available-rules)
* [Artifact cleanup policies](#artifactory-cleanup-policies)
- [Commands](#commands)
- [Available Rules](#available-rules)
- [Artifact cleanup policies](#artifact-cleanup-policies)
- [Helm Chart Usage](#helm-chart-usage)

<!-- tocstop -->

Expand Down Expand Up @@ -110,3 +113,17 @@ RULES = [
),
]
```

## Helm Chart Usage ##

Make sure you have (helm installed)[https://helm.sh/docs/intro/install/]!
Put your rules.py, containing your [cleanup rules](#available-rules), into the helm chart folder (besides `Chart.yaml`).
Create a copy of `values.yaml` called `answer.yaml` in the same folder.
In the `answer.yaml` remove everything but the values you want to overwrite.
There you should also provide your credentials and the Artifactory URL in the `artifactoryCleanupConfig` section.
On your terminal, navigate to the helm chart folder and install the chart using the following command:

```bash
helm upgrade -i <release name> . -n <namespace> -f answer.yaml
# e.g.: helm upgrade -i artifactory-cleanup . -n artifactory-cleanup -f answer.yaml
```
23 changes: 23 additions & 0 deletions helm/artifactory-cleanup/.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/
26 changes: 26 additions & 0 deletions helm/artifactory-cleanup/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
apiVersion: v2
name: artifactory-cleanup
description: |
artifactory-cleanup helm chart deploys a workload of type "CronJob" to periodically run "artifactory-cleanup".
Configuration if done in values.yaml.

# A chart can be either an 'application' or a 'library' chart.
#
# Application charts are a collection of templates that can be packaged into versioned archives
# to be deployed.
#
# Library charts provide useful utilities or functions for the chart developer. They're included as
# a dependency of application charts to inject those utilities and functions into the rendering
# pipeline. Library charts do not define any templates and therefore cannot be deployed.
type: application

# This is the chart version. This version number should be incremented each time you make changes
# to the chart and its templates, including the app version.
# Versions are expected to follow Semantic Versioning (https://semver.org/)
version: 1.0.0

# This is the version number of the application being deployed. This version number should be
# incremented each time you make changes to the application. Versions are not expected to
# follow Semantic Versioning. They should reflect the version the application is using.
# It is recommended to use it with quotes.
appVersion: "0.3"
5 changes: 5 additions & 0 deletions helm/artifactory-cleanup/templates/NOTES.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
The cronJob is deployed at namespace: {{ .Release.Namespace }}.
The workload name is: {{ include "artifactory-cleanup.fullname" . }}.
To view the logs run 'kubectl -n {{ .Release.Namespace }} logs <pod-name>'.
Use the <pod-name> of the job you want to see the logs from.
To get a list of all jobs of the parenting cronJob run: 'kubectl -n {{ .Release.Namespace }} describe cronjob {{ include "artifactory-cleanup.fullname" . }}'.
62 changes: 62 additions & 0 deletions helm/artifactory-cleanup/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
{{/*
Expand the name of the chart.
*/}}
{{- define "artifactory-cleanup.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 "artifactory-cleanup.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 "artifactory-cleanup.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
{{- end }}

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

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

{{/*
Create the name of the service account to use
*/}}
{{- define "artifactory-cleanup.serviceAccountName" -}}
{{- if .Values.serviceAccount.create }}
{{- default (include "artifactory-cleanup.fullname" .) .Values.serviceAccount.name }}
{{- else }}
{{- default "default" .Values.serviceAccount.name }}
{{- end }}
{{- end }}
8 changes: 8 additions & 0 deletions helm/artifactory-cleanup/templates/configMap-env.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: artifactory-cleanup-env
data:
{{- range $key, $val := .Values.artifactoryCleanupConfig }}
{{ $key }}: {{ $val | quote }}
{{- end }}
7 changes: 7 additions & 0 deletions helm/artifactory-cleanup/templates/configMap-rules.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: artifactory-cleanup-config-rules
data:
rules.py: |
{{ .Files.Get "rules.py" | indent 4 }}
50 changes: 50 additions & 0 deletions helm/artifactory-cleanup/templates/cronJob.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
apiVersion: batch/v1
kind: CronJob
metadata:
name: {{ include "artifactory-cleanup.fullname" . }}
labels:
{{- include "artifactory-cleanup.labels" . | nindent 4 }}
spec:
schedule: {{ .Values.cronJob.schedule }}
jobTemplate:
spec:
template:
spec:
restartPolicy: {{ .Values.cronJob.restartPolicy }}
{{- with .Values.imagePullSecrets }}
imagePullSecrets:
{{- toYaml . | nindent 12 }}
{{- end }}
serviceAccountName: {{ include "artifactory-cleanup.serviceAccountName" . }}
securityContext:
{{- toYaml .Values.podSecurityContext | nindent 12 }}
containers:
- name: {{ .Chart.Name }}
securityContext:
{{- toYaml .Values.securityContext | nindent 16 }}
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
envFrom:
- configMapRef:
name: artifactory-cleanup-env
volumeMounts:
- name: config-rules-volume
mountPath: /tmp/
resources:
{{- toYaml .Values.resources | nindent 16 }}
volumes:
- name: config-rules-volume
configMap:
name: artifactory-cleanup-config-rules
{{- with .Values.nodeSelector }}
nodeSelector:
{{- toYaml . | nindent 12 }}
{{- end }}
{{- with .Values.affinity }}
affinity:
{{- toYaml . | nindent 12 }}
{{- end }}
{{- with .Values.tolerations }}
tolerations:
{{- toYaml . | nindent 12 }}
{{- end }}
12 changes: 12 additions & 0 deletions helm/artifactory-cleanup/templates/serviceaccount.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{{- if .Values.serviceAccount.create -}}
apiVersion: v1
kind: ServiceAccount
metadata:
name: {{ include "artifactory-cleanup.serviceAccountName" . }}
labels:
{{- include "artifactory-cleanup.labels" . | nindent 4 }}
{{- with .Values.serviceAccount.annotations }}
annotations:
{{- toYaml . | nindent 4 }}
{{- end }}
{{- end }}
66 changes: 66 additions & 0 deletions helm/artifactory-cleanup/values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# Default values for artifactory-cleanup.
# This is a YAML-formatted file.
# Declare variables to be passed into your templates.

cronJob:
restartPolicy: Never
schedule: "0 * * * *"

artifactoryCleanupConfig:
ARTIFACTORY_RULES_CONFIG: "/tmp/rules.py"
ARTIFACTORY_URL: https://myarti.com/artifactory
ARTIFACTORY_USER: dummy
ARTIFACTORY_PASSWORD: xxx
ARTIFACTORY_DESTROY_ARTEFACTS: ""

image:
repository: my-repo.docer.com/artifactory-cleanup
pullPolicy: IfNotPresent
# Overrides the image tag whose default is the chart appVersion.
tag: "latest"

imagePullSecrets: []
nameOverride: ""
fullnameOverride: ""

serviceAccount:
# Specifies whether a service account should be created
create: true
# Annotations to add to the service account
annotations: {}
# The name of the service account to use.
# If not set and create is true, a name is generated using the fullname template
name: ""

podAnnotations: {}

podSecurityContext: {}
# fsGroup: 2000

securityContext: {}
# capabilities:
# drop:
# - ALL
# readOnlyRootFilesystem: true
# runAsNonRoot: true
# runAsUser: 1000

resources: {}
# We usually recommend not to specify default resources and to leave this as a conscious
# choice for the user. This also increases chances charts run on environments with little
# resources, such as Minikube. If you do want to specify resources, uncomment the following
# lines, adjust them as necessary, and remove the curly braces after 'resources:'.
# limits:
# cpu: 100m
# memory: 128Mi
# requests:
# cpu: 100m
# memory: 128Mi

# recommendation:
# kubernetes.io/os: linux
nodeSelector: {}

tolerations: []

affinity: {}