Skip to content

Commit

Permalink
Merge pull request #17 from mlbiam/main
Browse files Browse the repository at this point in the history
add labels to openunison ns
  • Loading branch information
mlbiam authored May 3, 2023
2 parents f360412 + 3832f79 commit af56fe8
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 9 deletions.
2 changes: 1 addition & 1 deletion build.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash

export VERSION="0.0.11"
export VERSION="0.0.12"

rm -rf target
mkdir -p target
Expand Down
3 changes: 2 additions & 1 deletion cmd/installAuthPortal.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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")
Expand Down
8 changes: 5 additions & 3 deletions cmd/installSatelite.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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")
}
13 changes: 13 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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 {
Expand Down
15 changes: 11 additions & 4 deletions openunison/deployer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -131,6 +133,8 @@ func NewSateliteDeployment(namespace string, operatorChart string, orchestraChar
return nil, err
}

ou.namespaceLabels = namespaceLabels

return ou, nil
}

Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit af56fe8

Please sign in to comment.