Skip to content

Commit e55a4f2

Browse files
kahirokunnMrFreezeexskitt
committed
Update demo scripts and CoreDNS setup for improved consistency and multi-arch support
- Update demo script to use Python 3. - Use absolute paths in demo scripts to ensure consistency. - Remove manual platform detection from demo script: - Switch to using a Docker container for consistent CoreDNS build across platforms. - Replace manual architecture detection and platform-specific binary handling with a container-based approach. - Use `realpath` for resolving script paths and simplify variable definitions. - Update CoreDNS setup: - Replace tar download with git clone to address the 'make' dependency. - Adjust platform handling to support multi-arch CoreDNS binaries. Signed-off-by: kahirokunn <[email protected]> Co-authored-by: Arthur Outhenin-Chalandre <[email protected]> Co-authored-by: Stephen Kitt <[email protected]>
1 parent a059461 commit e55a4f2

File tree

4 files changed

+44
-33
lines changed

4 files changed

+44
-33
lines changed

demo/demo.sh

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,18 @@
1414
# See the License for the specific language governing permissions and
1515
# limitations under the License.
1616

17-
cd $(dirname ${BASH_SOURCE})
18-
. ./udemo.sh
19-
. ../scripts/util.sh
17+
# Resolve the absolute path to this script directory.
18+
cd $(dirname "${BASH_SOURCE[0]}")
19+
demo_dir=$(realpath "$(pwd)")
20+
scripts_dir=$(realpath "$(pwd)/../scripts")
21+
22+
. "${demo_dir}/udemo.sh"
23+
. "${scripts_dir}/util.sh"
2024

2125
DEMO_AUTO_RUN=true
2226

23-
kubeconfig1=${KUBECONFIG1:-../scripts/c1.kubeconfig}
24-
kubeconfig2=${KUBECONFIG2:-../scripts/c2.kubeconfig}
27+
kubeconfig1="${KUBECONFIG1:-${scripts_dir}/c1.kubeconfig}"
28+
kubeconfig2="${KUBECONFIG2:-${scripts_dir}/c2.kubeconfig}"
2529

2630
k1="kubectl --kubeconfig ${kubeconfig1}"
2731
k2="kubectl --kubeconfig ${kubeconfig2}"
@@ -30,33 +34,33 @@ desc "Setup our demo namespace"
3034
run "${k1} create ns demo"
3135
run "${k2} create ns demo"
3236

33-
c1_pane=`tmux split-window -h -d -P`
37+
c1_pane=$(tmux split-window -h -d -P)
3438

3539
function cleanup() {
36-
tmux kill-pane -t $c1_pane
40+
tmux kill-pane -t "$c1_pane"
3741
}
3842
trap cleanup EXIT
3943

40-
tmux send -t $c1_pane "${k1} logs -f mcs-api-controller" Enter
44+
tmux send -t "$c1_pane" "${k1} logs -f mcs-api-controller" Enter
4145

4246
desc "Create our service in each cluster"
43-
run "${k1} apply -f yaml/dep1.yaml -f yaml/svc.yaml"
44-
run "${k2} apply -f yaml/dep2.yaml -f yaml/svc.yaml"
47+
run "${k1} apply -f ${script_dir}/yaml/dep1.yaml -f ${script_dir}/yaml/svc.yaml"
48+
run "${k2} apply -f ${script_dir}/yaml/dep2.yaml -f ${script_dir}/yaml/svc.yaml"
4549
run "${k1} get endpointslice -n demo"
4650

47-
4851
desc "Lets look at some requests to the service in cluster 1"
4952
run "${k1} -n demo run -i --rm --restart=Never --image=jeremyot/request:0a40de8 request -- --duration=5s --address=serve.demo.svc.cluster.local"
5053

5154
desc "Ok, looks normal. Let's import the service from our other cluster"
5255
ep_1=$(${k1} get endpointslice -n demo -l 'kubernetes.io/service-name=serve' --template="{{(index .items 0).metadata.name}}")
5356
ep_2=$(${k2} get endpointslice -n demo -l 'kubernetes.io/service-name=serve' --template="{{(index .items 0).metadata.name}}")
54-
run "${k1} get endpointslice -n demo ${ep_1} -o yaml | ./edit-meta --metadata '{name: imported-${ep_1}, namespace: demo, labels: {multicluster.kubernetes.io/service-name: serve}}' > yaml/slice-1.tmp"
55-
run "${k2} get endpointslice -n demo ${ep_2} -o yaml | ./edit-meta --metadata '{name: imported-${ep_2}, namespace: demo, labels: {multicluster.kubernetes.io/service-name: serve}}' > yaml/slice-2.tmp"
56-
run "${k1} apply -f yaml/serviceimport.yaml -f yaml/slice-1.tmp -f yaml/slice-2.tmp"
57-
run "${k2} apply -f yaml/serviceimport.yaml -f yaml/slice-1.tmp -f yaml/slice-2.tmp"
58-
run "${k1} apply -f yaml/serviceimport-with-vip.yaml -f yaml/slice-1.tmp -f yaml/slice-2.tmp"
59-
run "${k2} apply -f yaml/serviceimport-with-vip.yaml -f yaml/slice-1.tmp -f yaml/slice-2.tmp"
57+
58+
run "${k1} get endpointslice -n demo ${ep_1} -o yaml | ${script_dir}/edit-meta --metadata '{name: imported-${ep_1}, namespace: demo, labels: {multicluster.kubernetes.io/service-name: serve}}' > ${script_dir}/yaml/slice-1.tmp"
59+
run "${k2} get endpointslice -n demo ${ep_2} -o yaml | ${script_dir}/edit-meta --metadata '{name: imported-${ep_2}, namespace: demo, labels: {multicluster.kubernetes.io/service-name: serve}}' > ${script_dir}/yaml/slice-2.tmp"
60+
run "${k1} apply -f ${script_dir}/yaml/serviceimport.yaml -f ${script_dir}/yaml/slice-1.tmp -f ${script_dir}/yaml/slice-2.tmp"
61+
run "${k2} apply -f ${script_dir}/yaml/serviceimport.yaml -f ${script_dir}/yaml/slice-1.tmp -f ${script_dir}/yaml/slice-2.tmp"
62+
run "${k1} apply -f ${script_dir}/yaml/serviceimport-with-vip.yaml -f ${script_dir}/yaml/slice-1.tmp -f ${script_dir}/yaml/slice-2.tmp"
63+
run "${k2} apply -f ${script_dir}/yaml/serviceimport-with-vip.yaml -f ${script_dir}/yaml/slice-1.tmp -f ${script_dir}/yaml/slice-2.tmp"
6064

