Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: delete the sync deployment after deploy complete #78

Merged
merged 5 commits into from
Sep 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions pkg/controllers/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,16 @@ 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"
kerrors "k8s.io/apimachinery/pkg/api/errors"
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 (
Expand Down Expand Up @@ -86,6 +87,7 @@ func createSyncDeployment(c *daemon.Cluster) error {
return err
}
}

// update condition type and phase etc.
return nil
}
Expand Down
19 changes: 19 additions & 0 deletions 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 @@ -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
}

Expand Down Expand Up @@ -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)
}
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
}