diff --git a/charts/mcs-controller-manager/.helmignore b/charts/mcs-controller-manager/.helmignore new file mode 100644 index 00000000..0e8a0eb3 --- /dev/null +++ b/charts/mcs-controller-manager/.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/mcs-controller-manager/Chart.yaml b/charts/mcs-controller-manager/Chart.yaml new file mode 100644 index 00000000..959efa1a --- /dev/null +++ b/charts/mcs-controller-manager/Chart.yaml @@ -0,0 +1,24 @@ +apiVersion: v2 +name: mcs-controller-manager +description: A Helm chart for Kubernetes + +# 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.1.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: "v0.1.0" diff --git a/charts/mcs-controller-manager/README.md b/charts/mcs-controller-manager/README.md new file mode 100644 index 00000000..8cf6b445 --- /dev/null +++ b/charts/mcs-controller-manager/README.md @@ -0,0 +1,42 @@ +# Azure Fleet MultiClusterService Controller Manager Helm Chart + +## Install CRD + +```bash +# Go to root folder of fleet-networking repo +cd /fleet-networking +kubectl apply -f config/crd/* +``` + +## Install Chart + +```bash +# Helm install under root directory of fleet-networking repo +helm install mcs-controller-manager ./charts/mcs-controller-manager/ +``` + +_See [helm install](https://helm.sh/docs/helm/helm_install/) for command documentation._ + +## Upgrade Chart + +```bash +# Helm upgrade under root directory of fleet-networking repo +helm upgrade mcs-controller-manager ./charts/mcs-controller-manager/ +``` + +## Parameters + +| Parameter | Description | Default | +|:-|:-|:-| +| replicaCount | The number of mcs-controller-manager replicas to deploy | `1` | +| image.repository | Image repository | `ghcr.io/azure/fleet-networking/mcs-controller-manager` | +| image.pullPolicy | Image pullPolicy | `IfNotPresent` | +| image.tag | The image tag to use | `v0.1.0` | +| logVerbosity | Log level. Uses V logs (klog) | `2` | +| fleetSystemNamespace | Namespace that this Helm chart is installed on and reserved by fleet. | `fleet-system` | +| resources | The resource request/limits for the container image | limits: 500m CPU, 1Gi, requests: 100m CPU, 128Mi | +| podAnnotations | Pod Annotations | `{}` | +| affinity | The node affinity to use for pod scheduling | `{}` | +| tolerations | The toleration to use for pod scheduling | `[]` | + +## Contributing Changes diff --git a/charts/mcs-controller-manager/templates/_helpers.tpl b/charts/mcs-controller-manager/templates/_helpers.tpl new file mode 100644 index 00000000..c7109a77 --- /dev/null +++ b/charts/mcs-controller-manager/templates/_helpers.tpl @@ -0,0 +1,51 @@ +{{/* +Expand the name of the chart. +*/}} +{{- define "mcs-controller-manager.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 "mcs-controller-manager.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 "mcs-controller-manager.chart" -}} +{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }} +{{- end }} + +{{/* +Common labels +*/}} +{{- define "mcs-controller-manager.labels" -}} +helm.sh/chart: {{ include "mcs-controller-manager.chart" . }} +{{ include "mcs-controller-manager.selectorLabels" . }} +{{- if .Chart.AppVersion }} +app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} +{{- end }} +app.kubernetes.io/managed-by: {{ .Release.Service }} +{{- end }} + +{{/* +Selector labels +*/}} +{{- define "mcs-controller-manager.selectorLabels" -}} +app.kubernetes.io/name: {{ include "mcs-controller-manager.name" . }} +app.kubernetes.io/instance: {{ .Release.Name }} +{{- end }} diff --git a/charts/mcs-controller-manager/templates/deployment.yaml b/charts/mcs-controller-manager/templates/deployment.yaml new file mode 100644 index 00000000..ed3373df --- /dev/null +++ b/charts/mcs-controller-manager/templates/deployment.yaml @@ -0,0 +1,56 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: {{ include "mcs-controller-manager.fullname" . }} + namespace: {{ .Values.fleetSystemNamespace }} + labels: + {{- include "mcs-controller-manager.labels" . | nindent 4 }} +spec: + replicas: {{ .Values.replicaCount }} + selector: + matchLabels: + {{- include "mcs-controller-manager.selectorLabels" . | nindent 6 }} + template: + metadata: + {{- with .Values.podAnnotations }} + annotations: + {{- toYaml . | nindent 8 }} + {{- end }} + labels: + {{- include "mcs-controller-manager.selectorLabels" . | nindent 8 }} + spec: + serviceAccountName: {{ include "mcs-controller-manager.fullname" . }}-sa + containers: + - name: {{ .Chart.Name }} + image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}" + imagePullPolicy: {{ .Values.image.pullPolicy }} + args: + - --leader-elect={{ .Values.enableLeaderElection }} + - --fleet-system-namespace={{ .Values.fleetSystemNamespace }} + - --v={{ .Values.logVerbosity }} + ports: + - containerPort: 8081 + name: healthz + protocol: TCP + livenessProbe: + httpGet: + path: /healthz + port: healthz + readinessProbe: + httpGet: + path: /readyz + port: healthz + resources: + {{- toYaml .Values.resources | nindent 12 }} + {{- with .Values.nodeSelector }} + nodeSelector: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.affinity }} + affinity: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.tolerations }} + tolerations: + {{- toYaml . | nindent 8 }} + {{- end }} diff --git a/charts/mcs-controller-manager/templates/rbac.yaml b/charts/mcs-controller-manager/templates/rbac.yaml new file mode 100644 index 00000000..9e045f6e --- /dev/null +++ b/charts/mcs-controller-manager/templates/rbac.yaml @@ -0,0 +1,70 @@ +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRole +metadata: + creationTimestamp: null + name: {{ include "mcs-controller-manager.fullname" . }}-role +rules: +- apiGroups: + - "" + resources: + - services + verbs: + - create + - delete + - get + - list + - patch + - update + - watch +- apiGroups: + - networking.fleet.azure.com + resources: + - multiclusterservices + verbs: + - create + - delete + - get + - list + - patch + - update + - watch +- apiGroups: + - networking.fleet.azure.com + resources: + - multiclusterservices/finalizers + verbs: + - get + - update +- apiGroups: + - networking.fleet.azure.com + resources: + - multiclusterservices/status + verbs: + - get + - patch + - update +- apiGroups: + - networking.fleet.azure.com + resources: + - serviceimports + verbs: + - create + - delete + - get + - list + - patch + - update + - watch +--- +kind: ClusterRoleBinding +apiVersion: rbac.authorization.k8s.io/v1 +metadata: + name: {{ include "mcs-controller-manager.fullname" . }}-role-binding +roleRef: + apiGroup: rbac.authorization.k8s.io + kind: ClusterRole + name: {{ include "mcs-controller-manager.fullname" . }}-role +subjects: + - kind: ServiceAccount + name: {{ include "mcs-controller-manager.fullname" . }}-sa + namespace: {{ .Values.fleetSystemNamespace }} \ No newline at end of file diff --git a/charts/mcs-controller-manager/templates/serviceaccount.yaml b/charts/mcs-controller-manager/templates/serviceaccount.yaml new file mode 100644 index 00000000..b7254e8e --- /dev/null +++ b/charts/mcs-controller-manager/templates/serviceaccount.yaml @@ -0,0 +1,7 @@ +apiVersion: v1 +kind: ServiceAccount +metadata: + name: {{ include "mcs-controller-manager.fullname" . }}-sa + namespace: {{ .Values.fleetSystemNamespace }} + labels: + {{- include "mcs-controller-manager.labels" . | nindent 4 }} diff --git a/charts/mcs-controller-manager/values.yaml b/charts/mcs-controller-manager/values.yaml new file mode 100644 index 00000000..79ca68f8 --- /dev/null +++ b/charts/mcs-controller-manager/values.yaml @@ -0,0 +1,31 @@ +# Default values for mcs-controller-manager. +# This is a YAML-formatted file. +# Declare variables to be passed into your templates. + +replicaCount: 1 + +image: + repository: ghcr.io/azure/fleet-networking/mcs-controller-manager + pullPolicy: IfNotPresent + # Overrides the image tag whose default is the chart appVersion. + tag: "v0.1.0" + +logVerbosity: 2 + +fleetSystemNamespace: fleet-system + +resources: + limits: + cpu: 500m + memory: 1Gi + requests: + cpu: 100m + memory: 128Mi + +podAnnotations: {} + +nodeSelector: {} + +tolerations: [] + +affinity: {} diff --git a/cmd/hub-net-controller-manager/main.go b/cmd/hub-net-controller-manager/main.go index f63bb045..bb234504 100644 --- a/cmd/hub-net-controller-manager/main.go +++ b/cmd/hub-net-controller-manager/main.go @@ -50,7 +50,7 @@ func main() { var probeAddr string flag.StringVar(&metricsAddr, "metrics-bind-address", ":8080", "The address the metric endpoint binds to.") flag.StringVar(&probeAddr, "health-probe-bind-address", ":8081", "The address the probe endpoint binds to.") - flag.BoolVar(&enableLeaderElection, "leader-elect", false, + flag.BoolVar(&enableLeaderElection, "leader-elect", true, "Enable leader election for controller manager. "+ "Enabling this will ensure there is only one active controller manager.") opts := zap.Options{