Skip to content

Commit 6060f59

Browse files
committed
Squashed 'tools/' changes from 4fe078a..fd875e2
fd875e2 Fix test wrt shellcheck 54ec2d9 Don't capitalise error messages 19d3b6e Merge pull request #49 from weaveworks/pin-shfmt fea98f6 Go get from the vendor dir 1d867b0 Try and vendor a specific version of shfmt 76619c2 Merge pull request #48 from weaveworks/revert-41-user-tokens 4f96c51 Revert "Add experimental support for user tokens" d00033f Merge pull request #41 from weaveworks/user-tokens 245ed26 Merge pull request #47 from weaveworks/46-shfmt c1d7815 Fix shfmt error cb39746 Don't overright lint_result with 0 when shellcheck succeeds 8ab80e8 Merge pull request #45 from weaveworks/lint 83d5bd1 getting integration/config and test shellcheck-compliant cff9ec3 Fix some shellcheck errors 7a843d6 run shellcheck as part of lint if it is installed 31552a0 removing spurious space from test 6ca7c5f Merge pull request #44 from weaveworks/shfmt 952356d Allow lint to lint itself b7ac59c Run shfmt on all shell files in this repo 5570b0e Add shfmt formatting of shell files in lint 0a67594 fix circle build by splatting gopath permissions b990f48 Merge pull request #42 from kinvolk/lorenzo/fix-git-diff 224a145 Check if SHA1 exists before calling `git diff` 1c3000d Add auto_apply config for wcloud 0ebf5c0 Fix wcloud -serivice 354e083 Fixing lint 586060b Add experimental support for user tokens git-subtree-dir: tools git-subtree-split: fd875e27c5379d443574bcf20f24a52a594871ca
1 parent 3a63cf4 commit 6060f59

File tree

24 files changed

+5776
-365
lines changed

24 files changed

+5776
-365
lines changed

circle.yml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,18 @@ machine:
88

99
dependencies:
1010
post:
11+
- sudo chmod a+wr --recursive /usr/local/go/pkg
1112
- go clean -i net
1213
- go install -tags netgo std
1314
- mkdir -p $(dirname $SRCDIR)
1415
- cp -r $(pwd)/ $SRCDIR
15-
- go get github.com/golang/lint/golint github.com/fzipp/gocyclo github.com/kisielk/errcheck
16+
- |
17+
cd $SRCDIR;
18+
go get \
19+
github.com/fzipp/gocyclo \
20+
github.com/golang/lint/golint \
21+
github.com/kisielk/errcheck \
22+
./vendor/github.com/mvdan/sh/cmd/shfmt
1623
1724
test:
1825
override:

