Skip to content

Commit 85adf53

Browse files
authored
set default values for agent installation (#504)
* set default values for agent installation * fix error description * merge values * fix linter
1 parent 376df14 commit 85adf53

6 files changed

Lines changed: 62 additions & 7 deletions

File tree

cmd/plural/cd.go

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,14 @@ import (
44
"fmt"
55
"os"
66

7-
"github.com/urfave/cli"
8-
apierrors "k8s.io/apimachinery/pkg/api/errors"
9-
107
"github.com/pluralsh/plural-cli/pkg/cd"
118
"github.com/pluralsh/plural-cli/pkg/config"
129
"github.com/pluralsh/plural-cli/pkg/console"
1310
"github.com/pluralsh/plural-cli/pkg/utils"
11+
"github.com/pluralsh/polly/algorithms"
12+
"github.com/urfave/cli"
13+
apierrors "k8s.io/apimachinery/pkg/api/errors"
14+
"sigs.k8s.io/yaml"
1415
)
1516

1617
func init() {
@@ -118,12 +119,24 @@ func (p *Plural) doInstallOperator(url, token, values string) error {
118119
}
119120

120121
vals := map[string]interface{}{}
122+
globalVals := map[string]interface{}{}
123+
124+
settings, err := p.ConsoleClient.GetGlobalSettings()
125+
if err != nil {
126+
return err
127+
}
128+
if settings != nil && settings.AgentHelmValues != nil {
129+
if err := yaml.Unmarshal([]byte(*settings.AgentHelmValues), &globalVals); err != nil {
130+
return err
131+
}
132+
}
133+
121134
if values != "" {
122135
if err := utils.YamlFile(values, &vals); err != nil {
123136
return err
124137
}
125138
}
126-
139+
vals = algorithms.Merge(vals, globalVals)
127140
err = console.InstallAgent(url, token, console.OperatorNamespace, vals)
128141
if err == nil {
129142
utils.Success("deployment operator installed successfully\n")

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ require (
5555
github.com/packethost/packngo v0.29.0
5656
github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8
5757
github.com/pluralsh/cluster-api-migration v0.2.15
58-
github.com/pluralsh/console-client-go v0.1.3
58+
github.com/pluralsh/console-client-go v0.1.17
5959
github.com/pluralsh/gqlclient v1.11.0
6060
github.com/pluralsh/plural-operator v0.5.5
6161
github.com/pluralsh/polly v0.1.7

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1424,8 +1424,8 @@ github.com/pkg/sftp v1.10.1/go.mod h1:lYOWFsE0bwd1+KfKJaKeuokY15vzFx25BLbzYYoAxZ
14241424
github.com/pkg/sftp v1.13.1/go.mod h1:3HaPG6Dq1ILlpPZRO0HVMrsydcdLt6HRDccSgb87qRg=
14251425
github.com/pluralsh/cluster-api-migration v0.2.15 h1:TIfusD+wnhZTGmwNfIlKlKJOT2dE3rUaZawDJw98GjY=
14261426
github.com/pluralsh/cluster-api-migration v0.2.15/go.mod h1:J6lEvC/70KouikX16mE331cxc3y3sBwtmfHGwZqu06w=
1427-
github.com/pluralsh/console-client-go v0.1.3 h1:Nzg6qYKvLpOxNGMypMQ75h9qGTnRhYS+wtDMpK7ybhE=
1428-
github.com/pluralsh/console-client-go v0.1.3/go.mod h1:eyCiLA44YbXiYyJh8303jk5JdPkt9McgCo5kBjk4lKo=
1427+
github.com/pluralsh/console-client-go v0.1.17 h1:QMtnWdRvV13/sND/CFjFBUR8nyg3JJgwXReSyM6bK7A=
1428+
github.com/pluralsh/console-client-go v0.1.17/go.mod h1:eyCiLA44YbXiYyJh8303jk5JdPkt9McgCo5kBjk4lKo=
14291429
github.com/pluralsh/controller-reconcile-helper v0.0.4 h1:1o+7qYSyoeqKFjx+WgQTxDz4Q2VMpzprJIIKShxqG0E=
14301430
github.com/pluralsh/controller-reconcile-helper v0.0.4/go.mod h1:AfY0gtteD6veBjmB6jiRx/aR4yevEf6K0M13/pGan/s=
14311431
github.com/pluralsh/gqlclient v1.11.0 h1:FfXW7FiEJLHOfTAa7NxDb8jb3aMZNIpCAcG+bg8uHYA=

pkg/console/console.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ type ConsoleClient interface {
4747
ListNotificationSinks(after *string, first *int64) (*consoleclient.ListNotificationSinks_NotificationSinks, error)
4848
CreateNotificationSinks(attr consoleclient.NotificationSinkAttributes) (*consoleclient.NotificationSinkFragment, error)
4949
UpdateDeploymentSettings(attr consoleclient.DeploymentSettingsAttributes) (*consoleclient.UpdateDeploymentSettings, error)
50+
GetGlobalSettings() (*consoleclient.DeploymentSettingsFragment, error)
5051
}
5152

5253
type authedTransport struct {

pkg/console/settings.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,14 @@ func (c *consoleClient) UpdateDeploymentSettings(attr gqlclient.DeploymentSettin
1818

1919
return resp, nil
2020
}
21+
22+
func (c *consoleClient) GetGlobalSettings() (*gqlclient.DeploymentSettingsFragment, error) {
23+
resp, err := c.client.GetDeploymentSettings(c.ctx)
24+
if err != nil {
25+
return nil, api.GetErrorResponse(err, "GetDeploymentSettings")
26+
}
27+
if resp == nil {
28+
return nil, fmt.Errorf("returned GetDeploymentSettings object is nil")
29+
}
30+
return resp.DeploymentSettings, nil
31+
}

pkg/test/mocks/ConsoleClient.go

Lines changed: 30 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)