-
Notifications
You must be signed in to change notification settings - Fork 159
Expand file tree
/
Copy pathapplicationlayer_controller_test.go
More file actions
619 lines (547 loc) · 24.5 KB
/
Copy pathapplicationlayer_controller_test.go
File metadata and controls
619 lines (547 loc) · 24.5 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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
// Copyright (c) 2021-2026 Tigera, Inc. All rights reserved.
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package applicationlayer
import (
"context"
"fmt"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"github.com/stretchr/testify/mock"
admregv1 "k8s.io/api/admissionregistration/v1"
appsv1 "k8s.io/api/apps/v1"
batchv1 "k8s.io/api/batch/v1"
rbacv1 "k8s.io/api/rbac/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/types"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/reconcile"
v3 "github.com/tigera/api/pkg/apis/projectcalico/v3"
operatorv1 "github.com/tigera/operator/api/v1"
"github.com/tigera/operator/pkg/apis"
"github.com/tigera/operator/pkg/common"
"github.com/tigera/operator/pkg/components"
"github.com/tigera/operator/pkg/controller/status"
"github.com/tigera/operator/pkg/controller/utils"
ctrlrfake "github.com/tigera/operator/pkg/ctrlruntime/client/fake"
"github.com/tigera/operator/pkg/render/applicationlayer"
"github.com/tigera/operator/test"
)
var _ = Describe("Application layer controller tests", func() {
var c client.Client
var ctx context.Context
var r ReconcileApplicationLayer
var scheme *runtime.Scheme
var mockStatus *status.MockStatus
var installation *operatorv1.Installation
var fc *v3.FelixConfiguration
Context("image reconciliation", func() {
BeforeEach(func() {
// The schema contains all objects that should be known to the fake client when the test runs.
scheme = runtime.NewScheme()
Expect(apis.AddToScheme(scheme, false)).NotTo(HaveOccurred())
Expect(appsv1.SchemeBuilder.AddToScheme(scheme)).ShouldNot(HaveOccurred())
Expect(rbacv1.SchemeBuilder.AddToScheme(scheme)).ShouldNot(HaveOccurred())
Expect(batchv1.SchemeBuilder.AddToScheme(scheme)).ShouldNot(HaveOccurred())
Expect(operatorv1.SchemeBuilder.AddToScheme(scheme)).NotTo(HaveOccurred())
Expect(admregv1.SchemeBuilder.AddToScheme(scheme)).NotTo(HaveOccurred())
// Create a client that will have a crud interface of k8s objects.
c = ctrlrfake.DefaultFakeClientBuilder(scheme).Build()
ctx = context.Background()
installation = &operatorv1.Installation{
ObjectMeta: metav1.ObjectMeta{Name: "default"},
Spec: operatorv1.InstallationSpec{
Variant: operatorv1.CalicoEnterprise,
Registry: "some.registry.org/",
},
Status: operatorv1.InstallationStatus{
Variant: operatorv1.CalicoEnterprise,
Computed: &operatorv1.InstallationSpec{
Registry: "my-reg",
// The test is provider agnostic.
KubernetesProvider: operatorv1.ProviderNone,
},
},
}
mockStatus = &status.MockStatus{}
mockStatus.On("OnCRFound").Return()
r = ReconcileApplicationLayer{
client: c,
scheme: scheme,
provider: operatorv1.ProviderNone,
status: mockStatus,
licenseAPIReady: &utils.ReadyFlag{},
}
fc = &v3.FelixConfiguration{
ObjectMeta: metav1.ObjectMeta{
Name: "default",
},
Spec: v3.FelixConfigurationSpec{},
}
Expect(c.Create(ctx, fc)).NotTo(HaveOccurred())
// Mark that the watch for license key was successful.
r.licenseAPIReady.MarkAsReady()
})
AfterEach(func() {
Expect(c.Delete(ctx, fc)).NotTo(HaveOccurred())
})
It("should set PolicySyncPathPrefix if ALP is enabled", func() {
mockStatus.On("AddDaemonsets", mock.Anything).Return()
mockStatus.On("AddDeployments", mock.Anything).Return()
mockStatus.On("IsAvailable").Return(true)
mockStatus.On("AddStatefulSets", mock.Anything).Return()
mockStatus.On("AddCronJobs", mock.Anything)
mockStatus.On("OnCRNotFound").Return()
mockStatus.On("ClearDegraded")
mockStatus.On("ReadyToMonitor")
mockStatus.On("SetMetaData", mock.Anything).Return()
Expect(c.Create(ctx, installation)).NotTo(HaveOccurred())
By("applying the ApplicationLayer CR to the fake cluster")
enabled := operatorv1.ApplicationLayerPolicyEnabled
alSpec := &operatorv1.ApplicationLayer{
ObjectMeta: metav1.ObjectMeta{Name: "tigera-secure"},
Spec: operatorv1.ApplicationLayerSpec{
ApplicationLayerPolicy: &enabled,
},
}
Expect(c.Create(ctx, alSpec)).NotTo(HaveOccurred())
_, err := r.Reconcile(ctx, reconcile.Request{})
Expect(err).ShouldNot(HaveOccurred())
By("ensuring that felix configuration PolicySyncPathPrefix is set")
f1 := v3.FelixConfiguration{
ObjectMeta: metav1.ObjectMeta{
Name: "default",
},
}
Expect(test.GetResource(c, &f1)).To(BeNil())
Expect(f1.Spec.PolicySyncPathPrefix).To(Equal("/var/run/nodeagent"))
Expect(c.Delete(ctx, alSpec)).NotTo(HaveOccurred())
_, err = r.Reconcile(ctx, reconcile.Request{})
Expect(err).ShouldNot(HaveOccurred())
By("ensuring that felix configuration PolicySyncPathPrefix is left as is, even after ALP deletion")
f2 := v3.FelixConfiguration{
ObjectMeta: metav1.ObjectMeta{
Name: "default",
},
}
Expect(test.GetResource(c, &f2)).To(BeNil())
Expect(f2.Spec.PolicySyncPathPrefix).To(Equal("/var/run/nodeagent"))
})
It("should leave PolicySyncPathPrefix as is if already exists", func() {
Expect(c.Delete(ctx, fc)).NotTo(HaveOccurred())
Expect(c.Create(ctx, &v3.FelixConfiguration{
ObjectMeta: metav1.ObjectMeta{
Name: "default",
},
Spec: v3.FelixConfigurationSpec{
PolicySyncPathPrefix: "/var/run/myfelix",
},
})).NotTo(HaveOccurred())
mockStatus.On("OnCRNotFound").Return()
_, err := r.Reconcile(ctx, reconcile.Request{})
Expect(err).ShouldNot(HaveOccurred())
By("applying the ApplicationLayer CR to the fake cluster")
enabled := operatorv1.ApplicationLayerPolicyEnabled
alSpec := &operatorv1.ApplicationLayer{
ObjectMeta: metav1.ObjectMeta{Name: "tigera-secure"},
Spec: operatorv1.ApplicationLayerSpec{
ApplicationLayerPolicy: &enabled,
},
}
Expect(c.Create(ctx, alSpec)).NotTo(HaveOccurred())
By("ensuring that felix configuration PolicySyncPathPrefix, if preset, is retained")
f1 := v3.FelixConfiguration{
ObjectMeta: metav1.ObjectMeta{
Name: "default",
},
}
Expect(test.GetResource(c, &f1)).To(BeNil())
Expect(f1.Spec.PolicySyncPathPrefix).To(Equal("/var/run/myfelix"))
Expect(c.Delete(ctx, alSpec)).NotTo(HaveOccurred())
_, err = r.Reconcile(ctx, reconcile.Request{})
Expect(err).ShouldNot(HaveOccurred())
By("ensuring that felix configuration PolicySyncPathPrefix is left as is, even after ALP deletion")
f2 := v3.FelixConfiguration{
ObjectMeta: metav1.ObjectMeta{
Name: "default",
},
}
Expect(test.GetResource(c, &f2)).To(BeNil())
Expect(f2.Spec.PolicySyncPathPrefix).To(Equal("/var/run/myfelix"))
})
It("should leave TPROXYMode unset if log collection is disabled", func() {
// This test verifies a workaround for upgrade from versions that don't support TPROXY to versions
// that do. Setting an unknown felix config field causes older versions of felix to cyclicly restart,
// which causes a disruptive upgrade.
By("reconciling before without an app layer resource")
mockStatus.On("OnCRNotFound").Return()
_, err := r.Reconcile(ctx, reconcile.Request{})
Expect(err).ShouldNot(HaveOccurred())
By("ensuring that felix configuration TPROXYMode is nil")
fc := v3.FelixConfiguration{
ObjectMeta: metav1.ObjectMeta{
Name: "default",
},
}
Expect(test.GetResource(c, &fc)).To(BeNil())
Expect(fc.Spec.TPROXYMode).To(Equal(""))
})
It("should enable WAFEventLogsFileEnabled when the GatewayAPI WAF extension is enabled (no ApplicationLayer CR)", func() {
// The gateway data-plane WAF (design-25) emits audit events that flow through Felix's WAF event
// log, so it requires the same FelixConfiguration toggle as the legacy ApplicationLayer WAF — even
// when no ApplicationLayer CR is present.
mockStatus.On("OnCRNotFound").Return()
By("creating a GatewayAPI CR with the WAF extension enabled")
wafEnabled := operatorv1.WAFExtensionStateEnabled
Expect(c.Create(ctx, &operatorv1.GatewayAPI{
ObjectMeta: metav1.ObjectMeta{Name: "default"},
Spec: operatorv1.GatewayAPISpec{
Extensions: &operatorv1.GatewayAPIExtensions{
WAF: &operatorv1.WAFExtensionSpec{State: &wafEnabled},
},
},
})).NotTo(HaveOccurred())
By("reconciling without an ApplicationLayer resource")
_, err := r.Reconcile(ctx, reconcile.Request{})
Expect(err).ShouldNot(HaveOccurred())
By("ensuring felix WAFEventLogsFileEnabled is true")
fc := v3.FelixConfiguration{ObjectMeta: metav1.ObjectMeta{Name: "default"}}
Expect(test.GetResource(c, &fc)).To(BeNil())
Expect(fc.Spec.WAFEventLogsFileEnabled).NotTo(BeNil())
Expect(*fc.Spec.WAFEventLogsFileEnabled).To(BeTrue())
})
It("should render accurate resources for for log collection", func() {
mockStatus.On("AddDaemonsets", mock.Anything).Return()
mockStatus.On("AddDeployments", mock.Anything).Return()
mockStatus.On("IsAvailable").Return(true)
mockStatus.On("AddStatefulSets", mock.Anything).Return()
mockStatus.On("AddCronJobs", mock.Anything)
mockStatus.On("OnCRNotFound").Return()
mockStatus.On("ClearDegraded")
mockStatus.On("ReadyToMonitor")
mockStatus.On("SetMetaData", mock.Anything).Return()
Expect(c.Create(ctx, installation)).NotTo(HaveOccurred())
By("applying the ApplicationLayer CR to the fake cluster")
enabled := operatorv1.L7LogCollectionEnabled
Expect(c.Create(ctx, &operatorv1.ApplicationLayer{
ObjectMeta: metav1.ObjectMeta{Name: "tigera-secure"},
Spec: operatorv1.ApplicationLayerSpec{
LogCollection: &operatorv1.LogCollectionSpec{
CollectLogs: &enabled,
},
},
})).NotTo(HaveOccurred())
_, err := r.Reconcile(ctx, reconcile.Request{})
Expect(err).ShouldNot(HaveOccurred())
ds := appsv1.DaemonSet{
TypeMeta: metav1.TypeMeta{Kind: "DaemonSet", APIVersion: "apps/v1"},
ObjectMeta: metav1.ObjectMeta{
Name: applicationlayer.ApplicationLayerDaemonsetName,
Namespace: common.CalicoNamespace,
},
}
By("ensuring that log collection resources created properly")
Expect(test.GetResource(c, &ds)).To(BeNil())
Expect(ds.Spec.Template.Spec.Containers).To(HaveLen(2))
proxy := ds.Spec.Template.Spec.Containers[0]
Expect(proxy).ToNot(BeNil())
Expect(proxy.Image).To(Equal(fmt.Sprintf("some.registry.org/%s%s:%s",
components.TigeraImagePath,
components.ComponentEnvoyProxy.Image, components.ComponentEnvoyProxy.Version)))
l7collector := ds.Spec.Template.Spec.Containers[1]
Expect(l7collector).ToNot(BeNil())
Expect(l7collector.Image).To(Equal(fmt.Sprintf("some.registry.org/%s%s:%s",
components.TigeraImagePath,
components.ComponentTigeraCalico.Image, components.ComponentTigeraCalico.Version)))
By("ensuring that felix configuration updated to enabled")
fc := v3.FelixConfiguration{
ObjectMeta: metav1.ObjectMeta{
Name: "default",
},
}
Expect(test.GetResource(c, &fc)).To(BeNil())
Expect(fc.Spec.TPROXYMode).To(Equal("Enabled"))
By("deleting that ApplicationLayer CR")
Expect(c.Delete(ctx, &operatorv1.ApplicationLayer{
ObjectMeta: metav1.ObjectMeta{Name: "tigera-secure"},
})).NotTo(HaveOccurred())
_, err = r.Reconcile(ctx, reconcile.Request{})
Expect(err).ShouldNot(HaveOccurred())
By("ensuring that felix configuration updated to disabled")
fc = v3.FelixConfiguration{
ObjectMeta: metav1.ObjectMeta{
Name: "default",
},
}
Expect(test.GetResource(c, &fc)).To(BeNil())
Expect(fc.Spec.TPROXYMode).To(Equal("Disabled"))
})
It("should render proper SidecarWebhook status", func() {
mockStatus.On("AddDaemonsets", mock.Anything).Return()
mockStatus.On("AddDeployments", mock.Anything).Return()
mockStatus.On("IsAvailable").Return(true)
mockStatus.On("AddStatefulSets", mock.Anything).Return()
mockStatus.On("AddCronJobs", mock.Anything)
mockStatus.On("OnCRNotFound").Return()
mockStatus.On("ClearDegraded")
mockStatus.On("ReadyToMonitor")
mockStatus.On("SetMetaData", mock.Anything).Return()
Expect(c.Create(ctx, installation)).NotTo(HaveOccurred())
By("applying the ApplicationLayer CR to the fake cluster")
enabled := operatorv1.L7LogCollectionEnabled
Expect(c.Create(ctx, &operatorv1.ApplicationLayer{
ObjectMeta: metav1.ObjectMeta{Name: "tigera-secure"},
Spec: operatorv1.ApplicationLayerSpec{
LogCollection: &operatorv1.LogCollectionSpec{
CollectLogs: &enabled,
},
},
})).NotTo(HaveOccurred())
_, err := r.Reconcile(ctx, reconcile.Request{})
Expect(err).ShouldNot(HaveOccurred())
instance, err := getApplicationLayer(ctx, r.client)
Expect(err).ShouldNot(HaveOccurred())
Expect(*instance.Status.SidecarWebhook).To(Equal(operatorv1.SidecarWebhookStateDisabled))
By("creating sidecar mutatingwebhookconfiguration")
sidecarMutatingWebhook := &admregv1.MutatingWebhookConfiguration{
ObjectMeta: metav1.ObjectMeta{
Name: common.SidecarMutatingWebhookConfigName,
},
}
Expect(c.Create(ctx, sidecarMutatingWebhook)).NotTo(HaveOccurred())
_, err = r.Reconcile(ctx, reconcile.Request{})
Expect(err).ShouldNot(HaveOccurred())
instance, err = getApplicationLayer(ctx, r.client)
Expect(err).ShouldNot(HaveOccurred())
Expect(*instance.Status.SidecarWebhook).To(Equal(operatorv1.SidecarWebhookStateEnabled))
By("deleting sidecar mutatingwebhookconfiguration")
Expect(c.Delete(ctx, sidecarMutatingWebhook)).NotTo(HaveOccurred())
_, err = r.Reconcile(ctx, reconcile.Request{})
Expect(err).ShouldNot(HaveOccurred())
instance, err = getApplicationLayer(ctx, r.client)
Expect(err).ShouldNot(HaveOccurred())
Expect(*instance.Status.SidecarWebhook).To(Equal(operatorv1.SidecarWebhookStateDisabled))
})
Context("Reconcile for Condition status", func() {
generation := int64(2)
BeforeEach(func() {
enabled := operatorv1.L7LogCollectionEnabled
Expect(c.Create(ctx, &operatorv1.ApplicationLayer{
ObjectMeta: metav1.ObjectMeta{Name: "tigera-secure", Generation: 3},
Spec: operatorv1.ApplicationLayerSpec{
LogCollection: &operatorv1.LogCollectionSpec{
CollectLogs: &enabled,
},
},
})).NotTo(HaveOccurred())
})
It("should reconcile with creating new status condition with one item", func() {
mockStatus.On("AddDaemonsets", mock.Anything).Return()
mockStatus.On("AddDeployments", mock.Anything).Return()
mockStatus.On("IsAvailable").Return(true)
mockStatus.On("AddStatefulSets", mock.Anything).Return()
mockStatus.On("AddCronJobs", mock.Anything)
mockStatus.On("OnCRNotFound").Return()
mockStatus.On("ClearDegraded")
mockStatus.On("ReadyToMonitor")
mockStatus.On("SetMetaData", mock.Anything).Return()
Expect(c.Create(ctx, installation)).NotTo(HaveOccurred())
ts := &operatorv1.TigeraStatus{
ObjectMeta: metav1.ObjectMeta{Name: "applicationlayer"},
Spec: operatorv1.TigeraStatusSpec{},
Status: operatorv1.TigeraStatusStatus{
Conditions: []operatorv1.TigeraStatusCondition{
{
Type: operatorv1.ComponentAvailable,
Status: operatorv1.ConditionTrue,
Reason: string(operatorv1.AllObjectsAvailable),
Message: "All Objects are available",
ObservedGeneration: generation,
},
},
},
}
Expect(c.Create(ctx, ts)).NotTo(HaveOccurred())
_, err := r.Reconcile(ctx, reconcile.Request{NamespacedName: types.NamespacedName{
Name: "applicationlayer",
Namespace: "",
}})
Expect(err).ShouldNot(HaveOccurred())
instance, err := getApplicationLayer(ctx, r.client)
Expect(err).ShouldNot(HaveOccurred())
Expect(instance.Status.Conditions).To(HaveLen(1))
Expect(instance.Status.Conditions[0].Type).To(Equal("Ready"))
Expect(string(instance.Status.Conditions[0].Status)).To(Equal(string(operatorv1.ConditionTrue)))
Expect(instance.Status.Conditions[0].Reason).To(Equal(string(operatorv1.AllObjectsAvailable)))
Expect(instance.Status.Conditions[0].Message).To(Equal("All Objects are available"))
Expect(instance.Status.Conditions[0].ObservedGeneration).To(Equal(generation))
})
It("should reconcile with empty tigerastatus conditions ", func() {
mockStatus.On("AddDaemonsets", mock.Anything).Return()
mockStatus.On("AddDeployments", mock.Anything).Return()
mockStatus.On("IsAvailable").Return(true)
mockStatus.On("AddStatefulSets", mock.Anything).Return()
mockStatus.On("AddCronJobs", mock.Anything)
mockStatus.On("OnCRNotFound").Return()
mockStatus.On("ClearDegraded")
mockStatus.On("ReadyToMonitor")
mockStatus.On("SetMetaData", mock.Anything).Return()
Expect(c.Create(ctx, installation)).NotTo(HaveOccurred())
ts := &operatorv1.TigeraStatus{
ObjectMeta: metav1.ObjectMeta{Name: "applicationlayer"},
Spec: operatorv1.TigeraStatusSpec{},
Status: operatorv1.TigeraStatusStatus{},
}
Expect(c.Create(ctx, ts)).NotTo(HaveOccurred())
_, err := r.Reconcile(ctx, reconcile.Request{NamespacedName: types.NamespacedName{
Name: "applicationlayer",
Namespace: "",
}})
Expect(err).ShouldNot(HaveOccurred())
instance, err := getApplicationLayer(ctx, r.client)
Expect(err).ShouldNot(HaveOccurred())
Expect(instance.Status.Conditions).To(HaveLen(0))
})
It("should reconcile with creating new status condition with multiple conditions as true", func() {
mockStatus.On("AddDaemonsets", mock.Anything).Return()
mockStatus.On("AddDeployments", mock.Anything).Return()
mockStatus.On("IsAvailable").Return(true)
mockStatus.On("AddStatefulSets", mock.Anything).Return()
mockStatus.On("AddCronJobs", mock.Anything)
mockStatus.On("OnCRNotFound").Return()
mockStatus.On("ClearDegraded")
mockStatus.On("ReadyToMonitor")
mockStatus.On("SetMetaData", mock.Anything).Return()
Expect(c.Create(ctx, installation)).NotTo(HaveOccurred())
ts := &operatorv1.TigeraStatus{
ObjectMeta: metav1.ObjectMeta{Name: "applicationlayer"},
Spec: operatorv1.TigeraStatusSpec{},
Status: operatorv1.TigeraStatusStatus{
Conditions: []operatorv1.TigeraStatusCondition{
{
Type: operatorv1.ComponentAvailable,
Status: operatorv1.ConditionTrue,
Reason: string(operatorv1.AllObjectsAvailable),
Message: "All Objects are available",
ObservedGeneration: generation,
},
{
Type: operatorv1.ComponentProgressing,
Status: operatorv1.ConditionTrue,
Reason: string(operatorv1.ResourceNotReady),
Message: "Progressing Installation.operatorv1.tigera.io",
ObservedGeneration: generation,
},
{
Type: operatorv1.ComponentDegraded,
Status: operatorv1.ConditionTrue,
Reason: string(operatorv1.ResourceUpdateError),
Message: "Error resolving ImageSet for components",
ObservedGeneration: generation,
},
},
},
}
Expect(c.Create(ctx, ts)).NotTo(HaveOccurred())
_, err := r.Reconcile(ctx, reconcile.Request{NamespacedName: types.NamespacedName{
Name: "applicationlayer",
Namespace: "",
}})
Expect(err).ShouldNot(HaveOccurred())
instance, err := getApplicationLayer(ctx, r.client)
Expect(err).ShouldNot(HaveOccurred())
Expect(instance.Status.Conditions).To(HaveLen(3))
Expect(instance.Status.Conditions[0].Type).To(Equal("Ready"))
Expect(string(instance.Status.Conditions[0].Status)).To(Equal(string(operatorv1.ConditionTrue)))
Expect(instance.Status.Conditions[0].Reason).To(Equal(string(operatorv1.AllObjectsAvailable)))
Expect(instance.Status.Conditions[0].Message).To(Equal("All Objects are available"))
Expect(instance.Status.Conditions[0].ObservedGeneration).To(Equal(generation))
Expect(instance.Status.Conditions[1].Type).To(Equal("Progressing"))
Expect(string(instance.Status.Conditions[1].Status)).To(Equal(string(operatorv1.ConditionTrue)))
Expect(instance.Status.Conditions[1].Reason).To(Equal(string(operatorv1.ResourceNotReady)))
Expect(instance.Status.Conditions[1].Message).To(Equal("Progressing Installation.operatorv1.tigera.io"))
Expect(instance.Status.Conditions[1].ObservedGeneration).To(Equal(generation))
Expect(instance.Status.Conditions[2].Type).To(Equal("Degraded"))
Expect(string(instance.Status.Conditions[2].Status)).To(Equal(string(operatorv1.ConditionTrue)))
Expect(instance.Status.Conditions[2].Reason).To(Equal(string(operatorv1.ResourceUpdateError)))
Expect(instance.Status.Conditions[2].Message).To(Equal("Error resolving ImageSet for components"))
Expect(instance.Status.Conditions[2].ObservedGeneration).To(Equal(generation))
})
It("should reconcile with creating new status condition and toggle Available to true & others to false", func() {
mockStatus.On("AddDaemonsets", mock.Anything).Return()
mockStatus.On("AddDeployments", mock.Anything).Return()
mockStatus.On("IsAvailable").Return(true)
mockStatus.On("AddStatefulSets", mock.Anything).Return()
mockStatus.On("AddCronJobs", mock.Anything)
mockStatus.On("OnCRNotFound").Return()
mockStatus.On("ClearDegraded")
mockStatus.On("ReadyToMonitor")
mockStatus.On("SetMetaData", mock.Anything).Return()
Expect(c.Create(ctx, installation)).NotTo(HaveOccurred())
ts := &operatorv1.TigeraStatus{
ObjectMeta: metav1.ObjectMeta{Name: "applicationlayer"},
Spec: operatorv1.TigeraStatusSpec{},
Status: operatorv1.TigeraStatusStatus{
Conditions: []operatorv1.TigeraStatusCondition{
{
Type: operatorv1.ComponentAvailable,
Status: operatorv1.ConditionTrue,
Reason: string(operatorv1.AllObjectsAvailable),
Message: "All Objects are available",
ObservedGeneration: generation,
},
{
Type: operatorv1.ComponentProgressing,
Status: operatorv1.ConditionFalse,
Reason: string(operatorv1.NotApplicable),
Message: "Not Applicable",
ObservedGeneration: generation,
},
{
Type: operatorv1.ComponentDegraded,
Status: operatorv1.ConditionFalse,
Reason: string(operatorv1.NotApplicable),
Message: "Not Applicable",
ObservedGeneration: generation,
},
},
},
}
Expect(c.Create(ctx, ts)).NotTo(HaveOccurred())
_, err := r.Reconcile(ctx, reconcile.Request{NamespacedName: types.NamespacedName{
Name: "applicationlayer",
Namespace: "",
}})
Expect(err).ShouldNot(HaveOccurred())
instance, err := getApplicationLayer(ctx, r.client)
Expect(err).ShouldNot(HaveOccurred())
Expect(instance.Status.Conditions).To(HaveLen(3))
Expect(instance.Status.Conditions[0].Type).To(Equal("Ready"))
Expect(string(instance.Status.Conditions[0].Status)).To(Equal(string(operatorv1.ConditionTrue)))
Expect(instance.Status.Conditions[0].Reason).To(Equal(string(operatorv1.AllObjectsAvailable)))
Expect(instance.Status.Conditions[0].Message).To(Equal("All Objects are available"))
Expect(instance.Status.Conditions[0].ObservedGeneration).To(Equal(generation))
Expect(instance.Status.Conditions[1].Type).To(Equal("Progressing"))
Expect(string(instance.Status.Conditions[1].Status)).To(Equal(string(operatorv1.ConditionFalse)))
Expect(instance.Status.Conditions[1].Reason).To(Equal(string(operatorv1.NotApplicable)))
Expect(instance.Status.Conditions[1].Message).To(Equal("Not Applicable"))
Expect(instance.Status.Conditions[1].ObservedGeneration).To(Equal(generation))
Expect(instance.Status.Conditions[2].Type).To(Equal("Degraded"))
Expect(string(instance.Status.Conditions[2].Status)).To(Equal(string(operatorv1.ConditionFalse)))
Expect(instance.Status.Conditions[2].Reason).To(Equal(string(operatorv1.NotApplicable)))
Expect(instance.Status.Conditions[2].Message).To(Equal("Not Applicable"))
Expect(instance.Status.Conditions[2].ObservedGeneration).To(Equal(generation))
})
})
})
})