Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(platform): provider platform client nil when upgarde #1812

Merged
merged 1 commit into from
Mar 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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