From ddc0a30129cce1d9d5ae429cfc50b8301b6f77dc Mon Sep 17 00:00:00 2001 From: Joe Rocklin Date: Wed, 17 Oct 2018 21:46:58 -0400 Subject: [PATCH] Allow the override of the default namespace Signed-off-by: Joe Rocklin --- cmd/aws-service-operator/main.go | 12 ++++++++---- pkg/config/types.go | 30 ++++++++++++++++-------------- pkg/helpers/helpers.go | 2 +- 3 files changed, 25 insertions(+), 19 deletions(-) diff --git a/cmd/aws-service-operator/main.go b/cmd/aws-service-operator/main.go index 6fab183cd..3c3e86858 100644 --- a/cmd/aws-service-operator/main.go +++ b/cmd/aws-service-operator/main.go @@ -17,6 +17,7 @@ import ( var ( // cfgFile, masterURL, kubeConfig, awsRegion all help support passed in flags into the server cfgFile, masterURL, kubeconfig, awsRegion, logLevel, logFile, resources, clusterName, bucket, accountID string + defaultNamespace string // rootCmd represents the base command when called without any subcommands rootCmd = &cobra.Command{ @@ -50,6 +51,7 @@ func init() { rootCmd.PersistentFlags().StringVarP(&clusterName, "cluster-name", "i", "aws-operator", "Cluster name for the Application to run as, used to label the Cloudformation templated to avoid conflict") rootCmd.PersistentFlags().StringVarP(&bucket, "bucket", "b", "aws-operator", "To configure the operator you need a base bucket to contain the resources") rootCmd.PersistentFlags().StringVarP(&accountID, "account-id", "a", "", "AWS Account ID, this is used to configure outputs and operate on the proper account.") + rootCmd.PersistentFlags().StringVarP(&defaultNamespace, "default-namespace", "", "default", "The default namespace in which to look for CloudFormation templates") viper.BindPFlag("config", rootCmd.PersistentFlags().Lookup("config")) viper.BindPFlag("masterurl", rootCmd.PersistentFlags().Lookup("master-url")) @@ -61,6 +63,7 @@ func init() { viper.BindPFlag("clustername", rootCmd.PersistentFlags().Lookup("cluster-name")) viper.BindPFlag("bucket", rootCmd.PersistentFlags().Lookup("bucket")) viper.BindPFlag("accountid", rootCmd.PersistentFlags().Lookup("account-id")) + viper.BindPFlag("defaultnamespace", rootCmd.PersistentFlags().Lookup("default-namespace")) } // initConfig reads in config file and ENV variables if set. @@ -118,10 +121,11 @@ func getConfig() (c *config.Config, err error) { FullTimestamps: true, DisableTimestamps: false, }, - Resources: resourcesMap, - ClusterName: clusterName, - Bucket: bucket, - AccountID: accountID, + Resources: resourcesMap, + ClusterName: clusterName, + Bucket: bucket, + AccountID: accountID, + DefaultNamespace: defaultNamespace, } err = c.CreateContext(masterURL, kubeconfig) diff --git a/pkg/config/types.go b/pkg/config/types.go index 9b1fb375c..ba924c311 100644 --- a/pkg/config/types.go +++ b/pkg/config/types.go @@ -2,6 +2,7 @@ package config import ( "fmt" + "github.com/aws/aws-sdk-go/aws/session" awsclient "github.com/awslabs/aws-service-operator/pkg/client/clientset/versioned/typed/service-operator.aws/v1alpha1" "github.com/sirupsen/logrus" @@ -13,20 +14,21 @@ import ( // Config defines the configuration for the operator type Config struct { - Region string - Kubeconfig string - MasterURL string - AWSSession *session.Session - AWSClientset awsclient.ServiceoperatorV1alpha1Interface - KubeClientset kubernetes.Interface - RESTConfig *rest.Config - LoggingConfig *LoggingConfig - Logger *logrus.Entry - Resources map[string]bool - ClusterName string - Bucket string - AccountID string - Recorder record.EventRecorder + Region string + Kubeconfig string + MasterURL string + AWSSession *session.Session + AWSClientset awsclient.ServiceoperatorV1alpha1Interface + KubeClientset kubernetes.Interface + RESTConfig *rest.Config + LoggingConfig *LoggingConfig + Logger *logrus.Entry + Resources map[string]bool + ClusterName string + Bucket string + AccountID string + DefaultNamespace string + Recorder record.EventRecorder } // LoggingConfig defines the attributes for the logger diff --git a/pkg/helpers/helpers.go b/pkg/helpers/helpers.go index 75b9202a1..0333ecc2c 100644 --- a/pkg/helpers/helpers.go +++ b/pkg/helpers/helpers.go @@ -95,7 +95,7 @@ func GetCloudFormationTemplate(config *config.Config, rType string, name string, cName = rType } if namespace == "" { - cNamespace = "default" + cNamespace = config.DefaultNamespace } resource, err := clientSet.CloudFormationTemplates(cNamespace).Get(cName, metav1.GetOptions{})