From 959bad31d64f6239fb05a8e6993c4a53e0b23083 Mon Sep 17 00:00:00 2001 From: Priyank Upadhyay Date: Thu, 2 Feb 2023 18:18:08 +0530 Subject: [PATCH 1/7] feat(): Added values key to topology configuration Signed-off-by: Priyank Upadhyay --- pkg/internal/bootstrap-configuration.go | 2 ++ samples/template.yaml | 3 +++ 2 files changed, 5 insertions(+) diff --git a/pkg/internal/bootstrap-configuration.go b/pkg/internal/bootstrap-configuration.go index faf2fbe..b08771d 100644 --- a/pkg/internal/bootstrap-configuration.go +++ b/pkg/internal/bootstrap-configuration.go @@ -25,6 +25,8 @@ type HelmChartConfiguration struct { type HelmChart struct { ChartName string `yaml:"chart_name"` Version string `yaml:"version"` + // Values to be passed as --set arguments to helm install + Values map[string]string `yaml:"values"` } type KubeSliceConfiguration struct { diff --git a/samples/template.yaml b/samples/template.yaml index 8bf525d..702a6c0 100644 --- a/samples/template.yaml +++ b/samples/template.yaml @@ -39,12 +39,15 @@ configuration: controller_chart: chart_name: #{The name of the Controller Chart} version: #{The version of the chart to use. Leave blank for latest version} + values: #(Values to be passed as --set arguments to helm install) worker_chart: chart_name: #{The name of the Worker Chart} version: #{The version of the chart to use. Leave blank for latest version} + values: #(Values to be passed as --set arguments to helm install) ui_chart: chart_name: #{The name of the UI/Enterprise Chart} version: #{The version of the chart to use. Leave blank for latest version} + values: #(Values to be passed as --set arguments to helm install) helm_username: #{Helm Username if the repo is private} helm_password: #{Helm Password if the repo is private} image_pull_secret: #{The image pull secrets. Optional for OpenSource, required for enterprise} From 07c41e033cbbc3ba9e9ae03958f950a0bf09f3f5 Mon Sep 17 00:00:00 2001 From: Priyank Upadhyay Date: Tue, 7 Feb 2023 12:31:18 +0530 Subject: [PATCH 2/7] fix(): generation of values file Signed-off-by: Priyank Upadhyay --- pkg/internal/controller.go | 10 ++++--- pkg/internal/enterprise.go | 9 ++++-- pkg/internal/values.go | 61 ++++++++++++++++++++++++++++++++++++++ pkg/internal/worker.go | 13 ++++---- 4 files changed, 80 insertions(+), 13 deletions(-) create mode 100644 pkg/internal/values.go diff --git a/pkg/internal/controller.go b/pkg/internal/controller.go index ebaa879..f5ff32a 100644 --- a/pkg/internal/controller.go +++ b/pkg/internal/controller.go @@ -26,7 +26,7 @@ func InstallKubeSliceController(ApplicationConfiguration *ConfigurationSpecs) { cc := ApplicationConfiguration.Configuration.ClusterConfiguration hc := ApplicationConfiguration.Configuration.HelmChartConfiguration - generateControllerValuesFile(cc.ControllerCluster, ApplicationConfiguration.Configuration.HelmChartConfiguration.ImagePullSecret) + generateControllerValuesFile(cc.ControllerCluster, ApplicationConfiguration.Configuration.HelmChartConfiguration) util.Printf("%s Generated Helm Values file for Controller Installation %s", util.Tick, controllerValuesFileName) time.Sleep(200 * time.Millisecond) @@ -52,9 +52,11 @@ func UninstallKubeSliceController(ApplicationConfiguration *ConfigurationSpecs) // util.Printf("%s Waiting for KubeSlice Manager Pods to be removed...", util.Wait) } -func generateControllerValuesFile(cluster Cluster, imagePullSecret ImagePullSecrets) { - - util.DumpFile(fmt.Sprintf(controllerValuesTemplate+generateImagePullSecretsValue(imagePullSecret), cluster.ControlPlaneAddress), kubesliceDirectory+"/"+controllerValuesFileName) +func generateControllerValuesFile(cluster Cluster, hcConfig HelmChartConfiguration) { + err := generateValuesFile(kubesliceDirectory+"/"+controllerValuesFileName, &hcConfig.ControllerChart, fmt.Sprintf(controllerValuesTemplate+generateImagePullSecretsValue(hcConfig.ImagePullSecret), cluster.ControlPlaneAddress)) + if err != nil { + log.Fatalf("%s %s", util.Cross, err) + } } func installKubeSliceController(cluster Cluster, hc HelmChartConfiguration) { diff --git a/pkg/internal/enterprise.go b/pkg/internal/enterprise.go index 39a663d..a569ad8 100644 --- a/pkg/internal/enterprise.go +++ b/pkg/internal/enterprise.go @@ -29,7 +29,7 @@ func InstallKubeSliceUI(ApplicationConfiguration *ConfigurationSpecs) { hc := ApplicationConfiguration.Configuration.HelmChartConfiguration time.Sleep(200 * time.Millisecond) clusterType := ApplicationConfiguration.Configuration.ClusterConfiguration.ClusterType - generateUIValuesFile(clusterType, cc.ControllerCluster, ApplicationConfiguration.Configuration.HelmChartConfiguration.ImagePullSecret) + generateUIValuesFile(clusterType, cc.ControllerCluster, ApplicationConfiguration.Configuration.HelmChartConfiguration) installKubeSliceUI(cc.ControllerCluster, hc) util.Printf("%s Successfully installed helm chart %s/%s", util.Tick, hc.RepoAlias, hc.UIChart.ChartName) time.Sleep(200 * time.Millisecond) @@ -52,14 +52,17 @@ func UninstallKubeSliceUI(ApplicationConfiguration *ConfigurationSpecs) { } } -func generateUIValuesFile(clusterType string, cluster Cluster, imagePullSecrets ImagePullSecrets) { +func generateUIValuesFile(clusterType string, cluster Cluster, hcConfig HelmChartConfiguration) { serviceType := "" if clusterType == "kind" { serviceType = "NodePort" } else { serviceType = "LoadBalancer" } - util.DumpFile(fmt.Sprintf(UIValuesTemplate+generateImagePullSecretsValue(imagePullSecrets), serviceType), kubesliceDirectory+"/"+uiValuesFileName) + err := generateValuesFile(kubesliceDirectory+"/"+uiValuesFileName, &hcConfig.UIChart, fmt.Sprintf(UIValuesTemplate+generateImagePullSecretsValue(hcConfig.ImagePullSecret), serviceType)) + if err != nil { + log.Fatalf("%s %s", util.Cross, err) + } } func installKubeSliceUI(cluster Cluster, hc HelmChartConfiguration) { diff --git a/pkg/internal/values.go b/pkg/internal/values.go new file mode 100644 index 0000000..e2db774 --- /dev/null +++ b/pkg/internal/values.go @@ -0,0 +1,61 @@ +package internal + +import ( + "fmt" + "io/ioutil" + "strings" + + "gopkg.in/yaml.v2" +) + +func mergeMaps(dest, src map[interface{}]interface{}) map[interface{}]interface{} { + for k, v := range src { + if d, ok := dest[k]; ok { + switch d.(type) { + case map[interface{}]interface{}: + dest[k] = mergeMaps(d.(map[interface{}]interface{}), v.(map[interface{}]interface{})) + default: + dest[k] = v + } + } else { + dest[k] = v + } + } + return dest +} + +func generateValuesFile(filePath string, hc *HelmChart, defaults string) error { + valuesMap := make(map[interface{}]interface{}) + for k, v := range hc.Values { + keys := strings.Split(k, ".") + currentMap := valuesMap + for i, key := range keys { + if i == len(keys)-1 { + currentMap[key] = v + } else { + if currentMap[key] == nil { + currentMap[key] = make(map[interface{}]interface{}) + } + currentMap = currentMap[key].(map[interface{}]interface{}) + } + } + } + + defaultsMap := make(map[interface{}]interface{}) + if err := yaml.Unmarshal([]byte(defaults), &defaultsMap); err != nil { + return fmt.Errorf("error parsing defaults: %v", err) + } + + mergedMap := mergeMaps(valuesMap, defaultsMap) + + finalData, err := yaml.Marshal(mergedMap) + if err != nil { + return fmt.Errorf("error encoding final data as YAML: %v", err) + } + + if err := ioutil.WriteFile(filePath, finalData, 0644); err != nil { + return fmt.Errorf("error writing values file: %v", err) + } + + return nil +} diff --git a/pkg/internal/worker.go b/pkg/internal/worker.go index f95e5dc..7eda016 100644 --- a/pkg/internal/worker.go +++ b/pkg/internal/worker.go @@ -33,9 +33,7 @@ func InstallKubeSliceWorker(ApplicationConfiguration *ConfigurationSpecs) { filename := "helm-values-" + cluster.Name + ".yaml" generateWorkerValuesFile(cluster, filename, - ApplicationConfiguration.Configuration.HelmChartConfiguration.ImagePullSecret, - ApplicationConfiguration.Configuration.ClusterConfiguration.ControllerCluster, - ApplicationConfiguration.Configuration.KubeSliceConfiguration.ProjectName) + ApplicationConfiguration.Configuration) util.Printf("%s Generated Helm Values file for Worker Installation %s", util.Tick, filename) time.Sleep(200 * time.Millisecond) @@ -82,10 +80,10 @@ 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) } -func generateWorkerValuesFile(cluster Cluster, valuesFile string, imagePullSecrets ImagePullSecrets, cc Cluster, projectName string) { +func generateWorkerValuesFile(cluster Cluster, valuesFile string, config Configuration) { var secrets map[string]string err := Retry(3, 1*time.Second, func() (err error) { - secrets = fetchSecret(cluster.Name, cc, projectName) + secrets = fetchSecret(cluster.Name, config.ClusterConfiguration.ControllerCluster, config.KubeSliceConfiguration.ProjectName) if secrets["namespace"] == "" || secrets["controllerEndpoint"] == "" || secrets["ca.crt"] == "" || secrets["token"] == "" { return fmt.Errorf("secret is empty") } @@ -94,7 +92,10 @@ func generateWorkerValuesFile(cluster Cluster, valuesFile string, imagePullSecre if err != nil { log.Fatalf("Unable to fetch secrets\n%s", err) } - util.DumpFile(fmt.Sprintf(workerValuesTemplate+generateImagePullSecretsValue(imagePullSecrets), secrets["namespace"], secrets["controllerEndpoint"], secrets["ca.crt"], secrets["token"], cluster.Name, cluster.NodeIP, cluster.ControlPlaneAddress), kubesliceDirectory+"/"+valuesFile) + err = generateValuesFile(kubesliceDirectory+"/"+valuesFile, &config.HelmChartConfiguration.WorkerChart, fmt.Sprintf(workerValuesTemplate+generateImagePullSecretsValue(config.HelmChartConfiguration.ImagePullSecret), secrets["namespace"], secrets["controllerEndpoint"], secrets["ca.crt"], secrets["token"], cluster.Name, cluster.NodeIP, cluster.ControlPlaneAddress)) + if err != nil { + log.Fatalf("%s %s", util.Cross, err) + } } func installWorker(cluster Cluster, valuesName string, helmChartConfig HelmChartConfiguration) { From 80ebd99e8b256a3b2637755e8245a10fd5773bb2 Mon Sep 17 00:00:00 2001 From: Priyank Upadhyay Date: Tue, 7 Feb 2023 13:19:18 +0530 Subject: [PATCH 3/7] fix(): update skip ui installation message Signed-off-by: Priyank Upadhyay --- pkg/internal/enterprise.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/internal/enterprise.go b/pkg/internal/enterprise.go index a569ad8..8caf42c 100644 --- a/pkg/internal/enterprise.go +++ b/pkg/internal/enterprise.go @@ -22,7 +22,7 @@ kubeslice: func InstallKubeSliceUI(ApplicationConfiguration *ConfigurationSpecs) { util.Printf("\nInstalling KubeSlice Manager...") if ApplicationConfiguration.Configuration.HelmChartConfiguration.UIChart.ChartName == "" { - util.Printf("%s UI Helm Chart not found. Update UI chart configuration in topology file.", util.Cross) + util.Printf("%s Skipping Kubeslice Manager installaition. UI Helm Chart not found in topology file.", util.Warn) return } cc := ApplicationConfiguration.Configuration.ClusterConfiguration From 9a89db83786e2481ba4a99d8731912cc11d27bcb Mon Sep 17 00:00:00 2001 From: Priyank Upadhyay Date: Tue, 7 Feb 2023 16:04:20 +0530 Subject: [PATCH 4/7] fix(): aded info icon Signed-off-by: Priyank Upadhyay --- util/print-util.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/util/print-util.go b/util/print-util.go index 799d858..9583c93 100644 --- a/util/print-util.go +++ b/util/print-util.go @@ -9,7 +9,8 @@ const ( Cross = string(rune(0x274c)) Tick = string(rune(0x2714)) Wait = string(rune(0x267B)) - Run = string(rune(0x1F3C3)) + Run = string(rune(0x1F3C3)) + Warn = string(rune(0x26A0)) ) func Printf(format string, a ...interface{}) { @@ -27,4 +28,4 @@ func Fatalf(format string, a ...interface{}) { fmt.Println(format + "\n") } os.Exit(1) -} \ No newline at end of file +} From 984991657fff8aa505ac881e7639ec3a89ff94df Mon Sep 17 00:00:00 2001 From: Priyank Upadhyay Date: Mon, 20 Feb 2023 10:59:59 +0530 Subject: [PATCH 5/7] fix(): conditions added to check cluster type Signed-off-by: Priyank Upadhyay --- pkg/internal/bootstrap-configuration.go | 2 +- pkg/internal/get-network-info.go | 2 +- pkg/internal/verify-executables.go | 2 +- pkg/slicectl.go | 6 +++--- samples/template.yaml | 1 + 5 files changed, 7 insertions(+), 6 deletions(-) diff --git a/pkg/internal/bootstrap-configuration.go b/pkg/internal/bootstrap-configuration.go index b08771d..4f17c6b 100644 --- a/pkg/internal/bootstrap-configuration.go +++ b/pkg/internal/bootstrap-configuration.go @@ -38,7 +38,7 @@ type ClusterConfiguration struct { KubeConfigPath string `yaml:"kube_config_path"` ControllerCluster Cluster `yaml:"controller"` WorkerClusters []Cluster `yaml:"workers"` - ClusterType string `yaml:"cluster"` + ClusterType string `yaml:"cluster_type"` } type Cluster struct { diff --git a/pkg/internal/get-network-info.go b/pkg/internal/get-network-info.go index 3d85a15..de8f623 100644 --- a/pkg/internal/get-network-info.go +++ b/pkg/internal/get-network-info.go @@ -13,7 +13,7 @@ import ( func GatherNetworkInformation(ApplicationConfiguration *ConfigurationSpecs) { util.Printf("\nFetching Network Address for Clusters...") - if ApplicationConfiguration.Configuration.ClusterConfiguration.Profile == "" { + if ApplicationConfiguration.Configuration.ClusterConfiguration.Profile == "" && ApplicationConfiguration.Configuration.ClusterConfiguration.ClusterType != "kind" { setControlPlaneAddress(&ApplicationConfiguration.Configuration.ClusterConfiguration) setNodeIP(&ApplicationConfiguration.Configuration.ClusterConfiguration) } else { diff --git a/pkg/internal/verify-executables.go b/pkg/internal/verify-executables.go index 8ca5a81..8545150 100644 --- a/pkg/internal/verify-executables.go +++ b/pkg/internal/verify-executables.go @@ -14,7 +14,7 @@ import ( func VerifyExecutables(ApplicationConfiguration *ConfigurationSpecs) { util.Printf("Verifying Executables...") time.Sleep(200 * time.Millisecond) - if ApplicationConfiguration.Configuration.ClusterConfiguration.Profile != "" { + if ApplicationConfiguration.Configuration.ClusterConfiguration.Profile != "" || ApplicationConfiguration.Configuration.ClusterConfiguration.ClusterType == "kind" { util.ExecutablePaths = map[string]string{ "kind": "kind", "kubectl": "kubectl", diff --git a/pkg/slicectl.go b/pkg/slicectl.go index e221241..d590a80 100644 --- a/pkg/slicectl.go +++ b/pkg/slicectl.go @@ -62,9 +62,9 @@ func basicInstall(skipSteps map[string]string) { if !skipKind { internal.CreateKindClusters(ApplicationConfiguration) } - if !skipCalico { - internal.InstallCalico(&ApplicationConfiguration.Configuration.ClusterConfiguration) - } + } + if (ApplicationConfiguration.Configuration.ClusterConfiguration.Profile != "" || ApplicationConfiguration.Configuration.ClusterConfiguration.ClusterType == "kind") && !skipCalico { + internal.InstallCalico(&ApplicationConfiguration.Configuration.ClusterConfiguration) } internal.GatherNetworkInformation(ApplicationConfiguration) internal.AddHelmCharts(ApplicationConfiguration) diff --git a/samples/template.yaml b/samples/template.yaml index 702a6c0..f1d4a5c 100644 --- a/samples/template.yaml +++ b/samples/template.yaml @@ -2,6 +2,7 @@ configuration: cluster_configuration: profile: #{the KubeSlice Profile for the demo. Possible values [full-demo, minimal-demo]} kube_config_path: #{specify the kube config file to use for topology setup; for topology only} + cluster_type: #{optional: specify the type of cluster. Valid values are kind, cloud, data-center} controller: name: #{the user defined name of the controller cluster} context_name: #{the name of the context to use from kubeconfig file; for topology only} From a84539fda24f50d17b7c54ae091df8a6c0bbb524 Mon Sep 17 00:00:00 2001 From: Priyank Upadhyay Date: Mon, 20 Feb 2023 18:00:31 +0530 Subject: [PATCH 6/7] chore(): Version bump Signed-off-by: Priyank Upadhyay --- cmd/root.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/root.go b/cmd/root.go index c60983b..7db63dd 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -8,7 +8,7 @@ import ( // "github.com/spf13/cobra/doc" ) -var version = "0.4.2" +var version = "0.4.3" var rootCmd = &cobra.Command{ Use: "kubeslice-cli", Version: version, From f7f9e58622017f3e4ba9c2b9e7ab410e1fd8664f Mon Sep 17 00:00:00 2001 From: Priyank Upadhyay <105195271+priyank-upadhyay@users.noreply.github.com> Date: Mon, 20 Feb 2023 18:01:44 +0530 Subject: [PATCH 7/7] Update kubeslice-cli_install.md Signed-off-by: Priyank Upadhyay <105195271+priyank-upadhyay@users.noreply.github.com> --- doc/kubeslice-cli_install.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/kubeslice-cli_install.md b/doc/kubeslice-cli_install.md index ee349fb..e58a36b 100644 --- a/doc/kubeslice-cli_install.md +++ b/doc/kubeslice-cli_install.md @@ -36,7 +36,7 @@ kubeslice-cli install [flags] - worker-registration: Skips the registration of KubeSlice Workers on the Controller - worker: Skips the installation of KubeSlice Worker - demo: Skips the installation of additional example applications - - ui: Skips the installtion of enterprise UI components (Kubeslice-Manager) + - ui: Skips the installtion of enterprise UI components (Kubeslice-Manager) ``` ### Options inherited from parent commands