Skip to content
This repository has been archived by the owner on May 13, 2024. It is now read-only.

Commit

Permalink
fix: cluster deletion issue
Browse files Browse the repository at this point in the history
Signed-off-by: Lin Yang <reaver@flomesh.io>
  • Loading branch information
reaver-flomesh committed May 15, 2023
1 parent 92c6c5e commit fed7b56
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
22 changes: 20 additions & 2 deletions controllers/cluster/v1alpha1/cluster_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,10 @@ func (r *reconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Resu
return ctrl.Result{}, err
}

if cluster.DeletionTimestamp != nil {
r.destroyConnector(cluster)
}

mc := r.fctx.ConfigStore.MeshConfig.GetConfig()

result, err := r.deriveCodebases(mc)
Expand All @@ -124,7 +128,7 @@ func (r *reconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Resu
key := cluster.Key()
klog.V(5).Infof("Cluster key is %s", key)
bg, exists := r.backgrounds[key]
if exists && bg.context.SpecHash != util.SimpleHash(cluster.Spec) {
if exists && bg.context.Hash != clusterHash(cluster) {
klog.V(5).Infof("Background context of cluster [%s] exists, ")
// exists and the spec changed, then stop it and start a new one
if result, err = r.recreateConnector(ctx, bg, cluster, mc); err != nil {
Expand All @@ -142,6 +146,20 @@ func (r *reconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Resu
return ctrl.Result{}, nil
}

func clusterHash(cluster *clusterv1alpha1.Cluster) string {
return util.SimpleHash(
struct {
spec clusterv1alpha1.ClusterSpec
resourceVersion string
generation int64
}{
spec: cluster.Spec,
resourceVersion: cluster.ResourceVersion,
generation: cluster.Generation,
},
)
}

func (r *reconciler) deriveCodebases(mc *config.MeshConfig) (ctrl.Result, error) {
repoClient := r.fctx.RepoClient

Expand Down Expand Up @@ -204,7 +222,7 @@ func (r *reconciler) newConnector(ctx context.Context, cluster *clusterv1alpha1.
ClusterKey: key,
KubeConfig: kubeconfig,
ConnectorConfig: connCfg,
SpecHash: util.SimpleHash(cluster.Spec),
Hash: clusterHash(cluster),
}
_, cancel := context.WithCancel(&background)
stop := util.RegisterExitHandlers(cancel)
Expand Down
2 changes: 1 addition & 1 deletion pkg/mcs/context/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import (
type ConnectorContext struct {
context.Context
ClusterKey string
SpecHash string
Hash string
KubeConfig *rest.Config
ConnectorConfig *config.ConnectorConfig
Cancel func()
Expand Down

0 comments on commit fed7b56

Please sign in to comment.