diff --git a/.github/workflows/helm-release.yml b/.github/workflows/helm-release.yml new file mode 100644 index 0000000..e88114f --- /dev/null +++ b/.github/workflows/helm-release.yml @@ -0,0 +1,48 @@ +name: Build and Release Helm Chart + +on: + push: + branches: + - main + pull_request: + branches: + - main + +jobs: + build-and-release: + name: Build and Release Helm Chart to GitHub Registry + runs-on: ubuntu-latest + + steps: + # Checkout the repository + - name: Checkout code + uses: actions/checkout@v4 + + # Set up Helm + - name: Set up Helm + uses: azure/setup-helm@v4.2.0 + + # Log in to GitHub Container Registry + - name: Log in to GitHub Container Registry + run: | + echo ${{ secrets.GITHUB_TOKEN }} | helm registry login ghcr.io --username ${{ github.actor }} --password-stdin + + # Package the Helm chart + - name: Package Helm chart + run: | + helm package ./charts/homer-operator -d ./artifacts + + # Push Helm chart to GitHub Container Registry + - name: Push Helm chart to GitHub Registry + run: | + CHART_NAME=$(ls ./artifacts | grep .tgz) + helm push ./artifacts/$CHART_NAME oci://ghcr.io/${{ github.repository_owner }}/homer-operator + + # Optionally, create a GitHub release + - name: Create GitHub release + if: github.ref == 'refs/heads/main' + uses: softprops/action-gh-release@v2 + with: + files: ./artifacts/*.tgz + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.gitignore b/.gitignore index 63d5497..8b1f09b 100644 --- a/.gitignore +++ b/.gitignore @@ -25,3 +25,5 @@ go.work.sum .env /homer-operator + +*.tgz diff --git a/charts/homer-operator/.helmignore b/charts/homer-operator/.helmignore new file mode 100644 index 0000000..0e8a0eb --- /dev/null +++ b/charts/homer-operator/.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/charts/homer-operator/Chart.yaml b/charts/homer-operator/Chart.yaml new file mode 100644 index 0000000..8b37f41 --- /dev/null +++ b/charts/homer-operator/Chart.yaml @@ -0,0 +1,24 @@ +apiVersion: v2 +name: homer-operator +description: A Helm chart for Kubernetes + +# 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: 0.1.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: "latest" diff --git a/charts/homer-operator/templates/_helpers.tpl b/charts/homer-operator/templates/_helpers.tpl new file mode 100644 index 0000000..ee3afc6 --- /dev/null +++ b/charts/homer-operator/templates/_helpers.tpl @@ -0,0 +1,62 @@ +{{/* +Expand the name of the chart. +*/}} +{{- define "homer-operator.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 "homer-operator.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 "homer-operator.chart" -}} +{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }} +{{- end }} + +{{/* +Common labels +*/}} +{{- define "homer-operator.labels" -}} +helm.sh/chart: {{ include "homer-operator.chart" . }} +{{ include "homer-operator.selectorLabels" . }} +{{- if .Chart.AppVersion }} +app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} +{{- end }} +app.kubernetes.io/managed-by: {{ .Release.Service }} +{{- end }} + +{{/* +Selector labels +*/}} +{{- define "homer-operator.selectorLabels" -}} +app.kubernetes.io/name: {{ include "homer-operator.name" . }} +app.kubernetes.io/instance: {{ .Release.Name }} +{{- end }} + +{{/* +Create the name of the service account to use +*/}} +{{- define "homer-operator.serviceAccountName" -}} +{{- if .Values.serviceAccount.create }} +{{- default (include "homer-operator.fullname" .) .Values.serviceAccount.name }} +{{- else }} +{{- default "default" .Values.serviceAccount.name }} +{{- end }} +{{- end }} diff --git a/charts/homer-operator/templates/configmap.yaml b/charts/homer-operator/templates/configmap.yaml new file mode 100644 index 0000000..92f612c --- /dev/null +++ b/charts/homer-operator/templates/configmap.yaml @@ -0,0 +1,10 @@ +apiVersion: v1 +kind: ConfigMap +metadata: + name: {{ include "homer-operator.fullname" . }} + namespace: {{ .Release.Namespace }} + labels: + {{- include "homer-operator.labels" . | nindent 4 }} +data: + base_config.yml: |- +{{ .Values.baseConfig | indent 4 }} diff --git a/charts/homer-operator/templates/deployment.yaml b/charts/homer-operator/templates/deployment.yaml new file mode 100644 index 0000000..56d5905 --- /dev/null +++ b/charts/homer-operator/templates/deployment.yaml @@ -0,0 +1,66 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: {{ include "homer-operator.fullname" . }} + namespace: {{ .Release.Namespace }} + labels: + {{- include "homer-operator.labels" . | nindent 4 }} +spec: + replicas: {{ .Values.replicaCount }} + selector: + matchLabels: + {{- include "homer-operator.selectorLabels" . | nindent 6 }} + template: + metadata: + {{- with .Values.podAnnotations }} + annotations: + {{- toYaml . | nindent 8 }} + {{- end }} + labels: + {{- include "homer-operator.labels" . | nindent 8 }} + {{- with .Values.podLabels }} + {{- toYaml . | nindent 8 }} + {{- end }} + spec: + {{- with .Values.imagePullSecrets }} + imagePullSecrets: + {{- toYaml . | nindent 8 }} + {{- end }} + serviceAccountName: {{ include "homer-operator.serviceAccountName" . }} + securityContext: + {{- toYaml .Values.podSecurityContext | nindent 8 }} + containers: + - name: {{ .Chart.Name }} + securityContext: + {{- toYaml .Values.securityContext | nindent 12 }} + image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}" + imagePullPolicy: {{ .Values.image.pullPolicy }} + ports: + - name: http + containerPort: 8080 + protocol: TCP + livenessProbe: + {{- toYaml .Values.livenessProbe | nindent 12 }} + readinessProbe: + {{- toYaml .Values.readinessProbe | nindent 12 }} + resources: + {{- toYaml .Values.resources | nindent 12 }} + volumeMounts: + - name: base-config + mountPath: /www/assets/base_config.yml + volumes: + - name: base-config + configMap: + name: {{ include "homer-operator.fullname" . }} + {{- with .Values.nodeSelector }} + nodeSelector: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.affinity }} + affinity: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.tolerations }} + tolerations: + {{- toYaml . | nindent 8 }} + {{- end }} diff --git a/charts/homer-operator/templates/ingress.yaml b/charts/homer-operator/templates/ingress.yaml new file mode 100644 index 0000000..91e2f1e --- /dev/null +++ b/charts/homer-operator/templates/ingress.yaml @@ -0,0 +1,44 @@ +{{- if .Values.ingress.enabled -}} +apiVersion: networking.k8s.io/v1 +kind: Ingress +metadata: + name: {{ include "homer-operator.fullname" . }} + namespace: {{ .Release.Namespace }} + labels: + {{- include "homer-operator.labels" . | nindent 4 }} + {{- with .Values.ingress.annotations }} + annotations: + {{- toYaml . | nindent 4 }} + {{- end }} +spec: + {{- with .Values.ingress.className }} + ingressClassName: {{ . }} + {{- end }} + {{- if .Values.ingress.tls }} + tls: + {{- range .Values.ingress.tls }} + - hosts: + {{- range .hosts }} + - {{ . | quote }} + {{- end }} + secretName: {{ .secretName }} + {{- end }} + {{- end }} + rules: + {{- range .Values.ingress.hosts }} + - host: {{ .host | quote }} + http: + paths: + {{- range .paths }} + - path: {{ .path }} + {{- with .pathType }} + pathType: {{ . }} + {{- end }} + backend: + service: + name: {{ include "homer-operator.fullname" $ }} + port: + number: 8080 + {{- end }} + {{- end }} +{{- end }} diff --git a/charts/homer-operator/templates/role.yaml b/charts/homer-operator/templates/role.yaml new file mode 100644 index 0000000..b2ac075 --- /dev/null +++ b/charts/homer-operator/templates/role.yaml @@ -0,0 +1,11 @@ +apiVersion: rbac.authorization.k8s.io/v1 +kind: Role +metadata: + name: {{ include "homer-operator.serviceAccountName" . }} + namespace: {{ .Release.Namespace }} + labels: + {{- include "homer-operator.labels" . | nindent 4 }} +rules: + - apiGroups: ["networking.k8s.io"] + resources: ["ingresses"] + verbs: ["get", "list", "watch"] diff --git a/charts/homer-operator/templates/rolebinding.yaml b/charts/homer-operator/templates/rolebinding.yaml new file mode 100644 index 0000000..525272a --- /dev/null +++ b/charts/homer-operator/templates/rolebinding.yaml @@ -0,0 +1,14 @@ +apiVersion: rbac.authorization.k8s.io/v1 +kind: RoleBinding +metadata: + name: {{ include "homer-operator.serviceAccountName" . }} + namespace: {{ .Release.Namespace }} + labels: + {{- include "homer-operator.labels" . | nindent 4 }} +roleRef: + apiGroup: rbac.authorization.k8s.io + kind: Role + name: {{ include "homer-operator.serviceAccountName" . }} +subjects: + - kind: ServiceAccount + name: {{ include "homer-operator.serviceAccountName" . }} diff --git a/charts/homer-operator/templates/service.yaml b/charts/homer-operator/templates/service.yaml new file mode 100644 index 0000000..e6ca42e --- /dev/null +++ b/charts/homer-operator/templates/service.yaml @@ -0,0 +1,16 @@ +apiVersion: v1 +kind: Service +metadata: + name: {{ include "homer-operator.fullname" . }} + namespace: {{ .Release.Namespace }} + labels: + {{- include "homer-operator.labels" . | nindent 4 }} +spec: + type: {{ .Values.service.type }} + ports: + - port: 8080 + targetPort: http + protocol: TCP + name: http + selector: + {{- include "homer-operator.selectorLabels" . | nindent 4 }} diff --git a/charts/homer-operator/templates/serviceaccount.yaml b/charts/homer-operator/templates/serviceaccount.yaml new file mode 100644 index 0000000..372ba92 --- /dev/null +++ b/charts/homer-operator/templates/serviceaccount.yaml @@ -0,0 +1,12 @@ +apiVersion: v1 +kind: ServiceAccount +metadata: + name: {{ include "homer-operator.fullname" . }} + namespace: {{ .Release.Namespace }} + labels: + {{- include "homer-operator.labels" . | nindent 4 }} + {{- with .Values.serviceAccount.annotations }} + annotations: + {{- toYaml . | nindent 4 }} + {{- end }} +automountServiceAccountToken: {{ .Values.serviceAccount.automount }} diff --git a/charts/homer-operator/values.yaml b/charts/homer-operator/values.yaml new file mode 100644 index 0000000..a7efb93 --- /dev/null +++ b/charts/homer-operator/values.yaml @@ -0,0 +1,99 @@ +# Default values for homer-operator. +# This is a YAML-formatted file. +# Declare variables to be passed into your templates. + +# This will set the replicaset count more information can be found here: https://kubernetes.io/docs/concepts/workloads/controllers/replicaset/ +replicaCount: 1 + +# This sets the container image more information can be found here: https://kubernetes.io/docs/concepts/containers/images/ +image: + repository: ghcr.io/arch-anes/homer-operator + # This sets the pull policy for images. + pullPolicy: Always + # Overrides the image tag whose default is the chart appVersion. + tag: "" + +# This is for the secretes for pulling an image from a private repository more information can be found here: https://kubernetes.io/docs/tasks/configure-pod-container/pull-image-private-registry/ +imagePullSecrets: [] +# This is to override the chart name. +nameOverride: "" +fullnameOverride: "" + +baseConfig: |- + # Add your base homer config here + # ref: https://github.com/bastienwirtz/homer/blob/main/docs/configuration.md + +#This section builds out the service account more information can be found here: https://kubernetes.io/docs/concepts/security/service-accounts/ +serviceAccount: + # Automatically mount a ServiceAccount's API credentials? + automount: true + # Annotations to add to the service account + annotations: {} + +# This is for setting Kubernetes Annotations to a Pod. +# For more information checkout: https://kubernetes.io/docs/concepts/overview/working-with-objects/annotations/ +podAnnotations: {} +# This is for setting Kubernetes Labels to a Pod. +# For more information checkout: https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/ +podLabels: {} + +podSecurityContext: {} + # fsGroup: 2000 + +securityContext: {} + # capabilities: + # drop: + # - ALL + # readOnlyRootFilesystem: true + # runAsNonRoot: true + # runAsUser: 1000 + +# This is for setting up a service more information can be found here: https://kubernetes.io/docs/concepts/services-networking/service/ +service: + # This sets the service type more information can be found here: https://kubernetes.io/docs/concepts/services-networking/service/#publishing-services-service-types + type: ClusterIP + +# This block is for setting up the ingress for more information can be found here: https://kubernetes.io/docs/concepts/services-networking/ingress/ +ingress: + enabled: false + className: "" + annotations: {} + # kubernetes.io/ingress.class: nginx + # kubernetes.io/tls-acme: "true" + hosts: + - host: chart-example.local + paths: + - path: / + pathType: ImplementationSpecific + tls: [] + # - secretName: chart-example-tls + # hosts: + # - chart-example.local + +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 + +# This is to setup the liveness and readiness probes more information can be found here: https://kubernetes.io/docs/tasks/configure-pod-container/configure-liveness-readiness-startup-probes/ +livenessProbe: + httpGet: + path: / + port: http +readinessProbe: + httpGet: + path: / + port: http + +nodeSelector: {} + +tolerations: [] + +affinity: {}