diff --git a/.gitignore b/.gitignore index 0fc5541..3f5c7c9 100644 --- a/.gitignore +++ b/.gitignore @@ -4,9 +4,9 @@ build/ ################################# -# Secret files # +# Helm files # ################################# -/releases/dev/secret.yaml +/charts/xelon-ccm/values-dev.yaml ################################# # Golang files # diff --git a/charts/xelon-ccm/.helmignore b/charts/xelon-ccm/.helmignore new file mode 100644 index 0000000..07e33b6 --- /dev/null +++ b/charts/xelon-ccm/.helmignore @@ -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 diff --git a/charts/xelon-ccm/Chart.yaml b/charts/xelon-ccm/Chart.yaml new file mode 100644 index 0000000..3fdb6c2 --- /dev/null +++ b/charts/xelon-ccm/Chart.yaml @@ -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" diff --git a/charts/xelon-ccm/templates/NOTES.txt b/charts/xelon-ccm/templates/NOTES.txt new file mode 100644 index 0000000..4cedc91 --- /dev/null +++ b/charts/xelon-ccm/templates/NOTES.txt @@ -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 diff --git a/charts/xelon-ccm/templates/_helpers.tpl b/charts/xelon-ccm/templates/_helpers.tpl new file mode 100644 index 0000000..1f22252 --- /dev/null +++ b/charts/xelon-ccm/templates/_helpers.tpl @@ -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 }} diff --git a/charts/xelon-ccm/templates/deployment.yaml b/charts/xelon-ccm/templates/deployment.yaml new file mode 100644 index 0000000..d6f2978 --- /dev/null +++ b/charts/xelon-ccm/templates/deployment.yaml @@ -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 diff --git a/charts/xelon-ccm/templates/rbac.yaml b/charts/xelon-ccm/templates/rbac.yaml new file mode 100644 index 0000000..c28abf4 --- /dev/null +++ b/charts/xelon-ccm/templates/rbac.yaml @@ -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 diff --git a/charts/xelon-ccm/templates/secret.yaml b/charts/xelon-ccm/templates/secret.yaml new file mode 100644 index 0000000..fec29b1 --- /dev/null +++ b/charts/xelon-ccm/templates/secret.yaml @@ -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 }} diff --git a/charts/xelon-ccm/templates/serviceaccount.yaml b/charts/xelon-ccm/templates/serviceaccount.yaml new file mode 100644 index 0000000..f842219 --- /dev/null +++ b/charts/xelon-ccm/templates/serviceaccount.yaml @@ -0,0 +1,5 @@ +apiVersion: v1 +kind: ServiceAccount +metadata: + name: xelon-cloud-controller-manager + namespace: kube-system diff --git a/charts/xelon-ccm/values.yaml b/charts/xelon-ccm/values.yaml new file mode 100644 index 0000000..e4eb85d --- /dev/null +++ b/charts/xelon-ccm/values.yaml @@ -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: "" diff --git a/cmd/xelon-cloud-controller-manager/main.go b/cmd/xelon-cloud-controller-manager/main.go index d47b6f9..e15536b 100644 --- a/cmd/xelon-cloud-controller-manager/main.go +++ b/cmd/xelon-cloud-controller-manager/main.go @@ -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 { diff --git a/internal/xelon/cloud.go b/internal/xelon/cloud.go index 8c4b392..a53ffc0 100644 --- a/internal/xelon/cloud.go +++ b/internal/xelon/cloud.go @@ -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" @@ -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 != "" {