Skip to content

Commit

Permalink
set default values for agent installation (#504)
Browse files Browse the repository at this point in the history
* set default values for agent installation

* fix error description

* merge values

* fix linter
  • Loading branch information
zreigz committed Apr 17, 2024
1 parent 376df14 commit 85adf53
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 7 deletions.
21 changes: 17 additions & 4 deletions cmd/plural/cd.go
Expand Up @@ -4,13 +4,14 @@ import (
"fmt"
"os"

"github.com/urfave/cli"
apierrors "k8s.io/apimachinery/pkg/api/errors"

"github.com/pluralsh/plural-cli/pkg/cd"
"github.com/pluralsh/plural-cli/pkg/config"
"github.com/pluralsh/plural-cli/pkg/console"
"github.com/pluralsh/plural-cli/pkg/utils"
"github.com/pluralsh/polly/algorithms"
"github.com/urfave/cli"
apierrors "k8s.io/apimachinery/pkg/api/errors"
"sigs.k8s.io/yaml"
)

func init() {
Expand Down Expand Up @@ -118,12 +119,24 @@ 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 values != "" {
if err := utils.YamlFile(values, &vals); err != nil {
return err
}
}

vals = algorithms.Merge(vals, globalVals)
err = console.InstallAgent(url, token, console.OperatorNamespace, vals)
if err == nil {
utils.Success("deployment operator installed successfully\n")
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Expand Up @@ -55,7 +55,7 @@ require (
github.com/packethost/packngo v0.29.0
github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8
github.com/pluralsh/cluster-api-migration v0.2.15
github.com/pluralsh/console-client-go v0.1.3
github.com/pluralsh/console-client-go v0.1.17
github.com/pluralsh/gqlclient v1.11.0
github.com/pluralsh/plural-operator v0.5.5
github.com/pluralsh/polly v0.1.7
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Expand Up @@ -1424,8 +1424,8 @@ github.com/pkg/sftp v1.10.1/go.mod h1:lYOWFsE0bwd1+KfKJaKeuokY15vzFx25BLbzYYoAxZ
github.com/pkg/sftp v1.13.1/go.mod h1:3HaPG6Dq1ILlpPZRO0HVMrsydcdLt6HRDccSgb87qRg=
github.com/pluralsh/cluster-api-migration v0.2.15 h1:TIfusD+wnhZTGmwNfIlKlKJOT2dE3rUaZawDJw98GjY=
github.com/pluralsh/cluster-api-migration v0.2.15/go.mod h1:J6lEvC/70KouikX16mE331cxc3y3sBwtmfHGwZqu06w=
github.com/pluralsh/console-client-go v0.1.3 h1:Nzg6qYKvLpOxNGMypMQ75h9qGTnRhYS+wtDMpK7ybhE=
github.com/pluralsh/console-client-go v0.1.3/go.mod h1:eyCiLA44YbXiYyJh8303jk5JdPkt9McgCo5kBjk4lKo=
github.com/pluralsh/console-client-go v0.1.17 h1:QMtnWdRvV13/sND/CFjFBUR8nyg3JJgwXReSyM6bK7A=
github.com/pluralsh/console-client-go v0.1.17/go.mod h1:eyCiLA44YbXiYyJh8303jk5JdPkt9McgCo5kBjk4lKo=
github.com/pluralsh/controller-reconcile-helper v0.0.4 h1:1o+7qYSyoeqKFjx+WgQTxDz4Q2VMpzprJIIKShxqG0E=
github.com/pluralsh/controller-reconcile-helper v0.0.4/go.mod h1:AfY0gtteD6veBjmB6jiRx/aR4yevEf6K0M13/pGan/s=
github.com/pluralsh/gqlclient v1.11.0 h1:FfXW7FiEJLHOfTAa7NxDb8jb3aMZNIpCAcG+bg8uHYA=
Expand Down
1 change: 1 addition & 0 deletions pkg/console/console.go
Expand Up @@ -47,6 +47,7 @@ type ConsoleClient interface {
ListNotificationSinks(after *string, first *int64) (*consoleclient.ListNotificationSinks_NotificationSinks, error)
CreateNotificationSinks(attr consoleclient.NotificationSinkAttributes) (*consoleclient.NotificationSinkFragment, error)
UpdateDeploymentSettings(attr consoleclient.DeploymentSettingsAttributes) (*consoleclient.UpdateDeploymentSettings, error)
GetGlobalSettings() (*consoleclient.DeploymentSettingsFragment, error)
}

type authedTransport struct {
Expand Down
11 changes: 11 additions & 0 deletions pkg/console/settings.go
Expand Up @@ -18,3 +18,14 @@ func (c *consoleClient) UpdateDeploymentSettings(attr gqlclient.DeploymentSettin

return resp, nil
}

func (c *consoleClient) GetGlobalSettings() (*gqlclient.DeploymentSettingsFragment, error) {
resp, err := c.client.GetDeploymentSettings(c.ctx)
if err != nil {
return nil, api.GetErrorResponse(err, "GetDeploymentSettings")
}
if resp == nil {
return nil, fmt.Errorf("returned GetDeploymentSettings object is nil")
}
return resp.DeploymentSettings, nil
}
30 changes: 30 additions & 0 deletions pkg/test/mocks/ConsoleClient.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 85adf53

Please sign in to comment.