diff --git a/build.sh b/build.sh index a2c488f..cad9138 100755 --- a/build.sh +++ b/build.sh @@ -1,6 +1,6 @@ #!/bin/bash -export VERSION="0.0.11" +export VERSION="0.0.12" rm -rf target mkdir -p target diff --git a/cmd/installAuthPortal.go b/cmd/installAuthPortal.go index 8fb98aa..dff855d 100644 --- a/cmd/installAuthPortal.go +++ b/cmd/installAuthPortal.go @@ -28,7 +28,7 @@ var installAuthPortalCmd = &cobra.Command{ pathToValuesYaml = args[0] - openunisonDeployment, err := openunison.NewOpenUnisonDeployment(namespace, operatorChart, orchestraChart, orchestraLoginPortalChart, pathToValuesYaml, secretFile, clusterManagementChart, pathToDbPassword, pathToSmtpPassword, skipClusterManagement, parseChartSlices(&additionalCharts), parseChartSlices(&preCharts)) + openunisonDeployment, err := openunison.NewOpenUnisonDeployment(namespace, operatorChart, orchestraChart, orchestraLoginPortalChart, pathToValuesYaml, secretFile, clusterManagementChart, pathToDbPassword, pathToSmtpPassword, skipClusterManagement, parseChartSlices(&additionalCharts), parseChartSlices(&preCharts), parseNamespaceLabels(&namespaceLabels)) if err != nil { panic(err) @@ -86,6 +86,7 @@ func init() { installAuthPortalCmd.PersistentFlags().StringSliceVarP(&preCharts, "prerun-helm-charts", "u", []string{}, "Comma seperated list of chart=path to deploy charts before OpenUnison is deployed, adding '@version' installs the specific version") installAuthPortalCmd.PersistentFlags().StringSliceVarP(&additionalCharts, "additional-helm-charts", "r", []string{}, "Comma seperated list of chart=path to deploy additional charts after OpenUnison is deployed, adding '@version' installs the specific version") + installAuthPortalCmd.PersistentFlags().StringSliceVarP(&namespaceLabels, "namespace-labels", "j", []string{}, "Comma separated list of name=value of labels to add to the openunison namespace") // Cobra supports local flags which will only run when this command // is called directly, e.g.: // installAuthPortalCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle") diff --git a/cmd/installSatelite.go b/cmd/installSatelite.go index fe3ce41..28e20d4 100644 --- a/cmd/installSatelite.go +++ b/cmd/installSatelite.go @@ -32,7 +32,7 @@ var installSateliteCmd = &cobra.Command{ controlPlaneCtxName := args[1] sateliteCtxName := args[2] - openunisonDeployment, err := openunison.NewSateliteDeployment(namespace, operatorChart, orchestraChart, orchestraLoginPortalChart, pathToValuesYaml, secretFile, controlPlaneCtxName, sateliteCtxName, addClusterChart, pathToSateliteYaml, parseChartSlices(&additionalCharts), parseChartSlices(&preCharts)) + openunisonDeployment, err := openunison.NewSateliteDeployment(namespace, operatorChart, orchestraChart, orchestraLoginPortalChart, pathToValuesYaml, secretFile, controlPlaneCtxName, sateliteCtxName, addClusterChart, pathToSateliteYaml, parseChartSlices(&additionalCharts), parseChartSlices(&preCharts), parseNamespaceLabels(&namespaceLabels)) if err != nil { panic(err) @@ -59,6 +59,8 @@ func init() { preCharts = make([]string, 0) additionalCharts = make([]string, 0) - installSateliteCmd.PersistentFlags().StringSliceVarP(&preCharts, "prerun-helm-charts", "u", []string{}, "Comma seperated list of chart=path to deploy charts before OpenUnison is deployed, adding '@version' installs the specific version") - installSateliteCmd.PersistentFlags().StringSliceVarP(&additionalCharts, "additional-helm-charts", "r", []string{}, "Comma seperated list of chart=path to deploy additional charts after OpenUnison is deployed, adding '@version' installs the specific version") + installSateliteCmd.PersistentFlags().StringSliceVarP(&preCharts, "prerun-helm-charts", "u", []string{}, "Comma separated list of chart=path to deploy charts before OpenUnison is deployed, adding '@version' installs the specific version") + installSateliteCmd.PersistentFlags().StringSliceVarP(&additionalCharts, "additional-helm-charts", "r", []string{}, "Comma separated list of chart=path to deploy additional charts after OpenUnison is deployed, adding '@version' installs the specific version") + + installSateliteCmd.PersistentFlags().StringSliceVarP(&namespaceLabels, "namespace-labels", "j", []string{}, "Comma separated list of name=value of labels to add to the openunison namespace") } diff --git a/cmd/root.go b/cmd/root.go index 4ea0737..72e3335 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -45,6 +45,8 @@ var skipClusterManagement bool var additionalCharts []string var preCharts []string +var namespaceLabels []string + // Execute adds all child commands to the root command and sets flags appropriately. // This is called by main.main(). It only needs to happen once to the rootCmd. func Execute() { @@ -66,6 +68,17 @@ func init() { rootCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle") } +func parseNamespaceLabels(namespaceLabels *[]string) map[string]string { + nsLabelsMap := make(map[string]string) + + for _, labelPair := range *namespaceLabels { + split := strings.Split(labelPair, "=") + nsLabelsMap[split[0]] = split[1] + } + + return nsLabelsMap +} + func parseChartSlices(additionalCharts *[]string) []openunison.HelmChartInfo { var additionalChartsList []openunison.HelmChartInfo for _, chartPair := range *additionalCharts { diff --git a/openunison/deployer.go b/openunison/deployer.go index 1389c38..ad6419a 100644 --- a/openunison/deployer.go +++ b/openunison/deployer.go @@ -80,11 +80,13 @@ type OpenUnisonDeployment struct { additionalCharts []HelmChartInfo preCharts []HelmChartInfo + + namespaceLabels map[string]string } // creates a new deployment structure -func NewOpenUnisonDeployment(namespace string, operatorChart string, orchestraChart string, orchestraLoginPortalChart string, pathToValuesYaml string, secretFile string, clusterManagementChart string, pathToDbPassword string, pathToSmtpPassword string, skipClusterManagement bool, additionalCharts []HelmChartInfo, preCharts []HelmChartInfo) (*OpenUnisonDeployment, error) { - ou, err := NewSateliteDeployment(namespace, operatorChart, orchestraChart, orchestraLoginPortalChart, pathToValuesYaml, secretFile, "", "", "", "", additionalCharts, preCharts) +func NewOpenUnisonDeployment(namespace string, operatorChart string, orchestraChart string, orchestraLoginPortalChart string, pathToValuesYaml string, secretFile string, clusterManagementChart string, pathToDbPassword string, pathToSmtpPassword string, skipClusterManagement bool, additionalCharts []HelmChartInfo, preCharts []HelmChartInfo, namespaceLabels map[string]string) (*OpenUnisonDeployment, error) { + ou, err := NewSateliteDeployment(namespace, operatorChart, orchestraChart, orchestraLoginPortalChart, pathToValuesYaml, secretFile, "", "", "", "", additionalCharts, preCharts, namespaceLabels) if err != nil { return nil, err @@ -99,7 +101,7 @@ func NewOpenUnisonDeployment(namespace string, operatorChart string, orchestraCh } // creates a new deployment structure -func NewSateliteDeployment(namespace string, operatorChart string, orchestraChart string, orchestraLoginPortalChart string, pathToValuesYaml string, secretFile string, controlPlanContextName string, sateliteContextName string, addClusterChart string, pathToSateliteYaml string, additionalCharts []HelmChartInfo, preCharts []HelmChartInfo) (*OpenUnisonDeployment, error) { +func NewSateliteDeployment(namespace string, operatorChart string, orchestraChart string, orchestraLoginPortalChart string, pathToValuesYaml string, secretFile string, controlPlanContextName string, sateliteContextName string, addClusterChart string, pathToSateliteYaml string, additionalCharts []HelmChartInfo, preCharts []HelmChartInfo, namespaceLabels map[string]string) (*OpenUnisonDeployment, error) { ou := &OpenUnisonDeployment{} ou.namespace = namespace @@ -131,6 +133,8 @@ func NewSateliteDeployment(namespace string, operatorChart string, orchestraChar return nil, err } + ou.namespaceLabels = namespaceLabels + return ou, nil } @@ -1721,7 +1725,10 @@ func (ou *OpenUnisonDeployment) checkNamespace(label string, name string) error if err != nil { fmt.Printf("%s namespace %s does not exist, creating\n", label, name) - _, err = ou.clientset.CoreV1().Namespaces().Create(context.TODO(), &v1.Namespace{ObjectMeta: metav1.ObjectMeta{Name: name}}, metav1.CreateOptions{}) + + openUnisonNamespace := &v1.Namespace{ObjectMeta: metav1.ObjectMeta{Name: name, Labels: ou.namespaceLabels}} + + _, err = ou.clientset.CoreV1().Namespaces().Create(context.TODO(), openUnisonNamespace, metav1.CreateOptions{}) if err != nil { return err }