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

Add Kubectl binary download script for all Linux distributions #819

Merged

Conversation

k37y
Copy link
Contributor

@k37y k37y commented Jun 24, 2021

Changes

Kubectl binary download script modification has been done to accommodate all Linux distributions.

Submitter Checklist

  • Includes tests if functionality changed/was added
  • Includes docs if changes are user-facing
  • Set a kind label on this PR
  • Release notes block has been filled in, or marked NONE

Release Notes

NONE

@openshift-ci openshift-ci bot added the release-note-none Label for when a PR does not need a release note label Jun 24, 2021
@openshift-ci openshift-ci bot requested review from HeavyWombat and sbose78 June 24, 2021 05:56
@k37y k37y force-pushed the add-kubectl-download-script branch 3 times, most recently from 329a517 to ee7921e Compare June 25, 2021 06:12
Copy link
Contributor

@HeavyWombat HeavyWombat left a comment

Choose a reason for hiding this comment

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

Thanks for the PR. I do not know where other than the CI this script is being used, but having it more generic and supporting multiple Linux distributions is not a bad idea. However, I would opt for externalizing the logic. We should keep this brief and simple. If we were to start with the package manager switch, we could end up adding more and more cases that would need to be maintained.

For simplicity, I would suggest to adopt in the install kubectl with curl style.

Copy link
Contributor

@HeavyWombat HeavyWombat left a comment

Choose a reason for hiding this comment

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

This would be my suggestion:

#!/bin/bash

# Copyright The Shipwright Contributors
# 
# SPDX-License-Identifier: Apache-2.0

#
# Installs "kubectl"
#

set -euo pipefail

# Find a suitable install location
if [[ -w /usr/local/bin ]]; then
  TARGET_DIR=/usr/local/bin

elif [[ -w "${HOME}/bin" ]] && grep -q -e "${HOME}/bin" -e '\~/bin' <<<"$PATH"; then
  TARGET_DIR="${HOME}/bin"

else
  echo -e "Unable to determine a writable install location. Make sure that you have write access to either \\033[1m/usr/local/bin\\033[0m or \\033[1m${HOME}/bin\\033[0m and that is in your PATH."
  exit 1
fi

# Look-up current stable version from their release site
STABLE_VERSION="$(curl --fail --silent --location https://dl.k8s.io/release/stable.txt)"

echo "# Downloading kubectl binary..."
curl --fail --progress-bar --location "https://dl.k8s.io/release/${STABLE_VERSION}/bin/linux/amd64/kubectl" --output "${TARGET_DIR}/kubectl" && \
  chmod a+rx "${TARGET_DIR}/kubectl"

echo "# Validating kubectl binary..."
sha256sum --check <<<"$(curl --fail --silent --location "https://dl.k8s.io/${STABLE_VERSION}/bin/linux/amd64/kubectl.sha256") ${TARGET_DIR}/kubectl"

echo "# Kubectl version"
kubectl version --client

It is relatively short, requires no sudo and should run on most distros just fine. I checked it on Ubuntu, Fedora and UBI.

@k37y
Copy link
Contributor Author

k37y commented Jul 5, 2021

@HeavyWombat, It looks clean. I have made the suggested changes. Observed the same on shipwright-io/cli as well. Hence, shipwright-io/cli#31.

@k37y k37y force-pushed the add-kubectl-download-script branch from ee7921e to 0f2d68f Compare July 5, 2021 09:53
@qu1queee qu1queee requested a review from HeavyWombat July 5, 2021 15:34
@HeavyWombat
Copy link
Contributor

@kevydotvinu Could you help me by rebasing this branch to get the latest updates? I think there was a commit that addresses the deployment for the test cases.

@k37y k37y force-pushed the add-kubectl-download-script branch from 0f2d68f to 3905187 Compare July 8, 2021 10:03
@k37y
Copy link
Contributor Author

k37y commented Jul 8, 2021

@kevydotvinu Could you help me by rebasing this branch to get the latest updates? I think there was a commit that addresses the deployment for the test cases.

Yes, I have done that. Thanks, @HeavyWombat. :)

Copy link
Contributor

@HeavyWombat HeavyWombat left a comment

Choose a reason for hiding this comment

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

/lgtm

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Jul 8, 2021
Copy link
Member

@SaschaSchwarze0 SaschaSchwarze0 left a comment

Choose a reason for hiding this comment

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

/approve

@openshift-ci
Copy link
Contributor

openshift-ci bot commented Jul 13, 2021

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: SaschaSchwarze0

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-ci openshift-ci bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jul 13, 2021
@openshift-merge-robot openshift-merge-robot merged commit 29da836 into shipwright-io:main Jul 13, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. lgtm Indicates that a PR is ready to be merged. release-note-none Label for when a PR does not need a release note
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants