Skip to content

Commit

Permalink
Merge pull request #29 from pluralsh/agent-vals
Browse files Browse the repository at this point in the history
Add ability to specify custom values yaml on agent installs
  • Loading branch information
michaeljguarino authored Mar 16, 2024
2 parents 61f62c1 + 43371b0 commit 2fa8ba0
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 4 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ require (
github.com/mitchellh/go-homedir v1.1.0
github.com/pluralsh/console-client-go v0.0.96
github.com/pluralsh/plural-cli v0.8.5-0.20240216094552-efc34ee6de37
github.com/pluralsh/polly v0.1.4
github.com/pluralsh/polly v0.1.7
github.com/samber/lo v1.38.1
github.com/sirupsen/logrus v1.9.3
gopkg.in/yaml.v2 v2.4.0
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -864,6 +864,8 @@ github.com/pluralsh/plural-cli v0.8.5-0.20240216094552-efc34ee6de37 h1:DBnaKvKmb
github.com/pluralsh/plural-cli v0.8.5-0.20240216094552-efc34ee6de37/go.mod h1:ZjvgOn9wE5vQXkImmoQknKKP0/68Ph6Hj19fUE1WdDU=
github.com/pluralsh/polly v0.1.4 h1:Kz90peCgvsfF3ERt8cujr5TR9z4wUlqQE60Eg09ZItY=
github.com/pluralsh/polly v0.1.4/go.mod h1:Yo1/jcW+4xwhWG+ZJikZy4J4HJkMNPZ7sq5auL2c/tY=
github.com/pluralsh/polly v0.1.7 h1:MUuTb6rCUV1doisaFGC+iz+33ZPU4FZHOb/kFwSDkjw=
github.com/pluralsh/polly v0.1.7/go.mod h1:Yo1/jcW+4xwhWG+ZJikZy4J4HJkMNPZ7sq5auL2c/tY=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/polyfloyd/go-errorlint v1.4.5 h1:70YWmMy4FgRHehGNOUask3HtSFSOLKgmDn7ryNe7LqI=
Expand Down
2 changes: 1 addition & 1 deletion internal/resource/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func (r *clusterResource) Create(ctx context.Context, req resource.CreateRequest
return
}

handler, err := NewOperatorHandler(ctx, data.GetKubeconfig(), r.consoleUrl)
handler, err := NewOperatorHandler(ctx, data.GetKubeconfig(), data.HelmValues.ValueStringPointer(), r.consoleUrl)
if err != nil {
resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Unable to init operator handler, got error: %s", err))
return
Expand Down
1 change: 1 addition & 0 deletions internal/resource/cluster_model.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ type cluster struct {
Bindings *common.ClusterBindings `tfsdk:"bindings"`
NodePools types.Map `tfsdk:"node_pools"`
CloudSettings *ClusterCloudSettings `tfsdk:"cloud_settings"`
HelmValues types.String `tfsdk:"helm_values"`
Kubeconfig *Kubeconfig `tfsdk:"kubeconfig"`
}

Expand Down
18 changes: 16 additions & 2 deletions internal/resource/cluster_operator_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ import (

"github.com/pluralsh/plural-cli/pkg/console"
"github.com/pluralsh/plural-cli/pkg/helm"
"github.com/pluralsh/polly/algorithms"
"github.com/samber/lo"
"github.com/sirupsen/logrus"
"gopkg.in/yaml.v2"
"helm.sh/helm/v3/pkg/action"
"helm.sh/helm/v3/pkg/chart"
"helm.sh/helm/v3/pkg/chart/loader"
Expand All @@ -23,6 +25,9 @@ type OperatorHandler struct {
// url is an url to the Console API, i.e. https://console.mycluster.onplural.sh
url string

// additional values used on install
vals map[string]interface{}

// Preconfigured helm actions and chart
chart *chart.Chart
configuration *action.Configuration
Expand Down Expand Up @@ -129,12 +134,13 @@ func (oh *OperatorHandler) listReleases(state action.ListStates) ([]*release.Rel
}

func (oh *OperatorHandler) values(token string) map[string]interface{} {
return map[string]interface{}{
vals := map[string]interface{}{
"secrets": map[string]string{
"deployToken": token,
},
"consoleUrl": fmt.Sprintf("%s/ext/gql", oh.url),
}
return algorithms.Merge(vals, oh.vals)
}

func (oh *OperatorHandler) InstallOrUpgrade(token string) error {
Expand Down Expand Up @@ -165,11 +171,19 @@ func (oh *OperatorHandler) Uninstall() error {
return err
}

func NewOperatorHandler(ctx context.Context, kubeconfig *Kubeconfig, consoleUrl string) (*OperatorHandler, error) {
func NewOperatorHandler(ctx context.Context, kubeconfig *Kubeconfig, values *string, consoleUrl string) (*OperatorHandler, error) {
vals := map[string]interface{}{}
if values != nil {
if err := yaml.Unmarshal([]byte(*values), &vals); err != nil {
return nil, err
}
}

handler := &OperatorHandler{
ctx: ctx,
kubeconfig: kubeconfig,
url: consoleUrl,
vals: vals,
}

err := handler.init()
Expand Down
5 changes: 5 additions & 0 deletions internal/resource/cluster_schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,11 @@ func (r *clusterResource) schema() schema.Schema {
},
PlanModifiers: []planmodifier.Object{objectplanmodifier.RequiresReplace()},
},
"helm_values": schema.StringAttribute{
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.",
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.",
Optional: true,
},
"kubeconfig": r.kubeconfigSchema(false),
"node_pools": schema.MapNestedAttribute{
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.",
Expand Down

0 comments on commit 2fa8ba0

Please sign in to comment.