@@ -7,59 +7,75 @@ RESOURCE_COUNT=1
7
7
SYSTEM_COUNT=3
8
8
DOMAIN_COUNT=2
9
9
10
- # Test the number of components using kubctl get -o json and jq
10
+ MAX_RETRIES=5
11
+ RETRY_DELAY=10
12
+
13
+ # Function to check resource count with retries
14
+ check_resource_count () {
15
+ local resource_type=$1
16
+ local resource_type_singular=$2
17
+ local expected_count=$3
18
+ local exit_status=0
19
+ local attempt=1
20
+
21
+ while [ $attempt -le $MAX_RETRIES ]; do
22
+ count=$( kubectl get $resource_type -o json | jq ' [.items[] | select(.kind == "' ${resource_type_singular} ' ")] | length' )
23
+ if [ $count -ne $expected_count ]; then
24
+ echo " Expected $expected_count ${resource_type_singular} , found $count "
25
+ if [ $attempt -lt $MAX_RETRIES ]; then
26
+ sleep $RETRY_DELAY
27
+ else
28
+ echo " Retry limit reached for $resource_type "
29
+ exit_status=1
30
+ fi
31
+ else
32
+ break
33
+ fi
34
+ attempt=$(( attempt + 1 ))
35
+ done
36
+
37
+ return $exit_status
38
+ }
39
+
40
+ # Main test execution
11
41
exit_status=0
12
42
13
- for attempt in {1..5}; do
14
- count=$( kubectl get components.servicemodel.ext.grafana.com -o json | jq ' [.items[] | select(.kind == "Component")] | length' )
15
- if [ $count -ne $COMPONENT_COUNT ]; then
16
- echo " Expected $COMPONENT_COUNT components, found $count "
17
- else
18
- break
19
- fi
20
-
21
- if [ $attempt -lt 5 ]; then
22
- sleep 10
23
- else
24
- echo " Retry limit reached, exiting..."
25
- exit_status=1
26
- fi
27
- done
28
-
29
-
30
- count=$( kubectl get users.servicemodel.ext.grafana.com -o json | jq ' [.items[] | select(.kind == "User")] | length' )
31
- if [ $count -ne $USERS_COUNT ]; then
32
- echo " Expected $USERS_COUNT users, found $count "
43
+ # Check components
44
+ if ! check_resource_count " components.servicemodel.ext.grafana.com" " Component" $COMPONENT_COUNT ; then
33
45
exit_status=1
34
46
fi
35
47
36
- count=$( kubectl get resources.servicemodel.ext.grafana.com -o json | jq ' [.items[] | select(.kind == "Resource")] | length' )
37
- if [ $count -ne $RESOURCE_COUNT ]; then
38
- echo " Expected $RESOURCE_COUNT resources, found $count "
48
+ # Check users
49
+ if ! check_resource_count " users.servicemodel.ext.grafana.com" " User" $USERS_COUNT ; then
39
50
exit_status=1
40
51
fi
41
52
42
- count=$( kubectl get groups.servicemodel.ext.grafana.com -o json | jq ' [.items[] | select(.kind == "Group")] | length' )
43
- if [ $count -ne $GROUP_COUNT ]; then
44
- echo " Expected $GROUP_COUNT groups, found $count "
53
+ # Check resources
54
+ if ! check_resource_count " resources.servicemodel.ext.grafana.com" " Resource" $RESOURCE_COUNT ; then
45
55
exit_status=1
46
56
fi
47
57
48
- count=$( kubectl get systems.servicemodel.ext.grafana.com -o json | jq ' [.items[] | select(.kind == "System")] | length' )
49
- if [ $count -ne $SYSTEM_COUNT ]; then
50
- echo " Expected $SYSTEM_COUNT systems, found $count "
58
+ # Check groups
59
+ if ! check_resource_count " groups.servicemodel.ext.grafana.com" " Group" $GROUP_COUNT ; then
51
60
exit_status=1
52
61
fi
53
62
54
- count=$( kubectl get domains.servicemodel.ext.grafana.com -o json | jq ' [.items[] | select(.kind == "Domain")] | length' )
55
- if [ $count -ne $DOMAIN_COUNT ]; then
56
- echo " Expected $DOMAIN_COUNT domains, found $count "
63
+ # Check systems
64
+ if ! check_resource_count " systems.servicemodel.ext.grafana.com" " System" $SYSTEM_COUNT ; then
57
65
exit_status=1
58
66
fi
59
67
60
- exit $exit_status
68
+ # Check domains
69
+ if ! check_resource_count " domains.servicemodel.ext.grafana.com" " Domain" $DOMAIN_COUNT ; then
70
+ exit_status=1
71
+ fi
61
72
73
+ if [ $exit_status -eq 0 ]; then
74
+ echo " Integration test passed"
75
+ else
76
+ echo " Integration test failed"
77
+ fi
62
78
63
- echo " Integration test passed "
79
+ exit $exit_status
64
80
65
81
0 commit comments