forked from open-cluster-management-io/ocm
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmanagedclustersetbinding_test.go
More file actions
125 lines (107 loc) · 4.6 KB
/
managedclustersetbinding_test.go
File metadata and controls
125 lines (107 loc) · 4.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
package e2e
import (
"context"
"fmt"
ginkgo "github.com/onsi/ginkgo/v2"
gomega "github.com/onsi/gomega"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/api/meta"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/rand"
clusterv1beta2 "open-cluster-management.io/api/cluster/v1beta2"
)
var _ = ginkgo.Describe("ManagedClusterSetBinding", func() {
ginkgo.Context("ManagedClusterSetBinding", func() {
var namespace string
ginkgo.BeforeEach(func() {
// create a namespace for testing
namespace = fmt.Sprintf("ns-%s", rand.String(6))
ns := &corev1.Namespace{
ObjectMeta: metav1.ObjectMeta{
Name: namespace,
},
}
_, err := hub.KubeClient.CoreV1().Namespaces().Create(context.TODO(), ns, metav1.CreateOptions{})
gomega.Expect(err).NotTo(gomega.HaveOccurred())
// make sure the managedclustersetbinding can be created successfully
gomega.Eventually(func() error {
clusterSetName := fmt.Sprintf("clusterset-%s", rand.String(6))
managedClusterSetBinding := newManagedClusterSetBinding(namespace, clusterSetName, clusterSetName)
_, err := hub.ClusterClient.ClusterV1beta2().ManagedClusterSetBindings(namespace).
Create(context.TODO(), managedClusterSetBinding, metav1.CreateOptions{})
if err != nil {
return err
}
return hub.ClusterClient.ClusterV1beta2().ManagedClusterSetBindings(namespace).Delete(context.TODO(), clusterSetName, metav1.DeleteOptions{})
}).Should(gomega.Succeed())
})
ginkgo.AfterEach(func() {
err := hub.KubeClient.CoreV1().Namespaces().Delete(context.TODO(), namespace, metav1.DeleteOptions{})
if errors.IsNotFound(err) {
return
}
gomega.Expect(err).NotTo(gomega.HaveOccurred())
})
ginkgo.It("should bound a ManagedClusterSetBinding", func() {
clusterSetName := fmt.Sprintf("clusterset-%s", rand.String(6))
managedClusterSetBinding := newManagedClusterSetBinding(namespace, clusterSetName, clusterSetName)
_, err := hub.ClusterClient.ClusterV1beta2().ManagedClusterSetBindings(namespace).
Create(context.TODO(), managedClusterSetBinding, metav1.CreateOptions{})
gomega.Expect(err).ToNot(gomega.HaveOccurred())
// make sure the managedclustersetbinding status is correct
gomega.Eventually(func() error {
binding, err := hub.ClusterClient.ClusterV1beta2().ManagedClusterSetBindings(namespace).Get(context.TODO(), clusterSetName, metav1.GetOptions{})
if err != nil {
return err
}
if !meta.IsStatusConditionFalse(binding.Status.Conditions, clusterv1beta2.ClusterSetBindingBoundType) {
return fmt.Errorf("binding %s/%s condition should be false", namespace, clusterSetName)
}
return nil
}).Should(gomega.Succeed())
managedClusterSet := &clusterv1beta2.ManagedClusterSet{
ObjectMeta: metav1.ObjectMeta{
Name: clusterSetName,
},
}
_, err = hub.ClusterClient.ClusterV1beta2().ManagedClusterSets().Create(context.TODO(), managedClusterSet, metav1.CreateOptions{})
gomega.Expect(err).ToNot(gomega.HaveOccurred())
// make sure the managedclustersetbinding status is correct
gomega.Eventually(func() error {
binding, err := hub.ClusterClient.ClusterV1beta2().ManagedClusterSetBindings(namespace).Get(context.TODO(), clusterSetName, metav1.GetOptions{})
if err != nil {
return err
}
if !meta.IsStatusConditionTrue(binding.Status.Conditions, clusterv1beta2.ClusterSetBindingBoundType) {
return fmt.Errorf("binding %s/%s condition should be true", namespace, clusterSetName)
}
return nil
}).Should(gomega.Succeed())
err = hub.ClusterClient.ClusterV1beta2().ManagedClusterSets().Delete(context.TODO(), clusterSetName, metav1.DeleteOptions{})
gomega.Expect(err).ToNot(gomega.HaveOccurred())
// make sure the managedclustersetbinding status is correct
gomega.Eventually(func() error {
binding, err := hub.ClusterClient.ClusterV1beta2().ManagedClusterSetBindings(namespace).Get(context.TODO(), clusterSetName, metav1.GetOptions{})
if err != nil {
return err
}
if !meta.IsStatusConditionFalse(binding.Status.Conditions, clusterv1beta2.ClusterSetBindingBoundType) {
return fmt.Errorf("binding %s/%s condition should be false", namespace, clusterSetName)
}
return nil
}).Should(gomega.Succeed())
})
})
})
func newManagedClusterSetBinding(namespace, name string, clusterSet string) *clusterv1beta2.ManagedClusterSetBinding {
return &clusterv1beta2.ManagedClusterSetBinding{
ObjectMeta: metav1.ObjectMeta{
Namespace: namespace,
Name: name,
},
Spec: clusterv1beta2.ManagedClusterSetBindingSpec{
ClusterSet: clusterSet,
},
}
}