forked from bazelbuild/rules_k8s
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutil.sh
70 lines (63 loc) · 2.2 KB
/
util.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/usr/bin/env bash
# Copyright 2018 The Bazel Authors. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
SED=sed
if [[ "$(uname -s)" == "Darwin" ]]; then
SED=gsed
fi
export SED
# Function to validate the input args for the e2e-test.sh scripts.
validate_args() {
if [[ -z "${1:-}" ]]; then
echo "ERROR: None of execution type, kubernetes namspace and languages is provided!"
echo "Usage: $(basename $0) <'remote' or 'local' run> <kubernetes namespace> <language ...>"
exit 1
fi
local=false
if [[ "$1" == "local" ]]; then
local=true
elif [[ "$1" != "remote" ]]; then
echo "ERROR: Execution type must be either 'remote' or 'local'!"
echo "Usage: $(basename $0) <'remote' or 'local' run> <kubernetes namespace> <language ...>"
exit 1
fi
shift
if [[ -z "${1:-}" ]]; then
echo "ERROR: None of kubernetes namspace and languages is provided!"
echo "Usage: $(basename $0) <'remote' or 'local' run> <kubernetes namespace> <language ...>"
exit 1
fi
namespace="$1"
shift
if [[ -z "${1:-}" ]]; then
echo "ERROR: Languages not provided!"
echo "Usage: $(basename $0) <'remote' or 'local' run> <kubernetes namespace> <language ...>"
exit 1
fi
}
# Function to get the Kubernetes load balancer service IP address.
# Usage when running a cluster in minikube:
# get_lb_ip true <service name>
# Usage when running a cluster on GKE:
# get_lb_ip false <service name>
get_lb_ip() {
# Determine the location of variable to retrieve the service IP address
# based on execution type
ip_var='{.status.loadBalancer.ingress[0].ip}'
if $1; then
ip_var='{.spec.clusterIP}'
fi
kubectl --namespace="${namespace}" get service $2 \
-o jsonpath=$ip_var
}