Skip to content

Commit

Permalink
feat: helm integration (#12)
Browse files Browse the repository at this point in the history
* fix: unify env vars names across all products

- terraform provider
- ccm
- csi

* feat(helm): add helm chart for cloud provider
  • Loading branch information
pavel-github authored May 22, 2024
1 parent 123eb6c commit 0a32026
Show file tree
Hide file tree
Showing 12 changed files with 254 additions and 5 deletions.
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
build/

#################################
# Secret files #
# Helm files #
#################################
/releases/dev/secret.yaml
/charts/xelon-ccm/values-dev.yaml

#################################
# Golang files #
Expand Down
30 changes: 30 additions & 0 deletions charts/xelon-ccm/.helmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#################################
# Git & GitHub files #
#################################
.git/
.github/
.gitignore

#################################
# IDE generated files #
#################################
.idea/
.vscode/
.project
*.iml

#################################
# Logs and temp files #
#################################
*.bak
*.log
*.orig
*.swp
*~

#################################
# OS generated files #
#################################
Thumbs.db
.directory
.DS_Store
7 changes: 7 additions & 0 deletions charts/xelon-ccm/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
apiVersion: v2
name: xelon-cloud-controller-manager
version: 0.1.0
description: A Helm Chart for the Cloud Controller Manager on Xelon HQ
type: application

appVersion: "1.0.0"
4 changes: 4 additions & 0 deletions charts/xelon-ccm/templates/NOTES.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Xelon Cloud Provider {{ .Chart.AppVersion }} was deployed in namespace {{ .Release.Namespace }}.

To verify that xelon-cloud-controller-manager has successfully started, run:
kubectl -n kube-system logs --selector app=xelon-cloud-controller-manager
51 changes: 51 additions & 0 deletions charts/xelon-ccm/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
{{/*
Expand the name of the chart.
*/}}
{{- define "xelon-ccm.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 "xelon-ccm.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 "xelon-ccm.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
{{- end }}

{{/*
Common labels
*/}}
{{- define "xelon-ccm.labels" -}}
helm.sh/chart: {{ include "xelon-ccm.chart" . }}
{{ include "xelon-ccm.selectorLabels" . }}
{{- if .Chart.AppVersion }}
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
{{- end }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- end }}

{{/*
Selector labels
*/}}
{{- define "xelon-ccm.selectorLabels" -}}
app.kubernetes.io/name: {{ include "xelon-ccm.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end }}
71 changes: 71 additions & 0 deletions charts/xelon-ccm/templates/deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: xelon-cloud-controller-manager
namespace: kube-system
spec:
replicas: 1
revisionHistoryLimit: 2
selector:
matchLabels:
app: xelon-cloud-controller-manager
template:
metadata:
labels:
app: xelon-cloud-controller-manager
spec:
dnsPolicy: Default
hostNetwork: true
priorityClassName: ""
serviceAccountName: xelon-cloud-controller-manager
tolerations:
- key: "CriticalAddonsOnly"
operator: "Exists"
- key: "node.cloudprovider.kubernetes.io/uninitialized"
value: "true"
effect: NoSchedule
- key: "node-role.kubernetes.io/master"
effect: NoSchedule
- key: "node.kubernetes.io/not-ready"
operator: Exists
effect: NoSchedule
- key: "node.kubernetes.io/unreachable"
operator: Exists
effect: NoSchedule
containers:
- name: xelon-cloud-controller-manager
image: {{ .Values.image.repository }}:{{ .Values.image.tag }}
imagePullPolicy: {{ .Values.image.pullPolicy }}
args:
- "--leader-elect=false"
- "--v=2"
env:
- name: XELON_BASE_URL
valueFrom:
secretKeyRef:
name: xelon-ccm-credentials
key: baseUrl
- name: XELON_CLIENT_ID
valueFrom:
secretKeyRef:
name: xelon-ccm-credentials
key: clientId
- name: XELON_CLOUD_ID
valueFrom:
secretKeyRef:
name: xelon-ccm-credentials
key: cloudId
- name: XELON_KUBERNETES_CLUSTER_ID
valueFrom:
secretKeyRef:
name: xelon-ccm-credentials
key: kubernetesClusterId
- name: XELON_TOKEN
valueFrom:
secretKeyRef:
name: xelon-ccm-credentials
key: token
resources:
requests:
cpu: 100m
memory: 50Mi
52 changes: 52 additions & 0 deletions charts/xelon-ccm/templates/rbac.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
annotations:
rbac.authorization.kubernetes.io/autoupdate: "true"
name: system:xelon-cloud-controller-manager
rules:
- apiGroups: [""]
resources: ["endpoints"]
verbs: ["create", "get", "list", "update", "watch"]
- apiGroups: [""]
resources: ["events"]
verbs: ["create", "patch", "update"]
- apiGroups: [""]
resources: ["nodes"]
verbs: ["*"]
- apiGroups: [""]
resources: ["nodes/status"]
verbs: ["patch"]
- apiGroups: [""]
resources: ["secrets"]
verbs: ["get", "list", "watch"]
- apiGroups: [""]
resources: ["services"]
verbs: ["list", "patch", "update", "watch"]
- apiGroups: [""]
resources: ["services/status"]
verbs: ["list", "patch", "update", "watch"]
- apiGroups: [""]
resources: ["serviceaccounts"]
verbs: ["create"]
- apiGroups: [""]
resources: ["persistentvolumes"]
verbs: ["get", "list", "update", "watch"]
- apiGroups: ["coordination.k8s.io"]
resources: ["leases"]
verbs: ["create", "get", "list", "update", "watch"]

---
kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: system:xelon-cloud-controller-manager
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: system:xelon-cloud-controller-manager
subjects:
- kind: ServiceAccount
name: xelon-cloud-controller-manager
namespace: kube-system
12 changes: 12 additions & 0 deletions charts/xelon-ccm/templates/secret.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
apiVersion: v1
kind: Secret
metadata:
name: xelon-ccm-credentials
namespace: kube-system
type: Opaque
stringData:
baseUrl: {{ .Values.xelon.baseUrl | quote }}
clientId: {{ .Values.xelon.clientId | quote }}
cloudId: {{ .Values.xelon.cloudId | quote }}
kubernetesClusterId: {{ .Values.xelon.kubernetesClusterId | quote }}
token: {{ .Values.xelon.token | quote }}
5 changes: 5 additions & 0 deletions charts/xelon-ccm/templates/serviceaccount.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
apiVersion: v1
kind: ServiceAccount
metadata:
name: xelon-cloud-controller-manager
namespace: kube-system
17 changes: 17 additions & 0 deletions charts/xelon-ccm/values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
image:
repository: xelonag/xelon-cloud-controller-manager
tag: "dev"
pullPolicy: Always

replicaCount: 1

imagePullSecrets: []
nameOverride: ""
fullnameOverride: ""

xelon:
baseUrl: "https://vdc.xelon.ch/api/service/"
clientId: ""
cloudId: ""
kubernetesClusterId: ""
token: ""
2 changes: 1 addition & 1 deletion cmd/xelon-cloud-controller-manager/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func cloudInitializer(c *config.CompletedConfig) cloudprovider.Interface {
cloudConfig := c.ComponentConfig.KubeCloudShared.CloudProvider
cloud, err := cloudprovider.InitCloudProvider(cloudConfig.Name, cloudConfig.CloudConfigFile)
if err != nil {
klog.Errorf("failed to initizlize cloud provider: %v", err)
klog.Errorf("failed to initialize cloud provider: %v", err)
os.Exit(1)
}
if cloud == nil {
Expand Down
4 changes: 2 additions & 2 deletions internal/xelon/cloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
const (
ProviderName string = "xelon"

xelonAPIURLEnv string = "XELON_API_URL"
xelonBaseURLEnv string = "XELON_BASE_URL"
xelonClientIDEnv string = "XELON_CLIENT_ID"
xelonCloudIDEnv string = "XELON_CLOUD_ID"
xelonKubernetesClusterIDEnv string = "XELON_KUBERNETES_CLUSTER_ID"
Expand Down Expand Up @@ -57,7 +57,7 @@ func newCloud() (cloudprovider.Interface, error) {

userAgent := "xelon-cloud-controller-manager"
opts := []xelon.ClientOption{xelon.WithUserAgent(userAgent)}
if apiURL := os.Getenv(xelonAPIURLEnv); apiURL != "" {
if apiURL := os.Getenv(xelonBaseURLEnv); apiURL != "" {
opts = append(opts, xelon.WithBaseURL(apiURL))
}
if clientID := os.Getenv(xelonClientIDEnv); clientID != "" {
Expand Down

0 comments on commit 0a32026

Please sign in to comment.