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

/hack: improve shell script in hack #8143

Merged
merged 1 commit into from
Dec 28, 2019
Merged

/hack: improve shell script in hack #8143

merged 1 commit into from
Dec 28, 2019

Conversation

tanjunchen
Copy link
Member

@tanjunchen tanjunchen commented Dec 18, 2019

/cc @justinsb @mikesplain @rifelpet @robinpercy
/hold

Let's talk about there changes
i have run ./hack/update-header.sh before i commited it.

@k8s-ci-robot k8s-ci-robot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Dec 18, 2019
@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Dec 18, 2019
@tanjunchen tanjunchen changed the title /hack: improve shell in hack /hack: improve shell script in hack Dec 18, 2019
@@ -110,9 +110,9 @@ echo ==========
echo "Deleting cluster ${CLUSTER_NAME}. Elle est finie."

kops delete cluster \
--name $CLUSTER_NAME \
Copy link
Member Author

Choose a reason for hiding this comment

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

Double quote to prevent globbing and word splitting

Copy link
Member

Choose a reason for hiding this comment

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

your effort is appreciated!
as for the || exit here and likely in other spots as well, maybe we could set -e at the top?

Copy link
Member Author

Choose a reason for hiding this comment

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

nice


cleanup() {
chmod -R +w "${WORK_DIR}"
rm -rf "${WORK_DIR}"
}
trap cleanup EXIT

mkdir -p ${WORK_DIR}/go/
Copy link
Member Author

Choose a reason for hiding this comment

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

Double quote to prevent globbing and word splitting

@@ -18,45 +18,45 @@

. $(dirname "${BASH_SOURCE}")/common.sh

WORK_DIR=`mktemp -d`
Copy link
Member Author

Choose a reason for hiding this comment

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

Use $(...) notation instead of legacy backticked ...

@@ -12,21 +14,24 @@
# See the License for the specific language governing permissions and
# limitations under the License.

#!/bin/bash
Copy link
Member Author

Choose a reason for hiding this comment

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

The shebang must be on the first line

@@ -12,5 +14,4 @@
# See the License for the specific language governing permissions and
# limitations under the License.

#!/bin/sh -eu
Copy link
Member Author

Choose a reason for hiding this comment

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

The shebang must be on the first line

@@ -14,7 +14,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

if ! [ -z $DEBUG ]; then
Copy link
Member Author

Choose a reason for hiding this comment

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

recommend [ -n .. ] instead of ! [ -z .. ]

@@ -14,7 +15,7 @@
# limitations under the License.

KOPS_ROOT=$(git rev-parse --show-toplevel)
cd ${KOPS_ROOT}
Copy link
Member Author

Choose a reason for hiding this comment

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

in case cd fails.

@@ -25,7 +25,7 @@ changes=$(git status --porcelain || true)
if [ -n "${changes}" ]; then
echo "ERROR: go modules are not up to date; please run: go mod tidy"
echo "changed files:"
printf "${changes}\n"
Copy link
Member Author

Choose a reason for hiding this comment

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

Don't use variables in the printf format string. Use printf "..%s.." "$foo"

@@ -23,7 +23,7 @@ export API_OPTIONS="--verify-only"
if make apimachinery-codegen; then
echo "apimachinery is up to date"
else
echo "\n FAIL: - the verify-apimachinery.sh test failed, apimachinery is not up to date"
echo "\n FAIL: - please run the command 'make apimachinery'"
echo -e "\n FAIL: - the verify-apimachinery.sh test failed, apimachinery is not up to date"
Copy link
Member Author

Choose a reason for hiding this comment

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

echo "\n FAIL: - the verify-apimachinery.sh test failed, apimachinery is not up to date"

\n FAIL: - the verify-apimachinery.sh test failed, apimachinery is not up to date

--------------->
echo -e "\n FAIL: - the verify-apimachinery.sh test failed, apimachinery is not up to date"


