From 162755e7d6e08512560a977583bf8bc6c337fb0b Mon Sep 17 00:00:00 2001 From: Ishan Tyagi Date: Mon, 26 Aug 2024 16:36:22 +0530 Subject: [PATCH] WIP: some fixes for non-HA autonomous cluster. --- pkg/server/httpAPI.go | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/pkg/server/httpAPI.go b/pkg/server/httpAPI.go index 714bb717c..04b885f57 100644 --- a/pkg/server/httpAPI.go +++ b/pkg/server/httpAPI.go @@ -35,7 +35,6 @@ import ( "github.com/sirupsen/logrus" "go.etcd.io/etcd/clientv3" "k8s.io/client-go/util/retry" - "sigs.k8s.io/controller-runtime/pkg/client" ) const ( @@ -419,13 +418,6 @@ func (h *HTTPHandler) serveConfig(rw http.ResponseWriter, req *http.Request) { podNS := os.Getenv("POD_NAMESPACE") podName := os.Getenv("POD_NAME") - clientSet, err := miscellaneous.GetKubernetesClientSetOrError() - if err != nil { - h.Logger.Warnf("Failed to create clientset: %v", err) - rw.WriteHeader(http.StatusInternalServerError) - return - } - config["name"] = podName initAdPeerURL := config["initial-advertise-peer-urls"] @@ -456,7 +448,7 @@ func (h *HTTPHandler) serveConfig(rw http.ResponseWriter, req *http.Request) { rw.WriteHeader(http.StatusInternalServerError) return } - state, err := h.GetClusterState(req.Context(), clusterSize, clientSet, podName, podNS) + state, err := h.GetClusterState(req.Context(), clusterSize, podName, podNS) if err != nil { h.Logger.Warnf("failed to get cluster state %v", err) rw.WriteHeader(http.StatusInternalServerError) @@ -483,11 +475,18 @@ func (h *HTTPHandler) serveConfig(rw http.ResponseWriter, req *http.Request) { } // GetClusterState returns the Cluster state either `new` or `existing`. -func (h *HTTPHandler) GetClusterState(ctx context.Context, clusterSize int, client client.Client, podName string, podNS string) (string, error) { +func (h *HTTPHandler) GetClusterState(ctx context.Context, clusterSize int, podName string, podNS string) (string, error) { if clusterSize == 1 { return miscellaneous.ClusterStateNew, nil } + client, err := miscellaneous.GetKubernetesClientSetOrError() + if err != nil { + h.Logger.Warnf("Failed to create clientset: %v", err) + //rw.WriteHeader(http.StatusInternalServerError) + return "", fmt.Errorf("failed to get clusterState: %w", err) + } + // clusterSize > 1 state, err := miscellaneous.GetInitialClusterStateIfScaleup(ctx, *h.Logger, client, podName, podNS) if err != nil {