-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path_assertions.sh
executable file
·106 lines (81 loc) · 2.73 KB
/
_assertions.sh
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
#!/bin/bash
# SPDX-license-identifier: Apache-2.0
##############################################################################
# Copyright (c)
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Apache License, Version 2.0
# which accompanies this distribution, and is available at
# http://www.apache.org/licenses/LICENSE-2.0
##############################################################################
set -o pipefail
set -o errexit
set -o nounset
source _commons.sh
function assert_equals {
local input=$1
local expected=$2
if [ "$input" != "$expected" ]; then
error "Go $input expected $expected"
fi
}
function assert_contains {
local input=$1
local expected=$2
if ! echo "$input" | grep -q "$expected"; then
error "Got $input expected $expected"
fi
}
function assert_non_empty {
local input=$1
if [ -z "$input" ]; then
error "Empty input value"
fi
}
function assert_deployment_exists {
assert_k8s_resource_exists "deployment" "$@"
}
function assert_daemonset_exists {
assert_k8s_resource_exists "daemonset" "$@"
}
function assert_service_exists {
assert_k8s_resource_exists "service" "$@"
}
function assert_k8s_resource_exists {
local resource="$1/$2"
local namespace=${3:-kube-system}
if [ -z "$(kubectl get "$resource" -n "$namespace" --no-headers)" ]; then
error "$resource not exists in $namespace"
fi
}
function assert_helm_repo_exists {
local repo="$1"
if ! helm repo list | grep -q "$repo"; then
error "$repo helm repo does not exists"
fi
}
function assert_helm_repo_exists {
local repo="$1"
if ! helm repo list | grep -q "$repo"; then
error "$repo helm repo does not exists"
fi
}
function assert_helm_chart_installed {
local chart="$1"
if ! helm history "$chart" | grep -q "Install complete"; then
error "$chart helm chart installation is not complete"
fi
}
function assert_deployment_readiness {
local name="deployments/$1"
local namespace=${2:-kube-system}
ready_replicas="$(kubectl get -n "$namespace" "$name" -o=jsonpath --template='{.status.readyReplicas}')"
replicas="$(kubectl get -n "$namespace" "$name" -o=jsonpath --template='{.status.replicas}')"
assert_equals "$ready_replicas" "$replicas"
}
function assert_daemonset_readiness {
local name="daemonsets/$1"
local namespace=${2:-kube-system}
number_ready="$(kubectl get "$name" -n "$namespace" -o=jsonpath --template='{.status.numberReady}')"
desired_number_scheduled="$(kubectl get "$name" -n "$namespace" -o=jsonpath --template='{.status.desiredNumberScheduled}')"
assert_equals "$number_ready" "$desired_number_scheduled"
}