Skip to content

Commit

Permalink
update the source client
Browse files Browse the repository at this point in the history
Signed-off-by: myan <[email protected]>
  • Loading branch information
yanmxa committed Jun 19, 2024
1 parent 561c9d7 commit db488d7
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 15 deletions.
14 changes: 7 additions & 7 deletions test/e2e/pkg/resources_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,8 +272,8 @@ var _ = Describe("Resources", Ordered, Label("e2e-tests-resources"), func() {
Context("Resource ReadOnly UpdateStrategy Tests via gRPC", func() {
workName := "work-readonly-" + rand.String(5)
secretName := "auth"
It("create a sample screct in the target cluster", func() {
_, err := kubeClient.CoreV1().Secrets("default").Create(context.Background(), &corev1.Secret{
It("create a sample secret in the target cluster", func() {
_, err := consumer.ClientSet.CoreV1().Secrets("default").Create(ctx, &corev1.Secret{
ObjectMeta: metav1.ObjectMeta{
Name: secretName,
Namespace: "default",
Expand All @@ -299,7 +299,7 @@ var _ = Describe("Resources", Ordered, Label("e2e-tests-resources"), func() {
objectStr, _ := obj.MarshalJSON()
manifest := workv1.Manifest{}
manifest.Raw = objectStr
_, err := workClient.ManifestWorks(consumer_name).Create(ctx, &workv1.ManifestWork{
_, err := workClient.ManifestWorks(consumer.Name).Create(ctx, &workv1.ManifestWork{
ObjectMeta: metav1.ObjectMeta{
Name: workName,
},
Expand Down Expand Up @@ -343,7 +343,7 @@ var _ = Describe("Resources", Ordered, Label("e2e-tests-resources"), func() {

It("get the resource status back", func() {
Eventually(func() error {
work, err := workClient.ManifestWorks(consumer_name).Get(ctx, workName, metav1.GetOptions{})
work, err := workClient.ManifestWorks(consumer.Name).Get(ctx, workName, metav1.GetOptions{})
if err != nil {
return err
}
Expand All @@ -362,14 +362,14 @@ var _ = Describe("Resources", Ordered, Label("e2e-tests-resources"), func() {
})

It("delete the readonly resource", func() {
err := workClient.ManifestWorks(consumer_name).Delete(ctx, workName, metav1.DeleteOptions{})
err := workClient.ManifestWorks(consumer.Name).Delete(ctx, workName, metav1.DeleteOptions{})
Expect(err).ShouldNot(HaveOccurred())

err = kubeClient.CoreV1().Secrets("default").Delete(context.Background(), secretName, metav1.DeleteOptions{})
err = consumer.ClientSet.CoreV1().Secrets("default").Delete(ctx, secretName, metav1.DeleteOptions{})
Expect(err).ShouldNot(HaveOccurred())

Eventually(func() error {
_, err := kubeClient.CoreV1().Secrets("default").Get(context.Background(), secretName, metav1.GetOptions{})
_, err := consumer.ClientSet.CoreV1().Secrets("default").Get(ctx, secretName, metav1.GetOptions{})
if err != nil {
if errors.IsNotFound(err) {
return nil
Expand Down
13 changes: 6 additions & 7 deletions test/e2e/pkg/sourceclient_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ var _ = Describe("gRPC Source ManifestWork Client Test", func() {
BeforeEach(func() {
watchedWorks = []*workv1.ManifestWork{}

watcher, err := workClient.ManifestWorks(consumer_name).Watch(ctx, metav1.ListOptions{})
watcher, err := workClient.ManifestWorks(consumer.Name).Watch(ctx, metav1.ListOptions{})
Expect(err).ShouldNot(HaveOccurred())

go func() {
Expand Down Expand Up @@ -72,36 +72,36 @@ var _ = Describe("gRPC Source ManifestWork Client Test", func() {

By("create a work")
workName := "work-" + rand.String(5)
_, err = workClient.ManifestWorks(consumer_name).Create(ctx, NewManifestWork(workName), metav1.CreateOptions{})
_, err = workClient.ManifestWorks(consumer.Name).Create(ctx, NewManifestWork(workName), metav1.CreateOptions{})
Expect(err).ShouldNot(HaveOccurred())

// wait for few seconds to ensure the creation is finished
<-time.After(5 * time.Second)

By("list the works")
works, err := workClient.ManifestWorks(consumer_name).List(ctx, metav1.ListOptions{})
works, err := workClient.ManifestWorks(consumer.Name).List(ctx, metav1.ListOptions{})
Expect(err).ShouldNot(HaveOccurred())
Expect(len(works.Items) == 1).To(BeTrue())

// wait for few seconds to ensure the work status is updated by agent
<-time.After(5 * time.Second)

By("update a work")
work, err := workClient.ManifestWorks(consumer_name).Get(ctx, workName, metav1.GetOptions{})
work, err := workClient.ManifestWorks(consumer.Name).Get(ctx, workName, metav1.GetOptions{})
Expect(err).ShouldNot(HaveOccurred())

newWork := work.DeepCopy()
newWork.Spec.Workload.Manifests = []workv1.Manifest{NewManifest(workName)}
patchData, err := ToWorkPatch(work, newWork)
Expect(err).ShouldNot(HaveOccurred())
_, err = workClient.ManifestWorks(consumer_name).Patch(ctx, workName, types.MergePatchType, patchData, metav1.PatchOptions{})
_, err = workClient.ManifestWorks(consumer.Name).Patch(ctx, workName, types.MergePatchType, patchData, metav1.PatchOptions{})
Expect(err).ShouldNot(HaveOccurred())

// wait for few seconds to ensure the work status is updated by agent
<-time.After(5 * time.Second)

By("delete a work")
err = workClient.ManifestWorks(consumer_name).Delete(ctx, workName, metav1.DeleteOptions{})
err = workClient.ManifestWorks(consumer.Name).Delete(ctx, workName, metav1.DeleteOptions{})
Expect(err).ShouldNot(HaveOccurred())

Eventually(func() error {
Expand All @@ -123,7 +123,6 @@ var _ = Describe("gRPC Source ManifestWork Client Test", func() {

return nil
}, 30*time.Second, 1*time.Second).ShouldNot(HaveOccurred())

})
})
})
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/pkg/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ var (
cancel context.CancelFunc
ctx context.Context
sourceID string
cancel context.CancelFunc
)

func TestE2E(t *testing.T) {
Expand Down Expand Up @@ -88,6 +87,7 @@ var _ = BeforeSuite(func() {
grpcOptions = grpc.NewGRPCOptions()
grpcOptions.URL = grpcServerAddress

var err error
workClient, err = work.NewClientHolderBuilder(grpcOptions).
WithClientID(fmt.Sprintf("%s-watcher", sourceID)).
WithSourceID(sourceID).
Expand Down

0 comments on commit db488d7

Please sign in to comment.