Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: some fixes for non-HA autonomous cluster. #764

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 9 additions & 10 deletions pkg/server/httpAPI.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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"]
Expand Down Expand Up @@ -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)
Expand All @@ -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 {
Expand Down