forked from open-cluster-management-io/ocm
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclusterproperty_test.go
More file actions
124 lines (106 loc) · 3.97 KB
/
clusterproperty_test.go
File metadata and controls
124 lines (106 loc) · 3.97 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
package e2e
import (
"context"
"fmt"
"github.com/onsi/ginkgo/v2"
"github.com/onsi/gomega"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
aboutv1alpha1 "sigs.k8s.io/about-api/pkg/apis/v1alpha1"
aboutclient "sigs.k8s.io/about-api/pkg/generated/clientset/versioned"
ocmfeature "open-cluster-management.io/api/feature"
)
var _ = ginkgo.Describe("ClusterProperty API test", func() {
var aboutClusterClient aboutclient.Interface
var err error
ginkgo.BeforeEach(func() {
gomega.Eventually(func() error {
return spoke.EnableRegistrationFeature(universalKlusterletName, string(ocmfeature.ClusterProperty))
}).Should(gomega.Succeed())
aboutClusterClient, err = aboutclient.NewForConfig(spoke.RestConfig)
gomega.Expect(err).ToNot(gomega.HaveOccurred())
ginkgo.DeferCleanup(func() {
gomega.Eventually(func() error {
return spoke.RemoveRegistrationFeature(universalKlusterletName, string(ocmfeature.ClusterProperty))
}).Should(gomega.Succeed())
err = aboutClusterClient.AboutV1alpha1().ClusterProperties().DeleteCollection(
context.Background(), metav1.DeleteOptions{}, metav1.ListOptions{})
gomega.Expect(err).ToNot(gomega.HaveOccurred())
})
})
ginkgo.Context("create/update/delete clusterproperty", func() {
ginkgo.It("managed cluster should have clusterproperty synced", func() {
prop1 := &aboutv1alpha1.ClusterProperty{
ObjectMeta: metav1.ObjectMeta{
Name: "prop1",
},
Spec: aboutv1alpha1.ClusterPropertySpec{
Value: "value1",
},
}
gomega.Eventually(func() error {
_, err = aboutClusterClient.AboutV1alpha1().ClusterProperties().Create(
context.Background(), prop1, metav1.CreateOptions{})
return err
}).Should(gomega.Succeed())
ginkgo.By("create a cluster property")
gomega.Eventually(func() error {
managedCluster, err := hub.ClusterClient.ClusterV1().ManagedClusters().Get(
context.Background(), universalClusterName, metav1.GetOptions{})
if err != nil {
return err
}
for _, claim := range managedCluster.Status.ClusterClaims {
if claim.Name == "prop1" && claim.Value == "value1" {
return nil
}
}
return fmt.Errorf(
"managed cluster does not have prop1 synced, got %v", managedCluster.Status.ClusterClaims)
}).Should(gomega.Succeed())
ginkgo.By("update a cluster property")
gomega.Eventually(func() error {
p, err := aboutClusterClient.AboutV1alpha1().ClusterProperties().Get(
context.Background(), "prop1", metav1.GetOptions{})
if err != nil {
return err
}
p.Spec.Value = "value2"
_, err = aboutClusterClient.AboutV1alpha1().ClusterProperties().Update(
context.Background(), p, metav1.UpdateOptions{})
return err
}).Should(gomega.Succeed())
gomega.Eventually(func() error {
managedCluster, err := hub.ClusterClient.ClusterV1().ManagedClusters().Get(
context.Background(), universalClusterName, metav1.GetOptions{})
if err != nil {
return err
}
for _, claim := range managedCluster.Status.ClusterClaims {
if claim.Name == "prop1" && claim.Value == "value2" {
return nil
}
}
return fmt.Errorf(
"managed cluster does not have prop1 synced, got %v", managedCluster.Status.ClusterClaims)
}).Should(gomega.Succeed())
ginkgo.By("delete a cluster property")
err = aboutClusterClient.AboutV1alpha1().ClusterProperties().Delete(
context.Background(), "prop1", metav1.DeleteOptions{})
gomega.Expect(err).ToNot(gomega.HaveOccurred())
gomega.Eventually(func() error {
managedCluster, err := hub.ClusterClient.ClusterV1().ManagedClusters().Get(
context.Background(), universalClusterName, metav1.GetOptions{})
if err != nil {
return err
}
for _, claim := range managedCluster.Status.ClusterClaims {
if claim.Name == "prop1" && claim.Value == "value2" {
return fmt.Errorf(
"managed cluster should not have prop1 synced, got %v", managedCluster.Status.ClusterClaims)
}
}
return nil
}).Should(gomega.Succeed())
})
})
})