Skip to content

Commit

Permalink
Agent install command broke when auth-less (#505)
Browse files Browse the repository at this point in the history
You can technically run `plural cd install` w/o authenticating to the console, but the new global settings fetch breaks that.  Make that code a bit more defensive
  • Loading branch information
michaeljguarino committed Aug 28, 2024
1 parent 029b3f1 commit b3f8764
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
16 changes: 9 additions & 7 deletions cmd/plural/cd.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,9 @@ func (p *Plural) handleInstallDeploymentsOperator(c *cli.Context) error {
}
}

// we don't care if this fails to init as this command can be auth-less
_ = p.InitConsoleClient(consoleToken, consoleURL)

return p.doInstallOperator(c.String("url"), c.String("token"), c.String("values"))
}

Expand All @@ -121,13 +124,12 @@ func (p *Plural) doInstallOperator(url, token, values string) error {
vals := map[string]interface{}{}
globalVals := map[string]interface{}{}

settings, err := p.ConsoleClient.GetGlobalSettings()
if err != nil {
return err
}
if settings != nil && settings.AgentHelmValues != nil {
if err := yaml.Unmarshal([]byte(*settings.AgentHelmValues), &globalVals); err != nil {
return err
if p.ConsoleClient != nil {
settings, err := p.ConsoleClient.GetGlobalSettings()
if err == nil && settings != nil && settings.AgentHelmValues != nil {
if err := yaml.Unmarshal([]byte(*settings.AgentHelmValues), &globalVals); err != nil {
return err
}
}
}

Expand Down
6 changes: 6 additions & 0 deletions pkg/pr/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package pr

import (
"os"
"path/filepath"

"github.com/osteele/liquid"
)
Expand Down Expand Up @@ -32,6 +33,11 @@ func replaceTo(from, to string, rep func(data []byte) ([]byte, error)) error {
if err != nil {
return err
}

if err := os.MkdirAll(filepath.Dir(to), 0755); err != nil {
return err
}

return os.WriteFile(to, resData, info.Mode())
}

Expand Down

0 comments on commit b3f8764

Please sign in to comment.