Skip to content

Commit 3ea3892

Browse files
gkechhors
andauthored
K8SPG 798 remove watch secrets unit test (#1183)
* K8SPG-798 fix for watching secret env test * remove test completely * fix imports --------- Co-authored-by: Viacheslav Sarzhan <[email protected]>
1 parent 001be49 commit 3ea3892

File tree

1 file changed

+0
-225
lines changed

1 file changed

+0
-225
lines changed

percona/controller/pgcluster/controller_test.go

Lines changed: 0 additions & 225 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@ import (
77
"context"
88
"crypto/md5" //nolint:gosec
99
"fmt"
10-
"os"
1110
"strconv"
12-
"sync"
1311
"time"
1412

1513
. "github.com/onsi/ginkgo/v2"
@@ -25,15 +23,10 @@ import (
2523
"k8s.io/apimachinery/pkg/types"
2624
ctrl "sigs.k8s.io/controller-runtime"
2725
"sigs.k8s.io/controller-runtime/pkg/client"
28-
metricsServer "sigs.k8s.io/controller-runtime/pkg/metrics/server"
2926

30-
"github.com/percona/percona-postgresql-operator/internal/controller/postgrescluster"
31-
internalRuntime "github.com/percona/percona-postgresql-operator/internal/controller/runtime"
3227
"github.com/percona/percona-postgresql-operator/internal/feature"
3328
"github.com/percona/percona-postgresql-operator/internal/naming"
34-
perconaController "github.com/percona/percona-postgresql-operator/percona/controller"
3529
pNaming "github.com/percona/percona-postgresql-operator/percona/naming"
36-
"github.com/percona/percona-postgresql-operator/percona/runtime"
3730
v2 "github.com/percona/percona-postgresql-operator/pkg/apis/pgv2.percona.com/v2"
3831
"github.com/percona/percona-postgresql-operator/pkg/apis/postgres-operator.crunchydata.com/v1beta1"
3932
)
@@ -504,224 +497,6 @@ func (t *tracerWithCounter) Start(ctx context.Context, spanName string, opts ...
504497
return ctx, span
505498
}
506499

507-
func getReconcileCount(r *postgrescluster.Reconciler) int {
508-
return r.Tracer.(*tracerWithCounter).counter
509-
}
510-
511-
var _ = Describe("Watching secrets", Ordered, func() {
512-
ctx := context.Background()
513-
514-
const crName = "watch-secret-test"
515-
const ns = crName
516-
517-
crunchyR := crunchyReconciler()
518-
r := reconciler(&v2.PerconaPGCluster{
519-
ObjectMeta: metav1.ObjectMeta{
520-
Name: crName,
521-
Namespace: ns,
522-
},
523-
})
524-
525-
namespace := &corev1.Namespace{
526-
ObjectMeta: metav1.ObjectMeta{
527-
Name: crName,
528-
Namespace: ns,
529-
},
530-
}
531-
532-
mgrCtx, cancel := context.WithCancel(ctx)
533-
wg := sync.WaitGroup{}
534-
535-
BeforeAll(func() {
536-
By("Creating the Namespace to perform the tests")
537-
err := k8sClient.Create(ctx, namespace)
538-
Expect(err).NotTo(HaveOccurred())
539-
540-
gate := feature.NewGate()
541-
err = gate.SetFromMap(map[string]bool{})
542-
Expect(err).NotTo(HaveOccurred())
543-
544-
Expect(err).To(Not(HaveOccurred()))
545-
546-
os.Setenv("PGO_TARGET_NAMESPACE", "")
547-
mgr, err := runtime.CreateRuntimeManager(cfg, gate, internalRuntime.Options{
548-
LeaderElection: false,
549-
HealthProbeBindAddress: "0",
550-
Metrics: metricsServer.Options{
551-
BindAddress: "0",
552-
},
553-
})
554-
Expect(err).To(Succeed())
555-
Expect(v2.AddToScheme(mgr.GetScheme())).To(Succeed())
556-
557-
r.Client = mgr.GetClient()
558-
crunchyR.Client = mgr.GetClient()
559-
crunchyR.Tracer = &tracerWithCounter{t: crunchyR.Tracer}
560-
561-
cm := &perconaController.CustomManager{Manager: mgr}
562-
Expect(crunchyR.SetupWithManager(cm)).To(Succeed())
563-
564-
Expect(cm.Controller()).NotTo(BeNil())
565-
r.CrunchyController = cm.Controller()
566-
Expect(r.SetupWithManager(mgr)).To(Succeed())
567-
568-
wg.Add(1)
569-
go func() {
570-
Expect(mgr.Start(mgrCtx)).To(Succeed())
571-
wg.Done()
572-
}()
573-
})
574-
575-
AfterAll(func() {
576-
By("Stopping manager")
577-
cancel()
578-
wg.Wait()
579-
580-
By("Deleting the Namespace to perform the tests")
581-
_ = k8sClient.Delete(ctx, namespace)
582-
})
583-
584-
cr, err := readDefaultCR(crName, ns)
585-
It("should read default cr.yaml", func() {
586-
Expect(err).NotTo(HaveOccurred())
587-
})
588-
for i := range cr.Spec.Backups.PGBackRest.Repos {
589-
cr.Spec.Backups.PGBackRest.Repos[i].BackupSchedules = nil
590-
}
591-
592-
reconcileCount := 0
593-
Context("Create cluster and wait until Reconcile stops", func() {
594-
It("should create PerconaPGCluster and PostgresCluster", func() {
595-
status := cr.Status
596-
Expect(k8sClient.Create(ctx, cr)).Should(Succeed())
597-
cr.Status = status
598-
Expect(k8sClient.Status().Update(ctx, cr)).Should(Succeed())
599-
600-
Eventually(func() error {
601-
return k8sClient.Get(ctx, client.ObjectKeyFromObject(cr), new(v2.PerconaPGCluster))
602-
}, time.Second*15, time.Millisecond*250).Should(BeNil())
603-
604-
Eventually(func() error {
605-
return k8sClient.Get(ctx, client.ObjectKeyFromObject(cr), new(v1beta1.PostgresCluster))
606-
}, time.Second*15, time.Millisecond*250).Should(BeNil())
607-
})
608-
609-
It("should wait until PostgresCluster will stop to Reconcile multiple times", func() {
610-
Eventually(func() bool {
611-
pgCluster := new(v1beta1.PostgresCluster)
612-
err := k8sClient.Get(ctx, client.ObjectKeyFromObject(cr), pgCluster)
613-
if err != nil {
614-
return false
615-
}
616-
// When ManagedFields get field with `status` subresource, crunchy's Reconcile stops being called
617-
for _, f := range pgCluster.ManagedFields {
618-
if f.Manager == postgrescluster.ControllerName && f.Subresource == "status" {
619-
return true
620-
}
621-
}
622-
623-
return false
624-
}, time.Second*60, time.Millisecond*250).Should(Equal(true))
625-
reconcileCount = getReconcileCount(crunchyR)
626-
})
627-
})
628-
629-
var secret *corev1.Secret
630-
Context("Create secret", func() {
631-
secret = &corev1.Secret{
632-
ObjectMeta: metav1.ObjectMeta{
633-
Name: "some-secret",
634-
Namespace: ns,
635-
Labels: map[string]string{
636-
naming.LabelCluster: cr.Name,
637-
},
638-
},
639-
Data: map[string][]byte{
640-
"some-data": []byte("data"),
641-
},
642-
}
643-
It("should create secret", func() {
644-
Expect(k8sClient.Create(ctx, secret)).To(Succeed())
645-
Eventually(func() error {
646-
return k8sClient.Get(ctx, client.ObjectKeyFromObject(secret), new(corev1.Secret))
647-
}, time.Second*15, time.Millisecond*250).Should(BeNil())
648-
})
649-
650-
It("should reconcile 0 times", func() {
651-
Eventually(func() int { return getReconcileCount(crunchyR) }, time.Second*15, time.Millisecond*250).
652-
Should(Equal(reconcileCount))
653-
})
654-
})
655-
656-
Context("Update secret data", func() {
657-
It("should update secret data", func() {
658-
secret.Data["some-data"] = []byte("updated-data")
659-
Expect(k8sClient.Update(ctx, secret)).To(Succeed())
660-
})
661-
662-
It("should wait until secret is updated", func() {
663-
Eventually(func() bool {
664-
newSecret := new(corev1.Secret)
665-
err := k8sClient.Get(ctx, client.ObjectKeyFromObject(secret), newSecret)
666-
if err != nil {
667-
return false
668-
}
669-
return string(newSecret.Data["some-data"]) == "updated-data"
670-
}, time.Second*15, time.Millisecond*250).Should(BeTrue())
671-
})
672-
673-
It("should reconcile 1 time", func() {
674-
Eventually(func() int { return getReconcileCount(crunchyR) }, time.Second*20, time.Millisecond*250).
675-
Should(Equal(reconcileCount + 1))
676-
})
677-
678-
It("should update secret data", func() {
679-
secret.Data["some-data"] = []byte("updated-data-2")
680-
Expect(k8sClient.Update(ctx, secret)).To(Succeed())
681-
})
682-
683-
It("should wait until secret is updated", func() {
684-
Eventually(func() bool {
685-
newSecret := new(corev1.Secret)
686-
err := k8sClient.Get(ctx, client.ObjectKeyFromObject(secret), newSecret)
687-
if err != nil {
688-
return false
689-
}
690-
return string(newSecret.Data["some-data"]) == "updated-data-2"
691-
}, time.Second*15, time.Millisecond*250).Should(BeTrue())
692-
})
693-
694-
It("should reconcile 2 times", func() {
695-
Eventually(func() int { return getReconcileCount(crunchyR) }, time.Second*20, time.Millisecond*250).
696-
Should(Equal(reconcileCount + 2))
697-
})
698-
})
699-
700-
Context("Update secret data and remove labels", func() {
701-
It("should remove cluster label and update data", func() {
702-
secret.Labels = make(map[string]string)
703-
secret.Data["some-data"] = []byte("updated-data-3")
704-
Expect(k8sClient.Update(ctx, secret)).To(Succeed())
705-
})
706-
707-
It("should wait until secret is updated", func() {
708-
Eventually(func() bool {
709-
newSecret := new(corev1.Secret)
710-
err := k8sClient.Get(ctx, client.ObjectKeyFromObject(secret), newSecret)
711-
if err != nil {
712-
return false
713-
}
714-
return string(newSecret.Data["some-data"]) == "updated-data-3"
715-
}, time.Second*15, time.Millisecond*250).Should(BeTrue())
716-
})
717-
718-
It("should reconcile 2 times", func() {
719-
Eventually(func() int { return getReconcileCount(crunchyR) }, time.Second*15, time.Millisecond*250).
720-
Should(Equal(reconcileCount + 2))
721-
})
722-
})
723-
})
724-
725500
var _ = Describe("Users", Ordered, func() {
726501
ctx := context.Background()
727502

0 commit comments

Comments
 (0)