Skip to content

Commit

Permalink
[castai-scheduling-policies-controller] init (castai#504)
Browse files Browse the repository at this point in the history
* [castai-scheduling-policies-controller] init

* fix chart lint

* add test secret

* fix copy paste
  • Loading branch information
mindaugasCast authored Sep 13, 2024
1 parent 280b0c6 commit 981a3c5
Show file tree
Hide file tree
Showing 19 changed files with 660 additions and 0 deletions.
23 changes: 23 additions & 0 deletions charts/castai-scheduling-policies-controller/.helmignore
Original file line number Diff line number Diff line change
@@ -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/
6 changes: 6 additions & 0 deletions charts/castai-scheduling-policies-controller/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
apiVersion: v2
name: castai-scheduling-policies-controller
description: CAST AI scheduling policies controller.
type: application
version: 0.0.1
appVersion: "v0.0.1"
43 changes: 43 additions & 0 deletions charts/castai-scheduling-policies-controller/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# castai-scheduling-policies-controller

![Version: 0.0.1](https://img.shields.io/badge/Version-0.0.1-informational?style=flat-square) ![Type: application](https://img.shields.io/badge/Type-application-informational?style=flat-square) ![AppVersion: v0.0.1](https://img.shields.io/badge/AppVersion-v0.0.1-informational?style=flat-square)

CAST AI scheduling policies controller.

## Values

| Key | Type | Default | Description |
|-----|------|---------|-------------|
| castai.apiKey | string | `""` | |
| castai.apiKeySecretRef | string | `""` | |
| castai.apiUrl | string | `"https://api.cast.ai"` | |
| castai.clusterID | string | `""` | |
| castai.configMapRef | string | `""` | |
| dnsPolicy | string | `""` | DNS Policy Override - Needed when using custom CNI's. Defaults to "ClusterFirstWithHostNet" if hostNetwork is true |
| global | object | `{"commonAnnotations":{},"commonLabels":{}}` | Values to apply for the parent and child chart resources. |
| global.commonAnnotations | object | `{}` | Annotations to add to all resources. |
| global.commonLabels | object | `{}` | Labels to add to all resources. |
| hostNetwork | bool | `false` | |
| image.pullPolicy | string | `"IfNotPresent"` | |
| image.repository | string | `"us-docker.pkg.dev/castai-hub/library/scheduling-policies-controller"` | |
| image.tag | string | `""` | |
| podAnnotations | object | `{}` | Annotations added to each pod. |
| podLabels | object | `{}` | |
| podSecurityContext.fsGroup | int | `1005` | |
| podSecurityContext.runAsGroup | int | `1005` | |
| podSecurityContext.runAsNonRoot | bool | `true` | |
| podSecurityContext.runAsUser | int | `1005` | |
| priorityClass.enabled | bool | `false` | |
| priorityClass.name | string | `"system-cluster-critical"` | |
| replicas | int | `1` | |
| resources.limits.memory | string | `"100Mi"` | |
| resources.requests.cpu | string | `"20m"` | |
| resources.requests.memory | string | `"100Mi"` | |
| serviceAccount.annotations | object | `{}` | |
| serviceAccount.create | bool | `true` | |
| serviceAccount.name | string | `""` | |
| tolerations[0].key | string | `"scheduling.cast.ai/spot"` | |
| tolerations[0].operator | string | `"Exists"` | |
| webhook.failurePolicy | string | `"Ignore"` | |
| webhook.reinvocationPolicy | string | `"Never"` | |
| webhook.url | string | `""` | |
16 changes: 16 additions & 0 deletions charts/castai-scheduling-policies-controller/README.md.gotmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{{ template "chart.header" . }}
{{ template "chart.deprecationWarning" . }}

{{ template "chart.badgesSection" . }}

{{ template "chart.description" . }}

{{ template "chart.homepageLine" . }}

{{ template "chart.maintainersSection" . }}

{{ template "chart.sourcesSection" . }}

{{ template "chart.requirementsSection" . }}

{{ template "chart.valuesSection" . }}
30 changes: 30 additions & 0 deletions charts/castai-scheduling-policies-controller/ci/test-values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
castai:
apiURL: "https://api.cast.ai"
apiKey: ""
clusterID: "a24cd53c-0d56-4422-88e6-f82f78ef8f20"
apiKeySecretRef: "test"
resources:
limits:
cpu: 1000m
memory: 128Mi
requests:
cpu: 100m
memory: 128Mi
isTest: true
additionalEnv:
ANTICIPATE_WORKER_READY_STATUS: true
service:
port: 8443
type: ClusterIP
podLabels:
test: test
global:
commonAnnotations:
foo: bar
commonLabels:
faz: baz
x: b
serviceAccount:
create: true
annotations:
foo2: bar2
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
{{/*
Expand the name of the chart.
*/}}
{{- define "scheduling-policies-controller.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 "scheduling-policies-controller.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 "scheduling-policies-controller.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
{{- end }}

{{/*
Common labels
*/}}
{{- define "scheduling-policies-controller.labels" -}}
{{- if gt (len .Values.global.commonLabels) 0 }}
{{- with .Values.global.commonLabels }}
{{- toYaml . }}
{{- end }}
{{- end }}
helm.sh/chart: {{ include "scheduling-policies-controller.chart" . }}
{{ include "scheduling-policies-controller.selectorLabels" . }}
{{- if .Chart.AppVersion }}
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
{{- end }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- end }}

{{/*
Selector labels
*/}}
{{- define "scheduling-policies-controller.selectorLabels" -}}
app.kubernetes.io/name: {{ include "scheduling-policies-controller.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end }}

{{- define "scheduling-policies-controller.webhookName" -}}
{{ include "scheduling-policies-controller.fullname" . }}
{{- end }}

{{/*
Create the name of the service account to use
*/}}
{{- define "scheduling-policies-controller.serviceAccountName" -}}
{{- if .Values.serviceAccount.create }}
{{- default (include "scheduling-policies-controller.fullname" .) .Values.serviceAccount.name }}
{{- else }}
{{- default "default" .Values.serviceAccount.name }}
{{- end }}
{{- end }}

{{- define "scheduling-policies-controller.exludeSelfLabelSelectors" -}}
{{- range splitList "\n" (include "scheduling-policies-controller.selectorLabels" .) }}
{{- /* we split label keypair by `:`. Let's hope there are no `:` in the key*/ -}}
{{- $parts := splitn ":" 2 . -}}
{{- $key := trim $parts._0 -}}
{{- $value := trim $parts._1 }}
- key: {{ $key | quote }}
operator: NotIn
values:
- {{ $value | quote }}
{{- end }}
{{- end }}
{{- define "scheduling-policies-controller.certsSecretName" -}}
{{ include "scheduling-policies-controller.fullname" . }}-certs
{{- end }}
{{/*
Common Annotations
*/}}
{{- define "scheduling-policies-controller.annotations" -}}
{{- if gt (len .Values.global.commonAnnotations) 0 }}
{{- with .Values.global.commonAnnotations }}
{{- toYaml . }}
{{- end }}
{{- end }}
{{- end }}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: {{ include "scheduling-policies-controller.fullname" . }}
labels:
{{- include "scheduling-policies-controller.labels" . | nindent 4 }}
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: {{ include "scheduling-policies-controller.fullname" . }}
subjects:
- kind: ServiceAccount
name: {{ include "scheduling-policies-controller.serviceAccountName" . }}
namespace: {{ .Release.Namespace }}
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: {{ include "scheduling-policies-controller.fullname" . }}
labels:
{{- include "scheduling-policies-controller.labels" . | nindent 4 }}
rules:
# ---
# Required for basic Webhook functionality
# ---
- apiGroups:
- admissionregistration.k8s.io
resources:
- mutatingwebhookconfigurations
verbs:
- list
- watch
- apiGroups:
- admissionregistration.k8s.io
resourceNames:
- {{ include "scheduling-policies-controller.webhookName" . }}
resources:
- mutatingwebhookconfigurations
verbs:
- get
- patch
- update
# ---
# Write permissions for pod controllers (deployments) - required for rolling out new pods
# ---
- apiGroups:
- "apps"
resources:
- deployments
verbs:
- update
# ---
# Read only permissions to view pods/deployments/rollouts
# ---
- apiGroups:
- ""
resources:
- pods
verbs:
- get
- list
- watch
- apiGroups:
- apps
resources:
- deployments
verbs:
- get
- list
- watch
- apiGroups:
- "argoproj.io"
resources:
- rollouts
verbs:
- get
- list
- watch
# ---
# Read only permissions to view autoscaling resources
# ---
- apiGroups:
- autoscaling.cast.ai
resources:
- "*"
verbs:
- get
- list
- watch
# ---
# Write permissions for autoscaling resources (recommendations) - required for adding finalizers
# ---
- apiGroups:
- autoscaling.cast.ai
resources:
- "*"
verbs:
- update
- patch
- apiGroups:
- "apps"
resources:
- replicasets
verbs:
- get
- list
- watch
16 changes: 16 additions & 0 deletions charts/castai-scheduling-policies-controller/templates/config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{{- if .Values.castai.clusterID -}}
apiVersion: v1
kind: ConfigMap
metadata:
name: scheduling-policies-controller
namespace: {{ .Values.namespace }}
labels:
{{- include "scheduling-policies-controller.labels" . | nindent 4 }}
{{ if .Values.commonAnnotations -}}
annotations:
{{- include "scheduling-policies-controller.annotations" . | nindent 4 }}
{{- end }}
data:
API_URL: {{ required "castai.apiUrl must be provided" .Values.castai.apiUrl | quote }}
CLUSTER_ID: {{ required "clusterID must be provided" .Values.castai.clusterID | quote }}
{{- end }}
Loading

0 comments on commit 981a3c5

Please sign in to comment.