6165
desc "See what we've created..."
6266
run "${k1} get -n demo serviceimports"
@@ -70,7 +74,7 @@ function import_ip() {
7074
waitfor import_ip
7175

7276
vip=$(${k1} get serviceimport -n demo -o go-template --template='{{index (index .items 0).spec.ips 0}}')
73-
desc "Now grap the multi-cluster VIP from the serviceimport..."
77+
desc "Now grab the multi-cluster VIP from the serviceimport..."
7478
run "${k1} get serviceimport -n demo -o go-template --template='{{index (index .items 0).spec.ips 0}}{{\"\n\"}}'"
7579
desc "...and connect to it"
7680
run "${k1} -n demo run -i --rm --restart=Never --image=jeremyot/request:0a40de8 request -- --duration=10s --address=${vip}"

demo/edit-meta

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
1-
#!/usr/bin/env python
1+
#!/usr/bin/env python3
22

33
import sys
44
import argparse
55
import yaml
66

77
if __name__ == '__main__':
8-
parser = argparse.ArgumentParser()
9-
parser.add_argument('-m', '--metadata', dest='metadata', help="Overwrite the resource's metadata with this value, may be any valid YAML")
10-
args = parser.parse_args()
11-
data = yaml.load(sys.stdin, Loader=yaml.Loader)
12-
if args.metadata:
13-
value = yaml.load(args.metadata, Loader=yaml.Loader)
14-
data['metadata'] = value
15-
print yaml.dump(data, indent=2, default_flow_style=False, Dumper=yaml.Dumper)
8+
parser = argparse.ArgumentParser()
9+
parser.add_argument('-m', '--metadata', dest='metadata', help="Overwrite the resource's metadata with this value, may be any valid YAML")
10+
args = parser.parse_args()
11+
12+
data = yaml.load(sys.stdin, Loader=yaml.Loader)
13+
if args.metadata:
14+
value = yaml.load(args.metadata, Loader=yaml.Loader)
15+
data['metadata'] = value
16+
17+
print(yaml.dump(data, indent=2, default_flow_style=False, Dumper=yaml.Dumper))

demo/udemo.sh

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ readonly reset=$(tput sgr0)
1717
readonly green=$(tput bold; tput setaf 2)
1818
readonly yellow=$(tput bold; tput setaf 3)
1919
readonly blue=$(tput bold; tput setaf 6)
20-
readonly timeout=$(if [ "$(uname)" == "Darwin" ]; then echo "1"; else echo "0.1"; fi)
20+
readonly timeout=$(if [ "$(uname)" == "Darwin" ]; then echo "1"; else echo "0.1"; fi)
2121

2222
function desc() {
2323
maybe_first_prompt
@@ -52,7 +52,11 @@ function run() {
5252
sleep 0.5
5353
fi
5454
OFILE="$(mktemp -t $(basename $0).XXXXXX)"
55-
script -eq -c "$1" -f "$OFILE"
55+
if [[ "$OSTYPE" == "darwin"* ]]; then
56+
script -q -a "$OFILE" bash -c "$1"
57+
else
58+
script -eq -c "$1" -f "$OFILE"
59+
fi
5660
r=$?
5761
read -d '' -t "${timeout}" -n 10000 # clear stdin
5862
prompt
@@ -71,4 +75,4 @@ function relative() {
7175

7276
SSH_NODE=$(kubectl get nodes | tail -1 | cut -f1 -d' ')
7377

74-
trap "echo" EXIT
78+
trap "echo" EXIT

scripts/up.sh

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,16 @@ coredns_image="multicluster/coredns:latest"
4444
coredns_path="/tmp/coredns-${coredns_version}"
4545
if [ ! -d "${coredns_path}" ]; then
4646
pushd /tmp
47-
curl -fLO "https://github.com/coredns/coredns/archive/refs/tags/v${coredns_version}.tar.gz"
48-
tar xf v${coredns_version}.tar.gz
47+
git clone --depth 1 https://github.com/coredns/coredns.git --branch v${coredns_version} --single-branch "${coredns_path}"
4948
popd
5049
fi
5150
pushd "${coredns_path}"
5251
if ! grep -q -F 'multicluster:github.com/coredns/multicluster' "plugin.cfg"; then
5352
sed -i -e 's/^kubernetes:kubernetes$/&\nmulticluster:github.com\/coredns\/multicluster/' "plugin.cfg"
5453
fi
55-
make
54+
docker run --rm \
55+
-v $PWD:/go/src/github.com/coredns/coredns -w /go/src/github.com/coredns/coredns \
56+
golang:1.23 make gen coredns GOFLAGS=-buildvcs=false
5657
docker build -t "${coredns_image}" .
5758
popd
5859

0 commit comments

Comments
 (0)