Skip to content
Draft
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ test: manifests generate fmt vet setup-envtest ## Run tests.
# - CERT_MANAGER_INSTALL_SKIP=true
.PHONY: test-e2e
test-e2e: manifests generate fmt vet ## Run the e2e tests. Expected an isolated environment using Kind.
go test ./test/e2e/ -v -ginkgo.v
go test ./test/e2e/ -v -timeout 30m -ginkgo.v -ginkgo.flake-attempts=1

.PHONY: lint
lint: golangci-lint ## Run golangci-lint linter
Expand Down
65 changes: 64 additions & 1 deletion charts/castai-castware-operator/templates/cleanup-job.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,66 @@
---
apiVersion: v1
kind: ServiceAccount
metadata:
name: {{ include "castware-operator.fullname" . }}-cleanup
namespace: {{ .Release.Namespace }}
labels:
{{- include "castware-operator.labels" . | nindent 4 }}
annotations:
"helm.sh/hook": pre-delete
"helm.sh/hook-weight": "-10"
"helm.sh/hook-delete-policy": before-hook-creation,hook-succeeded,hook-failed
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: {{ include "castware-operator.fullname" . }}-cleanup
labels:
{{- include "castware-operator.labels" . | nindent 4 }}
annotations:
"helm.sh/hook": pre-delete
"helm.sh/hook-weight": "-10"
"helm.sh/hook-delete-policy": before-hook-creation,hook-succeeded,hook-failed
rules:
- apiGroups:
- castware.cast.ai
resources:
- clusters
- components
verbs:
- get
- list
- update
- patch
- delete
- apiGroups:
- apiextensions.k8s.io
resources:
- customresourcedefinitions
verbs:
- delete
- get
- list
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: {{ include "castware-operator.fullname" . }}-cleanup
labels:
{{- include "castware-operator.labels" . | nindent 4 }}
annotations:
"helm.sh/hook": pre-delete
"helm.sh/hook-weight": "-10"
"helm.sh/hook-delete-policy": before-hook-creation,hook-succeeded,hook-failed
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: {{ include "castware-operator.fullname" . }}-cleanup
subjects:
- kind: ServiceAccount
name: {{ include "castware-operator.fullname" . }}-cleanup
namespace: {{ .Release.Namespace }}
---
apiVersion: batch/v1
kind: Job
metadata:
Expand All @@ -22,7 +85,7 @@ spec:
{{- toYaml . | nindent 8 }}
{{- end }}

serviceAccountName: {{ include "castware-operator.fullname" . }}-controller-manager
serviceAccountName: {{ include "castware-operator.fullname" . }}-cleanup
restartPolicy: OnFailure
securityContext:
{{- toYaml .Values.podSecurityContext | nindent 8 }}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
{{- if .Values.preflightInstallCheck.enabled }}
apiVersion: batch/v1
kind: Job
metadata:
name: {{ include "castware-operator.fullname" . }}-preflight-install-check
namespace: {{ .Release.Namespace }}
labels:
{{- include "castware-operator.labels" . | nindent 4 }}
annotations:
"helm.sh/hook": pre-install
"helm.sh/hook-weight": "1"
"helm.sh/hook-delete-policy": before-hook-creation
spec:
backoffLimit: 0
activeDeadlineSeconds: 300
ttlSecondsAfterFinished: 300
template:
metadata:
name: {{ include "castware-operator.fullname" . }}-preflight-install-check
labels:
{{- include "castware-operator.selectorLabels" . | nindent 8 }}
spec:
{{- with .Values.imagePullSecrets }}
imagePullSecrets:
{{- toYaml . | nindent 8 }}
{{- end }}
restartPolicy: Never
securityContext:
{{- toYaml .Values.podSecurityContext | nindent 8 }}
containers:
- name: {{ .Chart.Name }}
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
args:
- preflight-install-check
command:
- /manager
env:
- name: POD_NAME
valueFrom:
fieldRef:
fieldPath: metadata.name
- name: POD_NAMESPACE
valueFrom:
fieldRef:
fieldPath: metadata.namespace
- name: OPERATOR_NAME
value: {{ include "castware-operator.fullname" . }}
- name: HELM_RELEASE_NAME
value: {{ .Release.Name }}
- name: LOG_LEVEL
value: "info"
- name: API_URL
value: {{ .Values.defaultCluster.api.apiUrl }}
- name: HELM_REPO_URL
value: {{ .Values.defaultCluster.helmRepoURL }}
- name: API_KEY
value: {{ .Values.apiKeySecret.apiKey }}
resources:
{{- toYaml .Values.resources | nindent 12 }}
securityContext:
{{- toYaml .Values.securityContext | nindent 12 }}
volumeMounts:
- mountPath: /.cache/helm
name: helm-cache
{{- with .Values.nodeSelector }}
nodeSelector:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.affinity }}
affinity:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.tolerations }}
tolerations:
{{- toYaml . | nindent 8 }}
{{- end }}
volumes:
- name: helm-cache
emptyDir:
sizeLimit: 500Mi
{{- end }}
3 changes: 3 additions & 0 deletions charts/castai-castware-operator/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ crdUpgrade:
preflightCheck:
enabled: true

