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 4 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
26 changes: 24 additions & 2 deletions pkg/controllers/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,17 @@ 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"
"k8s.io/client-go/util/retry"

"github.com/opencurve/curve-operator/pkg/daemon"
"github.com/opencurve/curve-operator/pkg/k8sutil"
)

const (
Expand Down Expand Up @@ -86,6 +88,7 @@ func createSyncDeployment(c *daemon.Cluster) error {
return err
}
}

// update condition type and phase etc.
return nil
}
Expand Down Expand Up @@ -154,3 +157,22 @@ func getReadConfigJobLabel(c *daemon.Cluster) map[string]string {
labels["curve"] = c.Kind
return labels
}

// deleteSyncConfigDeployment delete the SyncConfigDeployment after the cluster is deployed.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that put the func in k8sutil fold and deployment file is better

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, I've adjusted its directory

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
}
17 changes: 17 additions & 0 deletions pkg/controllers/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,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 +153,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 deleteSyncConfigDeployment(c, SyncConfigDeployment)
}