Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enchancement: updated naming convention from clientSet to dynamicClient (#203) #476

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions pkg/client/dynamic/dynamic.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ func CreateClientSet() (*dynamic.Interface, error) {
if err != nil {
return nil, err
}
clientSet, err := dynamic.NewForConfig(restConfig)
dynamicClient, err := dynamic.NewForConfig(restConfig)
if err != nil {
return nil, err
}
return &clientSet, nil
return &dynamicClient, nil
}
4 changes: 2 additions & 2 deletions pkg/client/kubernetes/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ func CreateClientSet() (*kubernetes.Clientset, error) {
if err != nil {
return &kubernetes.Clientset{}, err
}
clientSet, err := kubernetes.NewForConfig(restConfig)
dynamicClient, err := kubernetes.NewForConfig(restConfig)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we revert this change as this is not a dynamic client?

if err != nil {
return &kubernetes.Clientset{}, err
}
return clientSet, nil
return dynamicClient, nil
}
32 changes: 16 additions & 16 deletions tests/bdd/bdd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@ import (
)

var (
kubeconfig string
config *restclient.Config
client *kubernetes.Clientset
clientSet *chaosClient.LitmuschaosV1alpha1Client
kubeconfig string
config *restclient.Config
client *kubernetes.Clientset
dynamicClient *chaosClient.LitmuschaosV1alpha1Client
Copy link
Member

@ispeakc0de ispeakc0de Dec 26, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we change it to litmusClient as this is not a dynamic client? and change the rest of the places as well in this file

)

func TestChaos(t *testing.T) {
Expand All @@ -70,8 +70,8 @@ var _ = BeforeSuite(func() {
client, err = kubernetes.NewForConfig(config)
Expect(err).To(BeNil(), "failed to get client")

clientSet, err = chaosClient.NewForConfig(config)
Expect(err).To(BeNil(), "failed to get clientSet")
dynamicClient, err = chaosClient.NewForConfig(config)
Expect(err).To(BeNil(), "failed to get dynamicClient")

err = v1alpha1.AddToScheme(scheme.Scheme)
Expect(err).To(BeNil())
Expand Down Expand Up @@ -226,7 +226,7 @@ var _ = Describe("BDD on chaos-operator", func() {
},
}

_, err = clientSet.ChaosExperiments("litmus").Create(context.Background(), ChaosExperiment, metav1.CreateOptions{})
_, err = dynamicClient.ChaosExperiments("litmus").Create(context.Background(), ChaosExperiment, metav1.CreateOptions{})
Expect(err).To(BeNil())
klog.Infoln("ChaosExperiment created successfully...")

Expand Down Expand Up @@ -260,7 +260,7 @@ var _ = Describe("BDD on chaos-operator", func() {
},
}

_, err = clientSet.ChaosEngines("litmus").Create(context.Background(), chaosEngine, metav1.CreateOptions{})
_, err = dynamicClient.ChaosEngines("litmus").Create(context.Background(), chaosEngine, metav1.CreateOptions{})
Expect(err).To(BeNil())
klog.Infoln("Chaosengine created successfully...")

Expand All @@ -284,7 +284,7 @@ var _ = Describe("BDD on chaos-operator", func() {
klog.Infoln("runner pod created")

// Check for EngineStatus
engine, err := clientSet.ChaosEngines("litmus").Get(context.Background(), "engine-nginx", metav1.GetOptions{})
engine, err := dynamicClient.ChaosEngines("litmus").Get(context.Background(), "engine-nginx", metav1.GetOptions{})
Expect(err).To(BeNil())

isInit := engine.Status.EngineStatus == v1alpha1.EngineStatusInitialized
Expand All @@ -296,21 +296,21 @@ var _ = Describe("BDD on chaos-operator", func() {

It("Should delete chaos-resources", func() {

engine, err := clientSet.ChaosEngines("litmus").Get(context.Background(), "engine-nginx", metav1.GetOptions{})
engine, err := dynamicClient.ChaosEngines("litmus").Get(context.Background(), "engine-nginx", metav1.GetOptions{})
Expect(err).To(BeNil())

// setting the EngineState of chaosEngine to stop
engine.Spec.EngineState = v1alpha1.EngineStateStop

_, err = clientSet.ChaosEngines("litmus").Update(context.Background(), engine, metav1.UpdateOptions{})
_, err = dynamicClient.ChaosEngines("litmus").Update(context.Background(), engine, metav1.UpdateOptions{})
Expect(err).To(BeNil())
klog.Infoln("Chaosengine updated successfully...")

err = retry.
Times(uint(180 / 2)).
Wait(time.Duration(2) * time.Second).
Try(func(attempt uint) error {
engine, err := clientSet.ChaosEngines("litmus").Get(context.Background(), "engine-nginx", metav1.GetOptions{})
engine, err := dynamicClient.ChaosEngines("litmus").Get(context.Background(), "engine-nginx", metav1.GetOptions{})
if err != nil {
return fmt.Errorf("unable to get chaosengine, err: %v", err)
}
Expand Down Expand Up @@ -350,7 +350,7 @@ var _ = Describe("BDD on chaos-operator", func() {
Wait(time.Duration(2) * time.Second).
Try(func(attempt uint) error {
//Fetching engineStatus
engine, err := clientSet.ChaosEngines("litmus").Get(context.Background(), "engine-nginx", metav1.GetOptions{})
engine, err := dynamicClient.ChaosEngines("litmus").Get(context.Background(), "engine-nginx", metav1.GetOptions{})
Expect(err).To(BeNil())
if engine.Status.EngineStatus != v1alpha1.EngineStatusStopped {
fmt.Printf("engine is not in stopped state")
Expand All @@ -364,13 +364,13 @@ var _ = Describe("BDD on chaos-operator", func() {
Context("Deletion of ChaosEngine", func() {
It("Should delete chaos engine", func() {

err := clientSet.ChaosEngines("litmus").Delete(context.Background(), "engine-nginx", metav1.DeleteOptions{})
err := dynamicClient.ChaosEngines("litmus").Delete(context.Background(), "engine-nginx", metav1.DeleteOptions{})
Expect(err).To(BeNil())
err = retry.
Times(uint(180 / 2)).
Wait(time.Duration(2) * time.Second).
Try(func(attempt uint) error {
_, err := clientSet.ChaosEngines("litmus").Get(context.Background(), "engine-nginx", metav1.GetOptions{})
_, err := dynamicClient.ChaosEngines("litmus").Get(context.Background(), "engine-nginx", metav1.GetOptions{})
if err != nil && !k8serrors.IsNotFound(err) {
return fmt.Errorf("unable to get chaosengine, err: %v", err)
}
Expand Down Expand Up @@ -415,7 +415,7 @@ var _ = Describe("BDD on chaos-operator", func() {
},
}

_, err := clientSet.ChaosEngines("litmus").Create(context.Background(), chaosEngine, metav1.CreateOptions{})
_, err := dynamicClient.ChaosEngines("litmus").Create(context.Background(), chaosEngine, metav1.CreateOptions{})
Expect(err).To(BeNil())
})
})
Expand Down