preflightInstallCheck:
enabled: true

# Webhook configuration
webhook:
enabled: true
Expand Down
19 changes: 11 additions & 8 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,21 @@ package main
import (
"os"

"github.com/castai/castware-operator/internal/castai"
"github.com/castai/castware-operator/internal/config"
"github.com/spf13/cobra"

// Import all Kubernetes client auth plugins (e.g. Azure, GCP, OIDC, etc.)
// to ensure that exec-entrypoint and run can make use of them.
_ "k8s.io/client-go/plugin/pkg/client/auth"

apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
"k8s.io/apimachinery/pkg/runtime"
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
clientgoscheme "k8s.io/client-go/kubernetes/scheme"

// Import all Kubernetes client auth plugins (e.g. Azure, GCP, OIDC, etc.)
// to ensure that exec-entrypoint and run can make use of them.
_ "k8s.io/client-go/plugin/pkg/client/auth"
ctrl "sigs.k8s.io/controller-runtime"

castwarev1alpha1 "github.com/castai/castware-operator/api/v1alpha1"
"github.com/castai/castware-operator/internal/castai"
"github.com/castai/castware-operator/internal/config"
// +kubebuilder:scaffold:imports
)

Expand Down Expand Up @@ -70,7 +70,8 @@ func newRootCmd() *cobra.Command {

rootCmd.Flags().StringVar(&metricsAddr, "metrics-bind-address", "0", "The address the metrics endpoint binds to. "+
"Use :8443 for HTTPS or :8080 for HTTP, or leave as 0 to disable the metrics service.")
rootCmd.Flags().StringVar(&probeAddr, "health-probe-bind-address", ":8081", "The address the probe endpoint binds to.")
rootCmd.Flags().StringVar(&probeAddr, "health-probe-bind-address", ":8081",
"The address the probe endpoint binds to.")
rootCmd.Flags().BoolVar(&enableLeaderElection, "leader-elect", false,
"Enable leader election for controller manager. "+
"Enabling this will ensure there is only one active controller manager.")
Expand All @@ -80,7 +81,8 @@ func newRootCmd() *cobra.Command {
"The directory that contains the metrics server certificate.")
rootCmd.Flags().StringVar(&metricsCertName, "metrics-cert-name", "tls.crt",
"The name of the metrics server certificate file.")
rootCmd.Flags().StringVar(&metricsCertKey, "metrics-cert-key", "tls.key", "The name of the metrics server key file.")
rootCmd.Flags().StringVar(&metricsCertKey, "metrics-cert-key", "tls.key",
"The name of the metrics server key file.")
rootCmd.Flags().BoolVar(&enableHTTP2, "enable-http2", false,
"If set, HTTP/2 will be enabled for the metrics and webhook servers")

Expand All @@ -92,6 +94,7 @@ func main() {
rootCmd.AddCommand(newUpgradeCmd())
rootCmd.AddCommand(newCleanupCmd())
rootCmd.AddCommand(newPreflightCheckCmd())
rootCmd.AddCommand(newPreflightInstallCheckCmd())

version = config.CastwareOperatorVersion{
GitCommit: GitCommit,
Expand Down
Loading
Loading