Skip to content

Commit

Permalink
Style: adjusted the directory of the func
Browse files Browse the repository at this point in the history
for func DeleteSyncConfigDeployment()
  • Loading branch information
lizonglingo authored and caoxianfei1 committed Sep 12, 2023
1 parent 701ea2a commit 9bbfa61
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 21 deletions.
20 changes: 0 additions & 20 deletions pkg/controllers/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/kubernetes/scheme"
"k8s.io/client-go/tools/remotecommand"
"k8s.io/client-go/util/retry"

"github.com/opencurve/curve-operator/pkg/daemon"
"github.com/opencurve/curve-operator/pkg/k8sutil"
Expand Down Expand Up @@ -157,22 +156,3 @@ func getReadConfigJobLabel(c *daemon.Cluster) map[string]string {
labels["curve"] = c.Kind
return labels
}

// deleteSyncConfigDeployment delete the SyncConfigDeployment after the cluster is deployed.
func deleteSyncConfigDeployment(c *daemon.Cluster, syncConfigDeployment string) error {
err := retry.OnError(retry.DefaultRetry, func(err error) bool {
// retrying for any error that occurs
return true
}, func() error {
return c.Context.Clientset.AppsV1().Deployments(c.Namespace).Delete(syncConfigDeployment, &metav1.DeleteOptions{})
})

if err != nil {
return errors.Wrapf(err, "failed to delete deployment %s after the %s has been deployed",
SyncConfigDeployment, c.Kind)
}

logger.Infof("the %s has been deployed and the deployment %s has been deleted", c.Kind, SyncConfigDeployment)

return nil
}
4 changes: 3 additions & 1 deletion pkg/controllers/cluster.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
package controllers

import (
"context"
"time"

"github.com/coreos/pkg/capnslog"

"github.com/opencurve/curve-operator/pkg/chunkserver"
"github.com/opencurve/curve-operator/pkg/daemon"
"github.com/opencurve/curve-operator/pkg/etcd"
"github.com/opencurve/curve-operator/pkg/k8sutil"
"github.com/opencurve/curve-operator/pkg/mds"
"github.com/opencurve/curve-operator/pkg/metaserver"
"github.com/opencurve/curve-operator/pkg/monitor"
Expand Down Expand Up @@ -164,5 +166,5 @@ func reconcileCurveFSDaemons(c *daemon.Cluster) error {

// cleanClusterInstallEnv clean up the cluster install environment
func cleanClusterInstallEnv(c *daemon.Cluster) error {
return deleteSyncConfigDeployment(c, SyncConfigDeployment)
return k8sutil.DeleteSyncConfigDeployment(context.TODO(), &c.Context, SyncConfigDeployment, c.Namespace)
}
20 changes: 20 additions & 0 deletions pkg/k8sutil/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

appsv1 "k8s.io/api/apps/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/util/retry"

"github.com/opencurve/curve-operator/pkg/clusterd"
"github.com/opencurve/curve-operator/pkg/k8sutil/patch"
Expand Down Expand Up @@ -99,3 +100,22 @@ func WaitForDeploymentToStart(ctx context.Context, clusterdContext *clusterd.Con
}
return fmt.Errorf("gave up waiting for deployment %q to update", deployment.Name)
}

// DeleteSyncConfigDeployment delete the SyncConfigDeployment after the cluster is deployed.
func DeleteSyncConfigDeployment(ctx context.Context, clusterdContext *clusterd.Context, syncConfigDeployment, namespace string) error {
err := retry.OnError(retry.DefaultRetry, func(err error) bool {
// retrying for any error that occurs
return true
}, func() error {
return clusterdContext.Clientset.AppsV1().Deployments(namespace).Delete(syncConfigDeployment, &metav1.DeleteOptions{})
})

if err != nil {
return fmt.Errorf("failed to delete deployment %q after the curve cluster has been deployed. %v",
syncConfigDeployment, err)
}

logger.Infof("the curve cluster has been deployed and the deployment %q has been deleted", syncConfigDeployment)

return nil
}

0 comments on commit 9bbfa61

Please sign in to comment.