From b1cba050642d1bdc39128635dd78d2f4e92cdeb6 Mon Sep 17 00:00:00 2001 From: Mac Browning Date: Mon, 16 Oct 2023 19:20:03 -0700 Subject: [PATCH] Initial commit. --- .helmignore | 23 ++++++ LICENSE | 21 +++++ README.md | 20 +++++ charts/vantage-kubernetes-agent/Chart.yaml | 7 ++ .../templates/_helpers.tpl | 58 +++++++++++++ .../templates/clusterrole.yaml | 17 ++++ .../templates/clusterrolebinding.yaml | 18 ++++ .../templates/secret.yaml | 10 +++ .../templates/service.yaml | 15 ++++ .../templates/serviceaccount.yaml | 10 +++ .../templates/statefulset.yaml | 82 +++++++++++++++++++ .../templates/tests/test-connection.yaml | 15 ++++ charts/vantage-kubernetes-agent/values.yaml | 62 ++++++++++++++ 13 files changed, 358 insertions(+) create mode 100644 .helmignore create mode 100644 LICENSE create mode 100644 README.md create mode 100644 charts/vantage-kubernetes-agent/Chart.yaml create mode 100644 charts/vantage-kubernetes-agent/templates/_helpers.tpl create mode 100644 charts/vantage-kubernetes-agent/templates/clusterrole.yaml create mode 100644 charts/vantage-kubernetes-agent/templates/clusterrolebinding.yaml create mode 100644 charts/vantage-kubernetes-agent/templates/secret.yaml create mode 100644 charts/vantage-kubernetes-agent/templates/service.yaml create mode 100644 charts/vantage-kubernetes-agent/templates/serviceaccount.yaml create mode 100644 charts/vantage-kubernetes-agent/templates/statefulset.yaml create mode 100644 charts/vantage-kubernetes-agent/templates/tests/test-connection.yaml create mode 100644 charts/vantage-kubernetes-agent/values.yaml diff --git a/.helmignore b/.helmignore new file mode 100644 index 0000000..0e8a0eb --- /dev/null +++ b/.helmignore @@ -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/ diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..8aa2645 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) [year] [fullname] + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..f07ad90 --- /dev/null +++ b/README.md @@ -0,0 +1,20 @@ +## Usage + +[Helm](https://helm.sh) must be installed to use the charts. Please refer to +Helm's [documentation](https://helm.sh/docs) to get started. + +Once Helm has been set up correctly, add the repo as follows: + + helm repo add vantage https://vantage-sh.github.io/helm-charts + +If you had already added this repo earlier, run `helm repo update` to retrieve +the latest versions of the packages. You can then run `helm search repo +vantage` to see the charts. + +To install the `vantage-kubernetes-agent` chart: + + helm install -n vantage vantage-kubernetes-agent vantage/vantage-kubernetes-agent --set agent.token=$VANTAGE_API_TOKEN,agent.clusterID=$CLUSTER_ID + +To uninstall the chart: + + helm delete vantage-kubernetes-agent diff --git a/charts/vantage-kubernetes-agent/Chart.yaml b/charts/vantage-kubernetes-agent/Chart.yaml new file mode 100644 index 0000000..9c0b29a --- /dev/null +++ b/charts/vantage-kubernetes-agent/Chart.yaml @@ -0,0 +1,7 @@ +apiVersion: v2 +name: vantage-kubernetes-agent +description: A Helm chart for provisioning the Vantage Kubernetes agent. +type: application +version: 1.0.0 +appVersion: "1.0.0" +icon: "https://www.vantage.sh/nav-logo.svg" diff --git a/charts/vantage-kubernetes-agent/templates/_helpers.tpl b/charts/vantage-kubernetes-agent/templates/_helpers.tpl new file mode 100644 index 0000000..81dac25 --- /dev/null +++ b/charts/vantage-kubernetes-agent/templates/_helpers.tpl @@ -0,0 +1,58 @@ +{{/* +Expand the name of the chart. +*/}} +{{- define "vantage-kubernetes-agent.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 "vantage-kubernetes-agent.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 "vantage-kubernetes-agent.chart" -}} +{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }} +{{- end }} + +{{/* +Common labels +*/}} +{{- define "vantage-kubernetes-agent.labels" -}} +helm.sh/chart: {{ include "vantage-kubernetes-agent.chart" . }} +{{ include "vantage-kubernetes-agent.selectorLabels" . }} +{{- if .Chart.AppVersion }} +app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} +{{- end }} +app.kubernetes.io/managed-by: {{ .Release.Service }} +{{- end }} + +{{/* +Selector labels +*/}} +{{- define "vantage-kubernetes-agent.selectorLabels" -}} +app.kubernetes.io/name: {{ include "vantage-kubernetes-agent.name" . }} +app.kubernetes.io/instance: {{ .Release.Name }} +{{- end }} + +{{/* +Create the name of the service account to use +*/}} +{{- define "vantage-kubernetes-agent.serviceAccountName" -}} +{{- default (include "vantage-kubernetes-agent.fullname" .) .Values.serviceAccount.name }} +{{- end }} diff --git a/charts/vantage-kubernetes-agent/templates/clusterrole.yaml b/charts/vantage-kubernetes-agent/templates/clusterrole.yaml new file mode 100644 index 0000000..01267f3 --- /dev/null +++ b/charts/vantage-kubernetes-agent/templates/clusterrole.yaml @@ -0,0 +1,17 @@ +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRole +metadata: + name: {{ include "vantage-kubernetes-agent.fullname" . }} + labels: + {{- include "vantage-kubernetes-agent.labels" . | nindent 4 }} + {{- with .Values.clusterRole.annotations }} + annotations: + {{- toYaml . | nindent 4 }} + {{- end }} +rules: +- apiGroups: [""] + resources: ["nodes/metrics"] + verbs: ["get"] +- apiGroups: [""] + resources: ["nodes", "pods"] + verbs: ["get", "watch", "list"] diff --git a/charts/vantage-kubernetes-agent/templates/clusterrolebinding.yaml b/charts/vantage-kubernetes-agent/templates/clusterrolebinding.yaml new file mode 100644 index 0000000..d165d8c --- /dev/null +++ b/charts/vantage-kubernetes-agent/templates/clusterrolebinding.yaml @@ -0,0 +1,18 @@ +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRoleBinding +metadata: + name: {{ include "vantage-kubernetes-agent.fullname" . }} + labels: + {{- include "vantage-kubernetes-agent.labels" . | nindent 4 }} + {{- with .Values.clusterRoleBinding.annotations }} + annotations: + {{- toYaml . | nindent 4 }} + {{- end }} +subjects: +- kind: ServiceAccount + name: {{ include "vantage-kubernetes-agent.serviceAccountName" . }} + namespace: {{ .Release.Namespace }} +roleRef: + kind: ClusterRole + name: {{ include "vantage-kubernetes-agent.fullname" . }} + apiGroup: rbac.authorization.k8s.io diff --git a/charts/vantage-kubernetes-agent/templates/secret.yaml b/charts/vantage-kubernetes-agent/templates/secret.yaml new file mode 100644 index 0000000..e82c82a --- /dev/null +++ b/charts/vantage-kubernetes-agent/templates/secret.yaml @@ -0,0 +1,10 @@ +{{- $token := .Values.agent.token | required ".Values.agent.token is required."}} +apiVersion: v1 +kind: Secret +metadata: + name: {{ include "vantage-kubernetes-agent.fullname" . }} + labels: + {{- include "vantage-kubernetes-agent.labels" . | nindent 4 }} +type: Opaque +data: + token: {{ $token | b64enc | quote }} diff --git a/charts/vantage-kubernetes-agent/templates/service.yaml b/charts/vantage-kubernetes-agent/templates/service.yaml new file mode 100644 index 0000000..a9a7e85 --- /dev/null +++ b/charts/vantage-kubernetes-agent/templates/service.yaml @@ -0,0 +1,15 @@ +apiVersion: v1 +kind: Service +metadata: + name: {{ include "vantage-kubernetes-agent.fullname" . }} + labels: + {{- include "vantage-kubernetes-agent.labels" . | nindent 4 }} +spec: + type: {{ .Values.service.type }} + ports: + - port: {{ .Values.service.port }} + targetPort: {{ .Values.service.name }} + protocol: TCP + name: {{ .Values.service.name }} + selector: + {{- include "vantage-kubernetes-agent.selectorLabels" . | nindent 4 }} diff --git a/charts/vantage-kubernetes-agent/templates/serviceaccount.yaml b/charts/vantage-kubernetes-agent/templates/serviceaccount.yaml new file mode 100644 index 0000000..99e4091 --- /dev/null +++ b/charts/vantage-kubernetes-agent/templates/serviceaccount.yaml @@ -0,0 +1,10 @@ +apiVersion: v1 +kind: ServiceAccount +metadata: + name: {{ include "vantage-kubernetes-agent.serviceAccountName" . }} + labels: + {{- include "vantage-kubernetes-agent.labels" . | nindent 4 }} + {{- with .Values.serviceAccount.annotations }} + annotations: + {{- toYaml . | nindent 4 }} + {{- end }}q diff --git a/charts/vantage-kubernetes-agent/templates/statefulset.yaml b/charts/vantage-kubernetes-agent/templates/statefulset.yaml new file mode 100644 index 0000000..dc2346f --- /dev/null +++ b/charts/vantage-kubernetes-agent/templates/statefulset.yaml @@ -0,0 +1,82 @@ +{{- $clusterID := .Values.agent.clusterID | required ".Values.clusterID.token is required."}} +apiVersion: apps/v1 +kind: StatefulSet +metadata: + name: {{ include "vantage-kubernetes-agent.fullname" . }} + labels: + {{- include "vantage-kubernetes-agent.labels" . | nindent 4 }} +spec: + replicas: 1 + serviceName: vantage-agent + selector: + matchLabels: + {{- include "vantage-kubernetes-agent.selectorLabels" . | nindent 6 }} + template: + metadata: + {{- with .Values.podAnnotations }} + annotations: + {{- toYaml . | nindent 8 }} + {{- end }} + labels: + {{- include "vantage-kubernetes-agent.selectorLabels" . | nindent 8 }} + spec: + {{- with .Values.imagePullSecrets }} + imagePullSecrets: + {{- toYaml . | nindent 8 }} + {{- end }} + serviceAccountName: {{ include "vantage-kubernetes-agent.serviceAccountName" . }} + containers: + - name: {{ .Chart.Name }} + securityContext: + {{- toYaml .Values.securityContext | nindent 12 }} + image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}" + imagePullPolicy: {{ .Values.image.pullPolicy }} + env: + - name: VANTAGE_DEBUG + value: "{{ .Values.agent.debug }}" + - name: VANTAGE_LOG_LEVEL + value: "{{ .Values.agent.logLevel }}" + - name: VANTAGE_CLUSTER_ID + value: "{{ $clusterID }}" + - name: VANTAGE_API_TOKEN + valueFrom: + secretKeyRef: + name: {{ include "vantage-kubernetes-agent.fullname" . }} + key: token + {{- with .Values.agent.apiHost }} + - name: VANTAGE_API_HOST + value: "{{ . }}" + {{ end }} + {{- with .Values.persist }} + - name: VANTAGE_PERSIST_DIR + value: "{{ .mountPath }}" + {{ end }} + ports: + - name: {{ .Values.service.name }} + containerPort: {{ .Values.service.port }} + protocol: TCP + livenessProbe: + httpGet: + path: /healthz + port: {{ .Values.service.name }} + readinessProbe: + httpGet: + path: /healthz + port: {{ .Values.service.name }} + resources: + {{- toYaml .Values.resources | nindent 12 }} + {{- with .Values.persist }} + volumeMounts: + - name: {{ .name }} + mountPath: {{ .mountPath }} + {{ end }} + {{- with .Values.persist }} + volumeClaimTemplates: + - metadata: + name: {{ .name }} + spec: + accessModes: [ "ReadWriteOnce" ] + resources: + requests: + storage: {{ .size }} + {{ end }} diff --git a/charts/vantage-kubernetes-agent/templates/tests/test-connection.yaml b/charts/vantage-kubernetes-agent/templates/tests/test-connection.yaml new file mode 100644 index 0000000..871038a --- /dev/null +++ b/charts/vantage-kubernetes-agent/templates/tests/test-connection.yaml @@ -0,0 +1,15 @@ +apiVersion: v1 +kind: Pod +metadata: + name: "{{ include "vantage-kubernetes-agent.fullname" . }}-test-connection" + labels: + {{- include "vantage-kubernetes-agent.labels" . | nindent 4 }} + annotations: + "helm.sh/hook": test +spec: + containers: + - name: wget + image: busybox + command: ['wget'] + args: ['{{ include "vantage-kubernetes-agent.fullname" . }}:{{ .Values.service.port }}'] + restartPolicy: Never diff --git a/charts/vantage-kubernetes-agent/values.yaml b/charts/vantage-kubernetes-agent/values.yaml new file mode 100644 index 0000000..c9df2b9 --- /dev/null +++ b/charts/vantage-kubernetes-agent/values.yaml @@ -0,0 +1,62 @@ +# Default values for vantage-kubernetes-agent. +# This is a YAML-formatted file. +# Declare variables to be passed into your templates. + +image: + repository: "quay.io/vantage-sh/kubernetes-agent" + pullPolicy: IfNotPresent + # Overrides the image tag whose default is the chart appVersion. + tag: "" + +agent: + debug: false + # logLevel corresponds to https://pkg.go.dev/log/slog#Level + # Info: 0 + # Debug: -4 + logLevel: "0" + # Unique identifier for your cluster. + clusterID: "" + # Vantage API Token + token: "" + +persist: + mountPath: "/var/lib/vantage-agent" + name: "data" + size: "10Gi" + +service: + name: report + type: ClusterIP + port: 9010 + +resources: + limits: + cpu: 10m + memory: 50Mi + requests: + cpu: 10m + memory: 50Mi + + +imagePullSecrets: [] +nameOverride: "" +fullnameOverride: "" + + +serviceAccount: + 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: "" + +clusterRole: + annotations: {} +clusterRoleBinding: + annotations: {} + +podAnnotations: {} +podSecurityContext: {} +securityContext: {} +nodeSelector: {} +tolerations: [] +affinity: {}