Skip to content

Commit

Permalink
add orb instance from interface (#37)
Browse files Browse the repository at this point in the history
* refactor(main): delete install funcs

Signed-off-by: cuisongliu <[email protected]>

* refactor(main): add orb interface

Signed-off-by: cuisongliu <[email protected]>

* refactor(main): add orb interface  for lanuch vm server

Signed-off-by: cuisongliu <[email protected]>

* refactor(main): add orb interface  for lanuch vm server

Signed-off-by: cuisongliu <[email protected]>

* refactor(main): add orb instance  for lanuch vm server

Signed-off-by: cuisongliu <[email protected]>

---------

Signed-off-by: cuisongliu <[email protected]>
  • Loading branch information
cuisongliu authored Jul 2, 2023
1 parent 6d9719b commit a9fe172
Show file tree
Hide file tree
Showing 32 changed files with 979 additions and 590 deletions.
81 changes: 0 additions & 81 deletions cmd/install.go

This file was deleted.

3 changes: 1 addition & 2 deletions cmd/reset.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func newResetCmd() *cobra.Command {
return errors.New("cancelled")
}
}
if err := checkInstall(vm.Spec.Type); err != nil {
if err := checkProvider(); err != nil {
return err
}
t := metav1.Now()
Expand All @@ -55,7 +55,6 @@ func newResetCmd() *cobra.Command {
},
}
resetCmd.Flags().StringVarP(&vm.Name, "name", "n", "default", "name of cluster to applied init action")
resetCmd.Flags().StringVarP(&vm.Spec.Type, "type", "t", v1.MultipassType, "choose a type of infra, multipass")
return resetCmd
}
func init() {
Expand Down
11 changes: 10 additions & 1 deletion cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"fmt"
"github.com/labring/sealvm/pkg/system"
"github.com/labring/sealvm/pkg/template"
"github.com/labring/sealvm/pkg/utils/exec"
"os"
"path"
"runtime"
Expand Down Expand Up @@ -81,7 +82,6 @@ func init() {
{
Message: "System Management Commands:",
Commands: []*cobra.Command{
newInstallCmd(),
system.NewConfigCmd(),
template.NewTemplateCmd(),
template.NewValuesCmd(),
Expand Down Expand Up @@ -109,3 +109,12 @@ func onBootOnDie() {
}
logger.CfgConsoleAndFileLogger(debug, path.Join(clusterRootDir, "logs"), "sealvm", false)
}

func checkProvider() error {
defaultProvider, _ := system.Get(system.DefaultProvider)
logger.Debug("default provider is %s", defaultProvider)
if p := exec.ExecutableFilePath(defaultProvider); p == "" {
return fmt.Errorf("provider %s not found", defaultProvider)
}
return nil
}
10 changes: 5 additions & 5 deletions cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ func newRunCmd() *cobra.Command {
Use: "run",
Short: "Run cloud native vm nodes",
Example: `sealvm run -n node:2,master:1`,
Args: cobra.MaximumNArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
applier, err := apply.NewApplierFromArgs(&vm)
if err != nil {
Expand All @@ -50,13 +51,16 @@ func newRunCmd() *cobra.Command {
return applier.Apply()
},
PreRunE: func(cmd *cobra.Command, args []string) error {
if err := checkProvider(); err != nil {
return err
}
system.List()
template.NewTpl().List()
template.NewValues().List()
if len(args) != 0 {
defaultImage = args[0]
} else {
newDefaultImage, err := apply.GetDefaultImage()
newDefaultImage, err := system.GetDefaultImage()
if err != nil {
return err
}
Expand All @@ -76,9 +80,6 @@ func newRunCmd() *cobra.Command {
if strings.Contains(vm.Name, "-") {
return fmt.Errorf("your cluster name contains chart '-' ")
}
if err := checkInstall(vm.Spec.Type); err != nil {
return err
}

nodeMap, err := apply.ParseNodes(nodes)
if err != nil {
Expand Down Expand Up @@ -119,7 +120,6 @@ func newRunCmd() *cobra.Command {
},
}
runCmd.Flags().StringVar(&vm.Spec.SSH.PkPasswd, "pk-passwd", "", "passphrase for decrypting a PEM encoded private key")
runCmd.Flags().StringVarP(&vm.Spec.Type, "type", "t", v1.MultipassType, "choose a type of infra, multipass")
runCmd.Flags().StringVar(&vm.Name, "name", "default", "name of cluster to applied init action")
runCmd.Flags().StringVarP(&nodes, "nodes", "n", "", "number of nodes, eg: node:1,node2:2")
return runCmd
Expand Down
File renamed without changes.
File renamed without changes.
3 changes: 3 additions & 0 deletions docs/examples/orb/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## orb配置
需要注意一下,orb不必需要mount和unmount 默认会挂载/Users/cuisongliu目录到Linux服务器,需要调整对应的配置

35 changes: 35 additions & 0 deletions docs/examples/orb/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
apiVersion: virtual-machine.sealos.io/v1
kind: Action
spec:
data:
- mount:
source: /Users/cuisongliu/Workspaces/go/src/github.com/labring/sealos
target: /root/go/src/github.com/labring/sealos
- exec: |
sudo apt-get -y update
sudo apt-get install -y make gcc-aarch64-linux-gnu gcc-x86-64-linux-gnu
sudo apt-get install -y ntpdate
sudo apt-get install -y git
sudo ntpdate -s ntp1.aliyun.com
- copyContent:
content: |
#!/bin/bash
version=1.20.1
arch=arm64
rm -rf /root/go${version}.linux-${arch}.tar.gz
wget https://studygolang.com/dl/golang/go${version}.linux-${arch}.tar.gz -O /root/go${version}.linux-${arch}.tar.gz
rm -rf /usr/local/go && tar -C /usr/local -zxvf /root/go${version}.linux-${arch}.tar.gz
echo "export PATH=\$PATH:/usr/local/go/bin" > /etc/profile.d/golang.sh
chmod 0755 /etc/profile.d/golang.sh
rm -rf /root/go${version}.linux-${arch}.tar.gz
mkdir -p /root/go/src/github.com/labring /root/go/bin /root/go/pkg
source /etc/profile.d/golang.sh
go env -w GOPROXY="https://goproxy.io,direct"
target: /root/golang-install.sh
- exec: |
bash /root/golang-install.sh
source /etc/profile.d/golang.sh && echo $PATH
git config --global --add safe.directory /root/go/src/github.com/labring/sealos
cd /Users/cuisongliu/Workspaces/go/src/github.com/labring/sealos && source /etc/profile.d/golang.sh && make build
ons:
- role: master
10 changes: 10 additions & 0 deletions docs/examples/orb/rebuild.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
apiVersion: virtual-machine.sealos.io/v1
kind: Action
spec:
data:
- exec: |
cd /Users/cuisongliu/Workspaces/go/src/github.com/labring/sealos && source /etc/profile.d/golang.sh && make build
cp bin/linux_arm64/sealos /usr/bin/
cp bin/linux_arm64/sealctl /usr/bin/
ons:
- role: master
2 changes: 1 addition & 1 deletion docs/sealvm/sealvm.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ sealvm action -f action.yaml --debug

## 系统管理命令

### 安装(install)
### 安装(install) 新版本废弃(v0.2.0)

该命令用于安装虚拟机相关的工具。使用格式如下:

Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ require (
github.com/spf13/cobra v1.6.1
golang.org/x/crypto v0.3.0
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4
gopkg.in/yaml.v3 v3.0.1
k8s.io/api v0.25.0
k8s.io/apimachinery v0.25.3
k8s.io/client-go v0.25.0
Expand Down
Loading

0 comments on commit a9fe172

Please sign in to comment.