Skip to content

Commit

Permalink
feat(installer): limit one patch with one version
Browse files Browse the repository at this point in the history
  • Loading branch information
leonarliu committed Dec 22, 2020
1 parent db75df3 commit ca46f8a
Show file tree
Hide file tree
Showing 8 changed files with 383 additions and 186 deletions.
5 changes: 4 additions & 1 deletion cmd/tke-installer/app/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,13 @@ type Config struct {
SyncProjectsWithNamespaces bool
Replicas int
Upgrade bool
PrepareCustomK8sImages bool
Kubeconfig string
RegistryUsername string
RegistryPassword string
RegistryDomain string
RegistryNamespace string
CustomProviderResTag string
CustomUpgradeResourceDir string
}

// CreateConfigFromOptions creates a running configuration instance based
Expand All @@ -56,10 +57,12 @@ func CreateConfigFromOptions(serverName string, opts *options.Options) (*Config,
SyncProjectsWithNamespaces: *opts.SyncProjectsWithNamespaces,
Replicas: *opts.Replicas,
Upgrade: *opts.Upgrade,
PrepareCustomK8sImages: *opts.PrepareCustomK8sImages,
Kubeconfig: *opts.Kubeconfig,
RegistryUsername: *opts.RegistryUsername,
RegistryPassword: *opts.RegistryPassword,
RegistryDomain: *opts.RegistryDomain,
RegistryNamespace: *opts.RegistryNamespace,
CustomUpgradeResourceDir: *opts.CustomUpgradeResourceDir,
}, nil
}
16 changes: 9 additions & 7 deletions cmd/tke-installer/app/installer/constants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,15 @@
package constants

const (
DataDir = "data/"
ClusterFile = DataDir + "tke.json"
ClusterLogFile = DataDir + "tke.log"
CustomK8sImageDir = DataDir + "images/"
CustomK8sBinaryDir = DataDir + "bins/"
CustomK8sBinaryAmdDir = DataDir + "bins/linux-amd64/"
CustomK8sBinaryArmDir = DataDir + "bins/linux-arm64/"
DataDir = "data/"
ClusterFile = DataDir + "tke.json"
ClusterLogFile = DataDir + "tke.log"

DefaultCustomResourceDir = DataDir + "custom_upgrade_resource"
CustomK8sImageDirName = "images/"
CustomK8sBinaryDirName = "bins/"
CustomK8sBinaryAmdDirName = "bins/linux-amd64/"
CustomK8sBinaryArmDirName = "bins/linux-arm64/"

ProviderConfigFile = "provider/baremetal/conf/config.yaml"

Expand Down
76 changes: 50 additions & 26 deletions cmd/tke-installer/app/installer/installer.go
Original file line number Diff line number Diff line change
Expand Up @@ -474,13 +474,20 @@ func (t *TKE) runWithUI() error {

restful.Filter(globalLogging)

if t.Config.Upgrade {
switch {
case t.Config.PrepareCustomK8sImages:
err := t.prepareForPrepareCustomImages(context.Background())
if err != nil {
return err
}
go t.doPrepareCustomImages()
case t.Config.Upgrade:
err := t.prepareForUpgrade(context.Background())
if err != nil {
return err
}
go t.do()
} else {
default:
if t.isFromRestore {
go t.do()
}
Expand Down Expand Up @@ -955,7 +962,6 @@ func (t *TKE) findClusterProgress(request *restful.Request, response *restful.Re
}

func (t *TKE) do() {
start := time.Now()
ctx := t.log.WithContext(context.Background())

var taskType string
Expand All @@ -968,33 +974,11 @@ func (t *TKE) do() {
t.initSteps()
}

if t.Step == 0 {
t.log.Infof("===>starting %s task", taskType)
t.progress.Status = types.StatusDoing
}

if !t.Config.Upgrade && t.runAfterClusterReady() {
t.initDataForDeployTKE()
}

for t.Step < len(t.steps) {
wait.PollInfinite(10*time.Second, func() (bool, error) {
t.log.Infof("%d.%s doing", t.Step, t.steps[t.Step].Name)
start := time.Now()
err := t.steps[t.Step].Func(ctx)
if err != nil {
t.progress.Status = types.StatusRetrying
t.log.Errorf("%d.%s [Failed] [%fs] error %s", t.Step, t.steps[t.Step].Name, time.Since(start).Seconds(), err)
return false, nil
}
t.log.Infof("%d.%s [Success] [%fs]", t.Step, t.steps[t.Step].Name, time.Since(start).Seconds())

t.Step++
t.backup()
t.progress.Status = types.StatusDoing
return true, nil
})
}
t.doSteps(ctx, taskType)

t.progress.Status = types.StatusSuccess
if t.Para.Config.Gateway != nil {
Expand Down Expand Up @@ -1032,6 +1016,34 @@ func (t *TKE) do() {
}
t.progress.Servers = append(t.progress.Servers, t.servers...)

}

func (t *TKE) doSteps(ctx context.Context, taskType string) {
start := time.Now()
if t.Step == 0 {
t.log.Infof("===>starting %s task", taskType)
t.progress.Status = types.StatusDoing
}

for t.Step < len(t.steps) {
wait.PollInfinite(10*time.Second, func() (bool, error) {
t.log.Infof("%d.%s doing", t.Step, t.steps[t.Step].Name)
start := time.Now()
err := t.steps[t.Step].Func(ctx)
if err != nil {
t.progress.Status = types.StatusRetrying
t.log.Errorf("%d.%s [Failed] [%fs] error %s", t.Step, t.steps[t.Step].Name, time.Since(start).Seconds(), err)
return false, nil
}
t.log.Infof("%d.%s [Success] [%fs]", t.Step, t.steps[t.Step].Name, time.Since(start).Seconds())

t.Step++
t.backup()
t.progress.Status = types.StatusDoing
return true, nil
})
}

t.log.Infof("===>%s task [Sucesss] [%fs]", taskType, time.Since(start).Seconds())
}

Expand Down Expand Up @@ -2433,6 +2445,14 @@ func (t *TKE) writeKubeconfig(ctx context.Context) error {
}

func (t *TKE) patchPlatformVersion(ctx context.Context) error {
tkeVersion, _, err := t.getPlatformVersions(ctx)
if err != nil {
return err
}
if tkeVersion == spec.TKEVersion {
log.Info("skip patch platform version, current installer version is equal to platform version")
}

versionsByte, err := json.Marshal(spec.K8sValidVersions)
if err != nil {
return err
Expand All @@ -2443,6 +2463,10 @@ func (t *TKE) patchPlatformVersion(ctx context.Context) error {
"tkeVersion": spec.TKEVersion,
},
}
return t.patchClusterInfo(ctx, patchData)
}

func (t *TKE) patchClusterInfo(ctx context.Context, patchData interface{}) error {
patchByte, err := json.Marshal(patchData)
if err != nil {
return err
Expand Down
Loading

0 comments on commit ca46f8a

Please sign in to comment.