Skip to content

Commit

Permalink
fix: Skip reattached provider update checks (cloudquery#801)
Browse files Browse the repository at this point in the history
Co-authored-by: Kemal Hadimli <[email protected]>
  • Loading branch information
disq and disq authored May 27, 2022
1 parent f30c2fe commit 714b446
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 3 deletions.
11 changes: 11 additions & 0 deletions pkg/core/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,3 +114,14 @@ func CheckAvailableUpdates(ctx context.Context, reg registry.Registry, opts *Che
}
return updates, diags
}

// ManagedProviders returns list of providers which are not in reattach mode
func ManagedProviders(pm *plugin.Manager, provs []registry.Provider) []registry.Provider {
ret := make([]registry.Provider, 0, len(provs))
for i := range provs {
if !pm.IsReattachProvider(provs[i]) {
ret = append(ret, provs[i])
}
}
return ret
}
7 changes: 6 additions & 1 deletion pkg/plugin/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func (m *Manager) DownloadProviders(ctx context.Context, providers []registry.Pr
log.Debug().Interface("providers", providers).Msg("Downloading required providers")
downloaded := make([]registry.ProviderBinary, len(providers))
for i, rp := range providers {
if _, ok := m.clients[rp.Name]; ok {
if m.IsReattachProvider(rp) {
ui.ColorizedOutput(ui.ColorInfo, fmt.Sprintf("Skipping provider %s download, using reattach instead\n", ui.Colorize(ui.ColorSuccessBold, false, rp.Name)))
continue
}
Expand Down Expand Up @@ -126,6 +126,11 @@ func (m *Manager) ClosePlugin(p Plugin) {
}
}

func (m *Manager) IsReattachProvider(rp registry.Provider) bool {
_, ok := m.clients[rp.Name]
return ok
}

func (m *Manager) reattachProviders() error {
// used primarily by the SDK's acceptance testing framework.
unmanagedProviders, err := serve.ParseReattachProviders(viper.GetString("reattach-providers"))
Expand Down
5 changes: 4 additions & 1 deletion pkg/ui/console/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,10 @@ func (c Client) DownloadProviders(ctx context.Context) (diags diag.Diagnostics)
ui.ColorizedOutput(ui.ColorProgress, "Finished provider initialization...\n\n")

ui.ColorizedOutput(ui.ColorProgress, "Checking available provider updates...\n\n")
updates, dd := core.CheckAvailableUpdates(ctx, c.Registry, &core.CheckUpdatesOptions{Providers: c.Providers})
checkUpdateOpts := core.CheckUpdatesOptions{
Providers: core.ManagedProviders(c.PluginManager, c.Providers),
}
updates, dd := core.CheckAvailableUpdates(ctx, c.Registry, &checkUpdateOpts)
if dd.HasErrors() {
return diags.Add(dd)
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/ui/output.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,5 +96,5 @@ func strip(str string) string {
for _, s := range emojiStatus {
str = strings.ReplaceAll(str, s, "")
}
return strings.TrimSuffix(strings.TrimSpace(removeAnsi.ReplaceAllString(str, "")), ".")
return strings.TrimRight(strings.TrimSpace(removeAnsi.ReplaceAllString(str, "")), ".")
}

0 comments on commit 714b446

Please sign in to comment.