-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add
uncloud machine init
command to initialise a new cluster on loc…
…al machine
- Loading branch information
1 parent
58fb310
commit 3f71aec
Showing
7 changed files
with
220 additions
and
51 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,12 @@ | ||
.PHONY: build | ||
uncloudd-dev1: | ||
GOOS=linux GOARCH=amd64 go build -o uncloudd-linux-amd64 cmd/uncloudd/main.go && \ | ||
GOOS=linux GOARCH=amd64 go build -o uncloudd-linux-amd64 ./cmd/uncloudd && \ | ||
scp uncloudd-linux-amd64 [email protected]:~/ && \ | ||
ssh [email protected] sudo install ./uncloudd-linux-amd64 /usr/local/bin/uncloudd | ||
GOOS=linux GOARCH=amd64 go build -o uncloud-linux-amd64 ./cmd/uncloud && \ | ||
scp uncloud-linux-amd64 [email protected]:~/ && \ | ||
ssh [email protected] sudo install ./uncloud-linux-amd64 /usr/local/bin/uncloud | ||
|
||
.PHONY: proto | ||
proto: | ||
protoc --go_out=. --go_opt=paths=source_relative --go-grpc_out=. --go-grpc_opt=paths=source_relative internal/machine/cluster/pb/cluster.proto | ||
protoc --go_out=. --go_opt=paths=source_relative --go-grpc_out=. --go-grpc_opt=paths=source_relative internal/machine/api/pb/cluster.proto |
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,64 @@ | ||
package machine | ||
|
||
import ( | ||
"fmt" | ||
"github.com/spf13/cobra" | ||
"net/netip" | ||
"uncloud/internal/machine" | ||
"uncloud/internal/machine/api/pb" | ||
"uncloud/internal/machine/daemon" | ||
"uncloud/internal/machine/network" | ||
"uncloud/internal/secret" | ||
) | ||
|
||
type initOptions struct { | ||
name string | ||
network string | ||
userPublicKey string | ||
dataDir string | ||
} | ||
|
||
func NewInitCommand() *cobra.Command { | ||
opts := initOptions{} | ||
cmd := &cobra.Command{ | ||
Use: "init", | ||
Short: "Initialise a new cluster that consists of the local or remote machine", | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
netPrefix, err := netip.ParsePrefix(opts.network) | ||
if err != nil { | ||
return fmt.Errorf("parse network CIDR: %w", err) | ||
} | ||
|
||
var users []*pb.User | ||
if opts.userPublicKey != "" { | ||
pubKey, uErr := secret.FromHexString(opts.userPublicKey) | ||
if uErr != nil { | ||
return fmt.Errorf("parse user's public key: %w", uErr) | ||
} | ||
user := &pb.User{ | ||
Network: &pb.NetworkConfig{ | ||
ManagementIp: pb.NewIP(network.ManagementIP(pubKey)), | ||
PublicKey: pubKey, | ||
}, | ||
} | ||
users = append(users, user) | ||
} | ||
|
||
if err = daemon.InitCluster(opts.dataDir, opts.name, netPrefix, users); err != nil { | ||
return fmt.Errorf("initialise cluster: %w", err) | ||
} | ||
return nil | ||
}, | ||
} | ||
cmd.Flags().StringVarP(&opts.name, "name", "n", "", "Assign a name to the machine") | ||
cmd.Flags().StringVar(&opts.network, "network", network.DefaultNetwork.String(), | ||
"IPv4 network CIDR to use for machines and services") | ||
cmd.Flags().StringVarP(&opts.userPublicKey, "user-pubkey", "u", "", | ||
"User's public key which will be able to access the cluster (hex-encoded)") | ||
|
||
cmd.Flags().StringVarP(&opts.dataDir, "data-dir", "d", machine.DefaultDataDir, | ||
"Directory for storing persistent machine state") | ||
_ = cmd.MarkFlagDirname("data-dir") | ||
|
||
return cmd | ||
} |
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 |
---|---|---|
|
@@ -11,6 +11,7 @@ func NewRootCommand() *cobra.Command { | |
} | ||
cmd.AddCommand( | ||
NewAddCommand(), | ||
NewInitCommand(), | ||
) | ||
return cmd | ||
} |
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 was deleted.
Oops, something went wrong.
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