@@ -26,15 +26,33 @@ NPD_STAGING_PATH=${NPD_STAGING_PATH:-"gs://node-problem-detector-staging"}
26
26
NPD_STAGING_REGISTRY=${NPD_STAGING_REGISTRY:- " gcr.io/node-problem-detector-staging" }
27
27
PR_ENV_FILENAME=${PR_ENV_FILENAME:- " pr.env" }
28
28
CI_ENV_FILENAME=${CI_ENV_FILENAME:- " ci.env" }
29
+ CI_CUSTOM_FLAGS_ENV_FILENAME=${CI_CUSTOM_FLAGS_ENV_FILENAME:- " ci-custom-flags.env" }
29
30
ROOT_PATH=$( git rev-parse --show-toplevel)
30
31
GCS_URL_PREFIX=" https://storage.googleapis.com/"
31
32
33
+
32
34
function print-help() {
33
- echo " Usage: build.sh [args...]"
34
- echo " Available arguments:"
35
- echo " pr [pull_number]: Build node-problem-detector for presubmit jobs and push to staging."
36
- echo " ci: Build node-problem-detector for CI jobs and push to staging."
37
- echo " get-ci-env: Download environment variable file from staging for CI job."
35
+ echo " Usage: build.sh [flags] [command]"
36
+ echo
37
+ echo " Available flags:"
38
+ echo " -p [PR_NUMBER] Specify the pull request number when building for a presubmit job."
39
+ echo " -f Use custom flags."
40
+ echo
41
+ echo " Available commands:"
42
+ echo " help Print this help message"
43
+ echo " pr Build node-problem-detector for presubmit jobs and push to staging. Flag -p is required."
44
+ echo " ci Build node-problem-detector for CI jobs and push to staging."
45
+ echo " get-ci-env Download environment variable file from staging for CI job."
46
+ echo " install-lib Install the libraries needed."
47
+ echo
48
+ echo " Examples:"
49
+ echo " build.sh help"
50
+ echo " build.sh -p [PR_NUMBER] pr"
51
+ echo " build.sh -p [PR_NUMBER] -f pr"
52
+ echo " build.sh ci"
53
+ echo " build.sh get-ci-env"
54
+ echo " build.sh -f get-ci-env"
55
+ echo " build.sh install-lib"
38
56
}
39
57
40
58
function get-version() {
@@ -65,17 +83,43 @@ export NODE_PROBLEM_DETECTOR_TAR_HASH=$(sha1sum ${ROOT_PATH}/node-problem-detect
65
83
export EXTRA_ENVS=NODE_PROBLEM_DETECTOR_IMAGE=${REGISTRY} /node-problem-detector:${TAG}
66
84
EOF
67
85
86
+ if [[ -n " ${NODE_PROBLEM_DETECTOR_CUSTOM_FLAGS:- } " ]]; then
87
+ cat >> ${ROOT_PATH} /${env_file} << EOF
88
+ export NODE_PROBLEM_DETECTOR_CUSTOM_FLAGS="${NODE_PROBLEM_DETECTOR_CUSTOM_FLAGS} "
89
+ EOF
90
+ fi
91
+
68
92
echo " Written env file ${ROOT_PATH} /${env_file} :"
69
93
cat ${ROOT_PATH} /${env_file}
70
94
}
71
95
96
+ function build-npd-custom-flags() {
97
+ local -r kube_home=" /home/kubernetes"
98
+
99
+ local -r km_config=" ${kube_home} /node-problem-detector/config/kernel-monitor.json"
100
+ local -r dm_config=" ${kube_home} /node-problem-detector/config/docker-monitor.json"
101
+ local -r sm_config=" ${kube_home} /node-problem-detector/config/systemd-monitor.json"
102
+
103
+ local -r custom_km_config=" ${kube_home} /node-problem-detector/config/kernel-monitor-counter.json"
104
+ local -r custom_dm_config=" ${kube_home} /node-problem-detector/config/docker-monitor-counter.json"
105
+ local -r custom_sm_config=" ${kube_home} /node-problem-detector/config/systemd-monitor-counter.json"
106
+
107
+ flags=" --v=2"
108
+ flags+=" --logtostderr"
109
+ flags+=" --system-log-monitors=${km_config} ,${dm_config} ,${sm_config} "
110
+ flags+=" --custom-plugin-monitors=${custom_km_config} ,${custom_dm_config} ,${custom_sm_config} "
111
+ flags+=" --port=20256"
112
+
113
+ export NODE_PROBLEM_DETECTOR_CUSTOM_FLAGS=${flags}
114
+ }
115
+
72
116
function build-pr() {
73
- local -r PR_NUMBER=" ${1} "
74
117
if [[ -z " ${PR_NUMBER} " ]]; then
75
- echo " ERROR: pull_number is missing."
118
+ echo " ERROR: PR_NUMBER is missing."
76
119
print-help
77
120
exit 1
78
121
fi
122
+
79
123
# Use the PR number and current time as the name, e.g., pr261-20190314.224907.862195792
80
124
local -r PR=" pr${PR_NUMBER} -$( date +%Y%m%d.%H%M%S.%N) "
81
125
echo " Building for PR ${PR} ..."
@@ -96,42 +140,61 @@ function build-ci() {
96
140
export VERSION=" $( get-version) -$( date +%Y%m%d.%H%M) "
97
141
export TAG=" ${VERSION} "
98
142
make push
143
+
144
+ # Create the env file with and without custom flags at the same time.
145
+ build-npd-custom-flags
146
+ write-env-file ${CI_CUSTOM_FLAGS_ENV_FILENAME}
147
+ gsutil mv ${ROOT_PATH} /${CI_CUSTOM_FLAGS_ENV_FILENAME} ${UPLOAD_PATH}
148
+
149
+ export NODE_PROBLEM_DETECTOR_CUSTOM_FLAGS=" "
99
150
write-env-file ${CI_ENV_FILENAME}
100
151
gsutil mv ${ROOT_PATH} /${CI_ENV_FILENAME} ${UPLOAD_PATH}
101
152
}
102
153
103
154
function get-ci-env() {
104
- gsutil cp ${NPD_STAGING_PATH} /ci/${CI_ENV_FILENAME} ${ROOT_PATH} /${CI_ENV_FILENAME}
155
+ if [[ " ${USE_CUSTOM_FLAGS} " == " true" ]]; then
156
+ gsutil cp ${NPD_STAGING_PATH} /ci/${CI_CUSTOM_FLAGS_ENV_FILENAME} ${ROOT_PATH} /${CI_CUSTOM_FLAGS_ENV_FILENAME}
157
+ echo " Using env file ${ROOT_PATH} /${CI_CUSTOM_FLAGS_ENV_FILENAME} :"
158
+ cat ${ROOT_PATH} /${CI_CUSTOM_FLAGS_ENV_FILENAME}
159
+ else
160
+ gsutil cp ${NPD_STAGING_PATH} /ci/${CI_ENV_FILENAME} ${ROOT_PATH} /${CI_ENV_FILENAME}
161
+ echo " Using env file ${ROOT_PATH} /${CI_ENV_FILENAME} :"
162
+ cat ${ROOT_PATH} /${CI_ENV_FILENAME}
163
+ fi
164
+ }
165
+
166
+ main () {
167
+ cd ${ROOT_PATH}
105
168
106
- echo " Using env file ${ROOT_PATH} /${CI_ENV_FILENAME} :"
107
- cat ${ROOT_PATH} /${CI_ENV_FILENAME}
169
+ if [[ " ${USE_CUSTOM_FLAGS} " == " true" ]]; then
170
+ build-npd-custom-flags
171
+ fi
172
+
173
+ # This is for the deprecated usage: build.sh pr [PR_NUMBER]
174
+ if [[ -z " ${PR_NUMBER} " ]]; then
175
+ PR_NUMBER=" ${2:- } "
176
+ fi
177
+
178
+ case ${1:- } in
179
+ help) print-help;;
180
+ pr) build-pr;;
181
+ ci) build-ci;;
182
+ get-ci-env) get-ci-env;;
183
+ install-lib) install-lib;;
184
+ * ) print-help;;
185
+ esac
108
186
}
109
187
110
188
111
- cd ${ROOT_PATH}
189
+ USE_CUSTOM_FLAGS=" false"
190
+ PR_NUMBER=" "
112
191
113
- if [[ " $# " -ne 1 && " $# " -ne 2 ]]; then
114
- echo " ERROR: Illegal number of parameters."
115
- print-help
116
- exit 1
117
- fi
118
- COMMAND=" ${1} "
192
+ while getopts " fp:" opt; do
193
+ case ${opt} in
194
+ f) USE_CUSTOM_FLAGS=" true" ;;
195
+ p) PR_NUMBER=" ${OPTARG} " ;;
196
+ esac
197
+ done
198
+ shift " $(( OPTIND- 1 )) "
119
199
120
- if [[ " ${COMMAND} " == " pr" ]]; then
121
- if [[ " $# " -ne 2 ]]; then
122
- echo " ERROR: pull_number is missing."
123
- print-help
124
- exit 1
125
- fi
126
- build-pr " ${2} "
127
- elif [[ " ${COMMAND} " == " ci" ]]; then
128
- build-ci
129
- elif [[ " ${COMMAND} " == " get-ci-env" ]]; then
130
- get-ci-env
131
- elif [[ " ${COMMAND} " == " install-lib" ]]; then
132
- install-lib
133
- else
134
- echo " ERROR: Invalid command."
135
- print-help
136
- exit 1
137
- fi
200
+ main " $@ "
0 commit comments