cmd/wcloud/cli.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ func deploy(c Client, args []string) {
8181
username = flags.String("u", "", "Username to report to deploy service (default with be current user)")
8282
services ArrayFlags
8383
)
84-
flag.Var(&services, "service", "Service to update (can be repeated)")
84+
flags.Var(&services, "service", "Service to update (can be repeated)")
8585
if err := flags.Parse(args); err != nil {
8686
usage()
8787
return

cmd/wcloud/client.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ func (c Client) Deploy(deployment Deployment) error {
4747
return err
4848
}
4949
if res.StatusCode != 204 {
50-
return fmt.Errorf("Error making request: %s", res.Status)
50+
return fmt.Errorf("error making request: %s", res.Status)
5151
}
5252
return nil
5353
}
@@ -63,7 +63,7 @@ func (c Client) GetDeployments(from, through int64) ([]Deployment, error) {
6363
return nil, err
6464
}
6565
if res.StatusCode != 200 {
66-
return nil, fmt.Errorf("Error making request: %s", res.Status)
66+
return nil, fmt.Errorf("error making request: %s", res.Status)
6767
}
6868
var response struct {
6969
Deployments []Deployment `json:"deployments"`
@@ -85,7 +85,7 @@ func (c Client) GetEvents(from, through int64) ([]byte, error) {
8585
return nil, err
8686
}
8787
if res.StatusCode != 200 {
88-
return nil, fmt.Errorf("Error making request: %s", res.Status)
88+
return nil, fmt.Errorf("error making request: %s", res.Status)
8989
}
9090
return ioutil.ReadAll(res.Body)
9191
}
@@ -101,10 +101,10 @@ func (c Client) GetConfig() (*Config, error) {
101101
return nil, err
102102
}
103103
if res.StatusCode == 404 {
104-
return nil, fmt.Errorf("No configuration uploaded yet.")
104+
return nil, fmt.Errorf("no configuration uploaded yet")
105105
}
106106
if res.StatusCode != 200 {
107-
return nil, fmt.Errorf("Error making request: %s", res.Status)
107+
return nil, fmt.Errorf("error making request: %s", res.Status)
108108
}
109109
var config Config
110110
if err := json.NewDecoder(res.Body).Decode(&config); err != nil {
@@ -128,7 +128,7 @@ func (c Client) SetConfig(config *Config) error {
128128
return err
129129
}
130130
if res.StatusCode != 204 {
131-
return fmt.Errorf("Error making request: %s", res.Status)
131+
return fmt.Errorf("error making request: %s", res.Status)
132132
}
133133
return nil
134134
}
@@ -144,7 +144,7 @@ func (c Client) GetLogs(deployID string) ([]byte, error) {
144144
return nil, err
145145
}
146146
if res.StatusCode != 200 {
147-
return nil, fmt.Errorf("Error making request: %s", res.Status)
147+
return nil, fmt.Errorf("error making request: %s", res.Status)
148148
}
149149
return ioutil.ReadAll(res.Body)
150150
}

cmd/wcloud/types.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,11 @@ type Deployment struct {
2020
// Config for the deployment system for a user.
2121
type Config struct {
2222
RepoURL string `json:"repo_url" yaml:"repo_url"`
23-
RepoPath string `json:"repo_path" yaml:"repo_path"`
2423
RepoBranch string `json:"repo_branch" yaml:"repo_branch"`
24+
RepoPath string `json:"repo_path" yaml:"repo_path"`
2525
RepoKey string `json:"repo_key" yaml:"repo_key"`
2626
KubeconfigPath string `json:"kubeconfig_path" yaml:"kubeconfig_path"`
27+
AutoApply bool `json:"auto_apply" yaml:"auto_apply"`
2728

2829
Notifications []NotificationConfig `json:"notifications" yaml:"notifications"`
2930

@@ -35,7 +36,8 @@ type Config struct {
3536

3637
// NotificationConfig describes how to send notifications
3738
type NotificationConfig struct {
38-
SlackWebhookURL string `json:"slack_webhook_url" yaml:"slack_webhook_url"`
39-
SlackUsername string `json:"slack_username" yaml:"slack_username"`
40-
MessageTemplate string `json:"message_template" yaml:"message_template"`
39+
SlackWebhookURL string `json:"slack_webhook_url" yaml:"slack_webhook_url"`
40+
SlackUsername string `json:"slack_username" yaml:"slack_username"`
41+
MessageTemplate string `json:"message_template" yaml:"message_template"`
42+
ApplyMessageTemplate string `json:"apply_message_template" yaml:"apply_message_template"`
4143
}

image-tag

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@ set -o errexit
44
set -o nounset
55
set -o pipefail
66

7-
WORKING_SUFFIX=$(if ! git diff --exit-code --quiet HEAD >&2; \
8-
then echo "-WIP"; \
9-
else echo ""; \
10-
fi)
7+
WORKING_SUFFIX=$(if ! git diff --exit-code --quiet HEAD >&2; then echo "-WIP"; else echo ""; fi)
118
BRANCH_PREFIX=$(git rev-parse --abbrev-ref HEAD)
129
echo "${BRANCH_PREFIX//\//-}-$(git rev-parse --short HEAD)$WORKING_SUFFIX"

integration/assert.sh

100644100755
Lines changed: 34 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,15 @@ export CONTINUE=${CONTINUE:-}
2525

2626
args="$(getopt -n "$0" -l \
2727
verbose,help,stop,discover,invariant,continue vhxdic "$@")" \
28-
|| exit -1
28+
|| exit -1
2929
for arg in $args; do
3030
case "$arg" in
3131
-h)
3232
echo "$0 [-vxidc]" \
3333
"[--verbose] [--stop] [--invariant] [--discover] [--continue]"
34-
echo "$(sed 's/./ /g' <<< "$0") [-h] [--help]"
35-
exit 0;;
34+
echo "$(sed 's/./ /g' <<<"$0") [-h] [--help]"
35+
exit 0
36+
;;
3637
--help)
3738
cat <<EOF
3839
Usage: $0 [options]
@@ -47,17 +48,23 @@ Options:
4748
-h show brief usage information and exit
4849
--help show this help message and exit
4950
EOF
50-
exit 0;;
51-
-v|--verbose)
52-
DEBUG=1;;
53-
-x|--stop)
54-
STOP=1;;
55-
-i|--invariant)
56-
INVARIANT=1;;
57-
-d|--discover)
58-
DISCOVERONLY=1;;
59-
-c|--continue)
60-
CONTINUE=1;;
51+
exit 0
52+
;;
53+
-v | --verbose)
54+
DEBUG=1
55+
;;
56+
-x | --stop)
57+
STOP=1
58+
;;
59+
-i | --invariant)
60+
INVARIANT=1
61+
;;
62+
-d | --discover)
63+
DISCOVERONLY=1
64+
;;
65+
-c | --continue)
66+
CONTINUE=1
67+
;;
6168
esac
6269
done
6370

