Skip to content

Commit

Permalink
Merge pull request #504 from Xieql/refactor-clietn
Browse files Browse the repository at this point in the history
refactor: add getruntimeclient func
  • Loading branch information
kurator-bot authored Dec 8, 2023
2 parents a704ef2 + 018d03e commit 1845798
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
8 changes: 4 additions & 4 deletions pkg/fleet-manager/backup_restore_migrate_shared.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ func newSyncVeleroTaskFunc(ctx context.Context, clusterAccess *FleetCluster, obj

func syncVeleroObj(ctx context.Context, cluster *FleetCluster, veleroObj client.Object) error {
// Get the client
clusterClient := cluster.client.CtrlRuntimeClient()
clusterClient := cluster.GetRuntimeClient()

// create or update veleroRestore
_, syncErr := controllerutil.CreateOrUpdate(ctx, clusterClient, veleroObj, func() error {
Expand Down Expand Up @@ -206,7 +206,7 @@ func deleteResourcesInClusters(ctx context.Context, namespace, labelKey string,
for i := 0; i < itemsValue.Len(); i++ {
item := itemsValue.Index(i).Addr().Interface().(client.Object)

clusterClient := clusterAccess.client.CtrlRuntimeClient()
clusterClient := clusterAccess.GetRuntimeClient()

if err := clusterClient.Delete(ctx, item); err != nil && !apierrors.IsNotFound(err) {
log.Error(err, "Failed to delete resource in cluster", "ResourceName", item.GetName(), "ResourceNamespace", item.GetNamespace(), "ClusterName", clusterKey.Name)
Expand Down Expand Up @@ -289,7 +289,7 @@ func GetCronInterval(cronExpr string) (time.Duration, error) {

// getResourceFromClusterClient retrieves a specific Kubernetes resource from the provided cluster.
func getResourceFromClusterClient(ctx context.Context, name, namespace string, clusterAccess FleetCluster, obj client.Object) error {
clusterClient := clusterAccess.client.CtrlRuntimeClient()
clusterClient := clusterAccess.GetRuntimeClient()

resourceKey := types.NamespacedName{
Name: name,
Expand All @@ -301,7 +301,7 @@ func getResourceFromClusterClient(ctx context.Context, name, namespace string, c
// listResourcesFromClusterClient retrieves resources from a cluster based on the provided namespace and label.
func listResourcesFromClusterClient(ctx context.Context, namespace string, labelKey string, labelValue string, clusterAccess FleetCluster, objList client.ObjectList) error {
// Create the cluster client
clusterClient := clusterAccess.client.CtrlRuntimeClient()
clusterClient := clusterAccess.GetRuntimeClient()
// Create the label selector
labelSelector := labels.Set(map[string]string{labelKey: labelValue}).AsSelector()

Expand Down
4 changes: 4 additions & 0 deletions pkg/fleet-manager/fleet_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,3 +111,7 @@ func clientForCluster(client client.Client, ns string, cluster ClusterInterface)

return kclient.NewClient(kclient.NewRESTClientGetter(rest))
}

func (cluster FleetCluster) GetRuntimeClient() client.Client {
return cluster.client.CtrlRuntimeClient()
}
2 changes: 1 addition & 1 deletion pkg/fleet-manager/fleet_plugin_backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ func getObjStoreCredentials(ctx context.Context, client client.Client, namespace
// It uses the kube client from the FleetCluster instance to create the new secret in the respective cluster.
func createNewSecretInFleetCluster(ctx context.Context, cluster *FleetCluster, newSecret *corev1.Secret) error {
// Get the kubeclient.Interface instance
kubeClient := cluster.client.CtrlRuntimeClient()
kubeClient := cluster.GetRuntimeClient()

// Get the namespace of the secret
namespace := newSecret.Namespace
Expand Down

0 comments on commit 1845798

Please sign in to comment.