@@ -17,6 +17,7 @@ limitations under the License.
17
17
package controller
18
18
19
19
import (
20
+ "context"
20
21
"testing"
21
22
"time"
22
23
@@ -536,7 +537,7 @@ func TestProviderConfigSecretChanges(t *testing.T) {
536
537
expectSameHash bool
537
538
}{
538
539
{
539
- name : "With the same configmap data, the hash annotation doesn't change" ,
540
+ name : "With the same config secret data, the hash annotation doesn't change" ,
540
541
cmData : map [string ][]byte {
541
542
"some-key" : []byte ("some data" ),
542
543
"another-key" : []byte ("another data" ),
@@ -548,7 +549,7 @@ func TestProviderConfigSecretChanges(t *testing.T) {
548
549
expectSameHash : true ,
549
550
},
550
551
{
551
- name : "With the same configmap data, the hash annotation doesn't change " ,
552
+ name : "With different config secret data, the hash annotation changes " ,
552
553
cmData : map [string ][]byte {
553
554
"some-key" : []byte ("some data" ),
554
555
"another-key" : []byte ("another data" ),
@@ -569,18 +570,6 @@ func TestProviderConfigSecretChanges(t *testing.T) {
569
570
g .Expect (env .CleanupAndWait (ctx , objs ... )).To (Succeed ())
570
571
}()
571
572
572
- dataHash , err := calculateHash (tc .cmData )
573
- g .Expect (err ).ToNot (HaveOccurred ())
574
-
575
- updatedDataHash , err := calculateHash (tc .updatedCMData )
576
- g .Expect (err ).ToNot (HaveOccurred ())
577
-
578
- if tc .expectSameHash {
579
- g .Expect (updatedDataHash ).To (Equal (dataHash ))
580
- } else {
581
- g .Expect (updatedDataHash ).ToNot (Equal (dataHash ))
582
- }
583
-
584
573
cmSecretName := "test-config"
585
574
586
575
provider := & operatorv1.CoreProvider {
@@ -630,11 +619,14 @@ func TestProviderConfigSecretChanges(t *testing.T) {
630
619
g .Expect (env .CreateAndWait (ctx , secret .DeepCopy ())).To (Succeed ())
631
620
objs = append (objs , secret )
632
621
622
+ initialHash , err := calculateHash (ctx , env .Client , provider )
623
+ g .Expect (err ).ToNot (HaveOccurred ())
624
+
633
625
t .Log ("creating test provider" , provider .GetName ())
634
626
g .Expect (env .CreateAndWait (ctx , provider .DeepCopy ())).To (Succeed ())
635
627
objs = append (objs , provider )
636
628
637
- g .Eventually (generateExpectedResultChecker (provider , appliedConfigHashAnnotation , dataHash , corev1 .ConditionTrue ), timeout ).Should (BeEquivalentTo (true ))
629
+ g .Eventually (generateExpectedResultChecker (provider , initialHash , corev1 .ConditionTrue ), timeout ).Should (BeEquivalentTo (true ))
638
630
639
631
g .Eventually (func () error {
640
632
if err := env .Client .Get (ctx , client .ObjectKeyFromObject (secret ), secret ); err != nil {
@@ -647,6 +639,21 @@ func TestProviderConfigSecretChanges(t *testing.T) {
647
639
return env .Client .Update (ctx , secret )
648
640
}).Should (Succeed ())
649
641
642
+ var updatedDataHash string
643
+ if tc .expectSameHash {
644
+ g .Eventually (func () string {
645
+ updatedDataHash , err = calculateHash (ctx , env .Client , provider )
646
+ g .Expect (err ).ToNot (HaveOccurred ())
647
+ return updatedDataHash
648
+ }, 15 * time .Second ).Should (Equal (initialHash ))
649
+ } else {
650
+ g .Eventually (func () string {
651
+ updatedDataHash , err = calculateHash (ctx , env .Client , provider )
652
+ g .Expect (err ).ToNot (HaveOccurred ())
653
+ return updatedDataHash
654
+ }, 15 * time .Second ).ShouldNot (Equal (initialHash ))
655
+ }
656
+
650
657
g .Eventually (func () error {
651
658
if err := env .Client .Get (ctx , client .ObjectKeyFromObject (provider ), provider ); err != nil {
652
659
return err
@@ -664,7 +671,7 @@ func TestProviderConfigSecretChanges(t *testing.T) {
664
671
return env .Client .Update (ctx , provider )
665
672
}).Should (Succeed ())
666
673
667
- g .Eventually (generateExpectedResultChecker (provider , appliedConfigHashAnnotation , updatedDataHash , corev1 .ConditionTrue ), timeout ).Should (BeEquivalentTo (true ))
674
+ g .Eventually (generateExpectedResultChecker (provider , updatedDataHash , corev1 .ConditionTrue ), timeout ).Should (BeEquivalentTo (true ))
668
675
})
669
676
}
670
677
}
@@ -758,12 +765,6 @@ func TestProviderSpecChanges(t *testing.T) {
758
765
t .Run (tc .name , func (t * testing.T ) {
759
766
g := NewWithT (t )
760
767
761
- specHash , err := calculateHash (tc .spec )
762
- g .Expect (err ).ToNot (HaveOccurred ())
763
-
764
- updatedSpecHash , err := calculateHash (tc .updatedSpec )
765
- g .Expect (err ).ToNot (HaveOccurred ())
766
-
767
768
provider := & operatorv1.CoreProvider {
768
769
ObjectMeta : metav1.ObjectMeta {
769
770
Name : "cluster-api" ,
@@ -773,6 +774,15 @@ func TestProviderSpecChanges(t *testing.T) {
773
774
},
774
775
}
775
776
777
+ updatedProvider := provider .DeepCopy ()
778
+ updatedProvider .SetSpec (tc .updatedSpec )
779
+
780
+ specHash , err := calculateHash (context .Background (), env .Client , provider )
781
+ g .Expect (err ).ToNot (HaveOccurred ())
782
+
783
+ updatedSpecHash , err := calculateHash (context .Background (), env .Client , updatedProvider )
784
+ g .Expect (err ).ToNot (HaveOccurred ())
785
+
776
786
namespace := "test-provider-spec-changes"
777
787
778
788
ns , err := env .CreateNamespace (ctx , namespace )
@@ -785,7 +795,7 @@ func TestProviderSpecChanges(t *testing.T) {
785
795
t .Log ("creating test provider" , provider .GetName ())
786
796
g .Expect (env .CreateAndWait (ctx , provider .DeepCopy ())).To (Succeed ())
787
797
788
- g .Eventually (generateExpectedResultChecker (provider , appliedSpecHashAnnotation , specHash , corev1 .ConditionTrue ), timeout ).Should (BeEquivalentTo (true ))
798
+ g .Eventually (generateExpectedResultChecker (provider , specHash , corev1 .ConditionTrue ), timeout ).Should (BeEquivalentTo (true ))
789
799
790
800
g .Eventually (func () error {
791
801
if err := env .Client .Get (ctx , client .ObjectKeyFromObject (provider ), provider ); err != nil {
@@ -808,9 +818,9 @@ func TestProviderSpecChanges(t *testing.T) {
808
818
}).Should (Succeed ())
809
819
810
820
if ! tc .expectError {
811
- g .Eventually (generateExpectedResultChecker (provider , appliedSpecHashAnnotation , updatedSpecHash , corev1 .ConditionTrue ), timeout ).Should (BeEquivalentTo (true ))
821
+ g .Eventually (generateExpectedResultChecker (provider , updatedSpecHash , corev1 .ConditionTrue ), timeout ).Should (BeEquivalentTo (true ))
812
822
} else {
813
- g .Eventually (generateExpectedResultChecker (provider , appliedSpecHashAnnotation , "" , corev1 .ConditionFalse ), timeout ).Should (BeEquivalentTo (true ))
823
+ g .Eventually (generateExpectedResultChecker (provider , "" , corev1 .ConditionFalse ), timeout ).Should (BeEquivalentTo (true ))
814
824
}
815
825
816
826
// Clean up
@@ -819,14 +829,14 @@ func TestProviderSpecChanges(t *testing.T) {
819
829
}
820
830
}
821
831
822
- func generateExpectedResultChecker (provider genericprovider.GenericProvider , hashKey , specHash string , condStatus corev1.ConditionStatus ) func () bool {
832
+ func generateExpectedResultChecker (provider genericprovider.GenericProvider , specHash string , condStatus corev1.ConditionStatus ) func () bool {
823
833
return func () bool {
824
834
if err := env .Get (ctx , client .ObjectKeyFromObject (provider ), provider ); err != nil {
825
835
return false
826
836
}
827
837
828
838
// In case of error we don't want the spec annotation to be updated
829
- if provider .GetAnnotations ()[hashKey ] != specHash {
839
+ if provider .GetAnnotations ()[appliedSpecHashAnnotation ] != specHash {
830
840
return false
831
841
}
832
842
0 commit comments