Skip to content

Commit

Permalink
Make some fleet manager private functions public to facilitate usage.
Browse files Browse the repository at this point in the history
Signed-off-by: LiZhenCheng9527 <lizhencheng6@huawei.com>
  • Loading branch information
LiZhenCheng9527 committed Dec 21, 2023
1 parent ac64991 commit b453867
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 15 deletions.
10 changes: 5 additions & 5 deletions pkg/fleet-manager/fleet_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import (
type FleetCluster struct {
Secret string
SecretKey string
client *kclient.Client
Client *kclient.Client
}

type ClusterKey struct {
Expand All @@ -59,14 +59,14 @@ func BuildFleetClusters(ctx context.Context, client client.Client, fleet *fleeta
continue
}

kclient, err := clientForCluster(client, fleet.Namespace, clusterInterface)
kclient, err := ClientForCluster(client, fleet.Namespace, clusterInterface)
if err != nil {
return nil, err
}
res[ClusterKey{Kind: cluster.Kind, Name: cluster.Name}] = &FleetCluster{
Secret: clusterInterface.GetSecretName(),
SecretKey: clusterInterface.GetSecretKey(),
client: kclient,
Client: kclient,
}
}

Expand All @@ -92,7 +92,7 @@ func getFleetClusterInterface(ctx context.Context, client client.Client, kind st
}
}

