Send the error message to user when enabling canary feature fails. (#990)
* Send the error message to user when enabling canary feature fails. * Fix controller doesn’t reply canary error when promClient tries connect to invalid prometheus server
This commit is contained in:
committed by
Ta-Ching Chen
parent
89081b087b
commit
db5165e032
+3
-4
@@ -32,7 +32,6 @@ import (
|
||||
|
||||
"github.com/fission/fission"
|
||||
"github.com/fission/fission/crd"
|
||||
config "github.com/fission/fission/featureconfig"
|
||||
"github.com/fission/fission/fission/logdb"
|
||||
)
|
||||
|
||||
@@ -54,7 +53,7 @@ type (
|
||||
workflowApiUrl string
|
||||
functionNamespace string
|
||||
useIstio bool
|
||||
featureConfig *config.FeatureConfig
|
||||
featureStatus map[string]string
|
||||
}
|
||||
|
||||
logDBConfig struct {
|
||||
@@ -64,7 +63,7 @@ type (
|
||||
}
|
||||
)
|
||||
|
||||
func MakeAPI(featureConfig *config.FeatureConfig) (*API, error) {
|
||||
func MakeAPI(featureStatus map[string]string) (*API, error) {
|
||||
api, err := makeCRDBackedAPI()
|
||||
|
||||
u := os.Getenv("STORAGE_SERVICE_URL")
|
||||
@@ -95,7 +94,7 @@ func MakeAPI(featureConfig *config.FeatureConfig) (*API, error) {
|
||||
api.functionNamespace = "fission-function"
|
||||
}
|
||||
|
||||
api.featureConfig = featureConfig
|
||||
api.featureStatus = featureStatus
|
||||
|
||||
return api, err
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@ package controller
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
|
||||
@@ -27,11 +28,13 @@ import (
|
||||
|
||||
"github.com/fission/fission"
|
||||
"github.com/fission/fission/crd"
|
||||
config "github.com/fission/fission/featureconfig"
|
||||
)
|
||||
|
||||
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"))
|
||||
featureErr := a.featureStatus[config.CanaryFeature]
|
||||
if len(featureErr) > 0 {
|
||||
a.respondWithError(w, fission.MakeError(http.StatusInternalServerError, fmt.Sprintf("Error enabling canary feature: %v", featureErr)))
|
||||
return
|
||||
}
|
||||
|
||||
@@ -66,8 +69,9 @@ 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"))
|
||||
featureErr := a.featureStatus[config.CanaryFeature]
|
||||
if len(featureErr) > 0 {
|
||||
a.respondWithError(w, fission.MakeError(http.StatusInternalServerError, fmt.Sprintf("Error enabling canary feature: %v", featureErr)))
|
||||
return
|
||||
}
|
||||
|
||||
@@ -95,8 +99,9 @@ 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"))
|
||||
featureErr := a.featureStatus[config.CanaryFeature]
|
||||
if len(featureErr) > 0 {
|
||||
a.respondWithError(w, fission.MakeError(http.StatusInternalServerError, fmt.Sprintf("Error enabling canary feature: %v", featureErr)))
|
||||
return
|
||||
}
|
||||
|
||||
@@ -121,8 +126,9 @@ 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"))
|
||||
featureErr := a.featureStatus[config.CanaryFeature]
|
||||
if len(featureErr) > 0 {
|
||||
a.respondWithError(w, fission.MakeError(http.StatusInternalServerError, fmt.Sprintf("Error enabling canary feature: %v", featureErr)))
|
||||
return
|
||||
}
|
||||
|
||||
@@ -155,8 +161,9 @@ 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"))
|
||||
featureErr := a.featureStatus[config.CanaryFeature]
|
||||
if len(featureErr) > 0 {
|
||||
a.respondWithError(w, fission.MakeError(http.StatusInternalServerError, fmt.Sprintf("Error enabling canary feature: %v", featureErr)))
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
@@ -28,12 +28,13 @@ import (
|
||||
config "github.com/fission/fission/featureconfig"
|
||||
)
|
||||
|
||||
func ConfigCanaryFeature(context context.Context, fissionClient *crd.FissionClient, kubeClient *kubernetes.Clientset, featureConfig *config.FeatureConfig) error {
|
||||
func ConfigCanaryFeature(context context.Context, fissionClient *crd.FissionClient, kubeClient *kubernetes.Clientset, featureConfig *config.FeatureConfig, featureStatus map[string]string) error {
|
||||
// start the appropriate controller
|
||||
if featureConfig.CanaryConfig.IsEnabled {
|
||||
canaryCfgMgr, err := canaryconfigmgr.MakeCanaryConfigMgr(fissionClient, kubeClient, fissionClient.GetCrdClient(),
|
||||
featureConfig.CanaryConfig.PrometheusSvc)
|
||||
if err != nil {
|
||||
featureStatus[config.CanaryFeature] = err.Error()
|
||||
return fmt.Errorf("failed to start canary config manager: %v", err)
|
||||
}
|
||||
canaryCfgMgr.Run(context)
|
||||
@@ -44,22 +45,23 @@ func ConfigCanaryFeature(context context.Context, fissionClient *crd.FissionClie
|
||||
}
|
||||
|
||||
// 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) {
|
||||
func ConfigureFeatures(context context.Context, unitTestMode bool, fissionClient *crd.FissionClient, kubeClient *kubernetes.Clientset) (map[string]string, error) {
|
||||
// set feature enabled to false if unitTestMode
|
||||
if unitTestMode {
|
||||
featureConfig := &config.FeatureConfig{}
|
||||
return featureConfig, nil
|
||||
return nil, 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
|
||||
return nil, err
|
||||
}
|
||||
|
||||
featureStatus := make(map[string]string)
|
||||
|
||||
// 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
|
||||
err = ConfigCanaryFeature(context, fissionClient, kubeClient, featureConfig, featureStatus)
|
||||
return featureStatus, err
|
||||
}
|
||||
|
||||
@@ -44,15 +44,13 @@ func Start(port int, unitTestFlag bool) {
|
||||
}
|
||||
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
featureConfig, err := ConfigureFeatures(ctx, unitTestFlag, fc, kc)
|
||||
featureStatus, 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()
|
||||
|
||||
api, err := MakeAPI(featureConfig)
|
||||
api, err := MakeAPI(featureStatus)
|
||||
if err != nil {
|
||||
log.Fatalf("Failed to start controller: %v", err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user