Skip to content

Commit a3e9303

Browse files
committed
fixes unbind and remove resources
1 parent 68eeeca commit a3e9303

File tree

8 files changed

+566
-430
lines changed

8 files changed

+566
-430
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ IMG ?= cr.yandex/yc/ydb-operator:latest
1010
# Produce CRDs that work back to Kubernetes 1.11 (no version conversion)
1111
CRD_OPTIONS ?= "crd:trivialVersions=true,preserveUnknownFields=false"
1212
# ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary.
13-
ENVTEST_K8S_VERSION = 1.21
13+
ENVTEST_K8S_VERSION = 1.26
1414

1515
# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
1616
ifeq (,$(shell go env GOBIN))

internal/controllers/remotedatabasenodeset/controller_test.go

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"fmt"
66
"path/filepath"
7+
"reflect"
78
"strings"
89
"testing"
910
"time"
@@ -658,6 +659,71 @@ var _ = Describe("RemoteDatabaseNodeSet controller tests", func() {
658659

659660
return nil
660661
}, test.Timeout, test.Interval).ShouldNot(HaveOccurred())
662+
663+
By("update Secret in remote namespace")
664+
Eventually(func() error {
665+
localSecret := &corev1.Secret{}
666+
err := localClient.Get(ctx, types.NamespacedName{
667+
Name: testSecretName,
668+
Namespace: testobjects.YdbNamespace,
669+
}, localSecret)
670+
if err != nil {
671+
return err
672+
}
673+
localSecret.StringData = map[string]string{
674+
"message": "Updated message from k8s-mgmt-cluster",
675+
}
676+
return localClient.Update(ctx, localSecret)
677+
}, test.Timeout, test.Interval).Should(Succeed())
678+
679+
By("checking that Secrets are synced after update...")
680+
Eventually(func() error {
681+
foundRemoteDatabaseNodeSet := &v1alpha1.RemoteDatabaseNodeSet{}
682+
Expect(localClient.Get(ctx, types.NamespacedName{
683+
Name: databaseSample.Name + "-" + testNodeSetName + "-remote-dedicated",
684+
Namespace: testobjects.YdbNamespace,
685+
}, foundRemoteDatabaseNodeSet)).Should(Succeed())
686+
687+
localSecret := &corev1.Secret{}
688+
err := localClient.Get(ctx, types.NamespacedName{
689+
Name: testSecretName,
690+
Namespace: testobjects.YdbNamespace,
691+
}, localSecret)
692+
if err != nil {
693+
return err
694+
}
695+
696+
remoteSecret := &corev1.Secret{}
697+
err = remoteClient.Get(ctx, types.NamespacedName{
698+
Name: testSecretName,
699+
Namespace: testobjects.YdbNamespace,
700+
}, remoteSecret)
701+
if err != nil {
702+
return err
703+
}
704+
705+
primaryResourceDatabase, exist := remoteSecret.Annotations[ydbannotations.PrimaryResourceDatabaseAnnotation]
706+
if !exist {
707+
return fmt.Errorf("annotation %s does not exist on remoteSecret %s", ydbannotations.PrimaryResourceDatabaseAnnotation, remoteSecret.Name)
708+
}
709+
if primaryResourceDatabase != foundRemoteDatabaseNodeSet.Spec.DatabaseRef.Name {
710+
return fmt.Errorf("primaryResourceName %s does not equal databaseRef name %s", primaryResourceDatabase, foundRemoteDatabaseNodeSet.Spec.DatabaseRef.Name)
711+
}
712+
713+
remoteRV, exist := remoteSecret.Annotations[ydbannotations.RemoteResourceVersionAnnotation]
714+
if !exist {
715+
return fmt.Errorf("annotation %s does not exist on remoteSecret %s", ydbannotations.RemoteResourceVersionAnnotation, remoteSecret.Name)
716+
}
717+
if localSecret.GetResourceVersion() != remoteRV {
718+
return fmt.Errorf("localRV %s does not equal remoteRV %s", localSecret.GetResourceVersion(), remoteRV)
719+
}
720+
721+
if !reflect.DeepEqual(localSecret.StringData, remoteSecret.StringData) {
722+
return fmt.Errorf("localSecret StringData %s does not equal with remoteSecret %s", localSecret.StringData, remoteSecret.StringData)
723+
}
724+
725+
return nil
726+
}, test.Timeout, test.Interval).ShouldNot(HaveOccurred())
661727
})
662728
})
663729

@@ -904,6 +970,16 @@ func deleteAll(env *envtest.Environment, k8sClient client.Client, objs ...client
904970
Expect(client.IgnoreNotFound(ignoreMethodNotAllowed(err))).ShouldNot(HaveOccurred())
905971
}
906972

973+
// Delete all Services in this namespace
974+
serviceList := corev1.ServiceList{}
975+
err = k8sClient.List(ctx, &serviceList, client.InNamespace(ns.Name))
976+
Expect(err).ShouldNot(HaveOccurred())
977+
for _, svc := range serviceList.Items {
978+
policy := metav1.DeletePropagationForeground
979+
err = k8sClient.Delete(ctx, &svc, &client.DeleteOptions{PropagationPolicy: &policy})
980+
Expect(err).ShouldNot(HaveOccurred())
981+
}
982+
907983
Eventually(func() error {
908984
key := client.ObjectKeyFromObject(ns)
909985
if err := k8sClient.Get(ctx, key, ns); err != nil {

0 commit comments

Comments
 (0)