forked from netobserv/netobserv-cli
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathinject.sh
More file actions
executable file
·125 lines (109 loc) · 3.71 KB
/
inject.sh
File metadata and controls
executable file
·125 lines (109 loc) · 3.71 KB
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#!/usr/bin/env bash
set -x
cp -a ./commands/. ./tmp
cp ./scripts/functions.sh ./tmp/functions.sh
cp ./scripts/dependencies_check.sh ./tmp/dependencies_check.sh
if [ -z "$IMAGE" ]; then
echo "image not provided, keeping current one"
else
echo "updating CLI images to $IMAGE"
sed -i.bak "s|^img=.*|img=\"$IMAGE\"|" ./tmp/netobserv
fi
if [ -z "$PULL_POLICY" ]; then
echo "pull policy not provided, keeping current one"
else
echo "updating CLI pull policy to $PULL_POLICY"
sed -i.bak "s/--image-pull-policy=.*/--image-pull-policy='$PULL_POLICY' \\\\/" ./tmp/netobserv
fi
if [ -z "$AGENT_IMAGE" ]; then
echo "eBPF agent image not provided, keeping current one"
else
echo "updating eBPF agent images to $AGENT_IMAGE"
sed -i.bak "s|^agentImg=.*|agentImg=\"$AGENT_IMAGE\"|" ./tmp/functions.sh
fi
if [ -z "$VERSION" ]; then
echo "version not provided, keeping current one"
else
echo "updating CLI version to $VERSION"
sed -i.bak "s/^version=.*/version=\"$VERSION\"/" ./tmp/netobserv
fi
if [ -z "$REQUIRED_BASH_VERSION" ]; then
echo "require bash version is not set, keeping the current version"
else
echo "updating dependencies to check for bash $REQUIRED_BASH_VERSION"
sed -i.bak "s/^required_bash_version=.*/required_bash_version=\"$REQUIRED_BASH_VERSION\"/" ./tmp/netobserv
fi
if [ -z "$REQUIRED_YQ_VERSION" ]; then
echo "require yq version is not set, keeping the current version"
else
echo "updating dependencies to check for yq $REQUIRED_YQ_VERSION"
sed -i.bak "s/^required_yq_version=.*/required_yq_version=\"$REQUIRED_YQ_VERSION\"/" ./tmp/netobserv
fi
if [ -z "$SUPPORTED_ARCHS" ]; then
echo "list of supported archs is not set"
else
echo "updating dependencies_check with $SUPPORTED_ARCHS values"
sed -i.bak "s/^supported_archs=.*/supported_archs=\"$SUPPORTED_ARCHS\"/" ./tmp/netobserv
fi
prefix=
if [ -z "$KREW_PLUGIN" ] || [ "$KREW_PLUGIN" = "false" ]; then
if [ -z "$K8S_CLI_BIN" ]; then
echo "ERROR: K8S CLI not provided"
exit 1
fi
echo "updating K8S CLI to $K8S_CLI_BIN"
# remove beginning lines
sed -i.bak '1,/K8S_CLI_BIN_PATH=/d' ./tmp/functions.sh
# replace only first match to force default
sed -i.bak "s/^K8S_CLI_BIN=.*/K8S_CLI_BIN=$K8S_CLI_BIN/" ./tmp/functions.sh
# prefix with oc / kubectl for local install
prefix="$K8S_CLI_BIN-"
echo "prefixing with $prefix"
mv ./tmp/netobserv ./tmp/"$prefix"netobserv
fi
# inject YAML files to functions.sh
sed -i.bak '/namespaceYAMLContent/{r ./res/namespace.yml
d
}' ./tmp/functions.sh
sed -i.bak '/saYAMLContent/{r ./res/service-account.yml
d
}' ./tmp/functions.sh
sed -i.bak '/flowAgentYAMLContent/{r ./res/flow-capture.yml
d
}' ./tmp/functions.sh
sed -i.bak '/packetAgentYAMLContent/{r ./res/packet-capture.yml
d
}' ./tmp/functions.sh
sed -i.bak '/metricAgentYAMLContent/{r ./res/metric-capture.yml
d
}' ./tmp/functions.sh
sed -i.bak '/smYAMLContent/{r ./res/service-monitor.yml
d
}' ./tmp/functions.sh
sed -i.bak '/collectorServiceYAMLContent/{r ./res/collector-service.yml
d
}' ./tmp/functions.sh
# inject updated functions to commands
sed -i.bak '/^source "\.\/scripts\/functions\.sh"/{r ./tmp/functions.sh
d
}' ./tmp/"$prefix"netobserv
# inject updated dependencies_check to commands
sed -i.bak '/^source "\.\/scripts\/dependencies_check\.sh"/{r ./tmp/dependencies_check.sh
d
}' ./tmp/"$prefix"netobserv
if [ -z "$3" ]; then
echo "pull policy not provided, keeping current ones"
else
echo "updating CLI pull policy to $3"
sed -i.bak "s/--image-pull-policy=.*/--image-pull-policy='$3' \\\\/" ./tmp/oc-netobserv
fi
rm ./tmp/functions.sh
rm ./tmp/dependencies_check.sh
rm ./tmp/*.bak
if [ -z "$DIST_DIR" ]; then
echo "output generated in tmp folder"
else
echo "output generated in $DIST_DIR folder"
cp -a ./tmp/. ./"$DIST_DIR"
rm -rf ./tmp
fi