14
14
# See the License for the specific language governing permissions and
15
15
# limitations under the License.
16
16
17
+ set -x
17
18
set -e
18
19
set -o pipefail
19
20
@@ -75,10 +76,14 @@ set +e
75
76
kubectl proxy &
76
77
77
78
function kube_state_metrics_up() {
79
+ serviceName=" kube-state-metrics"
80
+ if [[ -n " $1 " ]]; then
81
+ serviceName=" $1 "
82
+ fi
78
83
is_kube_state_metrics_running=" false"
79
84
# this for loop waits until kube-state-metrics is running by accessing the healthz endpoint
80
85
for _ in {1..30}; do # timeout for 1 minutes
81
- KUBE_STATE_METRICS_STATUS=$( curl -s " http://localhost:8001/api/v1/namespaces/kube-system/services/kube-state-metrics :http-metrics/proxy/healthz" )
86
+ KUBE_STATE_METRICS_STATUS=$( curl -s " http://localhost:8001/api/v1/namespaces/kube-system/services/${serviceName} :http-metrics/proxy/healthz" )
82
87
if [[ " ${KUBE_STATE_METRICS_STATUS} " == " OK" ]]; then
83
88
is_kube_state_metrics_running=" true"
84
89
break
@@ -94,27 +99,76 @@ function kube_state_metrics_up() {
94
99
exit 1
95
100
fi
96
101
}
102
+ function kube_pod_up() {
103
+ is_pod_running=" false"
104
+
105
+ for _ in {1..90}; do # timeout for 3 minutes
106
+ kubectl get pods -A | grep " $1 " 1> /dev/null 2>&1
107
+ if [[ $? -ne 1 ]]; then
108
+ is_pod_running=" true"
109
+ break
110
+ fi
111
+
112
+ echo " waiting for pod $1 to come up"
113
+ sleep 2
114
+ done
115
+
116
+ if [[ ${is_pod_running} == " false" ]]; then
117
+ echo " Pod does not show up within 3 minutes"
118
+ exit 1
119
+ fi
120
+ }
121
+
97
122
function test_daemonset() {
98
123
sed -i " s|${KUBE_STATE_METRICS_CURRENT_IMAGE_NAME} :v.*|${KUBE_STATE_METRICS_IMAGE_NAME} :${KUBE_STATE_METRICS_IMAGE_TAG} |g" ./examples/daemonsetsharding/deployment.yaml
99
124
sed -i " s|${KUBE_STATE_METRICS_CURRENT_IMAGE_NAME} :v.*|${KUBE_STATE_METRICS_IMAGE_NAME} :${KUBE_STATE_METRICS_IMAGE_TAG} |g" ./examples/daemonsetsharding/daemonset.yaml
125
+ sed -i " s|${KUBE_STATE_METRICS_CURRENT_IMAGE_NAME} :v.*|${KUBE_STATE_METRICS_IMAGE_NAME} :${KUBE_STATE_METRICS_IMAGE_TAG} |g" ./examples/daemonsetsharding/deployment-no-node-pods.yaml
100
126
127
+ cat ./examples/daemonsetsharding/deployment-no-node-pods.yaml
128
+ sleep 3
101
129
kubectl get deployment -n kube-system
102
- kubectl create -f ./examples/daemonsetsharding
103
130
ls ./examples/daemonsetsharding
104
- kube_state_metrics_up
105
- curl -s " http://localhost:8001/api/v1/namespaces/kube-system/services/kube-state-metrics-shard:http-metrics/proxy/metrics" > ${KUBE_STATE_METRICS_LOG_DIR} /pod-metrics
106
- curl -s " http://localhost:8001/api/v1/namespaces/kube-system/services/kube-state-metrics:http-metrics/proxy/metrics" > ${KUBE_STATE_METRICS_LOG_DIR} /nonpod-metrics
107
- m1=" $( cat ${KUBE_STATE_METRICS_LOG_DIR} /pod-metrics | grep " # TYPE kube_pod_info" || true) "
108
- m2=" $( cat ${KUBE_STATE_METRICS_LOG_DIR} /nonpod-metrics | grep " # TYPE kube_pod_info" || true) "
109
- if [[ -z " ${m1} " ]]; then
110
- echo " can't found metric kube_pod_info from pod metrics service"
131
+ kubectl create -f ./examples/daemonsetsharding
132
+ kube_state_metrics_up kube-state-metrics-no-node-pods
133
+ kube_state_metrics_up kube-state-metrics
134
+ kube_state_metrics_up kube-state-metrics-shard
135
+ kubectl apply -f ./tests/e2e/testdata/pods.yaml
136
+ kube_pod_up runningpod1
137
+ kube_pod_up pendingpod2
138
+
139
+ kubectl get deployment -n default
140
+ # curl -s "http://localhost:8001/api/v1/namespaces/kube-system/services/kube-state-metrics-shard:http-metrics/proxy/metrics" >${KUBE_STATE_METRICS_LOG_DIR}/daemonset-scraped-metrics
141
+ # curl -s "http://localhost:8001/api/v1/namespaces/kube-system/services/kube-state-metrics:http-metrics/proxy/metrics" >${KUBE_STATE_METRICS_LOG_DIR}/deployment-scraped-metrics
142
+ # curl -s "http://localhost:8001/api/v1/namespaces/kube-system/services/kube-state-metrics-no-node-pods:http-metrics/proxy/metrics" >${KUBE_STATE_METRICS_LOG_DIR}/deployment-scraped-no-node-metrics
143
+
144
+ # cat ${KUBE_STATE_METRICS_LOG_DIR}/daemonset-scraped-metrics ${KUBE_STATE_METRICS_LOG_DIR}/deployment-scraped-metrics ${KUBE_STATE_METRICS_LOG_DIR}/deployment-scraped-no-node-metrics >> ${KUBE_STATE_METRICS_LOG_DIR}/all-metrics
145
+ # cat ${KUBE_STATE_METRICS_LOG_DIR}/all-metrics | grep "kube_pod_info"
146
+ runningpod1=" $( curl -s " http://localhost:8001/api/v1/namespaces/kube-system/services/kube-state-metrics-shard:http-metrics/proxy/metrics" | grep " runningpod1" | grep -c " kube_pod_info" ) "
147
+ node1=" $( curl -s " http://localhost:8001/api/v1/namespaces/kube-system/services/kube-state-metrics:http-metrics/proxy/metrics" | grep -c " # TYPE kube_node_info" ) "
148
+ expected_num_pod=1
149
+ if [ " ${runningpod1} " != " ${expected_num_pod} " ]; then
150
+ echo " metric kube_pod_info for runningpod1 doesn't show up only once, got ${runningpod1} times"
111
151
exit 1
112
152
fi
113
- if [[ -n " ${m2} " ]]; then
114
- echo " shouldn't find metric kube_pod_info from non-pod metrics service"
153
+
154
+ if [ " ${node1} " != " 1" ]; then
155
+ echo " metric kube_node_info doesn't show up only once, got ${node1} times"
115
156
exit 1
116
157
fi
117
158
159
+ kubectl logs deployment/kube-state-metrics-no-node-pods -n kube-system
160
+ sleep 3
161
+ curl -s " http://localhost:8001/api/v1/namespaces/kube-system/services/kube-state-metrics-no-node-pods:http-metrics/proxy/metrics"
162
+ sleep 3
163
+ kubectl get pods -A --field-selector spec.nodeName=" "
164
+ sleep 3
165
+ pendingpod2=" $( curl -s " http://localhost:8001/api/v1/namespaces/kube-system/services/kube-state-metrics-no-node-pods:http-metrics/proxy/metrics" | grep " pendingpod2" | grep -c " kube_pod_info" ) "
166
+ if [ " ${pendingpod2} " != " ${expected_num_pod} " ]; then
167
+ echo " metric kube_pod_info for pendingpod2 doesn't show up only once, got ${runningpod1} times"
168
+ exit 1
169
+ fi
170
+
171
+ kubectl delete -f ./tests/e2e/testdata/pods.yaml
118
172
kubectl delete -f ./examples/daemonsetsharding
119
173
sleep 20
120
174
}
@@ -144,6 +198,9 @@ set -e
144
198
kubectl version
145
199
146
200
# query kube-state-metrics image tag
201
+ cat pkg/options/types.go
202
+ sleep 3
203
+
147
204
REGISTRY=" registry.k8s.io/kube-state-metrics" make container
148
205
docker images -a
149
206
KUBE_STATE_METRICS_IMAGE_TAG=$( docker images -a| grep " ${KUBE_STATE_METRICS_IMAGE_NAME} " | grep -v ' latest' | awk ' {print $2}' | sort -u)
0 commit comments