Skip to content

Commit

Permalink
Add precheck job to validate options for ACE installer (#491)
Browse files Browse the repository at this point in the history
Signed-off-by: Rokibul Hasan <[email protected]>
Signed-off-by: Tamal Saha <[email protected]>
Co-authored-by: Tamal Saha <[email protected]>
  • Loading branch information
RokibulHasan7 and tamalsaha authored Oct 25, 2024
1 parent c420c59 commit 434d771
Show file tree
Hide file tree
Showing 10 changed files with 1,040 additions and 60 deletions.
15 changes: 15 additions & 0 deletions apis/installer/v1alpha1/ace_installer_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package v1alpha1
import (
configapi "go.bytebuilders.dev/resource-model/apis/config/v1alpha1"

core "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"kmodules.xyz/resource-metadata/apis/shared"
)
Expand Down Expand Up @@ -53,6 +54,20 @@ type AceInstallerSpec struct {
DeploymentType DeploymentType `json:"deploymentType"`
shared.BootstrapPresets `json:",inline,omitempty"`
SelfManagement configapi.SelfManagement `json:"selfManagement"`
Precheck AceInstallerPrecheckSpec `json:"precheck"`
}

type AceInstallerPrecheckSpec struct {
Enabled bool `json:"enabled"`
Image ImageReference `json:"image"`
PodAnnotations map[string]string `json:"podAnnotations"`
PodSecurityContext *core.PodSecurityContext `json:"podSecurityContext"`
SecurityContext *core.SecurityContext `json:"securityContext"`
Resources core.ResourceRequirements `json:"resources"`
//+optional
NodeSelector map[string]string `json:"nodeSelector"`
Tolerations []core.Toleration `json:"tolerations"`
Affinity *core.Affinity `json:"affinity"`
}

// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
Expand Down
54 changes: 54 additions & 0 deletions apis/installer/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

130 changes: 71 additions & 59 deletions charts/ace-installer/README.md

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions charts/ace-installer/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -111,3 +111,11 @@ Image Templates
{{- define "clustermanager.openshift" -}}
{{- ternary "true" "false" (.Capabilities.APIVersions.Has "project.openshift.io/v1/Project") -}}
{{- end }}

{{/*
Returns the registry used for app docker image
*/}}
{{- define "precheck.image.registry" -}}
{{- list .Values.image.proxies.ghcr .Values.precheck.image.registry | compact | join "/" }}
{{- end }}

38 changes: 38 additions & 0 deletions charts/ace-installer/templates/precheck/config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{{- if .Values.precheck.enabled }}

{{- $encodedLicenses := dig "license-proxyserver" "values" "encodedLicenses" (dict) .Values.helm.releases -}}
{{- $licenses := dict -}}
{{- range $k, $v := $encodedLicenses }}
{{ $_ := set $licenses $k (b64dec $v) }}
{{- end }}

kind: Secret
apiVersion: v1
metadata:
name: {{ include "ace-installer.fullname" . }}-precheck-config
namespace: {{ .Release.Namespace }}
labels:
{{- include "ace-installer.labels" . | nindent 4 }}
annotations:
"helm.sh/hook-weight": "0"
"helm.sh/hook": pre-install,pre-upgrade,pre-rollback
"helm.sh/hook-delete-policy": before-hook-creation,hook-succeeded
stringData:
options.yaml: |
{{- with $licenses }}
licenses: {{ . | toJson }}
{{- end }}
{{- if .Values.registry }}
registry:
{{- .Values.registry | toYaml | nindent 6 }}
{{- if .Values.image }}
image:
{{- .Values.image | toYaml | nindent 8 }}
{{- end }}
{{- end }}
{{- if .Values.selfManagement }}
selfManagement:
{{- .Values.selfManagement | toYaml | nindent 6 }}
{{- end }}
{{- end }}
73 changes: 73 additions & 0 deletions charts/ace-installer/templates/precheck/job.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
{{- if .Values.precheck.enabled }}

apiVersion: batch/v1
kind: Job
metadata:
name: {{ include "ace-installer.fullname" . }}-precheck
namespace: {{ .Release.Namespace }}
annotations:
"helm.sh/hook-weight": "0"
"helm.sh/hook": pre-install,pre-upgrade,pre-rollback
"helm.sh/hook-delete-policy": before-hook-creation,hook-succeeded
spec:
backoffLimit: 4
manualSelector: true
selector:
matchLabels:
{{- include "ace-installer.selectorLabels" . | nindent 6 }}
template:
metadata:
{{- with .Values.precheck.podAnnotations }}
annotations:
{{- toYaml . | nindent 8 }}
{{- end }}
labels:
{{- include "ace-installer.selectorLabels" . | nindent 8 }}
spec:
serviceAccountName: {{ include "ace-installer.fullname" . }}-precheck
securityContext:
{{- toYaml .Values.precheck.podSecurityContext | nindent 8 }}
containers:
- name: {{ .Chart.Name }}
securityContext:
{{- toYaml .Values.precheck.securityContext | nindent 12 }}
image: "{{ include "precheck.image.registry" . }}/{{ .Values.precheck.image.repository }}:{{ .Values.precheck.image.tag | default .Chart.AppVersion }}"
imagePullPolicy: Always
args:
- installer
- validate
- --options=/data/installer/options.yaml
resources:
{{- toYaml .Values.precheck.resources | nindent 12 }}
volumeMounts:
- name: tmp
mountPath: /tmp
- name: data
mountPath: /data
- name: installer-options
mountPath: /data/installer/options.yaml
subPath: options.yaml
volumes:
- name: tmp
emptyDir: {}
- name: data
emptyDir: {}
- name: installer-options
secret:
defaultMode: 420
secretName: {{ include "ace-installer.fullname" . }}-precheck-config
{{- with .Values.precheck.nodeSelector }}
nodeSelector:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.precheck.affinity }}
affinity:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.precheck.tolerations }}
tolerations:
{{- toYaml . | nindent 8 }}
{{- end }}
restartPolicy: Never

