diff --git a/pkg/controllers/client.go b/pkg/controllers/client.go index dd640f8a..94f080df 100644 --- a/pkg/controllers/client.go +++ b/pkg/controllers/client.go @@ -5,8 +5,6 @@ import ( "context" "fmt" - "github.com/opencurve/curve-operator/pkg/daemon" - "github.com/opencurve/curve-operator/pkg/k8sutil" "github.com/pkg/errors" apps "k8s.io/api/apps/v1" v1 "k8s.io/api/core/v1" @@ -14,6 +12,9 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/client-go/kubernetes/scheme" "k8s.io/client-go/tools/remotecommand" + + "github.com/opencurve/curve-operator/pkg/daemon" + "github.com/opencurve/curve-operator/pkg/k8sutil" ) const ( @@ -86,6 +87,7 @@ func createSyncDeployment(c *daemon.Cluster) error { return err } } + // update condition type and phase etc. return nil } diff --git a/pkg/controllers/cluster.go b/pkg/controllers/cluster.go index af086766..a0ac3b8e 100644 --- a/pkg/controllers/cluster.go +++ b/pkg/controllers/cluster.go @@ -1,6 +1,7 @@ package controllers import ( + "context" "time" "github.com/coreos/pkg/capnslog" @@ -8,6 +9,7 @@ import ( "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" @@ -115,6 +117,12 @@ func reconcileCurveDaemons(c *daemon.Cluster) error { return err } + // clean up the cluster install environment + err = cleanClusterInstallEnv(c) + if err != nil { + return err + } + return nil } @@ -147,5 +155,16 @@ func reconcileCurveFSDaemons(c *daemon.Cluster) error { return err } + // clean up the cluster install environment + err = cleanClusterInstallEnv(c) + if err != nil { + return err + } + return nil } + +// cleanClusterInstallEnv clean up the cluster install environment +func cleanClusterInstallEnv(c *daemon.Cluster) error { + return k8sutil.DeleteSyncConfigDeployment(context.TODO(), &c.Context, SyncConfigDeployment, c.Namespace) +} diff --git a/pkg/k8sutil/deployment.go b/pkg/k8sutil/deployment.go index c98181a9..97204726 100644 --- a/pkg/k8sutil/deployment.go +++ b/pkg/k8sutil/deployment.go @@ -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" @@ -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 +}