@@ -3,10 +3,12 @@ package resource
33import (
44 "context"
55 "fmt"
6+ "strings"
67 "time"
78
89 "terraform-provider-plural/internal/client"
910
11+ gqlclient "github.com/pluralsh/console-client-go"
1012 "github.com/pluralsh/plural-cli/pkg/console"
1113 "github.com/pluralsh/plural-cli/pkg/helm"
1214 "github.com/pluralsh/polly/algorithms"
@@ -33,6 +35,8 @@ type OperatorHandler struct {
3335 // kubeconfig is a model.Kubeconfig data model read from terraform
3436 kubeconfig * Kubeconfig
3537
38+ settings * gqlclient.DeploymentSettingsFragment
39+
3640 // url is an url to the Console API, i.e. https://console.mycluster.onplural.sh
3741 url string
3842
@@ -68,6 +72,8 @@ func (oh *OperatorHandler) init() error {
6872 return err
6973 }
7074
75+ oh .initSettings ()
76+
7177 err = oh .initRepo ()
7278 if err != nil {
7379 return err
@@ -85,12 +91,26 @@ func (oh *OperatorHandler) init() error {
8591 return nil
8692}
8793
94+ func (oh * OperatorHandler ) initSettings () {
95+ settings , err := oh .client .GetDeploymentSettings (oh .ctx )
96+ if err != nil {
97+ return
98+ }
99+ oh .settings = settings .DeploymentSettings
100+ }
101+
88102func (oh * OperatorHandler ) initRepo () error {
89103 return helm .AddRepo (console .ReleaseName , oh .repoUrl )
90104}
91105
92106func (oh * OperatorHandler ) initChart () error {
107+ vsn := ""
108+ if oh .settings != nil {
109+ vsn = oh .settings .AgentVsn
110+ }
111+
93112 client := action .NewInstall (oh .configuration )
113+ client .ChartPathOptions .Version = strings .TrimPrefix (vsn , "v" )
94114 locateName := fmt .Sprintf ("%s/%s" , console .ReleaseName , console .ChartName )
95115 path , err := client .ChartPathOptions .LocateChart (locateName , cli .New ())
96116 if err != nil {
@@ -161,12 +181,8 @@ func (oh *OperatorHandler) values(token string) (map[string]any, error) {
161181 "consoleUrl" : fmt .Sprintf ("%s/ext/gql" , oh .url ),
162182 }
163183
164- setting , err := oh .client .GetDeploymentSettings (oh .ctx )
165- if err != nil {
166- return nil , err
167- }
168- if setting != nil && setting .DeploymentSettings != nil && setting .DeploymentSettings .AgentHelmValues != nil {
169- if err := yaml .Unmarshal ([]byte (* setting .DeploymentSettings .AgentHelmValues ), & globalVals ); err != nil {
184+ if oh .settings != nil && oh .settings .AgentHelmValues != nil {
185+ if err := yaml .Unmarshal ([]byte (* oh .settings .AgentHelmValues ), & globalVals ); err != nil {
170186 return nil , err
171187 }
172188 }
0 commit comments