Skip to content

Commit f2baa53

Browse files
authored
doc(upgrade): upgrade instruction for nfs-provisioner (#123)
Signed-off-by: mayank <mayank.patel@mayadata.io>
1 parent b410fa5 commit f2baa53

File tree

2 files changed

+186
-0
lines changed

2 files changed

+186
-0
lines changed

docs/tutorial/upgrade-nfs-server.sh

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
#!/bin/bash
2+
3+
# Copyright 2021 The OpenEBS Authors. All rights reserved.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
#
17+
18+
set -e
19+
20+
print_help() {
21+
cat << EOF
22+
Usage:
23+
$0 <options> IMAGE_TAG
24+
25+
Example:
26+
$0 -n nfs-ns 0.7.1
27+
28+
IMAGE_TAG is required to execute this script.
29+
30+
By default, this script uses 'openebs' namespace to search nfs-server deployment.
31+
If you have used different namespace for nfs-server deployment then you must provide
32+
the namespace using option(-n).
33+
34+
Supported options are as below:
35+
-h Show this message and exit
36+
-n namespace for nfs-server deployment. Default namespace used is 'openebs'
37+
-d nfs-server deployment name. If option '-d' is not mentioned then this script will
38+
upgrade all the nfs-server deployments available in 'openebs' or (-n NS) namespace.
39+
EOF
40+
}
41+
42+
# NFS_SERVER_NS represent the namespace for nfs server deployment
43+
# By default, it is set to 'openebs'.
44+
NFS_SERVER_NS=openebs
45+
46+
# IMAGE_TAG represent the version for nfs server image
47+
IMAGE_TAG=
48+
49+
# DEPLOYMENTS represent the nfs-server deployment name/name-list
50+
DEPLOYMENTS=
51+
52+
# list_deployment list nfs-server deployment in NFS_SERVER_NS namespace
53+
list_deployment() {
54+
local -n deploy=$1
55+
deploy=$(kubectl get deployment -n ${NFS_SERVER_NS} -l openebs.io/nfs-server --no-headers -o custom-columns=:.metadata.name)
56+
}
57+
58+
# upgrade_deployment patch the given deployment in NFS_SERVER_NS with image-tag IMAGE_TAG
59+
upgrade_deployment() {
60+
deploymentName=$1
61+
62+
existingImage=$(kubectl get deployment -n openebs ${deploymentName} -o jsonpath='{.spec.template.spec.containers[0].image}')
63+
64+
repo=${existingImage%:*}
65+
newImage=${repo}:${IMAGE_TAG}
66+
patchJson="{\"spec\": {\"template\": {\"spec\": {\"containers\" : [{\"name\" : \"nfs-server\", \"image\" : \"${newImage}\"}]}}}}"
67+
68+
kubectl patch deploy -n ${NFS_SERVER_NS} ${deploymentName} -p "${patchJson}" > /dev/null
69+
exitCode=$?
70+
if [ $exitCode -ne 0 ]; then
71+
echo "ERROR: Failed to patch ${deploymentName} exit code: $exitCode"
72+
exit
73+
fi
74+
75+
rolloutStatus=$(kubectl rollout status -n ${NFS_SERVER_NS} deployment/${deploymentName})
76+
exitCode=$?
77+
if [[ ($exitCode -ne 0) || ! (${rolloutStatus} =~ "successfully rolled out") ]]; then
78+
echo "ERROR: Failed to rollout status for ${deploymentName} exit code: $exitCode"
79+
exit
80+
fi
81+
}
82+
83+
# options followed by ':' needs an argument
84+
# see `man getopt`
85+
shortOpts=hn:d:
86+
87+
# store the output of getopt so that we can assign it to "$@" using set command
88+
# since we are using "--options" in getopt, arguments are passed via -- "$@"
89+
PARSED=$(getopt --options ${shortOpts} --name "$0" -- "$@")
90+
if [[ $? -ne 0 ]]; then
91+
echo "invalid arguments"
92+
exit 1
93+
fi
94+
# assign arguments to "$@"
95+
eval set -- "${PARSED}"
96+
97+
while [[ $# -gt 0 ]]
98+
do
99+
case "$1" in
100+
-h)
101+
print_help
102+
exit 0
103+
;;
104+
-n)
105+
shift
106+
NFS_SERVER_NS=$1
107+
;;
108+
-d)
109+
shift
110+
DEPLOYMENTS=$1
111+
;;
112+
## argument without options is mentioned after '--'
113+
--)
114+
shift
115+
IMAGE_TAG=$1
116+
break
117+
esac
118+
shift # Expose the next argument
119+
done
120+
121+
[[ -z $IMAGE_TAG ]] && print_help && exit 0
122+
123+
[[ -z $DEPLOYMENTS ]] && list_deployment DEPLOYMENTS
124+
125+
for i in ${DEPLOYMENTS}; do
126+
upgrade_deployment ${i}
127+
echo "Deployment ${NFS_SERVER_NS}/${i} updated with image tag ${IMAGE_TAG}"
128+
done

