Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,9 @@ require (
)

require (
github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/tidwall/gjson v1.14.2 // indirect
github.com/tidwall/match v1.1.1 // indirect
github.com/tidwall/pretty v1.2.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)

require (
Expand Down
3 changes: 0 additions & 3 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
github.com/cpuguy83/go-md2man/v2 v2.0.2 h1:p1EgwI/C7NhT0JmVkwCD2ZBK8j4aeHQX2pMHHBfMQ6w=
github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/go-yaml/yaml v2.1.0+incompatible h1:RYi2hDdss1u4YE7GwixGzWwVo47T8UQwnTLB6vQiq+o=
github.com/go-yaml/yaml v2.1.0+incompatible/go.mod h1:w2MrLa16VYP0jy6N7M5kHaCkaLENm+P+Tv+MfurjSw0=
github.com/inconshreveable/mousetrap v1.0.1 h1:U3uMjPSQEBMNp1lFxmllqCPM6P5u/Xq7Pgzkat/bFNc=
github.com/inconshreveable/mousetrap v1.0.1/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk=
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/spf13/cobra v1.6.1 h1:o94oiPyS4KD1mPy2fmcYYHHfCxLqYjJOhGsCHFZtEzA=
github.com/spf13/cobra v1.6.1/go.mod h1:IOw/AERYS7UzyrGinqmz6HLUo219MORXGxhbaJUqzrY=
Expand All @@ -25,7 +23,6 @@ gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8
gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
sigs.k8s.io/yaml v1.2.0 h1:kr/MCeFWJWTwyaHoR9c8EjH9OumOmoF9YGiZd7lFm/Q=
sigs.k8s.io/yaml v1.2.0/go.mod h1:yfXDCHCao9+ENCvLSE62v9VSji2MKu5jeNfTrofGhJc=
11 changes: 6 additions & 5 deletions pkg/internal/bootstrap-configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,12 @@ type ClusterConfiguration struct {
}

type Cluster struct {
Name string `yaml:"name"`
ContextName string `yaml:"context_name"`
KubeConfigPath string `yaml:"kube_config_path"`
ControlPlaneAddress string `yaml:"control_plane_address"`
NodeIP string `yaml:"node_ip"`
Name string `yaml:"name"`
ContextName string `yaml:"context_name"`
KubeConfigPath string `yaml:"kube_config_path"`
ControlPlaneAddress string `yaml:"control_plane_address"`
NodeIP string `yaml:"node_ip"`
HelmValues map[string]interface{} `yaml:"helm_values,omitempty"`
}

type ImagePullSecrets struct {
Expand Down
30 changes: 29 additions & 1 deletion pkg/internal/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,30 @@ func Retry(backoffLimit int, sleep time.Duration, f func() error) (err error) {
return fmt.Errorf("retry failed after %d attempts (took %d seconds), last error: %s", backoffLimit, int(elapsed.Seconds()), err)
}

// CreateWorkerSpecificHelmChart merges global worker chart values with cluster-specific values
func CreateWorkerSpecificHelmChart(globalChart HelmChart, cluster Cluster) HelmChart {
// Start with a copy of the global chart
workerChart := HelmChart{
ChartName: globalChart.ChartName,
Version: globalChart.Version,
Values: make(map[string]interface{}),
}

// Copy global values first
for k, v := range globalChart.Values {
workerChart.Values[k] = v
}

// Override with cluster-specific values if they exist
if cluster.HelmValues != nil {
for k, v := range cluster.HelmValues {
workerChart.Values[k] = v
}
}

return workerChart
}

func generateWorkerValuesFile(cluster Cluster, valuesFile string, config Configuration, insecureMetrics bool) {
var secrets map[string]string
err := Retry(3, 1*time.Second, func() (err error) {
Expand All @@ -96,7 +120,11 @@ func generateWorkerValuesFile(cluster Cluster, valuesFile string, config Configu
if err != nil {
log.Fatalf("Unable to fetch secrets\n%s", err)
}
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))

// Create a worker-specific helm chart configuration
workerChart := CreateWorkerSpecificHelmChart(config.HelmChartConfiguration.WorkerChart, cluster)

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))
if err != nil {
log.Fatalf("%s %s", util.Cross, err)
}
Expand Down
Loading