-
Notifications
You must be signed in to change notification settings - Fork 93
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
create separate packages, endpoints, and components for HelmVM cluste…
…r management functionalities
- Loading branch information
Showing
35 changed files
with
1,709 additions
and
169 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package handlers | ||
|
||
import ( | ||
"context" | ||
"net/http" | ||
|
||
"github.com/gorilla/mux" | ||
"github.com/replicatedhq/kots/pkg/helmvm" | ||
"github.com/replicatedhq/kots/pkg/k8sutil" | ||
"github.com/replicatedhq/kots/pkg/logger" | ||
"k8s.io/apimachinery/pkg/api/errors" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
) | ||
|
||
func (h *Handler) DeleteHelmVMNode(w http.ResponseWriter, r *http.Request) { | ||
client, err := k8sutil.GetClientset() | ||
if err != nil { | ||
logger.Error(err) | ||
w.WriteHeader(http.StatusInternalServerError) | ||
return | ||
} | ||
|
||
restconfig, err := k8sutil.GetClusterConfig() | ||
if err != nil { | ||
logger.Error(err) | ||
w.WriteHeader(http.StatusInternalServerError) | ||
return | ||
} | ||
|
||
ctx := context.Background() | ||
nodeName := mux.Vars(r)["nodeName"] | ||
node, err := client.CoreV1().Nodes().Get(ctx, nodeName, metav1.GetOptions{}) | ||
if err != nil { | ||
if errors.IsNotFound(err) { | ||
logger.Errorf("Failed to delete node %s: not found", nodeName) | ||
w.WriteHeader(http.StatusNotFound) | ||
return | ||
} | ||
logger.Error(err) | ||
w.WriteHeader(http.StatusInternalServerError) | ||
return | ||
} | ||
|
||
if err := helmvm.DeleteNode(ctx, client, restconfig, node); err != nil { | ||
logger.Error(err) | ||
w.WriteHeader(http.StatusInternalServerError) | ||
return | ||
} | ||
logger.Infof("Node %s successfully deleted", node.Name) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package handlers | ||
|
||
import ( | ||
"context" | ||
"net/http" | ||
|
||
"github.com/gorilla/mux" | ||
"github.com/replicatedhq/kots/pkg/helmvm" | ||
"github.com/replicatedhq/kots/pkg/k8sutil" | ||
"github.com/replicatedhq/kots/pkg/logger" | ||
"k8s.io/apimachinery/pkg/api/errors" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
) | ||
|
||
func (h *Handler) DrainHelmVMNode(w http.ResponseWriter, r *http.Request) { | ||
client, err := k8sutil.GetClientset() | ||
if err != nil { | ||
logger.Error(err) | ||
w.WriteHeader(http.StatusInternalServerError) | ||
return | ||
} | ||
|
||
ctx := context.Background() | ||
nodeName := mux.Vars(r)["nodeName"] | ||
node, err := client.CoreV1().Nodes().Get(ctx, nodeName, metav1.GetOptions{}) | ||
if err != nil { | ||
if errors.IsNotFound(err) { | ||
logger.Errorf("Failed to drain node %s: not found", nodeName) | ||
w.WriteHeader(http.StatusNotFound) | ||
return | ||
} | ||
logger.Error(err) | ||
w.WriteHeader(http.StatusInternalServerError) | ||
return | ||
} | ||
|
||
// This pod may get evicted and not be able to respond to the request | ||
go func() { | ||
if err := helmvm.DrainNode(ctx, client, node); err != nil { | ||
logger.Error(err) | ||
return | ||
} | ||
logger.Infof("Node %s successfully drained", node.Name) | ||
}() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package handlers | ||
|
||
import ( | ||
"net/http" | ||
|
||
"github.com/replicatedhq/kots/pkg/helmvm" | ||
"github.com/replicatedhq/kots/pkg/k8sutil" | ||
"github.com/replicatedhq/kots/pkg/logger" | ||
) | ||
|
||
func (h *Handler) GetHelmVMNodes(w http.ResponseWriter, r *http.Request) { | ||
client, err := k8sutil.GetClientset() | ||
if err != nil { | ||
logger.Error(err) | ||
w.WriteHeader(http.StatusInternalServerError) | ||
return | ||
} | ||
|
||
nodes, err := helmvm.GetNodes(client) | ||
if err != nil { | ||
logger.Error(err) | ||
w.WriteHeader(http.StatusInternalServerError) | ||
return | ||
} | ||
JSON(w, http.StatusOK, nodes) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package handlers | ||
|
||
import ( | ||
"net/http" | ||
"time" | ||
|
||
"github.com/replicatedhq/kots/pkg/helmvm" | ||
"github.com/replicatedhq/kots/pkg/k8sutil" | ||
"github.com/replicatedhq/kots/pkg/logger" | ||
) | ||
|
||
type GenerateHelmVMNodeJoinCommandResponse struct { | ||
Command []string `json:"command"` | ||
Expiry string `json:"expiry"` | ||
} | ||
|
||
func (h *Handler) GenerateHelmVMNodeJoinCommandSecondary(w http.ResponseWriter, r *http.Request) { | ||
client, err := k8sutil.GetClientset() | ||
if err != nil { | ||
logger.Error(err) | ||
w.WriteHeader(http.StatusInternalServerError) | ||
return | ||
} | ||
|
||
command, expiry, err := helmvm.GenerateAddNodeCommand(client, false) | ||
if err != nil { | ||
logger.Error(err) | ||
w.WriteHeader(http.StatusInternalServerError) | ||
return | ||
} | ||
JSON(w, http.StatusOK, GenerateHelmVMNodeJoinCommandResponse{ | ||
Command: command, | ||
Expiry: expiry.Format(time.RFC3339), | ||
}) | ||
} | ||
|
||
func (h *Handler) GenerateHelmVMNodeJoinCommandPrimary(w http.ResponseWriter, r *http.Request) { | ||
client, err := k8sutil.GetClientset() | ||
if err != nil { | ||
logger.Error(err) | ||
w.WriteHeader(http.StatusInternalServerError) | ||
return | ||
} | ||
|
||
command, expiry, err := helmvm.GenerateAddNodeCommand(client, true) | ||
if err != nil { | ||
logger.Error(err) | ||
w.WriteHeader(http.StatusInternalServerError) | ||
return | ||
} | ||
JSON(w, http.StatusOK, GenerateHelmVMNodeJoinCommandResponse{ | ||
Command: command, | ||
Expiry: expiry.Format(time.RFC3339), | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.