-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathchainsaw-test.yaml
More file actions
146 lines (144 loc) · 4.84 KB
/
Copy pathchainsaw-test.yaml
File metadata and controls
146 lines (144 loc) · 4.84 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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
apiVersion: chainsaw.kyverno.io/v1alpha1
kind: Test
metadata:
name: recommend-mode
spec:
description: Verify that a AttunePolicy in Recommend mode discovers workloads and reaches Ready condition
timeouts:
apply: 30s
assert: 2m
delete: 30s
steps:
- name: create-resources
try:
- apply:
resource:
apiVersion: v1
kind: Namespace
metadata:
name: e2e-recommend-mode
- apply:
resource:
apiVersion: apps/v1
kind: Deployment
metadata:
name: test-app
namespace: e2e-recommend-mode
labels:
app: test-app
tier: api
spec:
replicas: 1
selector:
matchLabels:
app: test-app
template:
metadata:
labels:
app: test-app
tier: api
spec:
containers:
- name: app
image: registry.k8s.io/pause:3.9
resources:
requests:
cpu: 500m
memory: 512Mi
limits:
cpu: "1"
memory: 1Gi
- apply:
resource:
apiVersion: attune.io/v1alpha1
kind: AttunePolicy
metadata:
name: recommend-test
namespace: e2e-recommend-mode
spec:
targetRef:
kind: Deployment
selector:
matchLabels:
tier: api
metricsSource:
prometheus:
address: http://prometheus-server.monitoring:80
minimumDataPoints: 1
historyWindow: 1h
cpu:
percentile: 95
overhead: "20"
minAllowed: 50m
maxAllowed: "4000m"
controlledValues: RequestsAndLimits
memory:
percentile: 99
overhead: "30"
minAllowed: 64Mi
maxAllowed: 8Gi
controlledValues: RequestsAndLimits
updateStrategy:
type: Recommend
cooldown: 1m
- name: verify-deployment-ready
try:
- assert:
resource:
apiVersion: apps/v1
kind: Deployment
metadata:
name: test-app
namespace: e2e-recommend-mode
status:
readyReplicas: 1
- name: verify-status
try:
- script:
timeout: 3m
content: |
# The operator may transition quickly from InsufficientData to Monitoring
# when minimumDataPoints is 1 and Prometheus scrapes fast. Accept either
# state as valid — both prove the policy discovered the workload and
# the controller reconciled it.
for i in $(seq 1 36); do
reason=$(kubectl get attunepolicy recommend-test -n e2e-recommend-mode \
-o jsonpath='{.status.conditions[?(@.type=="Ready")].reason}' 2>/dev/null)
discovered=$(kubectl get attunepolicy recommend-test -n e2e-recommend-mode \
-o jsonpath='{.status.workloads.discovered}' 2>/dev/null)
if [ "$discovered" = "1" ]; then
if [ "$reason" = "InsufficientData" ] || [ "$reason" = "Monitoring" ]; then
echo "OK: workloads discovered=$discovered, Ready reason=$reason"
exit 0
fi
fi
echo "Waiting... discovered=$discovered reason=$reason"
sleep 5
done
echo "FAIL: timed out waiting for policy to discover workloads"
kubectl get attunepolicy recommend-test -n e2e-recommend-mode -o yaml
exit 1
- name: verify-no-resizes
try:
- assert:
resource:
apiVersion: attune.io/v1alpha1
kind: AttunePolicy
metadata:
name: recommend-test
namespace: e2e-recommend-mode
status:
workloads:
resized: 0
catch:
- describe:
apiVersion: attune.io/v1alpha1
kind: AttunePolicy
namespace: e2e-recommend-mode
- describe:
apiVersion: apps/v1
kind: Deployment
namespace: e2e-recommend-mode
- podLogs:
namespace: attune-system
selector: app.kubernetes.io/name=attune