diff --git a/charts/sleepcycles/.helmignore b/charts/sleepcycles/.helmignore new file mode 100644 index 0000000..0e8a0eb --- /dev/null +++ b/charts/sleepcycles/.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/sleepcycles/Chart.yaml b/charts/sleepcycles/Chart.yaml new file mode 100644 index 0000000..d37f379 --- /dev/null +++ b/charts/sleepcycles/Chart.yaml @@ -0,0 +1,21 @@ +apiVersion: v2 +name: sleepcycles +description: Define sleep and wake up cycles for your Kubernetes resources +# 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.2.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: "0.2.0" diff --git a/charts/sleepcycles/templates/_helpers.tpl b/charts/sleepcycles/templates/_helpers.tpl new file mode 100644 index 0000000..3e2e076 --- /dev/null +++ b/charts/sleepcycles/templates/_helpers.tpl @@ -0,0 +1,62 @@ +{{/* +Expand the name of the chart. +*/}} +{{- define "sleepcycles.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 "sleepcycles.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 "sleepcycles.chart" -}} +{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }} +{{- end }} + +{{/* +Common labels +*/}} +{{- define "sleepcycles.labels" -}} +helm.sh/chart: {{ include "sleepcycles.chart" . }} +{{ include "sleepcycles.selectorLabels" . }} +{{- if .Chart.AppVersion }} +app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} +{{- end }} +app.kubernetes.io/managed-by: {{ .Release.Service }} +{{- end }} + +{{/* +Selector labels +*/}} +{{- define "sleepcycles.selectorLabels" -}} +app.kubernetes.io/name: {{ include "sleepcycles.name" . }} +app.kubernetes.io/instance: {{ .Release.Name }} +{{- end }} + +{{/* +Create the name of the service account to use +*/}} +{{- define "sleepcycles.serviceAccountName" -}} +{{- if .Values.serviceAccount.create }} +{{- default (include "sleepcycles.fullname" .) .Values.serviceAccount.name }} +{{- else }} +{{- default "default" .Values.serviceAccount.name }} +{{- end }} +{{- end }} diff --git a/charts/sleepcycles/templates/deployment.yaml b/charts/sleepcycles/templates/deployment.yaml new file mode 100644 index 0000000..7a2ca9a --- /dev/null +++ b/charts/sleepcycles/templates/deployment.yaml @@ -0,0 +1,66 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: {{ include "sleepcycles.fullname" . }}-controller-manager + labels: + control-plane: controller-manager + {{- include "sleepcycles.labels" . | nindent 4 }} +spec: + replicas: {{ .Values.controllerManager.replicas }} + selector: + matchLabels: + control-plane: controller-manager + {{- include "sleepcycles.selectorLabels" . | nindent 6 }} + template: + metadata: + labels: + control-plane: controller-manager + {{- include "sleepcycles.selectorLabels" . | nindent 8 }} + annotations: + kubectl.kubernetes.io/default-container: manager + spec: + containers: + - args: {{- toYaml .Values.controllerManager.kubeRbacProxy.args | nindent 8 }} + env: + - name: KUBERNETES_CLUSTER_DOMAIN + value: {{ quote .Values.kubernetesClusterDomain }} + image: {{ .Values.controllerManager.kubeRbacProxy.image.repository }}:{{ .Values.controllerManager.kubeRbacProxy.image.tag + | default .Chart.AppVersion }} + name: kube-rbac-proxy + ports: + - containerPort: 8443 + name: https + protocol: TCP + resources: {{- toYaml .Values.controllerManager.kubeRbacProxy.resources | nindent + 10 }} + securityContext: {{- toYaml .Values.controllerManager.kubeRbacProxy.containerSecurityContext + | nindent 10 }} + - args: {{- toYaml .Values.controllerManager.manager.args | nindent 8 }} + command: + - /manager + env: + - name: KUBERNETES_CLUSTER_DOMAIN + value: {{ quote .Values.kubernetesClusterDomain }} + image: {{ .Values.controllerManager.manager.image.repository }}:{{ .Values.controllerManager.manager.image.tag + | default .Chart.AppVersion }} + livenessProbe: + httpGet: + path: /healthz + port: 8081 + initialDelaySeconds: 15 + periodSeconds: 20 + name: manager + readinessProbe: + httpGet: + path: /readyz + port: 8081 + initialDelaySeconds: 5 + periodSeconds: 10 + resources: {{- toYaml .Values.controllerManager.manager.resources | nindent 10 + }} + securityContext: {{- toYaml .Values.controllerManager.manager.containerSecurityContext + | nindent 10 }} + securityContext: + runAsNonRoot: true + serviceAccountName: {{ include "sleepcycles.fullname" . }}-controller-manager + terminationGracePeriodSeconds: 10 \ No newline at end of file diff --git a/charts/sleepcycles/templates/leader-election-rbac.yaml b/charts/sleepcycles/templates/leader-election-rbac.yaml new file mode 100644 index 0000000..522348f --- /dev/null +++ b/charts/sleepcycles/templates/leader-election-rbac.yaml @@ -0,0 +1,53 @@ +apiVersion: rbac.authorization.k8s.io/v1 +kind: Role +metadata: + name: {{ include "sleepcycles.fullname" . }}-leader-election-role + labels: + {{- include "sleepcycles.labels" . | nindent 4 }} +rules: +- apiGroups: + - "" + resources: + - configmaps + verbs: + - get + - list + - watch + - create + - update + - patch + - delete +- apiGroups: + - coordination.k8s.io + resources: + - leases + verbs: + - get + - list + - watch + - create + - update + - patch + - delete +- apiGroups: + - "" + resources: + - events + verbs: + - create + - patch +--- +apiVersion: rbac.authorization.k8s.io/v1 +kind: RoleBinding +metadata: + name: {{ include "sleepcycles.fullname" . }}-leader-election-rolebinding + labels: + {{- include "sleepcycles.labels" . | nindent 4 }} +roleRef: + apiGroup: rbac.authorization.k8s.io + kind: Role + name: '{{ include "sleepcycles.fullname" . }}-leader-election-role' +subjects: +- kind: ServiceAccount + name: '{{ include "sleepcycles.fullname" . }}-controller-manager' + namespace: '{{ .Release.Namespace }}' \ No newline at end of file diff --git a/charts/sleepcycles/templates/manager-config.yaml b/charts/sleepcycles/templates/manager-config.yaml new file mode 100644 index 0000000..cf1bb73 --- /dev/null +++ b/charts/sleepcycles/templates/manager-config.yaml @@ -0,0 +1,9 @@ +apiVersion: v1 +kind: ConfigMap +metadata: + name: {{ include "sleepcycles.fullname" . }}-manager-config + labels: + {{- include "sleepcycles.labels" . | nindent 4 }} +data: + controller_manager_config.yaml: {{ .Values.managerConfig.controllerManagerConfigYaml + | toYaml | indent 1 }} \ No newline at end of file diff --git a/charts/sleepcycles/templates/manager-rbac.yaml b/charts/sleepcycles/templates/manager-rbac.yaml new file mode 100644 index 0000000..7598e83 --- /dev/null +++ b/charts/sleepcycles/templates/manager-rbac.yaml @@ -0,0 +1,139 @@ +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRole +metadata: + name: {{ include "sleepcycles.fullname" . }}-manager-role + labels: + {{- include "sleepcycles.labels" . | nindent 4 }} +rules: +- apiGroups: + - "" + resources: + - events + verbs: + - create + - patch +- apiGroups: + - apps + resources: + - deployments + verbs: + - create + - delete + - get + - list + - patch + - update + - watch +- apiGroups: + - apps + resources: + - replicasets + verbs: + - create + - delete + - get + - list + - patch + - update + - watch +- apiGroups: + - apps + resources: + - statefulsets + verbs: + - create + - delete + - get + - list + - patch + - update + - watch +- apiGroups: + - autoscaling + resources: + - horizontalpodautoscalers + verbs: + - create + - delete + - get + - list + - patch + - update + - watch +- apiGroups: + - batch + resources: + - cronjobs + verbs: + - create + - delete + - get + - list + - patch + - update + - watch +- apiGroups: + - "" + resources: + - replicasets + verbs: + - create + - delete + - get + - list + - patch + - update + - watch +- apiGroups: + - "" + resources: + - serviceaccounts + verbs: + - create + - delete + - get + - list + - patch + - update + - watch +- apiGroups: + - core.rekuberate.io + resources: + - sleepcycles + verbs: + - create + - delete + - get + - list + - patch + - update + - watch +- apiGroups: + - core.rekuberate.io + resources: + - sleepcycles/finalizers + verbs: + - update +- apiGroups: + - core.rekuberate.io + resources: + - sleepcycles/status + verbs: + - get + - patch + - update +--- +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRoleBinding +metadata: + name: {{ include "sleepcycles.fullname" . }}-manager-rolebinding + labels: + {{- include "sleepcycles.labels" . | nindent 4 }} +roleRef: + apiGroup: rbac.authorization.k8s.io + kind: ClusterRole + name: '{{ include "sleepcycles.fullname" . }}-manager-role' +subjects: +- kind: ServiceAccount + name: '{{ include "sleepcycles.fullname" . }}-controller-manager' + namespace: '{{ .Release.Namespace }}' \ No newline at end of file diff --git a/charts/sleepcycles/templates/metrics-reader-rbac.yaml b/charts/sleepcycles/templates/metrics-reader-rbac.yaml new file mode 100644 index 0000000..d6c7b63 --- /dev/null +++ b/charts/sleepcycles/templates/metrics-reader-rbac.yaml @@ -0,0 +1,11 @@ +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRole +metadata: + name: {{ include "sleepcycles.fullname" . }}-metrics-reader + labels: + {{- include "sleepcycles.labels" . | nindent 4 }} +rules: +- nonResourceURLs: + - /metrics + verbs: + - get \ No newline at end of file diff --git a/charts/sleepcycles/templates/metrics-service.yaml b/charts/sleepcycles/templates/metrics-service.yaml new file mode 100644 index 0000000..525749d --- /dev/null +++ b/charts/sleepcycles/templates/metrics-service.yaml @@ -0,0 +1,14 @@ +apiVersion: v1 +kind: Service +metadata: + name: {{ include "sleepcycles.fullname" . }}-controller-manager-metrics-service + labels: + control-plane: controller-manager + {{- include "sleepcycles.labels" . | nindent 4 }} +spec: + type: {{ .Values.metricsService.type }} + selector: + control-plane: controller-manager + {{- include "sleepcycles.selectorLabels" . | nindent 4 }} + ports: + {{- .Values.metricsService.ports | toYaml | nindent 2 -}} \ No newline at end of file diff --git a/charts/sleepcycles/templates/proxy-rbac.yaml b/charts/sleepcycles/templates/proxy-rbac.yaml new file mode 100644 index 0000000..9d28501 --- /dev/null +++ b/charts/sleepcycles/templates/proxy-rbac.yaml @@ -0,0 +1,34 @@ +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRole +metadata: + name: {{ include "sleepcycles.fullname" . }}-proxy-role + labels: + {{- include "sleepcycles.labels" . | nindent 4 }} +rules: +- apiGroups: + - authentication.k8s.io + resources: + - tokenreviews + verbs: + - create +- apiGroups: + - authorization.k8s.io + resources: + - subjectaccessreviews + verbs: + - create +--- +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRoleBinding +metadata: + name: {{ include "sleepcycles.fullname" . }}-proxy-rolebinding + labels: + {{- include "sleepcycles.labels" . | nindent 4 }} +roleRef: + apiGroup: rbac.authorization.k8s.io + kind: ClusterRole + name: '{{ include "sleepcycles.fullname" . }}-proxy-role' +subjects: +- kind: ServiceAccount + name: '{{ include "sleepcycles.fullname" . }}-controller-manager' + namespace: '{{ .Release.Namespace }}' \ No newline at end of file diff --git a/charts/sleepcycles/templates/serviceaccount.yaml b/charts/sleepcycles/templates/serviceaccount.yaml new file mode 100644 index 0000000..e720ae9 --- /dev/null +++ b/charts/sleepcycles/templates/serviceaccount.yaml @@ -0,0 +1,8 @@ +apiVersion: v1 +kind: ServiceAccount +metadata: + name: {{ include "sleepcycles.fullname" . }}-controller-manager + labels: + {{- include "sleepcycles.labels" . | nindent 4 }} + annotations: + {{- toYaml .Values.controllerManager.serviceAccount.annotations | nindent 4 }} \ No newline at end of file diff --git a/charts/sleepcycles/templates/sleepcycle-crd.yaml b/charts/sleepcycles/templates/sleepcycle-crd.yaml new file mode 100644 index 0000000..a5a6664 --- /dev/null +++ b/charts/sleepcycles/templates/sleepcycle-crd.yaml @@ -0,0 +1,113 @@ +apiVersion: apiextensions.k8s.io/v1 +kind: CustomResourceDefinition +metadata: + name: sleepcycles.core.rekuberate.io + annotations: + controller-gen.kubebuilder.io/version: v0.9.2 + labels: + {{- include "sleepcycles.labels" . | nindent 4 }} +spec: + group: core.rekuberate.io + names: + kind: SleepCycle + listKind: SleepCycleList + plural: sleepcycles + singular: sleepcycle + scope: Namespaced + versions: + - additionalPrinterColumns: + - jsonPath: .spec.enabled + name: Enabled + type: boolean + - jsonPath: .status.state + name: State + type: string + - jsonPath: .status.targets + name: Targets + type: string + - jsonPath: .spec.shutdown + name: Shutdown Schedule + type: string + - jsonPath: .spec.shutdownTimeZone + name: Shutdown Timezone + type: string + - jsonPath: .spec.wakeup + name: Wakeup Schedule + type: string + - jsonPath: .spec.wakeupTimeZone + name: Wakeup Timezone + type: string + name: v1alpha1 + schema: + openAPIV3Schema: + description: SleepCycle is the Schema for the sleepcycles API + properties: + apiVersion: + description: 'APIVersion defines the versioned schema of this representation + of an object. Servers should convert recognized schemas to the latest + internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources' + type: string + kind: + description: 'Kind is a string value representing the REST resource this + object represents. Servers may infer this from the endpoint the client + submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds' + type: string + metadata: + type: object + spec: + description: SleepCycleSpec defines the desired state of SleepCycle + properties: + enabled: + type: boolean + failedJobsHistoryLimit: + default: 1 + format: int32 + maximum: 3 + minimum: 1 + type: integer + runnerImage: + default: akyriako78/rekuberate-io-sleepcycles-runners + type: string + shutdown: + pattern: (^((\*\/)?([0-5]?[0-9])((\,|\-|\/)([0-5]?[0-9]))*|\*)\s+((\*\/)?((2[0-3]|1[0-9]|[0-9]|00))((\,|\-|\/)(2[0-3]|1[0-9]|[0-9]|00))*|\*)\s+((\*\/)?([1-9]|[12][0-9]|3[01])((\,|\-|\/)([1-9]|[12][0-9]|3[01]))*|\*)\s+((\*\/)?([1-9]|1[0-2])((\,|\-|\/)([1-9]|1[0-2]))*|\*|(jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|des))\s+((\*\/)?[0-6]((\,|\-|\/)[0-6])*|\*|00|(sun|mon|tue|wed|thu|fri|sat))\s*$)|@(annually|yearly|monthly|weekly|daily|hourly|reboot) + type: string + shutdownTimeZone: + default: UTC + type: string + successfulJobsHistoryLimit: + default: 1 + format: int32 + maximum: 3 + minimum: 1 + type: integer + wakeup: + pattern: (^((\*\/)?([0-5]?[0-9])((\,|\-|\/)([0-5]?[0-9]))*|\*)\s+((\*\/)?((2[0-3]|1[0-9]|[0-9]|00))((\,|\-|\/)(2[0-3]|1[0-9]|[0-9]|00))*|\*)\s+((\*\/)?([1-9]|[12][0-9]|3[01])((\,|\-|\/)([1-9]|[12][0-9]|3[01]))*|\*)\s+((\*\/)?([1-9]|1[0-2])((\,|\-|\/)([1-9]|1[0-2]))*|\*|(jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|des))\s+((\*\/)?[0-6]((\,|\-|\/)[0-6])*|\*|00|(sun|mon|tue|wed|thu|fri|sat))\s*$)|@(annually|yearly|monthly|weekly|daily|hourly|reboot) + type: string + wakeupTimeZone: + default: UTC + type: string + required: + - enabled + - shutdown + type: object + status: + description: SleepCycleStatus defines the observed state of SleepCycle + properties: + enabled: + type: boolean + state: + type: string + targets: + type: string + type: object + type: object + served: true + storage: true + subresources: + status: {} +status: + acceptedNames: + kind: "" + plural: "" + conditions: [] + storedVersions: [] \ No newline at end of file diff --git a/charts/sleepcycles/values.yaml b/charts/sleepcycles/values.yaml new file mode 100644 index 0000000..dcb79a7 --- /dev/null +++ b/charts/sleepcycles/values.yaml @@ -0,0 +1,76 @@ +controllerManager: + kubeRbacProxy: + args: + - --secure-listen-address=0.0.0.0:8443 + - --upstream=http://127.0.0.1:8080/ + - --logtostderr=true + - --v=0 + containerSecurityContext: + allowPrivilegeEscalation: false + capabilities: + drop: + - ALL + image: + repository: gcr.io/kubebuilder/kube-rbac-proxy + tag: v0.13.0 + resources: + limits: + cpu: 500m + memory: 128Mi + requests: + cpu: 5m + memory: 64Mi + manager: + args: + - --health-probe-bind-address=:8081 + - --metrics-bind-address=127.0.0.1:8080 + - --leader-elect + containerSecurityContext: + allowPrivilegeEscalation: false + capabilities: + drop: + - ALL + image: + repository: akyriako78/rekuberate-io-sleepcycles + tag: 0.2.0 + resources: + limits: + cpu: 500m + memory: 128Mi + requests: + cpu: 10m + memory: 64Mi + replicas: 1 + serviceAccount: + annotations: {} +kubernetesClusterDomain: cluster.local +managerConfig: + controllerManagerConfigYaml: |- + apiVersion: controller-runtime.sigs.k8s.io/v1alpha1 + kind: ControllerManagerConfig + health: + healthProbeBindAddress: :8081 + metrics: + bindAddress: 127.0.0.1:8080 + webhook: + port: 9443 + leaderElection: + leaderElect: true + resourceName: 04cbe4c0.rekuberate.io + # leaderElectionReleaseOnCancel defines if the leader should step down volume + # when the Manager ends. This requires the binary to immediately end when the + # Manager is stopped, otherwise, this setting is unsafe. Setting this significantly + # speeds up voluntary leader transitions as the new leader don't have to wait + # LeaseDuration time first. + # In the default scaffold provided, the program ends immediately after + # the manager stops, so would be fine to enable this option. However, + # if you are doing or is intended to do any operation such as perform cleanups + # after the manager stops then its usage might be unsafe. + # leaderElectionReleaseOnCancel: true +metricsService: + ports: + - name: https + port: 8443 + protocol: TCP + targetPort: https + type: ClusterIP diff --git a/config/manager/kustomization.yaml b/config/manager/kustomization.yaml index 329ffa7..10452d2 100644 --- a/config/manager/kustomization.yaml +++ b/config/manager/kustomization.yaml @@ -13,4 +13,4 @@ kind: Kustomization images: - name: controller newName: akyriako78/rekuberate-io-sleepcycles - newTag: 0.1.2 + newTag: 0.2.0