|
4 | 4 | "context" |
5 | 5 | "fmt" |
6 | 6 | "path/filepath" |
| 7 | + "reflect" |
7 | 8 | "strings" |
8 | 9 | "testing" |
9 | 10 | "time" |
@@ -658,6 +659,71 @@ var _ = Describe("RemoteDatabaseNodeSet controller tests", func() { |
658 | 659 |
|
659 | 660 | return nil |
660 | 661 | }, 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()) |
661 | 727 | }) |
662 | 728 | }) |
663 | 729 |
|
@@ -904,6 +970,16 @@ func deleteAll(env *envtest.Environment, k8sClient client.Client, objs ...client |
904 | 970 | Expect(client.IgnoreNotFound(ignoreMethodNotAllowed(err))).ShouldNot(HaveOccurred()) |
905 | 971 | } |
906 | 972 |
|
| 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 | + |
907 | 983 | Eventually(func() error { |
908 | 984 | key := client.ObjectKeyFromObject(ns) |
909 | 985 | if err := k8sClient.Get(ctx, key, ns); err != nil { |
|
0 commit comments