diff --git a/pkg/apis/mobilesecurityservice/v1alpha1/mobilesecurityservice_types.go b/pkg/apis/mobilesecurityservice/v1alpha1/mobilesecurityservice_types.go index 60458ad5..7241d3f2 100644 --- a/pkg/apis/mobilesecurityservice/v1alpha1/mobilesecurityservice_types.go +++ b/pkg/apis/mobilesecurityservice/v1alpha1/mobilesecurityservice_types.go @@ -38,8 +38,9 @@ type MobileSecurityServiceSpec struct { OAuthPort int32 `json:"oAuthPort"` //CR optional configuration values - ConfigMapName string `json:"configMapName,omitempty"` - RouteName string `json:"routeName,omitempty"` + ConfigMapName string `json:"configMapName,omitempty"` + RouteName string `json:"routeName,omitempty"` + SkipNamespaceValidation bool `json:"skipNamespaceValidation,omitempty"` } // MobileSecurityServiceStatus defines the observed state of MobileSecurityService diff --git a/pkg/apis/mobilesecurityservice/v1alpha1/mobilesecurityserviceapp_types.go b/pkg/apis/mobilesecurityservice/v1alpha1/mobilesecurityserviceapp_types.go index 7aa1383e..ce5233f7 100644 --- a/pkg/apis/mobilesecurityservice/v1alpha1/mobilesecurityserviceapp_types.go +++ b/pkg/apis/mobilesecurityservice/v1alpha1/mobilesecurityserviceapp_types.go @@ -13,8 +13,11 @@ type MobileSecurityServiceAppSpec struct { // INSERT ADDITIONAL SPEC FIELDS - desired state of cluster // Important: Run "operator-sdk generate k8s" to regenerate code after modifying this file // Add custom validation using kubebuilder tags: https://book.kubebuilder.io/beyond_basics/generating_crd.html - AppName string `json:"appName"` - AppId string `json:"appId"` + AppName string `json:"appName"` + AppId string `json:"appId"` + + // Optional configuration values + SkipNamespaceValidation bool `json:"skipNamespaceValidation,omitempty"` } // MobileSecurityServiceAppStatus defines the observed state of MobileSecurityServiceApp @@ -24,7 +27,7 @@ type MobileSecurityServiceAppStatus struct { // Important: Run "operator-sdk generate k8s" to regenerate code after modifying this file // Add custom validation using kubebuilder tags: https://book.kubebuilder.io/beyond_basics/generating_crd.html SDKConfigMapName string `json:"sdkConfigMapName"` - BindStatus string `json:"bindStatus"` + BindStatus string `json:"bindStatus"` } // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object diff --git a/pkg/apis/mobilesecurityservice/v1alpha1/mobilesecurityservicedb_types.go b/pkg/apis/mobilesecurityservice/v1alpha1/mobilesecurityservicedb_types.go index 922a8793..807690db 100644 --- a/pkg/apis/mobilesecurityservice/v1alpha1/mobilesecurityservicedb_types.go +++ b/pkg/apis/mobilesecurityservice/v1alpha1/mobilesecurityservicedb_types.go @@ -1,10 +1,9 @@ package v1alpha1 import ( - "k8s.io/api/core/v1" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + v1 "k8s.io/api/core/v1" "k8s.io/api/extensions/v1beta1" - + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) // EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN! @@ -18,13 +17,13 @@ type MobileSecurityServiceDBSpec struct { // Add custom validation using kubebuilder tags: https://book.kubebuilder.io/beyond_basics/generating_crd.html //Enviroment Variables for the DB when the Service configMap was not found - DatabaseName string `json:"databaseName,omitempty"` - DatabasePassword string `json:"databasePassword,omitempty"` - DatabaseUser string `json:"databaseUser,omitempty"` - DatabaseNameParam string `json:"databaseNameParam"` - DatabasePasswordParam string `json:"databasePasswordParam"` - DatabaseUserParam string `json:"databaseUserParam"` - DatabasePort int32 `json:"databasePort"` + DatabaseName string `json:"databaseName,omitempty"` + DatabasePassword string `json:"databasePassword,omitempty"` + DatabaseUser string `json:"databaseUser,omitempty"` + DatabaseNameParam string `json:"databaseNameParam"` + DatabasePasswordParam string `json:"databasePasswordParam"` + DatabaseUserParam string `json:"databaseUserParam"` + DatabasePort int32 `json:"databasePort"` //CR mandatory configuration values Size int32 `json:"size"` @@ -33,6 +32,9 @@ type MobileSecurityServiceDBSpec struct { DatabaseMemoryLimit string `json:"databaseMemoryLimit"` DatabaseMemoryRequest string `json:"databaseMemoryRequest"` DatabaseStorageRequest string `json:"databaseStorageRequest"` + + // Optional configuration values + SkipNamespaceValidation bool `json:"skipNamespaceValidation,omitempty"` } // MobileSecurityServiceDBStatus defines the observed state of MobileSecurityServiceDB @@ -41,12 +43,12 @@ type MobileSecurityServiceDBStatus struct { // INSERT ADDITIONAL STATUS FIELD - define observed state of cluster // Important: Run "operator-sdk generate k8s" to regenerate code after modifying this file // Add custom validation using kubebuilder tags: https://book.kubebuilder.io/beyond_basics/generating_crd.html - PersistentVolumeClaimName string `json:"persistentVolumeClaimName"` - DeploymentName string `json:"deploymentName"` - DeploymentStatus v1beta1.DeploymentStatus `json:"deploymentStatus"` - ServiceName string `json:"serviceName"` - ServiceStatus v1.ServiceStatus `json:"serviceStatus"` - DatabaseStatus string `json:databaseStatus"` + PersistentVolumeClaimName string `json:"persistentVolumeClaimName"` + DeploymentName string `json:"deploymentName"` + DeploymentStatus v1beta1.DeploymentStatus `json:"deploymentStatus"` + ServiceName string `json:"serviceName"` + ServiceStatus v1.ServiceStatus `json:"serviceStatus"` + DatabaseStatus string `json:databaseStatus"` } // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object diff --git a/pkg/controller/mobilesecurityservice/controller.go b/pkg/controller/mobilesecurityservice/controller.go index 14c5a5f4..98886c89 100644 --- a/pkg/controller/mobilesecurityservice/controller.go +++ b/pkg/controller/mobilesecurityservice/controller.go @@ -2,6 +2,7 @@ package mobilesecurityservice import ( "context" + mobilesecurityservicev1alpha1 "github.com/aerogear/mobile-security-service-operator/pkg/apis/mobilesecurityservice/v1alpha1" "github.com/aerogear/mobile-security-service-operator/pkg/utils" "github.com/go-logr/logr" @@ -18,10 +19,10 @@ import ( ) const ( - CONFIGMAP = "ConfigMap" - DEEPLOYMENT = "Deployment" - SERVICE = "Service" - ROUTE = "Route" + CONFIGMAP = "ConfigMap" + DEEPLOYMENT = "Deployment" + SERVICE = "Service" + ROUTE = "Route" ) var log = logf.Log.WithName("controller_mobilesecurityservice") @@ -69,7 +70,7 @@ func add(mgr manager.Manager, r reconcile.Reconciler) error { } //Route - if err:= watchRoute(c); err != nil { + if err := watchRoute(c); err != nil { return err } @@ -98,7 +99,7 @@ func (r *ReconcileMobileSecurityService) update(obj runtime.Object, reqLogger lo } //Create the factory object and requeue -func (r *ReconcileMobileSecurityService) create( instance *mobilesecurityservicev1alpha1.MobileSecurityService, reqLogger logr.Logger, kind string, err error) (reconcile.Result, error) { +func (r *ReconcileMobileSecurityService) create(instance *mobilesecurityservicev1alpha1.MobileSecurityService, reqLogger logr.Logger, kind string, err error) (reconcile.Result, error) { obj, errBuildObject := r.buildFactory(reqLogger, instance, kind) if errBuildObject != nil { return reconcile.Result{}, errBuildObject @@ -118,7 +119,7 @@ func (r *ReconcileMobileSecurityService) create( instance *mobilesecurityservice } -//buildFactory will return the resource according to the kind defined +// buildFactory will return the resource according to the kind defined func (r *ReconcileMobileSecurityService) buildFactory(reqLogger logr.Logger, instance *mobilesecurityservicev1alpha1.MobileSecurityService, kind string) (runtime.Object, error) { reqLogger.Info("Check "+kind, "into the namespace", instance.Namespace) switch kind { @@ -136,8 +137,6 @@ func (r *ReconcileMobileSecurityService) buildFactory(reqLogger logr.Logger, ins } } - - // Reconcile reads that state of the cluster for a MobileSecurityService object and makes changes based on the state read // and what is in the MobileSecurityService.Spec // Note: @@ -147,13 +146,21 @@ func (r *ReconcileMobileSecurityService) Reconcile(request reconcile.Request) (r reqLogger := log.WithValues("Request.Namespace", request.Namespace, "Request.Name", request.Name) reqLogger.Info("Reconciling Mobile Security Service ...") + instance := &mobilesecurityservicev1alpha1.MobileSecurityService{} + + //Fetch the MobileSecurityService instance + err := r.client.Get(context.TODO(), request.NamespacedName, instance) + if err != nil { + return fetch(r, reqLogger, err) + } + // FIXME: Check if is a valid namespace // We should not checked if the namespace is valid or not. It is an workaround since currently is not possible watch/cache a List of Namespaces // The impl to allow do it is done and merged in the master branch of the lib but not released in an stable version. It should be removed when this feature be impl. // See the PR which we are working on to update the deps and have this feature: https://github.com/operator-framework/operator-sdk/pull/1388 - if isValidNamespace, err:= utils.IsValidOperatorNamespace(request.Namespace); err != nil || isValidNamespace == false { + if isValidNamespace, err := utils.IsValidOperatorNamespace(request.Namespace, instance.Spec.SkipNamespaceValidation); err != nil || isValidNamespace == false { // Stop reconcile - operatorNamespace, _ := k8sutil.GetOperatorNamespace(); + operatorNamespace, _ := k8sutil.GetOperatorNamespace() reqLogger.Error(err, "Unable to reconcile Mobile Security Service", "Request.Namespace", request.Namespace, "isValidNamespace", isValidNamespace, "Operator.Namespace", operatorNamespace) return reconcile.Result{}, nil } @@ -161,14 +168,6 @@ func (r *ReconcileMobileSecurityService) Reconcile(request reconcile.Request) (r reqLogger.Info("Valid namespace for Mobile Security Service", "Namespace", request.Namespace) reqLogger.Info("Start Reconciling Mobile Security Service ...") - instance := &mobilesecurityservicev1alpha1.MobileSecurityService{} - - //Fetch the MobileSecurityService instance - err := r.client.Get(context.TODO(), request.NamespacedName, instance) - if err != nil { - return fetch(r, reqLogger, err) - } - //Check specs if !hasMandatorySpecs(instance, reqLogger) { return reconcile.Result{Requeue: true}, nil @@ -209,7 +208,7 @@ func (r *ReconcileMobileSecurityService) Reconcile(request reconcile.Request) (r } //Update status for deployment - deploymentStatus, err := r.updateDeploymentStatus(reqLogger,instance) + deploymentStatus, err := r.updateDeploymentStatus(reqLogger, instance) if err != nil { return reconcile.Result{}, err } @@ -227,7 +226,7 @@ func (r *ReconcileMobileSecurityService) Reconcile(request reconcile.Request) (r } //Update status for App - if err:= r.updateStatus(reqLogger, configMapStatus, deploymentStatus, serviceStatus, routeStatus, instance); err != nil { + if err := r.updateStatus(reqLogger, configMapStatus, deploymentStatus, serviceStatus, routeStatus, instance); err != nil { return reconcile.Result{}, err } diff --git a/pkg/controller/mobilesecurityserviceapp/controller.go b/pkg/controller/mobilesecurityserviceapp/controller.go index c7ad52bc..9fb6dbd2 100644 --- a/pkg/controller/mobilesecurityserviceapp/controller.go +++ b/pkg/controller/mobilesecurityserviceapp/controller.go @@ -2,6 +2,7 @@ package mobilesecurityserviceapp import ( "context" + mobilesecurityservicev1alpha1 "github.com/aerogear/mobile-security-service-operator/pkg/apis/mobilesecurityservice/v1alpha1" "github.com/aerogear/mobile-security-service-operator/pkg/models" "github.com/aerogear/mobile-security-service-operator/pkg/service" @@ -109,13 +110,21 @@ func (r *ReconcileMobileSecurityServiceApp) Reconcile(request reconcile.Request) reqLogger := log.WithValues("Request.Namespace", request.Namespace, "Request.Name", request.Name) reqLogger.Info("Reconciling MobileSecurityServiceApp") + instance := &mobilesecurityservicev1alpha1.MobileSecurityServiceApp{} + + //Fetch the MobileSecurityService instance + err := r.client.Get(context.TODO(), request.NamespacedName, instance) + if err != nil { + return fetch(r, reqLogger, err) + } + // FIXME: Check if is a valid namespace // We should not checked if the namespace is valid or not. It is an workaround since currently is not possible watch/cache a List of Namespaces // The impl to allow do it is done and merged in the master branch of the lib but not released in an stable version. It should be removed when this feature be impl. // See the PR which we are working on to update the deps and have this feature: https://github.com/operator-framework/operator-sdk/pull/1388 - if isValidNamespace, err:= utils.IsValidAppNamespace(request.Namespace); err != nil || isValidNamespace == false { + if isValidNamespace, err := utils.IsValidAppNamespace(request.Namespace); err != nil || isValidNamespace == false { // Stop reconcile - envVar, _ := utils.GetAppNamespaces(); + envVar, _ := utils.GetAppNamespaces() reqLogger.Error(err, "Unable to reconcile Mobile Security Service App", "Request.Namespace", request.Namespace, "isValidNamespace", isValidNamespace, "EnvVar.APP_NAMESPACES", envVar) return reconcile.Result{}, nil } @@ -123,17 +132,9 @@ func (r *ReconcileMobileSecurityServiceApp) Reconcile(request reconcile.Request) reqLogger.Info("Valid namespace for MobileSecurityServiceApp", "Namespace", request.Namespace) reqLogger.Info("Start Reconciling MobileSecurityServiceApp ...") - instance := &mobilesecurityservicev1alpha1.MobileSecurityServiceApp{} - - //Fetch the MobileSecurityService instance - err := r.client.Get(context.TODO(), request.NamespacedName, instance) - if err != nil { - return fetch(r, reqLogger, err) - } - reqLogger.Info("Checking for service instance ...") serviceInstance := &mobilesecurityservicev1alpha1.MobileSecurityService{} - if err := r.client.Get(context.TODO(), types.NamespacedName{Name: utils.SERVICE_INSTANCE_NAME, Namespace: utils.SERVICE_INSTANCE_NAMESPACE }, serviceInstance); err != nil { + if err := r.client.Get(context.TODO(), types.NamespacedName{Name: utils.SERVICE_INSTANCE_NAME, Namespace: utils.SERVICE_INSTANCE_NAMESPACE}, serviceInstance); err != nil { // Return and don't create reqLogger.Info("Mobile Security Service instance resource not found. Ignoring since object must be deleted") return reconcile.Result{}, nil @@ -146,7 +147,7 @@ func (r *ReconcileMobileSecurityServiceApp) Reconcile(request reconcile.Request) reqLogger.Info("Checking if the route already exists ...") route := &routev1.Route{} - if err := r.client.Get(context.TODO(), types.NamespacedName{Name: utils.GetRouteName(serviceInstance), Namespace: utils.SERVICE_INSTANCE_NAMESPACE }, route); err != nil { + if err := r.client.Get(context.TODO(), types.NamespacedName{Name: utils.GetRouteName(serviceInstance), Namespace: utils.SERVICE_INSTANCE_NAMESPACE}, route); err != nil { return reconcile.Result{}, err } @@ -155,7 +156,7 @@ func (r *ReconcileMobileSecurityServiceApp) Reconcile(request reconcile.Request) //Check if ConfigMap for the app exist, if not create one. if _, err := r.fetchSDKConfigMap(reqLogger, instance); err != nil { - return r.create(instance, CONFIGMAP, serviceAPI , reqLogger, err) + return r.create(instance, CONFIGMAP, serviceAPI, reqLogger, err) } //Check if App is Bind in the REST Service, if not then bind it diff --git a/pkg/controller/mobilesecurityservicedb/controller.go b/pkg/controller/mobilesecurityservicedb/controller.go index 1012ceaf..c322f893 100644 --- a/pkg/controller/mobilesecurityservicedb/controller.go +++ b/pkg/controller/mobilesecurityservicedb/controller.go @@ -2,6 +2,8 @@ package mobilesecurityservicedb import ( "context" + "time" + mobilesecurityservicev1alpha1 "github.com/aerogear/mobile-security-service-operator/pkg/apis/mobilesecurityservice/v1alpha1" "github.com/aerogear/mobile-security-service-operator/pkg/utils" "github.com/go-logr/logr" @@ -16,7 +18,6 @@ import ( "sigs.k8s.io/controller-runtime/pkg/reconcile" logf "sigs.k8s.io/controller-runtime/pkg/runtime/log" "sigs.k8s.io/controller-runtime/pkg/source" - "time" ) var log = logf.Log.WithName("controller_mobilesecurityservicedb") @@ -82,7 +83,7 @@ type ReconcileMobileSecurityServiceDB struct { } //Update the object and reconcile it -func (r *ReconcileMobileSecurityServiceDB) update( obj runtime.Object, reqLogger logr.Logger) (reconcile.Result, error) { +func (r *ReconcileMobileSecurityServiceDB) update(obj runtime.Object, reqLogger logr.Logger) (reconcile.Result, error) { err := r.client.Update(context.TODO(), obj) if err != nil { reqLogger.Error(err, "Failed to update Spec") @@ -119,7 +120,7 @@ func (r *ReconcileMobileSecurityServiceDB) buildFactory(instance *mobilesecurity case PVC: return r.buildPVCForDB(instance), nil case DEEPLOYMENT: - return r.buildDBDeployment(instance,serviceInstance), nil + return r.buildDBDeployment(instance, serviceInstance), nil case SERVICE: return r.buildDBService(instance), nil default: @@ -137,13 +138,21 @@ func (r *ReconcileMobileSecurityServiceDB) Reconcile(request reconcile.Request) reqLogger := log.WithValues("Request.Namespace", request.Namespace, "Request.Name", request.Name) reqLogger.Info("Reconciling Mobile Security Service Database") + instance := &mobilesecurityservicev1alpha1.MobileSecurityServiceDB{} + + //Fetch the MobileSecurityService instance + err := r.client.Get(context.TODO(), request.NamespacedName, instance) + if err != nil { + return fetch(r, reqLogger, err) + } + // FIXME: Check if is a valid namespace // We should not checked if the namespace is valid or not. It is an workaround since currently is not possible watch/cache a List of Namespaces // The impl to allow do it is done and merged in the master branch of the lib but not released in an stable version. It should be removed when this feature be impl. // See the PR which we are working on to update the deps and have this feature: https://github.com/operator-framework/operator-sdk/pull/1388 - if isValidNamespace, err:= utils.IsValidOperatorNamespace(request.Namespace); err != nil || isValidNamespace == false { + if isValidNamespace, err := utils.IsValidOperatorNamespace(request.Namespace, instance.Spec.SkipNamespaceValidation); err != nil || isValidNamespace == false { // Stop reconcile - operatorNamespace, _ := k8sutil.GetOperatorNamespace(); + operatorNamespace, _ := k8sutil.GetOperatorNamespace() reqLogger.Error(err, "Unable to reconcile Mobile Security Service Database", "Request.Namespace", request.Namespace, "isValidNamespace", isValidNamespace, "Operator.Namespace", operatorNamespace) return reconcile.Result{}, nil } @@ -151,16 +160,9 @@ func (r *ReconcileMobileSecurityServiceDB) Reconcile(request reconcile.Request) reqLogger.Info("Valid namespace for Mobile Security Service DB", "Namespace", request.Namespace) reqLogger.Info("Start Reconciling Mobile Security Service DB ...") - instance := &mobilesecurityservicev1alpha1.MobileSecurityServiceDB{} - - //Fetch the MobileSecurityService instance - err := r.client.Get(context.TODO(), request.NamespacedName, instance) - if err != nil { - return fetch(r, reqLogger, err) - } - //Check if Deployment for the app exist, if not create one deployment, err := r.fetchDBDeployment(reqLogger, instance) + if err != nil { // To give time for the mobile security service be created time.Sleep(30 * time.Second) @@ -168,7 +170,7 @@ func (r *ReconcileMobileSecurityServiceDB) Reconcile(request reconcile.Request) // if the Instance cannot be found and/or its configMap was not created than the default values specified in its CR will be used reqLogger.Info("Checking for service instance ...") serviceInstance := &mobilesecurityservicev1alpha1.MobileSecurityService{} - r.client.Get(context.TODO(), types.NamespacedName{Name: utils.SERVICE_INSTANCE_NAME, Namespace: utils.SERVICE_INSTANCE_NAMESPACE }, serviceInstance) + r.client.Get(context.TODO(), types.NamespacedName{Name: utils.SERVICE_INSTANCE_NAME, Namespace: utils.SERVICE_INSTANCE_NAMESPACE}, serviceInstance) return r.create(instance, serviceInstance, DEEPLOYMENT, reqLogger, err) } @@ -191,7 +193,7 @@ func (r *ReconcileMobileSecurityServiceDB) Reconcile(request reconcile.Request) } //Update status for deployment - deploymentStatus, err := r.updateDeploymentStatus(reqLogger,instance) + deploymentStatus, err := r.updateDeploymentStatus(reqLogger, instance) if err != nil { return reconcile.Result{}, err } @@ -209,7 +211,7 @@ func (r *ReconcileMobileSecurityServiceDB) Reconcile(request reconcile.Request) } //Update status for DB - if err:= r.updateDBStatus(reqLogger, deploymentStatus, serviceStatus, pvcStatus, instance); err != nil { + if err := r.updateDBStatus(reqLogger, deploymentStatus, serviceStatus, pvcStatus, instance); err != nil { return reconcile.Result{}, err } diff --git a/pkg/utils/utils.go b/pkg/utils/utils.go index 26ec6e14..044f0cf0 100644 --- a/pkg/utils/utils.go +++ b/pkg/utils/utils.go @@ -2,10 +2,11 @@ package utils import ( "fmt" - mobilesecurityservicev1alpha1 "github.com/aerogear/mobile-security-service-operator/pkg/apis/mobilesecurityservice/v1alpha1" - "github.com/operator-framework/operator-sdk/pkg/k8sutil" "os" "strings" + + mobilesecurityservicev1alpha1 "github.com/aerogear/mobile-security-service-operator/pkg/apis/mobilesecurityservice/v1alpha1" + "github.com/operator-framework/operator-sdk/pkg/k8sutil" logf "sigs.k8s.io/controller-runtime/pkg/runtime/log" ) @@ -13,20 +14,20 @@ import ( // which is the namespace where the APP CR can applied. // The namespaces should be informed split by ";". const APP_NAMESPACE_ENV_VAR = "APP_NAMESPACES" -const SERVICE_INSTANCE_NAME = "mobile-security-service" -const SERVICE_INSTANCE_NAMESPACE = "mobile-security-service-operator" +const SERVICE_INSTANCE_NAME = "mobile-security-service" +const SERVICE_INSTANCE_NAMESPACE = "mobile-security-service-operator" var log = logf.Log.WithName("mobile-security-service-operator.utils") -//GetRouteName returns an string name with the name of the router -func GetRouteName(m *mobilesecurityservicev1alpha1.MobileSecurityService) string{ +// GetRouteName returns an string name with the name of the router +func GetRouteName(m *mobilesecurityservicev1alpha1.MobileSecurityService) string { if len(m.Spec.RouteName) > 0 { return m.Spec.RouteName } return m.Name } -//GetConfigMapName returns an string name with the name of the configMap +// GetConfigMapName returns an string name with the name of the configMap func GetConfigMapName(m *mobilesecurityservicev1alpha1.MobileSecurityService) string { if len(m.Spec.ConfigMapName) > 0 { return m.Spec.ConfigMapName @@ -34,8 +35,7 @@ func GetConfigMapName(m *mobilesecurityservicev1alpha1.MobileSecurityService) st return m.Name } - -// GetCustomWatchNamespaces returns the namespace the operator should be watching for changes +// GetAppNamespaces returns the namespace the operator should be watching for changes func GetAppNamespaces() (string, error) { ns, found := os.LookupEnv(APP_NAMESPACE_ENV_VAR) if !found { @@ -44,10 +44,9 @@ func GetAppNamespaces() (string, error) { return ns, nil } - -//IsValidAppNamespace return true when the namespace informed is declared in the ENV VAR APP_NAMESPACES +// IsValidAppNamespace return true when the namespace informed is declared in the ENV VAR APP_NAMESPACES func IsValidAppNamespace(namespace string) (bool, error) { - appNamespacesEnvVar,err := GetAppNamespaces() + appNamespacesEnvVar, err := GetAppNamespaces() if err != nil { log.Error(err, "Unable to check if is app namespace %s is valid", namespace) return false, err @@ -57,13 +56,18 @@ func IsValidAppNamespace(namespace string) (bool, error) { return true, nil } } - err = fmt.Errorf( "Invalid Namespace") + err = fmt.Errorf("Invalid Namespace") return false, err } +// IsValidOperatorNamespace return true when the namespace informed is declared in the ENV VAR APP_NAMESPACES +func IsValidOperatorNamespace(namespace string, skipCheck bool) (bool, error) { + //FIXME: this check is used to bypass validation of namespace. + // This is a workaround and should be removed in the future. + if skipCheck { + return true, nil + } -//IsValidAppNamespace return true when the namespace informed is declared in the ENV VAR APP_NAMESPACES -func IsValidOperatorNamespace(namespace string) (bool, error) { ns, err := k8sutil.GetOperatorNamespace() if err != nil { return false, err @@ -71,6 +75,6 @@ func IsValidOperatorNamespace(namespace string) (bool, error) { if ns == namespace { return true, nil } - err = fmt.Errorf( "Invalid Namespace") + err = fmt.Errorf("Invalid Namespace") return false, err -} \ No newline at end of file +}