Skip to content

Commit ddc0a30

Browse files
committed
Allow the override of the default namespace
Signed-off-by: Joe Rocklin <joe.rocklin@gmail.com>
1 parent 20d7d37 commit ddc0a30

File tree

3 files changed

+25
-19
lines changed

3 files changed

+25
-19
lines changed

cmd/aws-service-operator/main.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717
var (
1818
// cfgFile, masterURL, kubeConfig, awsRegion all help support passed in flags into the server
1919
cfgFile, masterURL, kubeconfig, awsRegion, logLevel, logFile, resources, clusterName, bucket, accountID string
20+
defaultNamespace string
2021

2122
// rootCmd represents the base command when called without any subcommands
2223
rootCmd = &cobra.Command{
@@ -50,6 +51,7 @@ func init() {
5051
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")
5152
rootCmd.PersistentFlags().StringVarP(&bucket, "bucket", "b", "aws-operator", "To configure the operator you need a base bucket to contain the resources")
5253
rootCmd.PersistentFlags().StringVarP(&accountID, "account-id", "a", "", "AWS Account ID, this is used to configure outputs and operate on the proper account.")
54+
rootCmd.PersistentFlags().StringVarP(&defaultNamespace, "default-namespace", "", "default", "The default namespace in which to look for CloudFormation templates")
5355

5456
viper.BindPFlag("config", rootCmd.PersistentFlags().Lookup("config"))
5557
viper.BindPFlag("masterurl", rootCmd.PersistentFlags().Lookup("master-url"))
@@ -61,6 +63,7 @@ func init() {
6163
viper.BindPFlag("clustername", rootCmd.PersistentFlags().Lookup("cluster-name"))
6264
viper.BindPFlag("bucket", rootCmd.PersistentFlags().Lookup("bucket"))
6365
viper.BindPFlag("accountid", rootCmd.PersistentFlags().Lookup("account-id"))
66+
viper.BindPFlag("defaultnamespace", rootCmd.PersistentFlags().Lookup("default-namespace"))
6467
}
6568

6669
// initConfig reads in config file and ENV variables if set.
@@ -118,10 +121,11 @@ func getConfig() (c *config.Config, err error) {
118121
FullTimestamps: true,
119122
DisableTimestamps: false,
120123
},
121-
Resources: resourcesMap,
122-
ClusterName: clusterName,
123-
Bucket: bucket,
124-
AccountID: accountID,
124+
Resources: resourcesMap,
125+
ClusterName: clusterName,
126+
Bucket: bucket,
127+
AccountID: accountID,
128+
DefaultNamespace: defaultNamespace,
125129
}
126130

127131
err = c.CreateContext(masterURL, kubeconfig)

pkg/config/types.go

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package config
22

33
import (
44
"fmt"
5+
56
"github.com/aws/aws-sdk-go/aws/session"
67
awsclient "github.com/awslabs/aws-service-operator/pkg/client/clientset/versioned/typed/service-operator.aws/v1alpha1"
78
"github.com/sirupsen/logrus"
@@ -13,20 +14,21 @@ import (
1314

1415
// Config defines the configuration for the operator
1516
type Config struct {
16-
Region string
17-
Kubeconfig string
18-
MasterURL string
19-
AWSSession *session.Session
20-
AWSClientset awsclient.ServiceoperatorV1alpha1Interface
21-
KubeClientset kubernetes.Interface
22-
RESTConfig *rest.Config
23-
LoggingConfig *LoggingConfig
24-
Logger *logrus.Entry
25-
Resources map[string]bool
26-
ClusterName string
27-
Bucket string
28-
AccountID string
29-
Recorder record.EventRecorder
17+
Region string
18+
Kubeconfig string
19+
MasterURL string
20+
AWSSession *session.Session
21+
AWSClientset awsclient.ServiceoperatorV1alpha1Interface
22+
KubeClientset kubernetes.Interface
23+
RESTConfig *rest.Config
24+
LoggingConfig *LoggingConfig
25+
Logger *logrus.Entry
26+
Resources map[string]bool
27+
ClusterName string
28+
Bucket string
29+
AccountID string
30+
DefaultNamespace string
31+
Recorder record.EventRecorder
3032
}
3133

3234
// LoggingConfig defines the attributes for the logger

pkg/helpers/helpers.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ func GetCloudFormationTemplate(config *config.Config, rType string, name string,
9595
cName = rType
9696
}
9797
if namespace == "" {
98-
cNamespace = "default"
98+
cNamespace = config.DefaultNamespace
9999
}
100100

101101
resource, err := clientSet.CloudFormationTemplates(cNamespace).Get(cName, metav1.GetOptions{})

0 commit comments

Comments
 (0)