bugfix: Apply twice will call initCluster twice that causes kubelet port occupied. (#2292)

This commit is contained in:
zhihui
2022-12-22 15:09:44 +08:00
committed by GitHub
parent 88c1746ba7
commit 747f205fc4
2 changed files with 11 additions and 3 deletions
@@ -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
+9 -2
View File
@@ -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
}