Feature flag to enable/disable canary + optional prometheus install (#937)
This commit is contained in:
+5
-1
@@ -32,6 +32,7 @@ import (
|
||||
|
||||
"github.com/fission/fission"
|
||||
"github.com/fission/fission/crd"
|
||||
config "github.com/fission/fission/featureconfig"
|
||||
"github.com/fission/fission/fission/logdb"
|
||||
)
|
||||
|
||||
@@ -53,6 +54,7 @@ type (
|
||||
workflowApiUrl string
|
||||
functionNamespace string
|
||||
useIstio bool
|
||||
featureConfig *config.FeatureConfig
|
||||
}
|
||||
|
||||
logDBConfig struct {
|
||||
@@ -62,7 +64,7 @@ type (
|
||||
}
|
||||
)
|
||||
|
||||
func MakeAPI() (*API, error) {
|
||||
func MakeAPI(featureConfig *config.FeatureConfig) (*API, error) {
|
||||
api, err := makeCRDBackedAPI()
|
||||
|
||||
u := os.Getenv("STORAGE_SERVICE_URL")
|
||||
@@ -93,6 +95,8 @@ func MakeAPI() (*API, error) {
|
||||
api.functionNamespace = "fission-function"
|
||||
}
|
||||
|
||||
api.featureConfig = featureConfig
|
||||
|
||||
return api, err
|
||||
}
|
||||
|
||||
|
||||
@@ -344,7 +344,7 @@ func TestMain(m *testing.M) {
|
||||
return
|
||||
}
|
||||
|
||||
go Start(8888, "http://localhost:9090")
|
||||
go Start(8888, true)
|
||||
|
||||
time.Sleep(5 * time.Second)
|
||||
g.client = client.MakeClient("http://localhost:8888")
|
||||
|
||||
@@ -25,10 +25,16 @@ import (
|
||||
log "github.com/sirupsen/logrus"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
|
||||
"github.com/fission/fission"
|
||||
"github.com/fission/fission/crd"
|
||||
)
|
||||
|
||||
func (a *API) CanaryConfigApiCreate(w http.ResponseWriter, r *http.Request) {
|
||||
if !a.featureConfig.CanaryConfig.IsEnabled {
|
||||
a.respondWithError(w, fission.MakeError(http.StatusBadRequest, "Please enable canary feature while installing fission"))
|
||||
return
|
||||
}
|
||||
|
||||
body, err := ioutil.ReadAll(r.Body)
|
||||
if err != nil {
|
||||
a.respondWithError(w, err)
|
||||
@@ -60,6 +66,11 @@ func (a *API) CanaryConfigApiCreate(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
func (a *API) CanaryConfigApiGet(w http.ResponseWriter, r *http.Request) {
|
||||
if !a.featureConfig.CanaryConfig.IsEnabled {
|
||||
a.respondWithError(w, fission.MakeError(http.StatusBadRequest, "Please enable canary feature while installing fission"))
|
||||
return
|
||||
}
|
||||
|
||||
vars := mux.Vars(r)
|
||||
name := vars["canaryConfig"]
|
||||
|
||||
@@ -84,6 +95,11 @@ func (a *API) CanaryConfigApiGet(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
func (a *API) CanaryConfigApiList(w http.ResponseWriter, r *http.Request) {
|
||||
if !a.featureConfig.CanaryConfig.IsEnabled {
|
||||
a.respondWithError(w, fission.MakeError(http.StatusBadRequest, "Please enable canary feature while installing fission"))
|
||||
return
|
||||
}
|
||||
|
||||
ns := a.extractQueryParamFromRequest(r, "namespace")
|
||||
if len(ns) == 0 {
|
||||
ns = metav1.NamespaceDefault
|
||||
@@ -105,6 +121,11 @@ func (a *API) CanaryConfigApiList(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
func (a *API) CanaryConfigApiUpdate(w http.ResponseWriter, r *http.Request) {
|
||||
if !a.featureConfig.CanaryConfig.IsEnabled {
|
||||
a.respondWithError(w, fission.MakeError(http.StatusBadRequest, "Please enable canary feature while installing fission"))
|
||||
return
|
||||
}
|
||||
|
||||
body, err := ioutil.ReadAll(r.Body)
|
||||
if err != nil {
|
||||
a.respondWithError(w, err)
|
||||
@@ -134,6 +155,11 @@ func (a *API) CanaryConfigApiUpdate(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
func (a *API) CanaryConfigApiDelete(w http.ResponseWriter, r *http.Request) {
|
||||
if !a.featureConfig.CanaryConfig.IsEnabled {
|
||||
a.respondWithError(w, fission.MakeError(http.StatusBadRequest, "Please enable canary feature while installing fission"))
|
||||
return
|
||||
}
|
||||
|
||||
vars := mux.Vars(r)
|
||||
name := vars["canaryConfig"]
|
||||
ns := a.extractQueryParamFromRequest(r, "namespace")
|
||||
|
||||
@@ -0,0 +1,65 @@
|
||||
/*
|
||||
Copyright 2018 The Fission Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package controller
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
log "github.com/sirupsen/logrus"
|
||||
"k8s.io/client-go/kubernetes"
|
||||
|
||||
"github.com/fission/fission/canaryconfigmgr"
|
||||
"github.com/fission/fission/crd"
|
||||
config "github.com/fission/fission/featureconfig"
|
||||
)
|
||||
|
||||
func ConfigCanaryFeature(context context.Context, fissionClient *crd.FissionClient, kubeClient *kubernetes.Clientset, featureConfig *config.FeatureConfig) error {
|
||||
// start the appropriate controller
|
||||
if featureConfig.CanaryConfig.IsEnabled {
|
||||
canaryCfgMgr, err := canaryconfigmgr.MakeCanaryConfigMgr(fissionClient, kubeClient, fissionClient.GetCrdClient(),
|
||||
featureConfig.CanaryConfig.PrometheusSvc)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to start canary config manager: %v", err)
|
||||
}
|
||||
canaryCfgMgr.Run(context)
|
||||
log.Printf("Started canary config manager")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// ConfigureFeatures gets the feature config and configures the features that are enabled
|
||||
func ConfigureFeatures(context context.Context, unitTestMode bool, fissionClient *crd.FissionClient, kubeClient *kubernetes.Clientset) (*config.FeatureConfig, error) {
|
||||
// set feature enabled to false if unitTestMode
|
||||
if unitTestMode {
|
||||
featureConfig := &config.FeatureConfig{}
|
||||
return featureConfig, nil
|
||||
}
|
||||
|
||||
// get the featureConfig from config map mounted onto the file system
|
||||
featureConfig, err := config.GetFeatureConfig()
|
||||
if err != nil {
|
||||
log.Printf("Error getting feature config : %v", err)
|
||||
return featureConfig, err
|
||||
}
|
||||
|
||||
// configure respective features
|
||||
// in the future when new optional features are added, we need to add corresponding feature handlers and invoke them here
|
||||
err = ConfigCanaryFeature(context, fissionClient, kubeClient, featureConfig)
|
||||
return featureConfig, err
|
||||
}
|
||||
@@ -21,11 +21,10 @@ import (
|
||||
"log"
|
||||
|
||||
"github.com/fission/fission"
|
||||
"github.com/fission/fission/canaryconfigmgr"
|
||||
"github.com/fission/fission/crd"
|
||||
)
|
||||
|
||||
func Start(port int, prometheusSvc string) {
|
||||
func Start(port int, unitTestFlag bool) {
|
||||
// setup a signal handler for SIGTERM
|
||||
fission.SetupStackTraceHandler()
|
||||
|
||||
@@ -44,16 +43,16 @@ func Start(port int, prometheusSvc string) {
|
||||
log.Fatalf("Error waiting for CRDs: %v", err)
|
||||
}
|
||||
|
||||
// create canary config manager
|
||||
canaryCfgMgr, err := canaryconfigmgr.MakeCanaryConfigMgr(fc, kc, fc.GetCrdClient(), prometheusSvc)
|
||||
if err != nil {
|
||||
log.Fatalf("Failed to start canary config manager: %v", err)
|
||||
}
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
featureConfig, err := ConfigureFeatures(ctx, unitTestFlag, fc, kc)
|
||||
if err != nil {
|
||||
log.Printf("Error configuring features : %v. Proceeding without optional features", err.Error())
|
||||
// set all features to false for the MakeApi call below
|
||||
featureConfig.CanaryConfig.IsEnabled = false
|
||||
}
|
||||
defer cancel()
|
||||
canaryCfgMgr.Run(ctx)
|
||||
|
||||
api, err := MakeAPI()
|
||||
api, err := MakeAPI(featureConfig)
|
||||
if err != nil {
|
||||
log.Fatalf("Failed to start controller: %v", err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user