@@ -74,17 +81,18 @@ assert_end() {
7481
# assert_end [suite ..]
7582
tests_endtime="$(date +%s%N)"
7683
# required visible decimal place for seconds (leading zeros if needed)
77-
tests_time="$( \
78-
printf "%010d" "$(( ${tests_endtime/%N/000000000}
79-
- ${tests_starttime/%N/000000000} ))")" # in ns
84+
tests_time="$(
85+
printf "%010d" "$((${tests_endtime/%N/000000000} - ${tests_starttime/%N/000000000}))"
86+
)" # in ns
8087
tests="$tests_ran ${*:+$* }tests"
8188
[[ -n "$DISCOVERONLY" ]] && echo "collected $tests." && _assert_reset && return
8289
[[ -n "$DEBUG" ]] && echo
8390
# to get report_time split tests_time on 2 substrings:
8491
# ${tests_time:0:${#tests_time}-9} - seconds
8592
# ${tests_time:${#tests_time}-9:3} - milliseconds
8693
if [[ -z "$INVARIANT" ]]; then
87-
report_time=" in ${tests_time:0:${#tests_time}-9}.${tests_time:${#tests_time}-9:3}s"
94+
idx=$((${#tests_time} - 9))
95+
report_time=" in ${tests_time:0:${idx}}.${tests_time:${idx}:3}s"
8896
else
8997
report_time=
9098
fi
@@ -100,26 +108,26 @@ assert_end() {
100108

101109
assert() {
102110
# assert <command> <expected stdout> [stdin]
103-
(( tests_ran++ )) || :
111+
((tests_ran++)) || :
104112
[[ -z "$DISCOVERONLY" ]] || return
105113
expected=$(echo -ne "${2:-}")
106-
result="$(eval 2>/dev/null "$1" <<< "${3:-}")" || true
114+
result="$(eval "$1" 2>/dev/null <<<"${3:-}")" || true
107115
if [[ "$result" == "$expected" ]]; then
108116
[[ -z "$DEBUG" ]] || echo -n .
109117
return
110118
fi
111-
result="$(sed -e :a -e '$!N;s/\n/\\n/;ta' <<< "$result")"
119+
result="$(sed -e :a -e '$!N;s/\n/\\n/;ta' <<<"$result")"
112120
[[ -z "$result" ]] && result="nothing" || result="\"$result\""
113121
[[ -z "$2" ]] && expected="nothing" || expected="\"$2\""
114122
_assert_fail "expected $expected${_indent}got $result" "$1" "$3"
115123
}
116124

117125
assert_raises() {
118126
# assert_raises <command> <expected code> [stdin]
119-
(( tests_ran++ )) || :
127+
((tests_ran++)) || :
120128
[[ -z "$DISCOVERONLY" ]] || return
121129
status=0
122-
(eval "$1" <<< "${3:-}") > /dev/null 2>&1 || status=$?
130+
(eval "$1" <<<"${3:-}") >/dev/null 2>&1 || status=$?
123131
expected=${2:-0}
124132
if [[ "$status" -eq "$expected" ]]; then
125133
[[ -z "$DEBUG" ]] || echo -n .
@@ -138,12 +146,12 @@ _assert_fail() {
138146
exit 1
139147
fi
140148
tests_errors[$tests_failed]="$report"
141-
(( tests_failed++ )) || :
149+
((tests_failed++)) || :
142150
}
143151

144152
skip_if() {
145153
# skip_if <command ..>
146-
(eval "$@") > /dev/null 2>&1 && status=0 || status=$?
154+
(eval "$@") >/dev/null 2>&1 && status=0 || status=$?
147155
[[ "$status" -eq 0 ]] || return
148156
skip
149157
}
@@ -175,9 +183,8 @@ _skip() {
175183
fi
176184
}
177185

178-
179186
_assert_reset
180-
: ${tests_suite_status:=0} # remember if any of the tests failed so far
187+
: ${tests_suite_status:=0} # remember if any of the tests failed so far
181188
_assert_cleanup() {
182189
local status=$?
183190
# modify exit code if it's not already non-zero

integration/config.sh

Lines changed: 30 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#!/bin/bash
12
# NB only to be sourced
23

34
set -e
@@ -16,49 +17,55 @@ N_MACHINES=${N_MACHINES:-3}
1617
IP_PREFIX=${IP_PREFIX:-192.168.48}
1718
IP_SUFFIX_BASE=${IP_SUFFIX_BASE:-10}
1819

19-
if [ -z "$HOSTS" ] ; then
20-
for i in $(seq 1 $N_MACHINES); do
21-
IP="${IP_PREFIX}.$((${IP_SUFFIX_BASE}+$i))"
20+
if [ -z "$HOSTS" ]; then
21+
for i in $(seq 1 "$N_MACHINES"); do
22+
IP="${IP_PREFIX}.$((IP_SUFFIX_BASE + i))"
2223
HOSTS="$HOSTS $IP"
2324
done
2425
fi
2526

2627
# these are used by the tests
27-
HOST1=$(echo $HOSTS | cut -f 1 -d ' ')
28-
HOST2=$(echo $HOSTS | cut -f 2 -d ' ')
29-
HOST3=$(echo $HOSTS | cut -f 3 -d ' ')
30-
28+
# shellcheck disable=SC2034
29+
HOST1=$(echo "$HOSTS" | cut -f 1 -d ' ')
30+
# shellcheck disable=SC2034
31+
HOST2=$(echo "$HOSTS" | cut -f 2 -d ' ')
32+
# shellcheck disable=SC2034
33+
HOST3=$(echo "$HOSTS" | cut -f 3 -d ' ')
34+
35+
# shellcheck disable=SC1090
3136
. "$DIR/assert.sh"
3237

3338
SSH_DIR=${SSH_DIR:-$DIR}
34-
SSH=${SSH:-ssh -l vagrant -i "$SSH_DIR/insecure_private_key" -o "UserKnownHostsFile=$SSH_DIR/.ssh_known_hosts" -o CheckHostIP=no -o StrictHostKeyChecking=no}
39+
SSH=${SSH:-ssh -l vagrant -i \"$SSH_DIR/insecure_private_key\" -o \"UserKnownHostsFile=$SSH_DIR/.ssh_known_hosts\" -o CheckHostIP=no -o StrictHostKeyChecking=no}
3540

3641
SMALL_IMAGE="alpine"
42+
# shellcheck disable=SC2034
3743
TEST_IMAGES="$SMALL_IMAGE"
3844

45+
# shellcheck disable=SC2034
3946
PING="ping -nq -W 1 -c 1"
4047
DOCKER_PORT=2375
4148

4249
remote() {
4350
rem=$1
4451
shift 1
45-
"$@" > >(while read line; do echo -e $'\e[0;34m'"$rem>"$'\e[0m'" $line"; done)
52+
"$@" > >(while read -r line; do echo -e $'\e[0;34m'"$rem>"$'\e[0m'" $line"; done)
4653
}
4754

4855
colourise() {
49-
[ -t 0 ] && echo -ne $'\e['$1'm' || true
56+
([ -t 0 ] && echo -ne $'\e['"$1"'m') || true
5057
shift
5158
# It's important that we don't do this in a subshell, as some
5259
# commands we execute need to modify global state
5360
"$@"
54-
[ -t 0 ] && echo -ne $'\e[0m' || true
61+
([ -t 0 ] && echo -ne $'\e[0m') || true
5562
}
5663

5764
whitely() {
5865
colourise '1;37' "$@"
5966
}
6067

61-
greyly () {
68+
greyly() {
6269
colourise '0;37' "$@"
6370
}
6471

@@ -73,46 +80,46 @@ greenly() {
7380
run_on() {
7481
host=$1
7582
shift 1
76-
[ -z "$DEBUG" ] || greyly echo "Running on $host: $@" >&2
77-
remote $host $SSH $host "$@"
83+
[ -z "$DEBUG" ] || greyly echo "Running on $host:" "$@" >&2
84+
remote "$host" "$SSH" "$host" "$@"
7885
}
7986

8087
docker_on() {
8188
host=$1
8289
shift 1
83-
[ -z "$DEBUG" ] || greyly echo "Docker on $host:$DOCKER_PORT: $@" >&2
84-
docker -H tcp://$host:$DOCKER_PORT "$@"
90+
[ -z "$DEBUG" ] || greyly echo "Docker on $host:$DOCKER_PORT:" "$@" >&2
91+
docker -H "tcp://$host:$DOCKER_PORT" "$@"
8592
}
8693

8794
weave_on() {
8895
host=$1
8996
shift 1
90-
[ -z "$DEBUG" ] || greyly echo "Weave on $host:$DOCKER_PORT: $@" >&2
97+
[ -z "$DEBUG" ] || greyly echo "Weave on $host:$DOCKER_PORT:" "$@" >&2
9198
DOCKER_HOST=tcp://$host:$DOCKER_PORT $WEAVE "$@"
9299
}
93100

94101
exec_on() {
95102
host=$1
96103
container=$2
97104
shift 2
98-
docker -H tcp://$host:$DOCKER_PORT exec $container "$@"
105+
docker -H "tcp://$host:$DOCKER_PORT" exec "$container" "$@"
99106
}
100107

101108
rm_containers() {
102109
host=$1
103110
shift
104-
[ $# -eq 0 ] || docker_on $host rm -f "$@" >/dev/null
111+
[ $# -eq 0 ] || docker_on "$host" rm -f "$@" >/dev/null
105112
}
106113

107114
start_suite() {
108115
for host in $HOSTS; do
109116
[ -z "$DEBUG" ] || echo "Cleaning up on $host: removing all containers and resetting weave"
110-
PLUGIN_ID=$(docker_on $host ps -aq --filter=name=weaveplugin)
117+
PLUGIN_ID=$(docker_on "$host" ps -aq --filter=name=weaveplugin)
111118
PLUGIN_FILTER="cat"
112119
[ -n "$PLUGIN_ID" ] && PLUGIN_FILTER="grep -v $PLUGIN_ID"
113-
rm_containers $host $(docker_on $host ps -aq 2>/dev/null | $PLUGIN_FILTER)
114-
run_on $host "docker network ls | grep -q ' weave ' && docker network rm weave" || true
115-
weave_on $host reset 2>/dev/null
120+
rm_containers "$host" "$(docker_on "$host" ps -aq 2>/dev/null | "$PLUGIN_FILTER")"
121+
run_on "$host" "docker network ls | grep -q ' weave ' && docker network rm weave" || true
122+
weave_on "$host" reset 2>/dev/null
116123
done
117124
whitely echo "$@"
118125
}
@@ -122,4 +129,3 @@ end_suite() {
122129
}
123130

124131
WEAVE=$DIR/../weave
125-

0 commit comments

Comments
 (0)