From fe23feff85db5bce524e667eb13d501ef9955ec7 Mon Sep 17 00:00:00 2001 From: yuswift Date: Fri, 26 Mar 2021 15:31:08 +0800 Subject: [PATCH] change http response code to 400 when the cluster is not ready Signed-off-by: yuswift --- pkg/apiserver/dispatch/dispatch.go | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/pkg/apiserver/dispatch/dispatch.go b/pkg/apiserver/dispatch/dispatch.go index 7241113e4..643b36036 100644 --- a/pkg/apiserver/dispatch/dispatch.go +++ b/pkg/apiserver/dispatch/dispatch.go @@ -18,18 +18,19 @@ package dispatch import ( "fmt" + "net/http" + "strings" + "k8s.io/apimachinery/pkg/api/errors" "k8s.io/apimachinery/pkg/util/httpstream" "k8s.io/apimachinery/pkg/util/proxy" "k8s.io/apiserver/pkg/endpoints/handlers/responsewriters" "k8s.io/klog" - "kubesphere.io/kubesphere/pkg/utils/clusterclient" - "net/http" - "strings" clusterv1alpha1 "kubesphere.io/kubesphere/pkg/apis/cluster/v1alpha1" "kubesphere.io/kubesphere/pkg/apiserver/request" clusterinformer "kubesphere.io/kubesphere/pkg/client/informers/externalversions/cluster/v1alpha1" + "kubesphere.io/kubesphere/pkg/utils/clusterclient" ) const proxyURLFormat = "/api/v1/namespaces/kubesphere-system/services/:ks-apiserver:/proxy%s" @@ -77,13 +78,13 @@ func (c *clusterDispatch) Dispatch(w http.ResponseWriter, req *http.Request, han } if !c.IsClusterReady(cluster) { - http.Error(w, fmt.Sprintf("cluster %s is not ready", cluster.Name), http.StatusInternalServerError) + http.Error(w, fmt.Sprintf("cluster %s is not ready", cluster.Name), http.StatusBadRequest) return } innCluster := c.GetInnerCluster(cluster.Name) if innCluster == nil { - http.Error(w, fmt.Sprintf("cluster %s is not ready", cluster.Name), http.StatusInternalServerError) + http.Error(w, fmt.Sprintf("cluster %s is not ready", cluster.Name), http.StatusBadRequest) return } -- GitLab