Skip to content

Commit cdda734

Browse files
committed
fix(topology): support unique helm values per worker cluster
Signed-off-by: Ankit Kr Chowdhury <rakesh856100@gmail.com>
1 parent 66c8854 commit cdda734

8 files changed

Lines changed: 749 additions & 12 deletions

File tree

go.mod

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,9 @@ require (
1010
)
1111

1212
require (
13-
github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect
14-
github.com/russross/blackfriday/v2 v2.1.0 // indirect
1513
github.com/tidwall/gjson v1.14.2 // indirect
1614
github.com/tidwall/match v1.1.1 // indirect
1715
github.com/tidwall/pretty v1.2.0 // indirect
18-
gopkg.in/yaml.v3 v3.0.1 // indirect
1916
)
2017

2118
require (

go.sum

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
1-
github.com/cpuguy83/go-md2man/v2 v2.0.2 h1:p1EgwI/C7NhT0JmVkwCD2ZBK8j4aeHQX2pMHHBfMQ6w=
21
github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
32
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
43
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
54
github.com/go-yaml/yaml v2.1.0+incompatible h1:RYi2hDdss1u4YE7GwixGzWwVo47T8UQwnTLB6vQiq+o=
65
github.com/go-yaml/yaml v2.1.0+incompatible/go.mod h1:w2MrLa16VYP0jy6N7M5kHaCkaLENm+P+Tv+MfurjSw0=
76
github.com/inconshreveable/mousetrap v1.0.1 h1:U3uMjPSQEBMNp1lFxmllqCPM6P5u/Xq7Pgzkat/bFNc=
87
github.com/inconshreveable/mousetrap v1.0.1/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
9-
github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk=
108
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
119
github.com/spf13/cobra v1.6.1 h1:o94oiPyS4KD1mPy2fmcYYHHfCxLqYjJOhGsCHFZtEzA=
1210
github.com/spf13/cobra v1.6.1/go.mod h1:IOw/AERYS7UzyrGinqmz6HLUo219MORXGxhbaJUqzrY=
@@ -25,7 +23,6 @@ gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8
2523
gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
2624
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
2725
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
28-
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
2926
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
3027
sigs.k8s.io/yaml v1.2.0 h1:kr/MCeFWJWTwyaHoR9c8EjH9OumOmoF9YGiZd7lFm/Q=
3128
sigs.k8s.io/yaml v1.2.0/go.mod h1:yfXDCHCao9+ENCvLSE62v9VSji2MKu5jeNfTrofGhJc=

pkg/internal/bootstrap-configuration.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,12 @@ type ClusterConfiguration struct {
4545
}
4646

4747
type Cluster struct {
48-
Name string `yaml:"name"`
49-
ContextName string `yaml:"context_name"`
50-
KubeConfigPath string `yaml:"kube_config_path"`
51-
ControlPlaneAddress string `yaml:"control_plane_address"`
52-
NodeIP string `yaml:"node_ip"`
48+
Name string `yaml:"name"`
49+
ContextName string `yaml:"context_name"`
50+
KubeConfigPath string `yaml:"kube_config_path"`
51+
ControlPlaneAddress string `yaml:"control_plane_address"`
52+
NodeIP string `yaml:"node_ip"`
53+
HelmValues map[string]interface{} `yaml:"helm_values,omitempty"`
5354
}
5455

5556
type ImagePullSecrets struct {

pkg/internal/worker.go

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,30 @@ func Retry(backoffLimit int, sleep time.Duration, f func() error) (err error) {
8484
return fmt.Errorf("retry failed after %d attempts (took %d seconds), last error: %s", backoffLimit, int(elapsed.Seconds()), err)
8585
}
8686

87+
// CreateWorkerSpecificHelmChart merges global worker chart values with cluster-specific values
88+
func CreateWorkerSpecificHelmChart(globalChart HelmChart, cluster Cluster) HelmChart {
89+
// Start with a copy of the global chart
90+
workerChart := HelmChart{
91+
ChartName: globalChart.ChartName,
92+
Version: globalChart.Version,
93+
Values: make(map[string]interface{}),
94+
}
95+
96+
// Copy global values first
97+
for k, v := range globalChart.Values {
98+
workerChart.Values[k] = v
99+
}
100+
101+
// Override with cluster-specific values if they exist
102+
if cluster.HelmValues != nil {
103+
for k, v := range cluster.HelmValues {
104+
workerChart.Values[k] = v
105+
}
106+
}
107+
108+
return workerChart
109+
}
110+
87111
func generateWorkerValuesFile(cluster Cluster, valuesFile string, config Configuration, insecureMetrics bool) {
88112
var secrets map[string]string
89113
err := Retry(3, 1*time.Second, func() (err error) {
@@ -96,7 +120,11 @@ func generateWorkerValuesFile(cluster Cluster, valuesFile string, config Configu
96120
if err != nil {
97121
log.Fatalf("Unable to fetch secrets\n%s", err)
98122
}
99-
err = generateValuesFile(kubesliceDirectory+"/"+valuesFile, &config.HelmChartConfiguration.WorkerChart, fmt.Sprintf(workerValuesTemplate+generateImagePullSecretsValue(config.HelmChartConfiguration.ImagePullSecret), secrets["namespace"], secrets["controllerEndpoint"], secrets["ca.crt"], secrets["token"], insecureMetrics, cluster.Name, cluster.ControlPlaneAddress))
123+
124+
// Create a worker-specific helm chart configuration
125+
workerChart := CreateWorkerSpecificHelmChart(config.HelmChartConfiguration.WorkerChart, cluster)
126+
127+
err = generateValuesFile(kubesliceDirectory+"/"+valuesFile, &workerChart, fmt.Sprintf(workerValuesTemplate+generateImagePullSecretsValue(config.HelmChartConfiguration.ImagePullSecret), secrets["namespace"], secrets["controllerEndpoint"], secrets["ca.crt"], secrets["token"], insecureMetrics, cluster.Name, cluster.ControlPlaneAddress))
100128
if err != nil {
101129
log.Fatalf("%s %s", util.Cross, err)
102130
}

0 commit comments

Comments
 (0)