Skip to content

Commit

Permalink
e2e: rename CtrlClient to Client
Browse files Browse the repository at this point in the history
as that is the only Client we have in the cluster context now.

To avoid shadowing of the client package from controller-runtime, the
package import name is changed to CtrlClient now.

Signed-off-by: Raghavendra Talur <[email protected]>
  • Loading branch information
raghavendra-talur authored and nirs committed Dec 5, 2024
1 parent 862614a commit 969fa6e
Show file tree
Hide file tree
Showing 11 changed files with 53 additions and 53 deletions.
22 changes: 11 additions & 11 deletions e2e/deployers/crud.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func CreateManagedClusterSetBinding(name, namespace string) error {
},
}

err := util.Ctx.Hub.CtrlClient.Create(context.Background(), mcsb)
err := util.Ctx.Hub.Client.Create(context.Background(), mcsb)
if err != nil {
if !errors.IsAlreadyExists(err) {
return err
Expand All @@ -68,7 +68,7 @@ func DeleteManagedClusterSetBinding(ctx types.Context, name, namespace string) e
},
}

err := util.Ctx.Hub.CtrlClient.Delete(context.Background(), mcsb)
err := util.Ctx.Hub.Client.Delete(context.Background(), mcsb)
if err != nil {
if !errors.IsNotFound(err) {
return err
Expand Down Expand Up @@ -99,7 +99,7 @@ func CreatePlacement(ctx types.Context, name, namespace string) error {
},
}

err := util.Ctx.Hub.CtrlClient.Create(context.Background(), placement)
err := util.Ctx.Hub.Client.Create(context.Background(), placement)
if err != nil {
if !errors.IsAlreadyExists(err) {
return err
Expand All @@ -120,7 +120,7 @@ func DeletePlacement(ctx types.Context, name, namespace string) error {
},
}

err := util.Ctx.Hub.CtrlClient.Delete(context.Background(), placement)
err := util.Ctx.Hub.Client.Delete(context.Background(), placement)
if err != nil {
if !errors.IsNotFound(err) {
return err
Expand Down Expand Up @@ -176,7 +176,7 @@ func CreateSubscription(ctx types.Context, s Subscription) error {
})
}

err := util.Ctx.Hub.CtrlClient.Create(context.Background(), subscription)
err := util.Ctx.Hub.Client.Create(context.Background(), subscription)
if err != nil {
if !errors.IsAlreadyExists(err) {
return err
Expand All @@ -200,7 +200,7 @@ func DeleteSubscription(ctx types.Context, s Subscription) error {
},
}

err := util.Ctx.Hub.CtrlClient.Delete(context.Background(), subscription)
err := util.Ctx.Hub.Client.Delete(context.Background(), subscription)
if err != nil {
if !errors.IsNotFound(err) {
return err
Expand Down Expand Up @@ -237,7 +237,7 @@ func CreatePlacementDecisionConfigMap(ctx types.Context, cmName string, cmNamesp

configMap := &corev1.ConfigMap{ObjectMeta: object, Data: data}

err := util.Ctx.Hub.CtrlClient.Create(context.Background(), configMap)
err := util.Ctx.Hub.Client.Create(context.Background(), configMap)
if err != nil {
if !errors.IsAlreadyExists(err) {
return fmt.Errorf("could not create configMap %q", cmName)
Expand All @@ -257,7 +257,7 @@ func DeleteConfigMap(ctx types.Context, cmName string, cmNamespace string) error
ObjectMeta: object,
}

err := util.Ctx.Hub.CtrlClient.Delete(context.Background(), configMap)
err := util.Ctx.Hub.Client.Delete(context.Background(), configMap)
if err != nil {
if !errors.IsNotFound(err) {
return fmt.Errorf("could not delete configMap %q", cmName)
Expand Down Expand Up @@ -338,7 +338,7 @@ func CreateApplicationSet(ctx types.Context, a ApplicationSet) error {
appset.Spec.Template.Spec.Source.Kustomize = patches
}

err := util.Ctx.Hub.CtrlClient.Create(context.Background(), appset)
err := util.Ctx.Hub.Client.Create(context.Background(), appset)
if err != nil {
if !errors.IsAlreadyExists(err) {
return err
Expand All @@ -362,7 +362,7 @@ func DeleteApplicationSet(ctx types.Context, a ApplicationSet) error {
},
}

err := util.Ctx.Hub.CtrlClient.Delete(context.Background(), appset)
err := util.Ctx.Hub.Client.Delete(context.Background(), appset)
if err != nil {
if !errors.IsNotFound(err) {
return err
Expand All @@ -378,7 +378,7 @@ func DeleteApplicationSet(ctx types.Context, a ApplicationSet) error {
func isLastAppsetInArgocdNs(namespace string) (bool, error) {
appsetList := &argocdv1alpha1hack.ApplicationSetList{}

err := util.Ctx.Hub.CtrlClient.List(
err := util.Ctx.Hub.Client.List(
context.Background(), appsetList, client.InNamespace(namespace))
if err != nil {
return false, fmt.Errorf("failed to list applicationsets: %w", err)
Expand Down
10 changes: 5 additions & 5 deletions e2e/deployers/discoveredapps.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func (d DiscoveredApps) Deploy(ctx types.Context) error {
return err
}

drpolicy, err := util.GetDRPolicy(util.Ctx.Hub.CtrlClient, util.DefaultDRPolicyName)
drpolicy, err := util.GetDRPolicy(util.Ctx.Hub.Client, util.DefaultDRPolicyName)
if err != nil {
return err
}
Expand All @@ -62,7 +62,7 @@ func (d DiscoveredApps) Deploy(ctx types.Context) error {
return err
}

if err = WaitWorkloadHealth(ctx, util.Ctx.C1.CtrlClient, namespace); err != nil {
if err = WaitWorkloadHealth(ctx, util.Ctx.C1.Client, namespace); err != nil {
return err
}

Expand All @@ -78,7 +78,7 @@ func (d DiscoveredApps) Undeploy(ctx types.Context) error {

log.Info("Undeploying workload")

drpolicy, err := util.GetDRPolicy(util.Ctx.Hub.CtrlClient, util.DefaultDRPolicyName)
drpolicy, err := util.GetDRPolicy(util.Ctx.Hub.Client, util.DefaultDRPolicyName)
if err != nil {
return err
}
Expand All @@ -99,13 +99,13 @@ func (d DiscoveredApps) Undeploy(ctx types.Context) error {
log.Infof("Deleting namespace %q on cluster %q", namespace, drpolicy.Spec.DRClusters[0])

// delete namespace on both clusters
if err := util.DeleteNamespace(util.Ctx.C1.CtrlClient, namespace, log); err != nil {
if err := util.DeleteNamespace(util.Ctx.C1.Client, namespace, log); err != nil {
return err
}

log.Infof("Deleting namespace %q on cluster %q", namespace, drpolicy.Spec.DRClusters[1])

if err := util.DeleteNamespace(util.Ctx.C2.CtrlClient, namespace, log); err != nil {
if err := util.DeleteNamespace(util.Ctx.C2.Client, namespace, log); err != nil {
return err
}

Expand Down
2 changes: 1 addition & 1 deletion e2e/deployers/retry.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func waitSubscriptionPhase(ctx types.Context, namespace, name string, phase subs
startTime := time.Now()

for {
sub, err := getSubscription(util.Ctx.Hub.CtrlClient, namespace, name)
sub, err := getSubscription(util.Ctx.Hub.Client, namespace, name)
if err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions e2e/deployers/subscription.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func (s Subscription) Deploy(ctx types.Context) error {
log.Info("Deploying workload")

// create subscription namespace
err := util.CreateNamespace(util.Ctx.Hub.CtrlClient, namespace)
err := util.CreateNamespace(util.Ctx.Hub.Client, namespace)
if err != nil {
return err
}
Expand Down Expand Up @@ -83,7 +83,7 @@ func (s Subscription) Undeploy(ctx types.Context) error {
return err
}

return util.DeleteNamespace(util.Ctx.Hub.CtrlClient, namespace, log)
return util.DeleteNamespace(util.Ctx.Hub.Client, namespace, log)
}

func (s Subscription) IsWorkloadSupported(w types.Workload) bool {
Expand Down
14 changes: 7 additions & 7 deletions e2e/dractions/actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func EnableProtection(ctx types.Context) error {
placementName := name
drpcName := name

placementDecision, err := waitPlacementDecision(util.Ctx.Hub.CtrlClient, namespace, placementName)
placementDecision, err := waitPlacementDecision(util.Ctx.Hub.Client, namespace, placementName)
if err != nil {
return err
}
Expand All @@ -57,7 +57,7 @@ func EnableProtection(ctx types.Context) error {
log.Info("Annotating placement")

err = retry.RetryOnConflict(retry.DefaultBackoff, func() error {
placement, err := getPlacement(util.Ctx.Hub.CtrlClient, namespace, placementName)
placement, err := getPlacement(util.Ctx.Hub.Client, namespace, placementName)
if err != nil {
return err
}
Expand All @@ -68,7 +68,7 @@ func EnableProtection(ctx types.Context) error {

placement.Annotations[OcmSchedulingDisable] = "true"

return updatePlacement(util.Ctx.Hub.CtrlClient, placement)
return updatePlacement(util.Ctx.Hub.Client, placement)
})
if err != nil {
return err
Expand All @@ -77,7 +77,7 @@ func EnableProtection(ctx types.Context) error {
log.Info("Creating drpc")

drpc := generateDRPC(name, namespace, clusterName, drPolicyName, placementName, appname)
if err = createDRPC(util.Ctx.Hub.CtrlClient, drpc); err != nil {
if err = createDRPC(util.Ctx.Hub.Client, drpc); err != nil {
return err
}

Expand All @@ -87,7 +87,7 @@ func EnableProtection(ctx types.Context) error {
return err
}

return waitDRPCReady(ctx, util.Ctx.Hub.CtrlClient, namespace, drpcName)
return waitDRPCReady(ctx, util.Ctx.Hub.Client, namespace, drpcName)
}

// remove DRPC
Expand All @@ -105,7 +105,7 @@ func DisableProtection(ctx types.Context) error {
name := ctx.Name()
namespace := ctx.Namespace()
drpcName := name
client := util.Ctx.Hub.CtrlClient
client := util.Ctx.Hub.Client

log.Info("Deleting drpc")

Expand Down Expand Up @@ -150,7 +150,7 @@ func failoverRelocate(ctx types.Context, action ramen.DRAction) error {
name := ctx.Name()
namespace := ctx.Namespace()
drpcName := name
client := util.Ctx.Hub.CtrlClient
client := util.Ctx.Hub.Client

if err := waitAndUpdateDRPC(ctx, client, namespace, drpcName, action); err != nil {
return err
Expand Down
10 changes: 5 additions & 5 deletions e2e/dractions/actionsdiscoveredapps.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func EnableProtectionDiscoveredApps(ctx types.Context) error {
}

// create drpc
drpolicy, err := util.GetDRPolicy(util.Ctx.Hub.CtrlClient, drPolicyName)
drpolicy, err := util.GetDRPolicy(util.Ctx.Hub.Client, drPolicyName)
if err != nil {
return err
}
Expand All @@ -46,12 +46,12 @@ func EnableProtectionDiscoveredApps(ctx types.Context) error {

drpc := generateDRPCDiscoveredApps(
name, namespace, clusterName, drPolicyName, placementName, appname, namespaceInDrCluster)
if err = createDRPC(util.Ctx.Hub.CtrlClient, drpc); err != nil {
if err = createDRPC(util.Ctx.Hub.Client, drpc); err != nil {
return err
}

// wait for drpc ready
return waitDRPCReady(ctx, util.Ctx.Hub.CtrlClient, namespace, drpcName)
return waitDRPCReady(ctx, util.Ctx.Hub.Client, namespace, drpcName)
}

// remove DRPC
Expand All @@ -66,7 +66,7 @@ func DisableProtectionDiscoveredApps(ctx types.Context) error {
placementName := name
drpcName := name

client := util.Ctx.Hub.CtrlClient
client := util.Ctx.Hub.Client

log.Info("Deleting drpc")

Expand Down Expand Up @@ -108,7 +108,7 @@ func failoverRelocateDiscoveredApps(ctx types.Context, action ramen.DRAction) er
namespaceInDrCluster := name // this namespace is in dr clusters

drpcName := name
client := util.Ctx.Hub.CtrlClient
client := util.Ctx.Hub.Client

currentCluster, err := getCurrentCluster(client, namespace, name)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion e2e/dractions/crud.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ func createPlacementManagedByRamen(ctx types.Context, name, namespace string) er
},
}

err := util.Ctx.Hub.CtrlClient.Create(context.Background(), placement)
err := util.Ctx.Hub.Client.Create(context.Background(), placement)
if err != nil {
if !errors.IsAlreadyExists(err) {
return err
Expand Down
4 changes: 2 additions & 2 deletions e2e/dractions/retry.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,10 +139,10 @@ func getCurrentCluster(client client.Client, namespace string, placementName str
// return dr cluster client
func getDRClusterClient(clusterName string, drpolicy *ramen.DRPolicy) client.Client {
if clusterName == drpolicy.Spec.DRClusters[0] {
return util.Ctx.C1.CtrlClient
return util.Ctx.C1.Client
}

return util.Ctx.C2.CtrlClient
return util.Ctx.C2.Client
}

func getTargetCluster(client client.Client, namespace, placementName string, drpolicy *ramen.DRPolicy) (string, error) {
Expand Down
16 changes: 8 additions & 8 deletions e2e/util/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/client-go/tools/clientcmd"
"k8s.io/kubectl/pkg/scheme"
"sigs.k8s.io/controller-runtime/pkg/client"
ctrlClient "sigs.k8s.io/controller-runtime/pkg/client"

// Placement
ocmv1b1 "open-cluster-management.io/api/cluster/v1beta1"
Expand All @@ -27,7 +27,7 @@ import (
var ConfigFile string

type Cluster struct {
CtrlClient client.Client
Client ctrlClient.Client
}

type Context struct {
Expand Down Expand Up @@ -63,7 +63,7 @@ func addToScheme(scheme *runtime.Scheme) error {
return ramen.AddToScheme(scheme)
}

func setupClient(kubeconfigPath string) (client.Client, error) {
func setupClient(kubeconfigPath string) (ctrlClient.Client, error) {
var err error

if kubeconfigPath == "" {
Expand All @@ -84,12 +84,12 @@ func setupClient(kubeconfigPath string) (client.Client, error) {
return nil, err
}

ctrlClient, err := client.New(cfg, client.Options{Scheme: scheme.Scheme})
client, err := ctrlClient.New(cfg, ctrlClient.Options{Scheme: scheme.Scheme})
if err != nil {
return nil, fmt.Errorf("failed to build controller client from kubeconfig (%s): %w", kubeconfigPath, err)
}

return ctrlClient, nil
return client, nil
}

func NewContext(log *zap.SugaredLogger, configFile string) (*Context, error) {
Expand All @@ -102,17 +102,17 @@ func NewContext(log *zap.SugaredLogger, configFile string) (*Context, error) {
panic(err)
}

ctx.Hub.CtrlClient, err = setupClient(config.Clusters["hub"].KubeconfigPath)
ctx.Hub.Client, err = setupClient(config.Clusters["hub"].KubeconfigPath)
if err != nil {
return nil, fmt.Errorf("failed to create clients for hub cluster: %w", err)
}

ctx.C1.CtrlClient, err = setupClient(config.Clusters["c1"].KubeconfigPath)
ctx.C1.Client, err = setupClient(config.Clusters["c1"].KubeconfigPath)
if err != nil {
return nil, fmt.Errorf("failed to create clients for c1 cluster: %w", err)
}

ctx.C2.CtrlClient, err = setupClient(config.Clusters["c2"].KubeconfigPath)
ctx.C2.Client, err = setupClient(config.Clusters["c2"].KubeconfigPath)
if err != nil {
return nil, fmt.Errorf("failed to create clients for c2 cluster: %w", err)
}
Expand Down
Loading

0 comments on commit 969fa6e

Please sign in to comment.