Skip to content

Commit

Permalink
quite a bit of renaming (#4106)
Browse files Browse the repository at this point in the history
* renaming things to 'embedded-cluster'

* rename frontend

* import ordering

* undo goland's wonderful formatting changes

* function naming

* undo whitespace change
  • Loading branch information
laverya authored Oct 23, 2023
1 parent 166b1fe commit 3289ee5
Show file tree
Hide file tree
Showing 34 changed files with 243 additions and 244 deletions.
4 changes: 2 additions & 2 deletions .github/actions/cmx-versions/dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7661,7 +7661,7 @@ async function getClusterVersions() {
clusterVersions.forEach((distribution) => {
const distroName = distribution.short_name;

if (distroName === 'helmvm' || distroName === 'kurl') {
if (distroName === 'embedded_cluster' || distroName === 'kurl') {
// excluding the embedded distributions
return;
}
Expand Down Expand Up @@ -7710,4 +7710,4 @@ getClusterVersions();

module.exports = __webpack_exports__;
/******/ })()
;
;
2 changes: 1 addition & 1 deletion .github/actions/cmx-versions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ async function getClusterVersions() {
clusterVersions.forEach((distribution) => {
const distroName = distribution.short_name;

if (distroName === 'helmvm' || distroName === 'kurl') {
if (distroName === 'embedded_cluster' || distroName === 'kurl') {
// excluding the embedded distributions
return;
}
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/regression.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -191,9 +191,9 @@ jobs:
is_upgrade: "1"
},
{
name: "type=helmvm cluster, env=online, phase=new install, rbac=cluster admin",
backend_config: "helmvm-online-install-backend-config.tfvars",
terraform_script: "helmvm-online-install.sh"
name: "type=embeddedcluster cluster, env=online, phase=new install, rbac=cluster admin",
backend_config: "embeddedcluster-online-install-backend-config.tfvars",
terraform_script: "embeddedcluster-online-install.sh"
}
]
steps:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
apiVersion: schemas.schemahero.io/v1alpha4
kind: Table
metadata:
name: k0s-tokens
name: embedded-cluster-tokens
spec:
name: k0s_tokens
name: embedded_cluster_tokens
requires: []
schema:
rqlite:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package helmvm
package embeddedcluster

import (
"context"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package helmvm
package embeddedcluster

import (
"context"
Expand Down
2 changes: 1 addition & 1 deletion pkg/helmvm/exec.go → pkg/embeddedcluster/exec.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package helmvm
package embeddedcluster

import (
corev1client "k8s.io/client-go/kubernetes/typed/core/v1"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package helmvm
package embeddedcluster

import (
"context"
Expand All @@ -7,7 +7,7 @@ import (
"strconv"
"strings"

"github.com/replicatedhq/kots/pkg/helmvm/types"
"github.com/replicatedhq/kots/pkg/embeddedcluster/types"
"github.com/replicatedhq/kots/pkg/k8sutil"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package helmvm
package embeddedcluster

import (
"context"

"github.com/pkg/errors"
"github.com/replicatedhq/kots/pkg/helmvm/types"
"github.com/replicatedhq/kots/pkg/embeddedcluster/types"
"github.com/replicatedhq/kots/pkg/k8sutil"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand All @@ -12,7 +13,7 @@ import (
)

// GetNodes will get a list of nodes with stats
func GetNodes(ctx context.Context, client kubernetes.Interface) (*types.HelmVMNodes, error) {
func GetNodes(ctx context.Context, client kubernetes.Interface) (*types.EmbeddedClusterNodes, error) {
nodes, err := client.CoreV1().Nodes().List(ctx, metav1.ListOptions{})
if err != nil {
return nil, errors.Wrap(err, "list nodes")
Expand All @@ -28,7 +29,7 @@ func GetNodes(ctx context.Context, client kubernetes.Interface) (*types.HelmVMNo
return nil, errors.Wrap(err, "failed to create metrics client")
}

toReturn := types.HelmVMNodes{}
toReturn := types.EmbeddedClusterNodes{}

for _, node := range nodes.Items {
nodeMet, err := nodeMetrics(ctx, client, metricsClient, node)
Expand All @@ -39,11 +40,11 @@ func GetNodes(ctx context.Context, client kubernetes.Interface) (*types.HelmVMNo
toReturn.Nodes = append(toReturn.Nodes, *nodeMet)
}

isHelmVM, err := IsHelmVM(client)
isEmbeddedCluster, err := IsEmbeddedCluster(client)
if err != nil {
return nil, errors.Wrap(err, "is helmvm")
return nil, errors.Wrap(err, "is embeddedcluster")
}
toReturn.IsHelmVMEnabled = isHelmVM
toReturn.IsEmbeddedClusterEnabled = isEmbeddedCluster

isHA, err := IsHA(client)
if err != nil {
Expand Down
8 changes: 4 additions & 4 deletions pkg/helmvm/node_join.go → pkg/embeddedcluster/node_join.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package helmvm
package embeddedcluster

import (
"context"
Expand All @@ -8,7 +8,7 @@ import (
"sync"
"time"

"github.com/replicatedhq/kots/pkg/helmvm/types"
"github.com/replicatedhq/kots/pkg/embeddedcluster/types"
corev1 "k8s.io/api/core/v1"
kuberneteserrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand All @@ -24,7 +24,7 @@ type joinTokenEntry struct {
var joinTokenMapMut = sync.Mutex{}
var joinTokenMap = map[string]*joinTokenEntry{}

// GenerateAddNodeToken will generate the HelmVM node add command for a primary or secondary node
// GenerateAddNodeToken will generate the embedded cluster node add command for a node with the specified roles
// join commands will last for 24 hours, and will be cached for 1 hour after first generation
func GenerateAddNodeToken(ctx context.Context, client kubernetes.Interface, nodeRole string) (string, error) {
// get the joinToken struct entry for this node role
Expand Down Expand Up @@ -214,7 +214,7 @@ func runAddNodeCommandPod(ctx context.Context, client kubernetes.Interface, node
}

// GenerateAddNodeCommand returns the command a user should run to add a node with the provided token
// the command will be of the form 'helmvm node join ip:port UUID'
// the command will be of the form 'embeddedcluster node join ip:port UUID'
func GenerateAddNodeCommand(ctx context.Context, client kubernetes.Interface, token string) (string, error) {
cm, err := ReadConfigMap(client)
if err != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ package types
const EMBEDDED_CLUSTER_LABEL = "kots.io/embedded-cluster"
const EMBEDDED_CLUSTER_ROLE_LABEL = EMBEDDED_CLUSTER_LABEL + "-role"

type HelmVMNodes struct {
Nodes []Node `json:"nodes"`
HA bool `json:"ha"`
IsHelmVMEnabled bool `json:"isHelmVMEnabled"`
type EmbeddedClusterNodes struct {
Nodes []Node `json:"nodes"`
HA bool `json:"ha"`
IsEmbeddedClusterEnabled bool `json:"isEmbeddedClusterEnabled"`
}

type Node struct {
Expand Down
4 changes: 2 additions & 2 deletions pkg/helmvm/util.go → pkg/embeddedcluster/util.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package helmvm
package embeddedcluster

import (
"context"
Expand All @@ -18,7 +18,7 @@ func ReadConfigMap(client kubernetes.Interface) (*corev1.ConfigMap, error) {
return client.CoreV1().ConfigMaps(configMapNamespace).Get(context.TODO(), configMapName, metav1.GetOptions{})
}

func IsHelmVM(clientset kubernetes.Interface) (bool, error) {
func IsEmbeddedCluster(clientset kubernetes.Interface) (bool, error) {
if clientset == nil {
return false, fmt.Errorf("clientset is nil")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ import (
"net/http"

"github.com/gorilla/mux"
"github.com/replicatedhq/kots/pkg/helmvm"
"github.com/replicatedhq/kots/pkg/embeddedcluster"
"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) {
func (h *Handler) DeleteEmbeddedClusterNode(w http.ResponseWriter, r *http.Request) {
client, err := k8sutil.GetClientset()
if err != nil {
logger.Error(err)
Expand Down Expand Up @@ -41,7 +41,7 @@ func (h *Handler) DeleteHelmVMNode(w http.ResponseWriter, r *http.Request) {
return
}

if err := helmvm.DeleteNode(ctx, client, restconfig, node); err != nil {
if err := embeddedcluster.DeleteNode(ctx, client, restconfig, node); err != nil {
logger.Error(err)
w.WriteHeader(http.StatusInternalServerError)
return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ import (
"net/http"

"github.com/gorilla/mux"
"github.com/replicatedhq/kots/pkg/helmvm"
"github.com/replicatedhq/kots/pkg/embeddedcluster"
"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) {
func (h *Handler) DrainEmbeddedClusterNode(w http.ResponseWriter, r *http.Request) {
client, err := k8sutil.GetClientset()
if err != nil {
logger.Error(err)
Expand All @@ -36,7 +36,7 @@ func (h *Handler) DrainHelmVMNode(w http.ResponseWriter, r *http.Request) {

// 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 {
if err := embeddedcluster.DrainNode(ctx, client, node); err != nil {
logger.Error(err)
return
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,20 @@ import (
"net/http"

"github.com/gorilla/mux"
"github.com/replicatedhq/kots/pkg/helmvm"
"github.com/replicatedhq/kots/pkg/embeddedcluster"
"github.com/replicatedhq/kots/pkg/k8sutil"
"github.com/replicatedhq/kots/pkg/logger"
)

func (h *Handler) GetHelmVMNodes(w http.ResponseWriter, r *http.Request) {
func (h *Handler) GetEmbeddedClusterNodes(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(r.Context(), client)
nodes, err := embeddedcluster.GetNodes(r.Context(), client)
if err != nil {
logger.Error(err)
w.WriteHeader(http.StatusInternalServerError)
Expand All @@ -26,7 +26,7 @@ func (h *Handler) GetHelmVMNodes(w http.ResponseWriter, r *http.Request) {
JSON(w, http.StatusOK, nodes)
}

func (h *Handler) GetHelmVMNode(w http.ResponseWriter, r *http.Request) {
func (h *Handler) GetEmbeddedClusterNode(w http.ResponseWriter, r *http.Request) {
client, err := k8sutil.GetClientset()
if err != nil {
logger.Error(err)
Expand All @@ -35,7 +35,7 @@ func (h *Handler) GetHelmVMNode(w http.ResponseWriter, r *http.Request) {
}

nodeName := mux.Vars(r)["nodeName"]
node, err := helmvm.GetNode(r.Context(), client, nodeName)
node, err := embeddedcluster.GetNode(r.Context(), client, nodeName)
if err != nil {
logger.Error(err)
w.WriteHeader(http.StatusInternalServerError)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,36 +5,36 @@ import (
"fmt"
"net/http"

"github.com/replicatedhq/kots/pkg/helmvm"
"github.com/replicatedhq/kots/pkg/embeddedcluster"
"github.com/replicatedhq/kots/pkg/k8sutil"
"github.com/replicatedhq/kots/pkg/logger"
"github.com/replicatedhq/kots/pkg/store/kotsstore"
)

type GenerateK0sNodeJoinCommandResponse struct {
type GenerateEmbeddedClusterNodeJoinCommandResponse struct {
Command []string `json:"command"`
}

type GetK0sNodeJoinCommandResponse struct {
type GetEmbeddedClusterNodeJoinCommandResponse struct {
ClusterID string `json:"clusterID"`
K0sJoinCommand string `json:"k0sJoinCommand"`
K0sToken string `json:"k0sToken"`
}

type GenerateHelmVMNodeJoinCommandRequest struct {
type GenerateEmbeddedClusterNodeJoinCommandRequest struct {
Roles []string `json:"roles"`
}

func (h *Handler) GenerateK0sNodeJoinCommand(w http.ResponseWriter, r *http.Request) {
generateHelmVMNodeJoinCommandRequest := GenerateHelmVMNodeJoinCommandRequest{}
if err := json.NewDecoder(r.Body).Decode(&generateHelmVMNodeJoinCommandRequest); err != nil {
func (h *Handler) GenerateEmbeddedClusterNodeJoinCommand(w http.ResponseWriter, r *http.Request) {
generateEmbeddedClusterNodeJoinCommandRequest := GenerateEmbeddedClusterNodeJoinCommandRequest{}
if err := json.NewDecoder(r.Body).Decode(&generateEmbeddedClusterNodeJoinCommandRequest); err != nil {
logger.Error(fmt.Errorf("failed to decode request body: %w", err))
w.WriteHeader(http.StatusBadRequest)
return
}

store := kotsstore.StoreFromEnv()
token, err := store.SetK0sInstallCommandRoles(generateHelmVMNodeJoinCommandRequest.Roles)
token, err := store.SetEmbeddedClusterInstallCommandRoles(generateEmbeddedClusterNodeJoinCommandRequest.Roles)
if err != nil {
logger.Error(fmt.Errorf("failed to set k0s install command roles: %w", err))
w.WriteHeader(http.StatusInternalServerError)
Expand All @@ -47,24 +47,24 @@ func (h *Handler) GenerateK0sNodeJoinCommand(w http.ResponseWriter, r *http.Requ
w.WriteHeader(http.StatusInternalServerError)
return
}
nodeJoinCommand, err := helmvm.GenerateAddNodeCommand(r.Context(), client, token)
nodeJoinCommand, err := embeddedcluster.GenerateAddNodeCommand(r.Context(), client, token)
if err != nil {
logger.Error(fmt.Errorf("failed to generate add node command: %w", err))
w.WriteHeader(http.StatusInternalServerError)
return
}

JSON(w, http.StatusOK, GenerateK0sNodeJoinCommandResponse{
JSON(w, http.StatusOK, GenerateEmbeddedClusterNodeJoinCommandResponse{
Command: []string{nodeJoinCommand},
})
}

// this function relies on the token being valid for authentication
func (h *Handler) GetK0sNodeJoinCommand(w http.ResponseWriter, r *http.Request) {
func (h *Handler) GetEmbeddedClusterNodeJoinCommand(w http.ResponseWriter, r *http.Request) {
// read query string, ensure that the token is valid
token := r.URL.Query().Get("token")
store := kotsstore.StoreFromEnv()
roles, err := store.GetK0sInstallCommandRoles(token)
roles, err := store.GetEmbeddedClusterInstallCommandRoles(token)
if err != nil {
logger.Error(fmt.Errorf("failed to get k0s install command roles: %w", err))
w.WriteHeader(http.StatusInternalServerError)
Expand All @@ -87,28 +87,28 @@ func (h *Handler) GetK0sNodeJoinCommand(w http.ResponseWriter, r *http.Request)
}
}

k0sToken, err := helmvm.GenerateAddNodeToken(r.Context(), client, k0sRole)
k0sToken, err := embeddedcluster.GenerateAddNodeToken(r.Context(), client, k0sRole)
if err != nil {
logger.Error(fmt.Errorf("failed to generate add node token: %w", err))
w.WriteHeader(http.StatusInternalServerError)
return
}

k0sJoinCommand, err := helmvm.GenerateK0sJoinCommand(r.Context(), client, roles)
k0sJoinCommand, err := embeddedcluster.GenerateK0sJoinCommand(r.Context(), client, roles)
if err != nil {
logger.Error(fmt.Errorf("failed to generate k0s join command: %w", err))
w.WriteHeader(http.StatusInternalServerError)
return
}

clusterID, err := helmvm.ClusterID(client)
clusterID, err := embeddedcluster.ClusterID(client)
if err != nil {
logger.Error(fmt.Errorf("failed to get cluster id: %w", err))
w.WriteHeader(http.StatusInternalServerError)
return
}

JSON(w, http.StatusOK, GetK0sNodeJoinCommandResponse{
JSON(w, http.StatusOK, GetEmbeddedClusterNodeJoinCommandResponse{
ClusterID: clusterID,
K0sJoinCommand: k0sJoinCommand,
K0sToken: k0sToken,
Expand Down
Loading

0 comments on commit 3289ee5

Please sign in to comment.