Skip to content

Commit

Permalink
fix(platform): provider platform client nil when upgarde (#1812)
Browse files Browse the repository at this point in the history
  • Loading branch information
wl-chen authored Mar 30, 2022
1 parent 70aab77 commit f53bee5
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
12 changes: 12 additions & 0 deletions cmd/tke-installer/app/installer/upgrader.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ import (

// import platform schema
_ "tkestack.io/tke/api/platform/install"
baremetalcluster "tkestack.io/tke/pkg/platform/provider/baremetal/cluster"
)

const (
Expand Down Expand Up @@ -347,6 +348,17 @@ func (t *TKE) prepareForUpgrade(ctx context.Context) error {
if err != nil {
return err
}

provider, err := baremetalcluster.NewProvider()
if err != nil {
return err
}
provider.PlatformClient = t.platformClient
if err := clusterprovider.ReRegister(provider.Name(), provider); err != nil {
return err
}
t.clusterProvider = provider

t.Cluster, err = clusterprovider.GetV1ClusterByName(ctx, t.platformClient, "global", clusterprovider.AdminUsername)
if err != nil {
return err
Expand Down
11 changes: 11 additions & 0 deletions pkg/platform/provider/cluster/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,17 @@ func Register(name string, provider Provider) {
providers[name] = provider
}

// re register provider, if provider's name exists, new provider will replace old provider
func ReRegister(name string, provider Provider) error {
providersMu.Lock()
defer providersMu.Unlock()
if provider == nil {
return fmt.Errorf("cluster: Register provider is nil")
}
providers[name] = provider
return nil
}

// RegisterHandler register all provider's hanlder.
func RegisterHandler(mux *mux.PathRecorderMux) {
for _, p := range providers {
Expand Down

0 comments on commit f53bee5

Please sign in to comment.