diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..5ace460 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,6 @@ +version: 2 +updates: + - package-ecosystem: "github-actions" + directory: "/" + schedule: + interval: "weekly" diff --git a/.github/workflows/lint-test.yml b/.github/workflows/lint-test.yml index f9412b5..0bd5f26 100644 --- a/.github/workflows/lint-test.yml +++ b/.github/workflows/lint-test.yml @@ -7,7 +7,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout - uses: actions/checkout@v6 + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # 7.0.1 with: fetch-depth: 0 # This prepares directory where github/codeql-action/upload-sarif@v1 looks up report files by default. @@ -16,7 +16,7 @@ jobs: run: mkdir -p ../results - name: Scan yaml files with kube-linter - uses: stackrox/kube-linter-action@v1.0.7 + uses: stackrox/kube-linter-action@87802a2f4e01abebb3ee3c67a3002fea71f6eae5 # 1.0.7 id: kube-linter-action-scan with: # Adjust this directory to the location where your kubernetes resources and helm charts are located. @@ -28,7 +28,7 @@ jobs: continue-on-error: true - name: Upload SARIF report files to GitHub - uses: github/codeql-action/upload-sarif@v4 + uses: github/codeql-action/upload-sarif@e4fba868fa4b1b91e1fdab776edc8cfbe6e9fb81 #4.73.3 # Ensure the workflow eventually fails if files did not pass kube-linter checks. - name: Verify kube-linter-action succeeded @@ -40,23 +40,23 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout - uses: actions/checkout@v6 + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # 7.0.1 with: fetch-depth: 0 - name: Set up Helm - uses: azure/setup-helm@v4.3.1 + uses: azure/setup-helm@9bc31f4ebc9c6b171d7bfbaa5d006ae7abdb4310 # 5.0.1 with: version: v3.17.0 - - uses: actions/setup-python@v6.2.0 + - uses: actions/setup-python@5fda3b95a4ea91299a34e894583c3862153e4b97 # 7.0.0 with: python-version: "3.x" check-latest: true # https://github.com/helm/chart-testing-action - name: Set up chart-testing - uses: helm/chart-testing-action@v2.8.0 + uses: helm/chart-testing-action@6ec842c01de15ebb84c8627d2744a0c2f2755c9f # 2.8.0 - name: Run chart-testing (list-changed) id: list-changed @@ -72,8 +72,33 @@ jobs: - name: Create kind cluster if: steps.list-changed.outputs.changed == 'true' - uses: helm/kind-action@v1.12.0 + uses: helm/kind-action@ef37e7f390d99f746eb8b610417061a60e82a6cc # v1.14.0 + + - name: Create Namespace and Env + run: | + kubectl create namespace ct-tests + kubectl create secret generic orthos2 \ + --from-literal=NetboxToken='nbt_zs4YYi6Uo6IN.3qoyyTHhBugnUlPtwrMT9XfDgtvFPToyOiuQ9GHN' \ + --from-literal=OIDCsecret='C8e10s83w6mWl46im3jX9XhzjwcRQ7DyamWFKPLOvVLeG3crBy86LbFjueqJ269yo7S7MoQP7xmZ33q4!' \ + --from-literal=OrthosKey='xx3%7wbay2723)xqfhe+w$f5sj4z9!d&chlx7av%^15da$$w*b!' \ + --namespace=ct-tests + kubectl create configmap orthos2-env \ + --from-literal=ORTHOS2_NETBOX_AUTH_SCHEME=Bearer \ + --from-literal=ORTHOS2_NETBOX_URL=http://netbox.orthos2.test:8081 \ + --from-literal=ORTHOS2_SUPERUSER_PASSWORD=QGIzDq5RVYoP \ + --from-literal=ORTHOS2_DB_ENGINE=django.db.backends.sqlite3 \ + --from-literal=ALLOWED_HOSTS="orthos2 orthos.local localhost" \ + --from-literal=CSRF_TRUSTED_ORIGINS=https://orthos2.orthos2.test \ + --from-literal=CSRF_ALLOWED_ORIGIN=https://orthos2.orthos2.test \ + --from-literal=CROSS_ORIGINS_WHITELIST=https://orthos2.orthos2.test \ + --from-literal=OIDC_ENDPOINT=https://authentik.orthos2.test/application/o/orthos \ + --from-literal=NETBOX_SUPERUSER_NAME=admin \ + --from-literal=NETBOX_SUPERUSER_PASSWORD=K2jPoo7eKfad \ + --namespace=ct-tests - name: Run chart-testing (install) if: steps.list-changed.outputs.changed == 'true' - run: ct install --target-branch ${{ github.event.repository.default_branch }} + run: | + ct install \ + --target-branch ${{ github.event.repository.default_branch }} \ + --namespace ct-tests diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index a0fb5d0..b094d1b 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -12,7 +12,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout - uses: actions/checkout@v6 + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # 7.0.1 with: fetch-depth: 0 @@ -23,6 +23,6 @@ jobs: # https://github.com/helm/chart-releaser-action - name: Run chart-releaser - uses: helm/chart-releaser-action@v1.7.0 + uses: helm/chart-releaser-action@cae68fefc6b5f367a0275617c9f83181ba54714f # 1.7.0 env: CR_TOKEN: "${{ secrets.GITHUB_TOKEN }}" diff --git a/.gitignore b/.gitignore index 617acbb..22eab11 100644 --- a/.gitignore +++ b/.gitignore @@ -15,3 +15,10 @@ #Ignore vscode AI rules .github/instructions/codacy.instructions.md + +#Ignore ENV files +.env + +#Ignore files for local actions runner +.actrc +event.json diff --git a/charts/orthos2/.helmignore b/charts/orthos2/.helmignore new file mode 100644 index 0000000..0e8a0eb --- /dev/null +++ b/charts/orthos2/.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/orthos2/Chart.yaml b/charts/orthos2/Chart.yaml new file mode 100644 index 0000000..ae74c78 --- /dev/null +++ b/charts/orthos2/Chart.yaml @@ -0,0 +1,10 @@ +apiVersion: v2 +name: orthos2 +description: A Helm chart for Kubernetes +type: application +version: 0.1.0 +appVersion: "1.13.0" +maintainers: + - name: SchoolGuy + email: matrixfueller@gmail.com + url: https://github.com/SchoolGuy diff --git a/charts/orthos2/configmap/.env.example b/charts/orthos2/configmap/.env.example new file mode 100644 index 0000000..32e0e57 --- /dev/null +++ b/charts/orthos2/configmap/.env.example @@ -0,0 +1,11 @@ +ORTHOS2_NETBOX_AUTH_SCHEME= +ORTHOS2_NETBOX_URL= +ORTHOS2_SUPERUSER_PASSWORD= +ORTHOS2_DB_ENGINE= +ALLOWED_HOSTS= +CSRF_TRUSTED_ORIGINS= +CSRF_ALLOWED_ORIGIN= +CROSS_ORIGINS_WHITELIST= +OIDC_ENDPOINT= +NETBOX_SUPERUSER_NAME= +NETBOX_SUPERUSER_PASSWORD= diff --git a/charts/orthos2/templates/NOTES.txt b/charts/orthos2/templates/NOTES.txt new file mode 100644 index 0000000..81511c6 --- /dev/null +++ b/charts/orthos2/templates/NOTES.txt @@ -0,0 +1,35 @@ +1. Get the application URL by running these commands: +{{- if .Values.httpRoute.enabled }} +{{- if .Values.httpRoute.hostnames }} + export APP_HOSTNAME={{ .Values.httpRoute.hostnames | first }} +{{- else }} + export APP_HOSTNAME=$(kubectl get --namespace {{(first .Values.httpRoute.parentRefs).namespace | default .Release.Namespace }} gateway/{{ (first .Values.httpRoute.parentRefs).name }} -o jsonpath="{.spec.listeners[0].hostname}") + {{- end }} +{{- if and .Values.httpRoute.rules (first .Values.httpRoute.rules).matches (first (first .Values.httpRoute.rules).matches).path.value }} + echo "Visit http://$APP_HOSTNAME{{ (first (first .Values.httpRoute.rules).matches).path.value }} to use your application" + + NOTE: Your HTTPRoute depends on the listener configuration of your gateway and your HTTPRoute rules. + The rules can be set for path, method, header and query parameters. + You can check the gateway configuration with 'kubectl get --namespace {{(first .Values.httpRoute.parentRefs).namespace | default .Release.Namespace }} gateway/{{ (first .Values.httpRoute.parentRefs).name }} -o yaml' +{{- end }} +{{- else if .Values.ingress.enabled }} +{{- range $host := .Values.ingress.hosts }} + {{- range .paths }} + http{{ if $.Values.ingress.tls }}s{{ end }}://{{ $host.host }}{{ .path }} + {{- end }} +{{- end }} +{{- else if contains "NodePort" .Values.service.type }} + export NODE_PORT=$(kubectl get --namespace {{ .Release.Namespace }} -o jsonpath="{.spec.ports[0].nodePort}" services {{ include "orthos2.fullname" . }}) + export NODE_IP=$(kubectl get nodes --namespace {{ .Release.Namespace }} -o jsonpath="{.items[0].status.addresses[0].address}") + echo http://$NODE_IP:$NODE_PORT +{{- else if contains "LoadBalancer" .Values.service.type }} + NOTE: It may take a few minutes for the LoadBalancer IP to be available. + You can watch its status by running 'kubectl get --namespace {{ .Release.Namespace }} svc -w {{ include "orthos2.fullname" . }}' + export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ include "orthos2.fullname" . }} --template "{{"{{ range (index .status.loadBalancer.ingress 0) }}{{.}}{{ end }}"}}") + echo http://$SERVICE_IP:{{ .Values.service.port }} +{{- else if contains "ClusterIP" .Values.service.type }} + export POD_NAME=$(kubectl get pods --namespace {{ .Release.Namespace }} -l "app.kubernetes.io/name={{ include "orthos2.name" . }},app.kubernetes.io/instance={{ .Release.Name }}" -o jsonpath="{.items[0].metadata.name}") + export CONTAINER_PORT=$(kubectl get pod --namespace {{ .Release.Namespace }} $POD_NAME -o jsonpath="{.spec.containers[0].ports[0].containerPort}") + echo "Visit http://127.0.0.1:8080 to use your application" + kubectl --namespace {{ .Release.Namespace }} port-forward $POD_NAME 8080:$CONTAINER_PORT +{{- end }} diff --git a/charts/orthos2/templates/_helpers.tpl b/charts/orthos2/templates/_helpers.tpl new file mode 100644 index 0000000..03faadd --- /dev/null +++ b/charts/orthos2/templates/_helpers.tpl @@ -0,0 +1,62 @@ +{{/* +Expand the name of the chart. +*/}} +{{- define "orthos2.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 "orthos2.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 "orthos2.chart" -}} +{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }} +{{- end }} + +{{/* +Common labels +*/}} +{{- define "orthos2.labels" -}} +helm.sh/chart: {{ include "orthos2.chart" . }} +{{ include "orthos2.selectorLabels" . }} +{{- if .Chart.AppVersion }} +app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} +{{- end }} +app.kubernetes.io/managed-by: {{ .Release.Service }} +{{- end }} + +{{/* +Selector labels +*/}} +{{- define "orthos2.selectorLabels" -}} +app.kubernetes.io/name: {{ include "orthos2.name" . }} +app.kubernetes.io/instance: {{ .Release.Name }} +{{- end }} + +{{/* +Create the name of the service account to use +*/}} +{{- define "orthos2.serviceAccountName" -}} +{{- if .Values.serviceAccount.create }} +{{- default (include "orthos2.fullname" .) .Values.serviceAccount.name }} +{{- else }} +{{- default "default" .Values.serviceAccount.name }} +{{- end }} +{{- end }} diff --git a/charts/orthos2/templates/deployment.yaml b/charts/orthos2/templates/deployment.yaml new file mode 100644 index 0000000..635f540 --- /dev/null +++ b/charts/orthos2/templates/deployment.yaml @@ -0,0 +1,263 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: {{ include "orthos2.fullname" . }} + labels: + {{- include "orthos2.labels" . | nindent 4 }} +spec: + {{- if not .Values.autoscaling.enabled }} + replicas: {{ .Values.replicaCount }} + {{- end }} + selector: + matchLabels: + {{- include "orthos2.selectorLabels" . | nindent 6 }} + template: + metadata: + {{- with .Values.podAnnotations }} + annotations: + {{- toYaml . | nindent 8 }} + {{- end }} + labels: + {{- include "orthos2.labels" . | nindent 8 }} + {{- with .Values.podLabels }} + {{- toYaml . | nindent 8 }} + {{- end }} + spec: + restartPolicy: Always + {{- with .Values.imagePullSecrets }} + imagePullSecrets: + {{- toYaml . | nindent 8 }} + {{- end }} + serviceAccountName: {{ include "orthos2.serviceAccountName" . }} + containers: + - name: {{ .Chart.Name }} + {{- with .Values.securityContext }} + securityContext: + {{- toYaml . | nindent 12 }} + {{- end }} + image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}" + imagePullPolicy: {{ .Values.image.pullPolicy }} + envFrom: + - configMapRef: + name: orthos2-env + ports: + - name: http + containerPort: {{ .Values.service.port }} + protocol: TCP + startupProbe: + httpGet: + path: / + port: http + httpHeaders: + - name: Host + value: localhost + failureThreshold: 30 + periodSeconds: 2 + {{- with .Values.livenessProbe }} + livenessProbe: + {{- toYaml . | nindent 12 }} + {{- end }} + {{- with .Values.readinessProbe }} + readinessProbe: + {{- toYaml . | nindent 12 }} + {{- end }} + {{- with .Values.resources }} + resources: + {{- toYaml . | nindent 12 }} + {{- end }} + {{- with .Values.volumeMounts }} + volumeMounts: + {{- toYaml . | nindent 12 }} + {{- end }} + {{- with .Values.volumes }} + volumes: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.nodeSelector }} + nodeSelector: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.affinity }} + affinity: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.tolerations }} + tolerations: + {{- toYaml . | nindent 8 }} + {{- end }} +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + name: {{ include "orthos2.fullname" . }}-taskmanager + labels: + {{- include "orthos2.labels" . | nindent 4 }} + app-component: taskmanager +spec: + {{- if not .Values.autoscaling.enabled }} + replicas: {{ .Values.replicaCount }} + {{- end }} + selector: + matchLabels: + {{- include "orthos2.selectorLabels" . | nindent 6 }} + app-component: taskmanager + template: + metadata: + {{- with .Values.podAnnotations }} + annotations: + {{- toYaml . | nindent 8 }} + {{- end }} + labels: + {{- include "orthos2.labels" . | nindent 8 }} + app-component: taskmanager + {{- with .Values.podLabels }} + {{- toYaml . | nindent 8 }} + {{- end }} + spec: + restartPolicy: Always + {{- with .Values.imagePullSecrets }} + imagePullSecrets: + {{- toYaml . | nindent 8 }} + {{- end }} + serviceAccountName: {{ include "orthos2.serviceAccountName" . }} + containers: + - name: {{ .Chart.Name }}-taskmanager + {{- with .Values.securityContext }} + securityContext: + {{- toYaml . | nindent 12 }} + {{- end }} + image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}" + imagePullPolicy: {{ .Values.image.pullPolicy }} + envFrom: + - configMapRef: + name: orthos2-env + ports: + - name: http + containerPort: {{ .Values.service.port }} + protocol: TCP + startupProbe: + httpGet: + path: / + port: http + httpHeaders: + - name: Host + value: localhost + failureThreshold: 30 + periodSeconds: 2 + {{- with .Values.livenessProbe }} + livenessProbe: + {{- toYaml . | nindent 12 }} + {{- end }} + {{- with .Values.readinessProbe }} + readinessProbe: + {{- toYaml . | nindent 12 }} + {{- end }} + {{- with .Values.resources }} + resources: + {{- toYaml . | nindent 12 }} + {{- end }} + {{- with .Values.volumeMounts }} + volumeMounts: + {{- toYaml . | nindent 12 }} + {{- end }} + {{- with .Values.volumes }} + volumes: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.nodeSelector }} + nodeSelector: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.affinity }} + affinity: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.tolerations }} + tolerations: + {{- toYaml . | nindent 8 }} + {{- end }} +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + annotations: + ignore-check.kube-linter.io/run-as-non-root: "nginx upstream not configured for non-root execution" + ignore-check.kube-linter.io/privileged-ports: "nginx upstream not configured for non-root execution" + name: {{ include "orthos2.fullname" . }}-static + labels: + {{- include "orthos2.labels" . | nindent 4 }} + app-component: static +spec: + {{- if not .Values.autoscaling.enabled }} + replicas: {{ .Values.replicaCount }} + {{- end }} + selector: + matchLabels: + {{- include "orthos2.selectorLabels" . | nindent 6 }} + app-component: static + template: + metadata: + labels: + {{- include "orthos2.labels" . | nindent 8 }} + app-component: static + {{- with .Values.podLabels }} + {{- toYaml . | nindent 8 }} + {{- end }} + spec: + restartPolicy: Always + {{- with .Values.imagePullSecrets }} + imagePullSecrets: + {{- toYaml . | nindent 8 }} + {{- end }} + serviceAccountName: {{ include "orthos2.serviceAccountName" . }} + containers: + - name: {{ .Chart.Name }}-static + securityContext: + readOnlyRootFilesystem: true + image: "{{ .Values.image.repositoryStatic }}:{{ .Values.image.tag | default .Chart.AppVersion }}" + imagePullPolicy: {{ .Values.image.pullPolicy }} + ports: + - name: static-http + containerPort: 80 + protocol: TCP + startupProbe: + httpGet: + path: / + port: 80 + httpHeaders: + - name: Host + value: localhost + failureThreshold: 30 + periodSeconds: 2 + livenessProbe: + httpGet: + path: / + port: 80 + readinessProbe: + httpGet: + path: / + port: 80 + {{- with .Values.resources }} + resources: + {{- toYaml . | nindent 12 }} + {{- end }} + {{- with .Values.volumeMounts }} + volumeMounts: + {{- toYaml . | nindent 12 }} + {{- end }} + {{- with .Values.volumes }} + volumes: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- 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/orthos2/templates/hpa.yaml b/charts/orthos2/templates/hpa.yaml new file mode 100644 index 0000000..710bfcd --- /dev/null +++ b/charts/orthos2/templates/hpa.yaml @@ -0,0 +1,32 @@ +{{- if .Values.autoscaling.enabled }} +apiVersion: autoscaling/v2 +kind: HorizontalPodAutoscaler +metadata: + name: {{ include "orthos2.fullname" . }} + labels: + {{- include "orthos2.labels" . | nindent 4 }} +spec: + scaleTargetRef: + apiVersion: apps/v1 + kind: Deployment + name: {{ include "orthos2.fullname" . }} + minReplicas: {{ .Values.autoscaling.minReplicas }} + maxReplicas: {{ .Values.autoscaling.maxReplicas }} + metrics: + {{- 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 }} diff --git a/charts/orthos2/templates/httproute.yaml b/charts/orthos2/templates/httproute.yaml new file mode 100644 index 0000000..bd91afe --- /dev/null +++ b/charts/orthos2/templates/httproute.yaml @@ -0,0 +1,38 @@ +{{- if .Values.httpRoute.enabled -}} +{{- $fullName := include "orthos2.fullname" . -}} +{{- $svcPort := .Values.service.port -}} +apiVersion: gateway.networking.k8s.io/v1 +kind: HTTPRoute +metadata: + name: {{ $fullName }} + labels: + {{- include "orthos2.labels" . | nindent 4 }} + {{- with .Values.httpRoute.annotations }} + annotations: + {{- toYaml . | nindent 4 }} + {{- end }} +spec: + parentRefs: + {{- with .Values.httpRoute.parentRefs }} + {{- toYaml . | nindent 4 }} + {{- end }} + {{- with .Values.httpRoute.hostnames }} + hostnames: + {{- toYaml . | nindent 4 }} + {{- end }} + rules: + {{- range .Values.httpRoute.rules }} + {{- with .matches }} + - matches: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .filters }} + filters: + {{- toYaml . | nindent 8 }} + {{- end }} + backendRefs: + - name: {{ $fullName }} + port: {{ $svcPort }} + weight: 1 + {{- end }} +{{- end }} diff --git a/charts/orthos2/templates/ingress.yaml b/charts/orthos2/templates/ingress.yaml new file mode 100644 index 0000000..9c8bb27 --- /dev/null +++ b/charts/orthos2/templates/ingress.yaml @@ -0,0 +1,43 @@ +{{- if .Values.ingress.enabled -}} +apiVersion: networking.k8s.io/v1 +kind: Ingress +metadata: + name: {{ include "orthos2.fullname" . }} + labels: + {{- include "orthos2.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 "orthos2.fullname" $ }} + port: + number: {{ .port | default $.Values.service.port }} + {{- end }} + {{- end }} +{{- end }} diff --git a/charts/orthos2/templates/service.yaml b/charts/orthos2/templates/service.yaml new file mode 100644 index 0000000..aa0fd05 --- /dev/null +++ b/charts/orthos2/templates/service.yaml @@ -0,0 +1,19 @@ +apiVersion: v1 +kind: Service +metadata: + name: {{ include "orthos2.fullname" . }} + labels: + {{- include "orthos2.labels" . | nindent 4 }} +spec: + type: {{ .Values.service.type }} + ports: + - port: {{ .Values.service.port }} + targetPort: http + protocol: TCP + name: http + - port: 80 + targetPort: 80 + protocol: TCP + name: static + selector: + {{- include "orthos2.selectorLabels" . | nindent 4 }} diff --git a/charts/orthos2/templates/serviceaccount.yaml b/charts/orthos2/templates/serviceaccount.yaml new file mode 100644 index 0000000..03a183f --- /dev/null +++ b/charts/orthos2/templates/serviceaccount.yaml @@ -0,0 +1,13 @@ +{{- if .Values.serviceAccount.create -}} +apiVersion: v1 +kind: ServiceAccount +metadata: + name: {{ include "orthos2.serviceAccountName" . }} + labels: + {{- include "orthos2.labels" . | nindent 4 }} + {{- with .Values.serviceAccount.annotations }} + annotations: + {{- toYaml . | nindent 4 }} + {{- end }} +automountServiceAccountToken: {{ .Values.serviceAccount.automount }} +{{- end }} diff --git a/charts/orthos2/templates/tests/test-connection.yaml b/charts/orthos2/templates/tests/test-connection.yaml new file mode 100644 index 0000000..17688c8 --- /dev/null +++ b/charts/orthos2/templates/tests/test-connection.yaml @@ -0,0 +1,27 @@ +apiVersion: v1 +kind: Pod +metadata: + annotations: + "helm.sh/hook": test + ignore-check.kube-linter.io/default-service-account: "This is a Helm testcontainer" + ignore-check.kube-linter.io/latest-tag: "This is a Helm testcontainer" + ignore-check.kube-linter.io/no-liveness-probe: "This is a Helm testcontainer" + ignore-check.kube-linter.io/no-readiness-probe: "This is a Helm testcontainer" + ignore-check.kube-linter.io/restart-policy: "This is a Helm testcontainer" + ignore-check.kube-linter.io/no-read-only-root-fs: "This is a Helm testcontainer" + labels: + {{- include "orthos2.labels" . | nindent 4 }} + name: "{{ include "orthos2.fullname" . }}-test-connection" +spec: + containers: + - args: + - '--spider' + - '--header=Host: localhost' + - '{{ include "orthos2.fullname" . }}:{{ .Values.service.port }}' + command: ['wget'] + image: busybox + name: wget + restartPolicy: Never + securityContext: + runAsGroup: 1000 + runAsUser: 1000 diff --git a/charts/orthos2/values.yaml b/charts/orthos2/values.yaml new file mode 100644 index 0000000..5dfba5b --- /dev/null +++ b/charts/orthos2/values.yaml @@ -0,0 +1,205 @@ +# Default values for orthos2. +# 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: registry.opensuse.org/systemsmanagement/orthos2/containers/orthos2 + repositoryStatic: registry.opensuse.org/systemsmanagement/orthos2/containers/orthos2-static + # This sets the pull policy for images. + pullPolicy: IfNotPresent + # Overrides the image tag whose default is the chart appVersion. + tag: "1.16" + +# This is for the secrets 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: "" + +# This section builds out the service account more information can be found here: https://kubernetes.io/docs/concepts/security/service-accounts/ +serviceAccount: + # Specifies whether a service account should be created. + create: true + # Automatically mount a ServiceAccount's API credentials? + automount: 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: "" + +# 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: false + runAsUser: 499 + +# 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 sets the ports more information can be found here: https://kubernetes.io/docs/concepts/services-networking/service/#field-spec-ports + port: 8000 + +# 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: true + className: "nginx" + hosts: + - host: orthos.local + paths: + - path: /static/ + pathType: Prefix + port: 80 + - path: / + pathType: Prefix + annotations: {} + # kubernetes.io/ingress.class: nginx + # kubernetes.io/tls-acme: "true" + tls: [] + # - secretName: chart-example-tls + # hosts: + # - chart-example.local + +# -- Expose the service via gateway-api HTTPRoute +# Requires Gateway API resources and suitable controller installed within the cluster +# (see: https://gateway-api.sigs.k8s.io/guides/) +httpRoute: + # HTTPRoute enabled. + enabled: false + # HTTPRoute annotations. + annotations: {} + # Which Gateways this Route is attached to. + parentRefs: + - name: gateway + sectionName: http + # namespace: default + # Hostnames matching HTTP header. + hostnames: + - chart-example.local + # List of rules and filters applied. + rules: + - matches: + - path: + type: PathPrefix + value: /headers + # filters: + # - type: RequestHeaderModifier + # requestHeaderModifier: + # set: + # - name: My-Overwrite-Header + # value: this-is-the-only-value + # remove: + # - User-Agent + # - matches: + # - path: + # type: PathPrefix + # value: /echo + # headers: + # - name: version + # value: v2 + +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 + httpHeaders: + - name: Host + value: "localhost" +readinessProbe: + httpGet: + path: / + port: http + httpHeaders: + - name: Host + value: "localhost" + +# This section is for setting up autoscaling more information can be found here: https://kubernetes.io/docs/concepts/workloads/autoscaling/ +autoscaling: + enabled: false + minReplicas: 1 + maxReplicas: 1 + targetCPUUtilizationPercentage: 80 + # targetMemoryUtilizationPercentage: 80 + +# Additional volumes on the output Deployment definition. +volumes: + - name: sqlite-data + emptyDir: {} + + - name: logs + emptyDir: {} + + - name: tmp + emptyDir: {} + + - name: run + emptyDir: {} + + - name: orthos-secrets + secret: + secretName: orthos2 + +# Additional volumeMounts on the output Deployment definition. +volumeMounts: + - name: sqlite-data + mountPath: /var/lib/orthos2/database + + - name: logs + mountPath: /var/log/orthos2 + + - name: tmp + mountPath: /tmp + + - name: run + mountPath: /run + + - name: orthos-secrets + readOnly: true + mountPath: /run/secrets/NetboxToken + subPath: NetboxToken + + - name: orthos-secrets + readOnly: true + mountPath: /run/secrets/OIDCsecret + subPath: OIDCsecret + + - name: orthos-secrets + readOnly: true + mountPath: /run/secrets/OrthosKey + subPath: OrthosKey + +nodeSelector: {} + +tolerations: [] + +affinity: {} diff --git a/documentation.md b/documentation.md new file mode 100644 index 0000000..8a59687 --- /dev/null +++ b/documentation.md @@ -0,0 +1,34 @@ +# Orthos 2 setup + +## 1. Create a namespace (Optional) +Its recommended you create a namespace for this project using + +```bash +kubectl create namespace [namespace] +``` + +## 2. Create the Secret +Create a secret named orthos2 in its namespace, containing the Netbox Token, the OIDC Secret, and the Orthos Key + +```bash +kubectl create secret generic orthos2 \ + --from-literal=NetboxToken=[Netbox Token here] \ + --from-literal=OIDCsecret=[OIDC Secret here] \ + --from-literal=OrthosKey=[Orthos Key here] \ + --namespace=[Namespace] +``` +## 3. Create Environment Variables +Create an Environment Variables named orthos2-env. +This most easily done by making an env file using the env.example in charts/orthos2/configmap/ and executing this command: + +```bash +kubectl create configmap orthos2-env \ + --from-env-file=charts/orthos2/configmap/.env \ + --namespace=[Namespace] +``` +## 4. Start the pods +The pods can be started using + +```bash +helm install orthos2 charts/orthos2/ +```