func clientForCluster(client client.Client, ns string, cluster ClusterInterface) (*kclient.Client, error) {
func ClientForCluster(client client.Client, ns string, cluster ClusterInterface) (*kclient.Client, error) {
secret := &corev1.Secret{}
nn := types.NamespacedName{Namespace: ns, Name: cluster.GetSecretName()}
if err := client.Get(context.Background(), nn, secret); err != nil {
Expand All @@ -113,5 +113,5 @@ func clientForCluster(client client.Client, ns string, cluster ClusterInterface)
}

func (cluster FleetCluster) GetRuntimeClient() client.Client {
return cluster.client.CtrlRuntimeClient()
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 @@ -237,7 +237,7 @@ func createNewSecretInFleetCluster(ctx context.Context, cluster *FleetCluster, n
// updateNewSecretOwnerReference updates the OwnerReferences of the given secret in the specified fleet cluster.
func (f *FleetManager) updateNewSecretOwnerReference(ctx context.Context, clusterName string, cluster *FleetCluster, newSecret *corev1.Secret) error {
// Get the kubeclient.Interface instance
kubeClient := cluster.client.KubeClient()
kubeClient := cluster.Client.KubeClient()

veleroDeploymentName := getVeleroDeploymentName(clusterName)
veleroDeployment, err := kubeClient.AppsV1().Deployments(newSecret.Namespace).Get(ctx, veleroDeploymentName, metav1.GetOptions{})
Expand Down
18 changes: 9 additions & 9 deletions pkg/fleet-manager/fleet_plugin_metric.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,12 @@ func (f *FleetManager) reconcileObjStoreSecretOwnerReference(ctx context.Context

// reconcile objstore secret's owner reference
// a statefulset named prometheus-prometheus-prometheus is created by HelmRelease in each cluster
sts, err := fleetCluster.client.KubeClient().AppsV1().StatefulSets(MonitoringNamespace).Get(ctx, "prometheus-prometheus-prometheus", metav1.GetOptions{})
sts, err := fleetCluster.Client.KubeClient().AppsV1().StatefulSets(MonitoringNamespace).Get(ctx, "prometheus-prometheus-prometheus", metav1.GetOptions{})
if err != nil {
return err
}

secret, err := fleetCluster.client.KubeClient().CoreV1().Secrets(MonitoringNamespace).Get(ctx, fleet.Spec.Plugin.Metric.Thanos.ObjectStoreConfig.SecretName, metav1.GetOptions{})
secret, err := fleetCluster.Client.KubeClient().CoreV1().Secrets(MonitoringNamespace).Get(ctx, fleet.Spec.Plugin.Metric.Thanos.ObjectStoreConfig.SecretName, metav1.GetOptions{})
if err != nil {
return err
}
Expand All @@ -67,7 +67,7 @@ func (f *FleetManager) reconcileObjStoreSecretOwnerReference(ctx context.Context
}
if !capiutil.HasOwnerRef(secret.OwnerReferences, stsOwnerReference) {
secret.OwnerReferences = append(secret.OwnerReferences, stsOwnerReference)
if _, err := fleetCluster.client.KubeClient().CoreV1().Secrets(MonitoringNamespace).Update(ctx, secret, metav1.UpdateOptions{}); err != nil {
if _, err := fleetCluster.Client.KubeClient().CoreV1().Secrets(MonitoringNamespace).Update(ctx, secret, metav1.UpdateOptions{}); err != nil {
return err
}
}
Expand All @@ -89,7 +89,7 @@ func (f *FleetManager) reconcileSidecarRemoteService(ctx context.Context, fleet
continue
}

svc, err := fleetCluster.client.KubeClient().CoreV1().Services(MonitoringNamespace).Get(ctx, PrometheusThanosServiceName, metav1.GetOptions{})
svc, err := fleetCluster.Client.KubeClient().CoreV1().Services(MonitoringNamespace).Get(ctx, PrometheusThanosServiceName, metav1.GetOptions{})
if err != nil {
return err
}
Expand Down Expand Up @@ -199,9 +199,9 @@ func (f *FleetManager) reconcileSidecarRemoteService(ctx context.Context, fleet

// syncObjStoreSecret syncs the secret to the cluster
func (f *FleetManager) syncObjStoreSecret(ctx context.Context, fleetCluster *FleetCluster, secret *corev1.Secret) error {
_, err := fleetCluster.client.KubeClient().CoreV1().Namespaces().Get(ctx, secret.Namespace, metav1.GetOptions{})
_, err := fleetCluster.Client.KubeClient().CoreV1().Namespaces().Get(ctx, secret.Namespace, metav1.GetOptions{})
if apierrors.IsNotFound(err) {
_, err := fleetCluster.client.KubeClient().CoreV1().Namespaces().Create(ctx, &corev1.Namespace{
_, err := fleetCluster.Client.KubeClient().CoreV1().Namespaces().Create(ctx, &corev1.Namespace{
ObjectMeta: metav1.ObjectMeta{
Name: secret.Namespace,
},
Expand All @@ -213,9 +213,9 @@ func (f *FleetManager) syncObjStoreSecret(ctx context.Context, fleetCluster *Fle
return nil
}

s, err := fleetCluster.client.KubeClient().CoreV1().Secrets(secret.Namespace).Get(ctx, secret.Name, metav1.GetOptions{})
s, err := fleetCluster.Client.KubeClient().CoreV1().Secrets(secret.Namespace).Get(ctx, secret.Name, metav1.GetOptions{})
if apierrors.IsNotFound(err) {
_, err := fleetCluster.client.KubeClient().CoreV1().Secrets(secret.Namespace).Create(ctx, secret, metav1.CreateOptions{})
_, err := fleetCluster.Client.KubeClient().CoreV1().Secrets(secret.Namespace).Create(ctx, secret, metav1.CreateOptions{})
if err != nil {
return err
}
Expand All @@ -224,7 +224,7 @@ func (f *FleetManager) syncObjStoreSecret(ctx context.Context, fleetCluster *Fle
}

s.Data = secret.Data
_, err = fleetCluster.client.KubeClient().CoreV1().Secrets(secret.Namespace).Update(ctx, s, metav1.UpdateOptions{})
_, err = fleetCluster.Client.KubeClient().CoreV1().Secrets(secret.Namespace).Update(ctx, s, metav1.UpdateOptions{})
if err != nil {
return err
}
Expand Down

0 comments on commit b453867

Please sign in to comment.