Topics

How to override the default helm chart values in values.yaml using hapi?


benjamin <benjamin_wang@...>
 

I use the following code (golang) to deploy helm chart into kubernetes. I removed the error handling code for simplicity. 

The last parameter "values" is used to override the values of some fields defined in values.yaml . But after the chart is created, the values used by the POD are still the default values defined in values.yaml in the chart instead of the values included in the last parameter of the following function. What did I miss? Thanks!

func deploy(tillerEndpoint, helmChartDir, helmChartName string, values map[string]*chart.Value) error {
conn, err := grpc.Dial(tillerEndpoint, grpc.WithInsecure())
defer conn.Close()
tillerClient := services.NewReleaseServiceClient(conn)
helmChart, err := chartutil.Load(helmChartDir)
cc := chart.Config{
Raw:    helmChart.Values.Raw,
Values: values,
}
req := &services.InstallReleaseRequest{
Chart:        helmChart,
Values:       &cc,
Name:         helmChartName,
Namespace:    "default",
DryRun:       false,
DisableHooks: true,
}
err = chartutil.ProcessRequirementsEnabled(req.Chart, req.Values)
err = chartutil.ProcessRequirementsImportValues(req.Chart)
_, err = tillerClient.InstallRelease(helm.NewContext(), req)
return err
}


Matt Fisher
 

If you want to override values, you'll want to add your values as a ValueOverride option to InstallRelease. An example can be found within Draft: https://github.com/Azure/draft/blob/9e1f18aa6d9bd382bf9602b66eeb870b99213f8b/pkg/builder/builder.go#L411-L421


1504220459230_microsoft.png

Matthew Fisher, Caffeinated Software Engineer

Microsoft Azure Platform

Nanoose Bay, BC Canada

Emailmatt.fisher@...

Phone: 1(250)937-1478


From: cncf-helm@... <cncf-helm@...> on behalf of benjamin via Lists.Cncf.Io <benjamin_wang=aliyun.com@...>
Sent: Tuesday, June 12, 2018 8:28 AM
To: cncf-helm@...
Cc: cncf-helm@...
Subject: [cncf-helm] How to override the default helm chart values in values.yaml using hapi?
 
I use the following code (golang) to deploy helm chart into kubernetes. I removed the error handling code for simplicity. 

The last parameter "values" is used to override the values of some fields defined in values.yaml . But after the chart is created, the values used by the POD are still the default values defined in values.yaml in the chart instead of the values included in the last parameter of the following function. What did I miss? Thanks!

func deploy(tillerEndpoint, helmChartDir, helmChartName string, values map[string]*chart.Value) error {
conn, err := grpc.Dial(tillerEndpoint, grpc.WithInsecure())
defer conn.Close()
tillerClient := services.NewReleaseServiceClient(conn)
helmChart, err := chartutil.Load(helmChartDir)
cc := chart.Config{
Raw:    helmChart.Values.Raw,
Values: values,
}
req := &services.InstallReleaseRequest{
Chart:        helmChart,
Values:       &cc,
Name:         helmChartName,
Namespace:    "default",
DryRun:       false,
DisableHooks: true,
}
err = chartutil.ProcessRequirementsEnabled(req.Chart, req.Values)
err = chartutil.ProcessRequirementsImportValues(req.Chart)
_, err = tillerClient.InstallRelease(helm.NewContext(), req)
return err
}


benjamin <benjamin_wang@...>
 

Note that I did not use helm client, instead, I use gRPC API to communicate with tiller server directly. 

 

I just reviewed the source code of helm client. It just configures the InstallReleaseRequest.Values with the overrides values. I followed the same logic,  so I just updated InstallReleaseRequest.Values with the override values directly.  The new source code is something as below, but it did not work either. The helm chart can be created successfully, but the POD still uses the default values defined in values.yaml in the chart instead of the override values. Can someone help to point out what’s the reason? 

 

func deploy(tillerEndpoint, helmChartDir, helmChartName string, overrideValues map[string]interface{}) error {

conn, err := grpc.Dial(tillerEndpoint, grpc.WithInsecure())

defer conn.Close()

tillerClient := services.NewReleaseServiceClient(conn)

helmChart, err := chartutil.Load(helmChartDir)

cc := chart.Config{ Raw:    helmChart.Values.Raw }

         If overrideValues != nil {

vals, err := chartutil.Values(overrideValues).YAML()

                cc = chart.Config{Raw: vals }

  }

req := &services.InstallReleaseRequest{

Chart:        helmChart,

Values:       &cc,

Name:         helmChartName,

Namespace:    "default",

DryRun:       false,

DisableHooks: true,

}

err = chartutil.ProcessRequirementsEnabled(req.Chart, req.Values)

err = chartutil.ProcessRequirementsImportValues(req.Chart)

_, err = tillerClient.InstallRelease(helm.NewContext(), req)

return err

}


benjamin <benjamin_wang@...>
 

 

I tried to use command “helm install —set app1.key1=abc my chart”, and it worked. So I read the source code helm command, eventually I figured out the root cause.

The structure of the values map should be hierarchical.

Previously the value map was created with the following code,

 

Values := make(map[string]interface{})

values[“app1.key1”] = “abc”

 

The above code isn’t correct, and it should be something as below,

Base := make(map[string]interface{})

InnerApp1 = make(map[string]interface{})

innerApp1[“key1”] = “abc”

base[“app1”] = innerApp1