docs/tutorial/upgrade.md

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# Upgrade
2+
3+
NFS Provisioner upgrade requires upgrading NFS Provisioner deployment and NFS server Deployment. It is not necessary to upgrade NFS server Deployment, unless mentioned in changelog/release-notes.
4+
5+
## Upgrade NFS Provisioner
6+
### Installed using Helm
7+
Before executing the helm upgrade, you need to download the latest chart. To update the helm repo with latest chart, run below command:
8+
9+
```bash
10+
helm repo update
11+
```
12+
13+
To upgrade nfs-provisioner to latest version, run below command:
14+
15+
```bash
16+
helm upgrade nfs openebs-nfs/nfs-provisioner -n openebs
17+
```
18+
19+
Above command will update the nfs-provisioner to latest version. If you want to upgrade to a specific version, run below command:
20+
21+
```bash
22+
helm upgrade nfs openebs-nfs/nfs-provisioner -n openebs --version=<DESIRED_VERSION>
23+
```
24+
25+
*Note: In above command, `nfs` is helm repo name.*
26+
27+
### Installed using kubectl
28+
If you have installed the nfs-provisioner through kubectl, then you can upgrade the nfs-provisioner deployment to latest version by running the below command:
29+
30+
```bash
31+
kubectl apply -f https://openebs.github.io/charts/nfs-operator.yaml
32+
```
33+
34+
Above command will upgrade the nfs-provisioner to latest version. You can also upgrade to specific version by running the below command:
35+
36+
```bash
37+
kubectl apply -f https://openebs.github.io/charts/versioned/<OPENEBS VERSION>/nfs-operator.yaml
38+
```
39+
40+
## Upgrading NFS server Deployment
41+
To update the nfs-server deployment, run below command:
42+
43+
```bash
44+
./docs/tutorial/upgrade-nfs-server.sh 0.7.1
45+
```
46+
47+
Above command assumes that nfs-server deployments are running in *openebs* namespace. If you have configured nfs provisioner to create nfs-server deployment in different namespace, run below command:
48+
49+
```bash
50+
./docs/tutorial/upgrade-nfs-server.sh -n <NFS_SERVER_NS> 0.7.1
51+
```
52+
53+
To upgrade specific nfs-server deployment, run below command:
54+
55+
```bash
56+
./docs/tutorial/upgrade-nfs-server.sh -d <NFS_SERVER_DEPLOYMENT_NAME> 0.7.1
57+
```
58+
*Note: Upgrading NFS server deployment recreates the nfs-server pod with the updated image tag. This action will cause downtime(**downtime = time to kill existing nfs-server pod + pull time for new nfs-server image + boot time for new nfs-server pod**) for IOs.*

0 commit comments

Comments
 (0)