Skip to content

Commit

Permalink
Add kubeadm join to topo manager (#521)
Browse files Browse the repository at this point in the history
add kubeadm join to topo manager
  • Loading branch information
alexmasi authored Mar 26, 2024
1 parent c83a451 commit 5e92c29
Show file tree
Hide file tree
Showing 6 changed files with 341 additions and 104 deletions.
27 changes: 27 additions & 0 deletions controller/server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,14 @@ import (
"fmt"
"net"
"os"
"os/exec"
"path/filepath"
"sync"
"time"

log "github.com/golang/glog"
"github.com/openconfig/kne/deploy"
"github.com/openconfig/kne/exec/run"
cpb "github.com/openconfig/kne/proto/controller"
tpb "github.com/openconfig/kne/proto/topo"
"github.com/openconfig/kne/topo"
Expand Down Expand Up @@ -514,6 +516,31 @@ func (s *server) ResetConfig(ctx context.Context, req *cpb.ResetConfigRequest) (
return &cpb.ResetConfigResponse{}, nil
}

func (s *server) JoinCluster(ctx context.Context, req *cpb.JoinClusterRequest) (*cpb.JoinClusterResponse, error) {
log.Infof("Received JoinCluster request: %v", req)
if _, err := exec.LookPath("kubeadm"); err != nil {
return nil, status.Errorf(codes.FailedPrecondition, "install kubeadm to join")
}
args := []string{"kubeadm", "join"}
if req.GetApiServerEndpoint() == "" {
return nil, status.Errorf(codes.FailedPrecondition, "api server endpoint required")
}
args = append(args, req.GetApiServerEndpoint())
if req.GetToken() != "" {
args = append(args, "--token", req.GetToken())
}
if req.GetDiscoveryTokenCaCertHash() != "" {
args = append(args, "--discovery-token-ca-cert-hash", req.GetDiscoveryTokenCaCertHash())
}
if req.GetCriSocket() != "" {
args = append(args, "--cri-socket", req.GetCriSocket())
}
if err := run.LogCommand("sudo", args...); err != nil {
return nil, status.Errorf(codes.Internal, "failed to join kubeadm cluster: %v", err)
}
return &cpb.JoinClusterResponse{}, nil
}

func validatePath(path string) (string, error) {
path, err := filepath.Abs(path)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion proto/alpine/alpine.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions proto/controller.proto
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ service TopologyManager {
rpc ResetConfig(ResetConfigRequest) returns (ResetConfigResponse) {}
// Applies kubeyaml to a running cluster.
rpc ApplyCluster(ApplyClusterRequest) returns (ApplyClusterResponse) {}
// Joins host into an existing Kubeadm cluster.
rpc JoinCluster(JoinClusterRequest) returns (JoinClusterResponse) {}
}

// Kind cluster specifications
Expand Down Expand Up @@ -262,3 +264,15 @@ message ApplyClusterRequest {
// Returns apply cluster response.
message ApplyClusterResponse {
}

// Request message to join in to a Kubeadm cluster.
message JoinClusterRequest {
string api_server_endpoint = 1;
string token = 2;
string discovery_token_ca_cert_hash = 3;
string cri_socket = 4;
}

// Returns join cluster response.
message JoinClusterResponse {
}
Loading

0 comments on commit 5e92c29

Please sign in to comment.