{{- end }}
49 changes: 49 additions & 0 deletions charts/ace-installer/templates/precheck/rbac.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
{{- if .Values.precheck.enabled }}

apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: {{ include "ace-installer.fullname" . }}-precheck
labels:
{{- include "ace-installer.labels" . | nindent 4 }}
annotations:
"helm.sh/hook-weight": "0"
"helm.sh/hook": pre-install,pre-upgrade,pre-rollback
"helm.sh/hook-delete-policy": before-hook-creation,hook-succeeded
rules:
- apiGroups: [""]
resources: ["configmaps"]
resourceNames: ["cluster-info"]
verbs: ["get"]
- apiGroups: ["apps"]
resources: ["deployments"]
verbs: ["get", "list", "watch"]
- apiGroups: [""]
resources: ["services"]
verbs: ["get", "list", "watch"]
- apiGroups: ["storage.k8s.io"]
resources: ["storageclasses"]
verbs: ["get", "list", "watch"]

---

apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: {{ include "ace-installer.fullname" . }}-precheck
labels:
{{- include "ace-installer.labels" . | nindent 4 }}
annotations:
"helm.sh/hook-weight": "0"
"helm.sh/hook": pre-install,pre-upgrade,pre-rollback
"helm.sh/hook-delete-policy": before-hook-creation,hook-succeeded
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: {{ include "ace-installer.fullname" . }}-precheck
subjects:
- kind: ServiceAccount
name: {{ include "ace-installer.fullname" . }}-precheck
namespace: {{ .Release.Namespace }}

{{- end }}
13 changes: 13 additions & 0 deletions charts/ace-installer/templates/precheck/serviceaccount.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{{- if .Values.precheck.enabled }}

apiVersion: v1
kind: ServiceAccount
metadata:
name: {{ include "ace-installer.fullname" . }}-precheck
namespace: {{ .Release.Namespace }}
annotations:
"helm.sh/hook-weight": "0"
"helm.sh/hook": pre-install,pre-upgrade,pre-rollback
"helm.sh/hook-delete-policy": before-hook-creation,hook-succeeded

{{- end }}
Loading

0 comments on commit 434d771

Please sign in to comment.