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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add kas artifact #879

Closed
wants to merge 9 commits into from
Closed
Show file tree
Hide file tree
Changes from 8 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
6 changes: 6 additions & 0 deletions kas/Pluralfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
REPO kas
ATTRIBUTES Plural repository.yaml

TF terraform/*
HELM helm/*
RECIPE plural/recipes/*
23 changes: 23 additions & 0 deletions kas/helm/kas/.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 kas/helm/kas/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
apiVersion: v1
name: kas
description: k8s agent server
type: application
version: 0.0.0
appVersion: "0.0.0"
15 changes: 15 additions & 0 deletions kas/helm/kas/deps.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
apiVersion: plural.sh/v1alpha1
kind: Dependencies
metadata:
application: true
description: Deploys kas crafted for the target cloud
spec:
dependencies:
- type: helm
name: bootstrap
repo: bootstrap
version: '>= 0.5.1'
- type: terraform
name: kube
repo: kas
version: '>= 0.1.0'
76 changes: 76 additions & 0 deletions kas/helm/kas/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
{{/*
Expand the name of the chart.
*/}}
{{- define "kas.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 "kas.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 "kas.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
{{- end }}

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

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

{{/*
Create the name of the service to use
*/}}
{{- define "kas.serviceName" -}}
{{- printf "%s-service" (include "kas.fullname" .) }}
{{- end }}

{{/*
Create the name of the config map to use
*/}}
{{- define "kas.configMapName" -}}
{{- printf "%s-config" (include "kas.fullname" .) }}
{{- end }}

{{/*
Create the name of the service account to use
*/}}
{{- define "kas.serviceAccountName" -}}
{{- if .Values.serviceAccount.create }}
{{- default (include "kas.fullname" .) .Values.serviceAccount.name }}
{{- else }}
{{- default "default" .Values.serviceAccount.name }}
{{- end }}
{{- end }}
9 changes: 9 additions & 0 deletions kas/helm/kas/templates/configmap.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ template "kas.configMapName" . }}
labels:
{{- include "kas.labels" . | nindent 4 }}
data:
config.yaml: |
plural_url: "" # TODO: Add full config.
99 changes: 99 additions & 0 deletions kas/helm/kas/templates/deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ template "kas.fullname" . }}
labels:
{{- include "kas.labels" . | nindent 4 }}
spec:
selector:
matchLabels:
{{- include "kas.selectorLabels" . | nindent 6 }}
template:
metadata:
annotations:
checksum/config: {{ include (print $.Template.BasePath "/configmap.yaml") . | sha256sum }}
cluster-autoscaler.kubernetes.io/safe-to-evict: "true"
{{- if and .Values.metrics.enabled (not .Values.metrics.serviceMonitor.enabled) }}
prometheus.io/scrape: "true"
prometheus.io/port: {{ .Values.observability.port | quote }}
prometheus.io/path: {{ .Values.metrics.path }}
{{- end }}
{{- with .Values.podAnnotations }}
{{- toYaml . | nindent 8 }}
{{- end }}
labels:
{{- include "kas.selectorLabels" . | nindent 8 }}
spec:
automountServiceAccountToken: false
{{- with .Values.imagePullSecrets }}
imagePullSecrets:
{{- toYaml . | nindent 8 }}
{{- end }}
securityContext:
{{- toYaml .Values.podSecurityContext | nindent 8 }}
{{- with .Values.priorityClassName }}
priorityClassName: {{ . }}
{{- end }}
serviceAccountName: {{ include "kas.serviceAccountName" . }}
containers:
- name: {{ .Chart.Name }}
image: {{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}
imagePullPolicy: {{ .Values.image.pullPolicy }}
securityContext:
{{- toYaml .Values.securityContext | nindent 12 }}
args:
- "--configuration-file=/etc/kas/config.yaml"
{{- range .Values.extraArgs }}
- {{ . }}
{{- end }}
env:
- name: POD_IP
valueFrom:
fieldRef:
fieldPath: status.podIP
{{- if .Values.extraEnv }}
{{- toYaml .Values.extraEnv | nindent 12 }}
{{- end }}
ports:
- containerPort: {{ .Values.service.internalPort }}
- containerPort: {{ .Values.service.kubernetesApiPort }}
- containerPort: {{ .Values.service.privateApiPort }}
- containerPort: {{ .Values.service.observabilityPort }}
readinessProbe:
httpGet:
path: /readiness
port: {{ .Values.service.observabilityPort }}
initialDelaySeconds: 5
periodSeconds: 10
livenessProbe:
httpGet:
path: /liveness
port: {{ .Values.service.observabilityPort }}
initialDelaySeconds: 15
periodSeconds: 20
resources:
{{- toYaml .Values.resources | nindent 12 }}
volumeMounts:
- name: etc-kas
mountPath: /etc/kas
readOnly: true
terminationGracePeriodSeconds: 300
volumes:
- name: etc-kas
projected:
defaultMode: 0440
sources:
- configMap:
name: {{ template "kas.configMapName" . }}
{{- with .Values.nodeSelector }}
nodeSelector:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.affinity }}
affinity:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.tolerations }}
tolerations:
{{- toYaml . | nindent 8 }}
{{- end }}
40 changes: 40 additions & 0 deletions kas/helm/kas/templates/hpa.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{{- if .Values.autoscaling.enabled }}
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
name: {{ include "kas.fullname" . }}
labels:
{{- include "kas.labels" . | nindent 4 }}
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: {{ include "kas.fullname" . }}
minReplicas: {{ .Values.autoscaling.minReplicas }}
maxReplicas: {{ .Values.autoscaling.maxReplicas }}
metrics:
{{- if .Values.autoscaling.targetCPUAverageValue }}
- type: Resource
resource:
name: cpu
target:
type: AverageValue
averageValue: {{ .Values.autoscaling.targetCPUAverageValue }}
{{- end }}
{{- if .Values.autoscaling.targetCPUUtilizationPercentage }}
- type: Resource
resource:
name: cpu
target:
type: Utilization
averageUtilization: {{ .Values.autoscaling.targetCPUUtilizationPercentage }}
{{- end }}
{{- if .Values.autoscaling.targetMemoryUtilizationPercentage }}
- type: Resource
resource:
name: memory
target:
type: Utilization
averageUtilization: {{ .Values.autoscaling.targetMemoryUtilizationPercentage }}
{{- end }}
{{- end }}
12 changes: 12 additions & 0 deletions kas/helm/kas/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 "kas.serviceAccountName" . }}
labels:
{{- include "kas.labels" . | nindent 4 }}
{{- with .Values.serviceAccount.annotations }}
annotations:
{{- toYaml . | nindent 4 }}
{{- end }}
{{- end }}
25 changes: 25 additions & 0 deletions kas/helm/kas/templates/servicemonitor.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{{- if and .Values.metrics.enabled .Values.metrics.serviceMonitor.enabled -}}
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
name: {{ template "kas.serviceName" . }}
labels:
{{- include "kas.labels" . | nindent 4 }}
{{- with .Values.metrics.serviceMonitor.additionalLabels }}
{{- toYaml . | nindent 4 }}
{{- end }}
spec:
namespaceSelector:
matchNames:
- {{ $.Release.Namespace }}
selector:
matchLabels:
app: {{ template "kas.name" . }}
release: {{ .Release.Name }}
endpoints:
- port: http-metrics
path: {{ .Values.metrics.path }}
{{- with .Values.metrics.serviceMonitor.endpointConfig }}
{{- toYaml . | nindent 6 }}
{{- end }}
{{- end -}}
Loading