FAIL: - the verify-apimachinery.sh test failed, apimachinery is not up to date

@tanjunchen
Copy link
Member Author

/assign @geojaz

Copy link
Member

@geojaz geojaz left a comment

Choose a reason for hiding this comment

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

I don't have any major problems with this and am in favor of cleaning these scripts up and making them more consistent. I provided some suggestions, but didn't point them out each time.

Was there a specific reason to refactor these files right now or were they broken in your use case?

@@ -110,9 +110,9 @@ echo ==========
echo "Deleting cluster ${CLUSTER_NAME}. Elle est finie."

kops delete cluster \
--name $CLUSTER_NAME \
Copy link
Member

Choose a reason for hiding this comment

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

your effort is appreciated!
as for the || exit here and likely in other spots as well, maybe we could set -e at the top?

@@ -1,4 +1,5 @@
#!/usr/bin/env bash

# Copyright 2017 The Kubernetes Authors.
Copy link
Member

Choose a reason for hiding this comment

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

This is an open question that I've been running into frequently these days, but don't currently have an answer to. When you touch a file, do you update the boilerplate date? i've seen what appears to be new code PRed with a date in the past, and dates that aren't being updated when code is touched. Do we (cncf/k8s org) have a standard for this? random selection of people who may know: @justinsb @thockin @mikesplain @joshbranham @luxas

Copy link
Member Author

Choose a reason for hiding this comment

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

so we need to talk about it

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah I am unsure so curious to hear from others here

mkdir -p ${WORK_DIR}/go/
ln -s ${GOPATH}/src/k8s.io/kops/vendor/ ${WORK_DIR}/go/src
mkdir -p "${WORK_DIR}"/go/
ln -s "${GOPATH}"/src/k8s.io/kops/vendor/ "${WORK_DIR}"/go/src
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
ln -s "${GOPATH}"/src/k8s.io/kops/vendor/ "${WORK_DIR}"/go/src
ln -s "${GOPATH}/src/k8s.io/kops/vendor/" "${WORK_DIR}/go/src"


unset GOBIN
GOPATH=${WORK_DIR}/go/ go install -v k8s.io/code-generator/cmd/conversion-gen/
cp ${WORK_DIR}/go/bin/conversion-gen ${GOPATH}/bin/
cp "${WORK_DIR}"/go/bin/conversion-gen "${GOPATH}"/bin/
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
cp "${WORK_DIR}"/go/bin/conversion-gen "${GOPATH}"/bin/
cp "${WORK_DIR}/go/bin/conversion-gen" "${GOPATH}/bin/"

Copy link
Member

Choose a reason for hiding this comment

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

(and so on. i did not point out each incident of this stylistic suggestion)

--name $CLUSTER_NAME \
--state $KOPS_STATE_STORE \
-v $VERBOSITY \
--name "$CLUSTER_NAME" \
Copy link
Member

Choose a reason for hiding this comment

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

the rest of the interpolations mostly use "${CLUSTER_NAME}" form. if you're going to add the "'s, I think we may as well go the whole way.

@k8s-ci-robot k8s-ci-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Dec 25, 2019
@tanjunchen
Copy link
Member Author

/cc @geojaz
/cc @joshbranham @justinsb @rifelpet
The so many scripts are changed before , I think it is not a good way.
we can open an new pr to improve the other files in the futrue , it is good for everybody.
/hold cancel

@k8s-ci-robot k8s-ci-robot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Dec 25, 2019
@justinsb
Copy link
Member

These changes all look good, and we can always do more cleanups in other PRs.

We don't have a position that we know of on updating copyright years.

/approve
/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Dec 28, 2019
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: justinsb, tanjunchen

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

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Dec 28, 2019
@k8s-ci-robot k8s-ci-robot merged commit e7ad6a9 into kubernetes:master Dec 28, 2019
@k8s-ci-robot k8s-ci-robot added this to the v1.18 milestone Dec 28, 2019
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. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants