Skip to content

Commit 2fa8ba0

Browse files
Merge pull request #29 from pluralsh/agent-vals
Add ability to specify custom values yaml on agent installs
2 parents 61f62c1 + 43371b0 commit 2fa8ba0

File tree

6 files changed

+26
-4
lines changed

6 files changed

+26
-4
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ require (
1414
github.com/mitchellh/go-homedir v1.1.0
1515
github.com/pluralsh/console-client-go v0.0.96
1616
github.com/pluralsh/plural-cli v0.8.5-0.20240216094552-efc34ee6de37
17-
github.com/pluralsh/polly v0.1.4
17+
github.com/pluralsh/polly v0.1.7
1818
github.com/samber/lo v1.38.1
1919
github.com/sirupsen/logrus v1.9.3
2020
gopkg.in/yaml.v2 v2.4.0

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -864,6 +864,8 @@ github.com/pluralsh/plural-cli v0.8.5-0.20240216094552-efc34ee6de37 h1:DBnaKvKmb
864864
github.com/pluralsh/plural-cli v0.8.5-0.20240216094552-efc34ee6de37/go.mod h1:ZjvgOn9wE5vQXkImmoQknKKP0/68Ph6Hj19fUE1WdDU=
865865
github.com/pluralsh/polly v0.1.4 h1:Kz90peCgvsfF3ERt8cujr5TR9z4wUlqQE60Eg09ZItY=
866866
github.com/pluralsh/polly v0.1.4/go.mod h1:Yo1/jcW+4xwhWG+ZJikZy4J4HJkMNPZ7sq5auL2c/tY=
867+
github.com/pluralsh/polly v0.1.7 h1:MUuTb6rCUV1doisaFGC+iz+33ZPU4FZHOb/kFwSDkjw=
868+
github.com/pluralsh/polly v0.1.7/go.mod h1:Yo1/jcW+4xwhWG+ZJikZy4J4HJkMNPZ7sq5auL2c/tY=
867869
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
868870
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
869871
github.com/polyfloyd/go-errorlint v1.4.5 h1:70YWmMy4FgRHehGNOUask3HtSFSOLKgmDn7ryNe7LqI=

internal/resource/cluster.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ func (r *clusterResource) Create(ctx context.Context, req resource.CreateRequest
7171
return
7272
}
7373

74-
handler, err := NewOperatorHandler(ctx, data.GetKubeconfig(), r.consoleUrl)
74+
handler, err := NewOperatorHandler(ctx, data.GetKubeconfig(), data.HelmValues.ValueStringPointer(), r.consoleUrl)
7575
if err != nil {
7676
resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Unable to init operator handler, got error: %s", err))
7777
return

internal/resource/cluster_model.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ type cluster struct {
2525
Bindings *common.ClusterBindings `tfsdk:"bindings"`
2626
NodePools types.Map `tfsdk:"node_pools"`
2727
CloudSettings *ClusterCloudSettings `tfsdk:"cloud_settings"`
28+
HelmValues types.String `tfsdk:"helm_values"`
2829
Kubeconfig *Kubeconfig `tfsdk:"kubeconfig"`
2930
}
3031

internal/resource/cluster_operator_handler.go

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@ import (
77

88
"github.com/pluralsh/plural-cli/pkg/console"
99
"github.com/pluralsh/plural-cli/pkg/helm"
10+
"github.com/pluralsh/polly/algorithms"
1011
"github.com/samber/lo"
1112
"github.com/sirupsen/logrus"
13+
"gopkg.in/yaml.v2"
1214
"helm.sh/helm/v3/pkg/action"
1315
"helm.sh/helm/v3/pkg/chart"
1416
"helm.sh/helm/v3/pkg/chart/loader"
@@ -23,6 +25,9 @@ type OperatorHandler struct {
2325
// url is an url to the Console API, i.e. https://console.mycluster.onplural.sh
2426
url string
2527

28+
// additional values used on install
29+
vals map[string]interface{}
30+
2631
// Preconfigured helm actions and chart
2732
chart *chart.Chart
2833
configuration *action.Configuration
@@ -129,12 +134,13 @@ func (oh *OperatorHandler) listReleases(state action.ListStates) ([]*release.Rel
129134
}
130135

131136
func (oh *OperatorHandler) values(token string) map[string]interface{} {
132-
return map[string]interface{}{
137+
vals := map[string]interface{}{
133138
"secrets": map[string]string{
134139
"deployToken": token,
135140
},
136141
"consoleUrl": fmt.Sprintf("%s/ext/gql", oh.url),
137142
}
143+
return algorithms.Merge(vals, oh.vals)
138144
}
139145

140146
func (oh *OperatorHandler) InstallOrUpgrade(token string) error {
@@ -165,11 +171,19 @@ func (oh *OperatorHandler) Uninstall() error {
165171
return err
166172
}
167173

168-
func NewOperatorHandler(ctx context.Context, kubeconfig *Kubeconfig, consoleUrl string) (*OperatorHandler, error) {
174+
func NewOperatorHandler(ctx context.Context, kubeconfig *Kubeconfig, values *string, consoleUrl string) (*OperatorHandler, error) {
175+
vals := map[string]interface{}{}
176+
if values != nil {
177+
if err := yaml.Unmarshal([]byte(*values), &vals); err != nil {
178+
return nil, err
179+
}
180+
}
181+
169182
handler := &OperatorHandler{
170183
ctx: ctx,
171184
kubeconfig: kubeconfig,
172185
url: consoleUrl,
186+
vals: vals,
173187
}
174188

175189
err := handler.init()

internal/resource/cluster_schema.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,11 @@ func (r *clusterResource) schema() schema.Schema {
108108
},
109109
PlanModifiers: []planmodifier.Object{objectplanmodifier.RequiresReplace()},
110110
},
111+
"helm_values": schema.StringAttribute{
112+
Description: "Additional helm values you'd like to use in deployment agent helm installs. This is useful for BYOK clusters that need to use custom images or other constructs.",
113+
MarkdownDescription: "Additional helm values you'd like to use in deployment agent helm installs. This is useful for BYOK clusters that need to use custom images or other constructs.",
114+
Optional: true,
115+
},
111116
"kubeconfig": r.kubeconfigSchema(false),
112117
"node_pools": schema.MapNestedAttribute{
113118
Description: "Experimental, not ready for production use. Map of node pool specs managed by this cluster, where the key is name of the node pool and value contains the spec. Leave empty for bring your own cluster.",

0 commit comments

Comments
 (0)