From 747f205fc40e9eaa49cd9b19eb50b545f9064f9a Mon Sep 17 00:00:00 2001 From: zhihui <82888636+mond77@users.noreply.github.com> Date: Thu, 22 Dec 2022 15:09:44 +0800 Subject: [PATCH] bugfix: Apply twice will call initCluster twice that causes kubelet port occupied. (#2292) --- pkg/apply/applydrivers/apply_drivers_default.go | 3 ++- pkg/apply/run.go | 11 +++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/pkg/apply/applydrivers/apply_drivers_default.go b/pkg/apply/applydrivers/apply_drivers_default.go index f974c0f07..e536147ca 100644 --- a/pkg/apply/applydrivers/apply_drivers_default.go +++ b/pkg/apply/applydrivers/apply_drivers_default.go @@ -84,11 +84,12 @@ func (c *Applier) Apply() error { } }() c.initStatus() - if c.ClusterDesired.CreationTimestamp.IsZero() { + if c.ClusterDesired.CreationTimestamp.IsZero() && (c.ClusterCurrent == nil || c.ClusterCurrent.CreationTimestamp.IsZero()) { err = c.initCluster() c.ClusterDesired.CreationTimestamp = metav1.Now() } else { err = c.reconcileCluster() + c.ClusterDesired.CreationTimestamp = c.ClusterCurrent.CreationTimestamp } c.updateStatus(err) return err diff --git a/pkg/apply/run.go b/pkg/apply/run.go index 10620bee3..8c5b21dd9 100644 --- a/pkg/apply/run.go +++ b/pkg/apply/run.go @@ -95,7 +95,6 @@ func NewApplierFromFile(path string, args *Args) (applydrivers.Interface, error) } path = filepath.Join(pa, path) } - Clusterfile := clusterfile.NewClusterFile(path, clusterfile.WithCustomValues(args.Values), clusterfile.WithCustomSets(args.Sets), @@ -110,10 +109,18 @@ func NewApplierFromFile(path string, args *Args) (applydrivers.Interface, error) return nil, fmt.Errorf("cluster name cannot be empty, make sure %s file is correct", path) } + localpath := constants.Clusterfile(cluster.Name) + cf := clusterfile.NewClusterFile(localpath) + err := cf.Process() + if err != nil && err != clusterfile.ErrClusterFileNotExists { + return nil, err + } + currentCluster := cf.GetCluster() + return &applydrivers.Applier{ ClusterDesired: cluster, ClusterFile: Clusterfile, - ClusterCurrent: cluster, + ClusterCurrent: currentCluster, RunNewImages: nil, }, nil }