@@ -2,6 +2,7 @@ package reaper
2
2
3
3
import (
4
4
"context"
5
+ "k8s.io/apimachinery/pkg/api/errors"
5
6
"k8s.io/apimachinery/pkg/api/resource"
6
7
"k8s.io/utils/ptr"
7
8
"testing"
@@ -64,6 +65,7 @@ func TestReaper(t *testing.T) {
64
65
t .Run ("CreateReaperWithAuthEnabled" , reaperControllerTest (ctx , testEnv , testCreateReaperWithAuthEnabled ))
65
66
t .Run ("CreateReaperWithAuthEnabledExternalSecret" , reaperControllerTest (ctx , testEnv , testCreateReaperWithAuthEnabledExternalSecret ))
66
67
t .Run ("CreateReaperWithLocalStorageBackend" , reaperControllerTest (ctx , testEnv , testCreateReaperWithLocalStorageType ))
68
+ t .Run ("CreateReaperWithHttpAuthEnabled" , reaperControllerTest (ctx , testEnv , testCreateReaperWithHttpAuthEnabled ))
67
69
}
68
70
69
71
func newMockManager () reaper.Manager {
@@ -570,6 +572,72 @@ func testCreateReaperWithLocalStorageType(t *testing.T, ctx context.Context, k8s
570
572
assert .Equal (t , "reaper-data" , dataVolumeMount .Name )
571
573
}
572
574
575
+ func testCreateReaperWithHttpAuthEnabled (t * testing.T , ctx context.Context , k8sClient client.Client , testNamespace string ) {
576
+ t .Log ("create the Reaper object" )
577
+ r := newReaper (testNamespace )
578
+ r .Spec .StorageType = reaperapi .StorageTypeLocal
579
+ r .Spec .StorageConfig = newStorageConfig ()
580
+ r .Spec .HttpManagement .Enabled = true
581
+
582
+ err := k8sClient .Create (ctx , r )
583
+ require .NoError (t , err )
584
+
585
+ t .Log ("check that the stateful set is created" )
586
+ stsKey := types.NamespacedName {Namespace : testNamespace , Name : reaperName }
587
+ sts := & appsv1.StatefulSet {}
588
+
589
+ require .Eventually (t , func () bool {
590
+ return k8sClient .Get (ctx , stsKey , sts ) == nil
591
+ }, timeout , interval , "stateful set creation check failed" )
592
+
593
+ // if the http auth is enabled, reaper controller should prepare the secret where k8s controller will place per-cluster secrets
594
+ secretKey := types.NamespacedName {Namespace : testNamespace , Name : reaper .GetTruststoresSecretName (r .Name )}
595
+ truststoresSecret := & corev1.Secret {}
596
+ require .Eventually (t , func () bool {
597
+ return k8sClient .Get (ctx , secretKey , truststoresSecret ) == nil
598
+ }, timeout , interval , "truststore secret creation check failed" )
599
+ assert .True (t , truststoresSecret .Data == nil )
600
+ assert .Equal (t , 0 , len (truststoresSecret .Data ))
601
+
602
+ // In this configuration, we expect Reaper to also have a mount for the http auth secrets
603
+ assert .Len (t , sts .Spec .Template .Spec .Containers [0 ].VolumeMounts , 3 )
604
+ confVolumeMount := sts .Spec .Template .Spec .Containers [0 ].VolumeMounts [0 ].DeepCopy ()
605
+ assert .Equal (t , "conf" , confVolumeMount .Name )
606
+ dataVolumeMount := sts .Spec .Template .Spec .Containers [0 ].VolumeMounts [2 ].DeepCopy ()
607
+ assert .Equal (t , "reaper-data" , dataVolumeMount .Name )
608
+ truststoresVolumeMount := sts .Spec .Template .Spec .Containers [0 ].VolumeMounts [1 ].DeepCopy ()
609
+ assert .Equal (t , "management-api-keystores-per-cluster" , truststoresVolumeMount .Name )
610
+
611
+ // when we delete reaper, the STS and the secret both go away due to the owner reference
612
+ // however, that does not happen in env tests
613
+ err = k8sClient .Delete (ctx , r )
614
+ require .NoError (t , err )
615
+
616
+ reaperKey := types.NamespacedName {Namespace : testNamespace , Name : reaperName }
617
+ assert .Eventually (t , func () bool {
618
+ err = k8sClient .Get (ctx , reaperKey , r )
619
+ return errors .IsNotFound (err )
620
+ }, timeout , interval , "reaper stateful set deletion check failed" )
621
+
622
+ assert .Eventually (t , func () bool {
623
+ err = k8sClient .Get (ctx , stsKey , sts )
624
+ // we'd expect errors.IsNotFound(err) here, except for some reason this is not happening in env tests
625
+ return err == nil
626
+ }, timeout , interval , "reaper stateful set deletion check failed" )
627
+
628
+ assert .Eventually (t , func () bool {
629
+ err = k8sClient .Get (ctx , secretKey , truststoresSecret )
630
+ // again, we'd expect errors.IsNotFound(err) ...
631
+ return err == nil
632
+ }, timeout , interval , "reaper truststore secret deletion check failed" )
633
+
634
+ // so we delete stuff manually
635
+ err = k8sClient .Delete (ctx , sts )
636
+ require .NoError (t , err )
637
+ err = k8sClient .Delete (ctx , truststoresSecret )
638
+ require .NoError (t , err )
639
+ }
640
+
573
641
// Check if env var exists
574
642
func envVarExists (envVars []corev1.EnvVar , name string ) bool {
575
643
for _ , envVar := range envVars {
0 commit comments