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

Ensures availability of unzip & yq; Updates yq commands for v4 #51

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
48 changes: 27 additions & 21 deletions utils/setup_nfs_provisioner.sh
Original file line number Diff line number Diff line change
Expand Up @@ -76,38 +76,44 @@ THEZIP=kubernetes-incubator.zip
curl -s -L -o $THEZIP https://github.com/kubernetes-incubator/external-storage/archive/master.zip
if [ $? -ne 0 ]; then
echo "ERROR: failed to download external storage zip -- aborting..."
exit 6
exit 8
fi

which unzip 2>&1 >/dev/null || yum -y install unzip
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit hash also tests for the existence of an executable and also updates bash's cache of where programs are located.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While refreshing bash's cache with a new search may not be much, I like hash is silent in stdout, and I wouldn't have to do the >/dev/null thing. Will update my PR.

if [ $? -ne 0 ]; then
echo "ERROR: unzip command unavailable -- aborting..."
exit 9
fi
unzip -q $THEZIP

cd external-storage-master/nfs-client/

echo "INFO: generating deployment.yaml for ppc64le..."

YQSCR=update_deployment.yaml
echo "- command: update
path: spec.template.spec.containers[0].image
value: docker.io/ibmcom/nfs-client-provisioner-ppc64le:latest
- command: update
path: spec.template.spec.containers[0].env.(name==NFS_SERVER).value
value: $SVRADDR
- command: update
path: spec.template.spec.containers[0].env.(name==NFS_PATH).value
value: $LOCALDIR
- command: update
path: spec.template.spec.volumes[0].nfs.server
value: $SVRADDR
- command: update
path: spec.template.spec.volumes[0].nfs.path
value: $LOCALDIR
" >$YQSCR
which go 2>&1 >/dev/null || yum -y install golang-bin
which yq 2>&1 >/dev/null || GO111MODULE=on go get github.com/mikefarah/yq/v4
if [ $? -ne 0 ]; then
echo "ERROR: yq command unavailable -- aborting..."
exit 10
fi
test -z "$GOBIN" && PATH=$PATH:~/go/bin || PATH=$PATH:$GOBIN
yq --version | grep -q 'version 4\.'
if [ $? -ne 0 ]; then
echo "ERROR: only yq v4 supported -- aborting..."
exit 11
fi

DEPLYAML=deploy/deployment-ppc64le.yaml
yq write -s $YQSCR deploy/deployment.yaml > $DEPLYAML
yq eval " \
.spec.template.spec.containers[0].image = \"docker.io/ibmcom/nfs-client-provisioner-ppc64le:latest\" | \
(.spec.template.spec.containers[0].env[] | select(.name==\"NFS_SERVER\")).value = \"$SVRADDR\" | \
(.spec.template.spec.containers[0].env[] | select(.name==\"NFS_PATH\")).value = \"$LOCALDIR\" | \
.spec.template.spec.volumes[0].nfs.server = \"$SVRADDR\" | \
.spec.template.spec.volumes[0].nfs.path = \"$LOCALDIR\" \
" deploy/deployment.yaml > $DEPLYAML
if [ $? -ne 0 -o ! -s $DEPLYAML ]; then
echo "ERROR: failed to update deployment.yaml -- aborting..."
exit 7
exit 12
fi

echo "INFO: executing oc commands to set up NFS provisioner..."
Expand All @@ -120,4 +126,4 @@ cp -pf $DEPLYAML /tmp/nfs-provisioner-deploy.yaml

popd > /dev/null

rm -rf $WORKDIR
rm -rf $WORKDIR