Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

V23.5.x add support for upgrading crds via Helm Hooks #537

Merged
merged 2 commits into from
May 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
# Build the manager binary
FROM golang:1.20 as builder

ARG TARGETARCH=amd64

WORKDIR /workspace
# Copy the Go Modules manifests
COPY go.mod go.mod
Expand All @@ -29,6 +31,17 @@ COPY api/ api/
COPY controllers/ controllers/
COPY pkg/ pkg/

# Add kubectl tool
RUN curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/${TARGETARCH}/kubectl"
adrianchiris marked this conversation as resolved.
Show resolved Hide resolved
RUN chmod +x ./kubectl

# Add helm chart DIR to get CRDs from it
COPY deployment/network-operator chart
# copy CRDs from helm charts
RUN mkdir crds && \
cp -r chart/crds /workspace/crds/network-operator/ && \
cp -r chart/charts/sriov-network-operator/crds /workspace/crds/sriov-network-operator/

# Build
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -o manager main.go

Expand Down Expand Up @@ -57,6 +70,9 @@ LABEL org.label-schema.vcs-url="https://github.com/Mellanox/network-operator"

WORKDIR /
COPY --from=builder /workspace/manager .
COPY --from=builder /workspace/kubectl /usr/local/bin
COPY --from=builder /workspace/crds /crds

COPY manifests/ manifests/
USER 65532:65532

Expand Down
14 changes: 8 additions & 6 deletions deployment/network-operator/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -169,11 +169,6 @@ Notes:
Before starting the upgrade to a specific release version, please, check release notes for this version to ensure that
no additional actions are required.

Since Helm doesn’t support auto-upgrade of existing CRDs, the user needs to follow a two-step process to upgrade the
network-operator release:

- Upgrade CRD to the latest version
- Apply helm chart update

### Check available releases

Expand All @@ -183,7 +178,12 @@ helm search repo mellanox/network-operator -l

> __NOTE__: add `--devel` option if you want to list beta releases as well

### Download CRDs for the specific release
### Upgrade CRDs to compatible version

The network-operator helm chart contains a pre-upgrade hook that will automatically upgrade required CRDs in the cluster.
The hook is enabled by default. If you don't want to upgrade CRDs with helm automatically,
you can disable auto upgrade by setting `upgradeCRDs: false` in the helm chart values.
Then you can follow the guide below to download and apply CRDs for the concrete version of the network-operator.

It is possible to retrieve updated CRDs from the Helm chart or from the release branch on GitHub. Example bellow show
how to download and unpack Helm chart for specified release and then apply CRDs update from it.
Expand Down Expand Up @@ -331,10 +331,12 @@ parameters.

### General parameters

<<<<<<< HEAD
| Name | Type | Default | description |
| ---- |--------| ------- |------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `nfd.enabled` | bool | `True` | deploy Node Feature Discovery |
| `sriovNetworkOperator.enabled` | bool | `False` | deploy SR-IOV Network Operator |
| `upgradeCRDs` | bool | `True` | enable CRDs upgrade with helm pre-upgrade hook |
| `sriovNetworkOperator.configDaemonNodeSelectorExtra` | object | `{"node-role.kubernetes.io/worker": ""}` | Additional nodeSelector for sriov-network-operator config daemon. These values will be added in addition to default values managed by the network-operator.|
| `psp.enabled` | bool | `False` | deploy Pod Security Policy |
| `imagePullSecrets` | list | `[]` | An optional list of references to secrets to use for pulling any of the Network Operator image if it's not overrided |
Expand Down
37 changes: 37 additions & 0 deletions deployment/network-operator/templates/upgrade-crd.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{{- if .Values.upgradeCRDs }}
apiVersion: batch/v1
kind: Job
metadata:
name: network-operator-upgrade-crd
namespace: {{ .Release.Namespace }}
annotations:
"helm.sh/hook": pre-upgrade
"helm.sh/hook-weight": "1"
"helm.sh/hook-delete-policy": hook-succeeded,before-hook-creation
labels:
{{- include "network-operator.labels" . | nindent 4 }}
app.kubernetes.io/component: "network-operator"
spec:
template:
metadata:
name: network-operator-upgrade-crd
labels:
{{- include "network-operator.labels" . | nindent 8 }}
app.kubernetes.io/component: "network-operator"
spec:
serviceAccountName: {{ include "network-operator.fullname" . }}
imagePullSecrets: {{ include "network-operator.operator.imagePullSecrets" . | nindent 6 }}
containers:
- name: upgrade-crd
image: "{{ .Values.operator.repository }}/{{ .Values.operator.image }}:{{ .Values.operator.tag | default .Chart.AppVersion }}"
imagePullPolicy: IfNotPresent
command:
- /bin/sh
- -c
- >
kubectl apply -f /crds/network-operator;
{{- if .Values.sriovNetworkOperator.enabled }}
kubectl apply -f /crds/sriov-network-operator;
{{- end }}
restartPolicy: OnFailure
{{- end }}
2 changes: 2 additions & 0 deletions deployment/network-operator/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ nfd:
psp:
enabled: false

upgradeCRDs: true

sriovNetworkOperator:
enabled: false
# inject additional values to nodeSelector for config daemon
Expand Down