Skip to content

Commit

Permalink
feat(autok3s): support hosted UI and API
Browse files Browse the repository at this point in the history
Signed-off-by: JacieChao <kathyyy@163.com>
  • Loading branch information
JacieChao authored and Jason-ZW committed Feb 3, 2021
1 parent 9677d25 commit 06d3c89
Show file tree
Hide file tree
Showing 145 changed files with 11,089 additions and 375 deletions.
16 changes: 12 additions & 4 deletions .drone.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,24 @@ platform:
os: linux
arch: amd64
steps:
- name: build
image: maiwj/drone-dapper:v0.4.2
privileged: true
environment:
BY: dapper
CROSS: false
commands:
- make autok3s build only
volumes:
- name: docker
path: /var/run/docker.sock
- name: verify
image: maiwj/drone-dapper:v0.4.2
privileged: true
environment:
BY: dapper
commands:
- make autok3s unit
- make autok3s unit only
volumes:
- name: docker
path: /var/run/docker.sock
Expand Down Expand Up @@ -121,8 +132,6 @@ volumes:
trigger:
event:
include:
- push
- pull_request
- tag
node:
instance: agent-amd64
Expand Down Expand Up @@ -171,7 +180,6 @@ trigger:
- "refs/tags/v*"
event:
include:
- push
- tag
node:
instance: agent-amd64
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,4 @@ main
**/Dockerfile.dapper*
!**/Dockerfile.dapper
.autok3s/
static/
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ See the providers' links below for more usage details:
- [alibaba](docs/i18n/en_us/alibaba/README.md) - Bootstrap Kubernetes with k3s onto Alibaba ECS
- [tencent](docs/i18n/en_us/tencent/README.md) - Bootstrap Kubernetes with k3s onto Tencent CVM
- [native](docs/i18n/en_us/native/README.md) - Bootstrap Kubernetes with k3s onto any VM
- [amazone](docs/i18n/en_us/amazone/README.md) - Bootstrap Kubernetes with k3s onto Amazone ECS
- [aws](docs/i18n/en_us/aws/README.md) - Bootstrap Kubernetes with k3s onto Amazon EC2

## Quick Start
The following command use the `alibaba` provider, with prerequisites that refer to the [alibaba](docs/i18n/en_us/alibaba/README.md) document.
Expand All @@ -49,6 +49,10 @@ export ECS_ACCESS_KEY_SECRET='<Your secret access key>'
autok3s -d create -p alibaba --name myk3s --master 1 --worker 1
```

## Quick Start with UI

If you want to use hosted UI instead of command line, please run `autok3s serve`

## Demo Video
The demo install Kubernetes (k3s) onto Alibaba ECS machines in around 1 minutes.

Expand Down
10 changes: 9 additions & 1 deletion cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (

// import custom provider
_ "github.com/cnrancher/autok3s/pkg/providers/alibaba"
_ "github.com/cnrancher/autok3s/pkg/providers/amazone"
_ "github.com/cnrancher/autok3s/pkg/providers/aws"
_ "github.com/cnrancher/autok3s/pkg/providers/native"
_ "github.com/cnrancher/autok3s/pkg/providers/tencent"

Expand Down Expand Up @@ -67,6 +67,14 @@ func initCfg() {
logrus.Fatalln(err)
}

if err := utils.EnsureFolderExist(common.GetLogPath()); err != nil {
logrus.Fatalln(err)
}

if err := utils.EnsureFolderExist(common.GetClusterStatePath()); err != nil {
logrus.Fatalln(err)
}

kubeCfg := fmt.Sprintf("%s/%s", common.CfgPath, common.KubeCfgFile)
if err := os.Setenv(clientcmd.RecommendedConfigPathEnvVar, kubeCfg); err != nil {
logrus.Errorf("[kubectl] failed to set %s=%s env\n", clientcmd.RecommendedConfigPathEnvVar, kubeCfg)
Expand Down
10 changes: 5 additions & 5 deletions cmd/common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ import (
"github.com/cnrancher/autok3s/pkg/common"
"github.com/cnrancher/autok3s/pkg/providers"
"github.com/cnrancher/autok3s/pkg/providers/alibaba"
"github.com/cnrancher/autok3s/pkg/providers/amazone"
"github.com/cnrancher/autok3s/pkg/providers/aws"
"github.com/cnrancher/autok3s/pkg/providers/tencent"
"github.com/cnrancher/autok3s/pkg/types"
typesAli "github.com/cnrancher/autok3s/pkg/types/alibaba"
typesAmazone "github.com/cnrancher/autok3s/pkg/types/amazone"
typesaws "github.com/cnrancher/autok3s/pkg/types/aws"
typesTencent "github.com/cnrancher/autok3s/pkg/types/tencent"
"github.com/cnrancher/autok3s/pkg/utils"

Expand Down Expand Up @@ -139,12 +139,12 @@ func GetProviderByState(c types.Cluster) (providers.Provider, error) {
Options: *option,
Status: c.Status,
}, nil
case "amazone":
option := &typesAmazone.Options{}
case "aws":
option := &typesaws.Options{}
if err := yaml.Unmarshal(b, option); err != nil {
return nil, err
}
return &amazone.Amazone{
return &aws.Amazon{
Metadata: c.Metadata,
Options: *option,
Status: c.Status,
Expand Down
10 changes: 7 additions & 3 deletions cmd/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"github.com/cnrancher/autok3s/cmd/common"
"github.com/cnrancher/autok3s/pkg/providers"
"github.com/cnrancher/autok3s/pkg/types"
"github.com/cnrancher/autok3s/pkg/utils"

"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -46,14 +47,14 @@ func CreateCommand() *cobra.Command {
createCmd.Flags().StringVar(&cSSH.Password, "ssh-password", cSSH.Password, "SSH login password")
createCmd.Flags().BoolVar(&cSSH.SSHAgentAuth, "ssh-agent", cSSH.SSHAgentAuth, "Enable ssh agent")

createCmd.Flags().AddFlagSet(cp.GetCredentialFlags(createCmd))
createCmd.Flags().AddFlagSet(cp.GetCreateFlags(createCmd))
createCmd.Flags().AddFlagSet(utils.ConvertFlags(createCmd, cp.GetCredentialFlags()))
createCmd.Flags().AddFlagSet(utils.ConvertFlags(createCmd, cp.GetOptionFlags()))
createCmd.Example = cp.GetUsageExample("create")
}

createCmd.PreRunE = func(cmd *cobra.Command, args []string) error {
if cProvider == "" {
logrus.Fatalln("required flags(s) \"[provider]\" not set")
logrus.Fatalln("required flags(s) \"--provider\" not set")
}
common.InitPFlags(cmd, cp)
return common.MakeSureCredentialFlag(cmd.Flags(), cp)
Expand All @@ -62,6 +63,9 @@ func CreateCommand() *cobra.Command {
createCmd.Run = func(cmd *cobra.Command, args []string) {
// generate cluster name. e.g. input: "--name k3s1 --region cn-hangzhou" output: "k3s1.cn-hangzhou.<provider>"
cp.GenerateClusterName()
if err := cp.CreateCheck(cSSH); err != nil {
logrus.Fatalln(err)
}

// create k3s cluster with generated cluster name.
if err := cp.CreateK3sCluster(cSSH); err != nil {
Expand Down
3 changes: 2 additions & 1 deletion cmd/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package cmd
import (
"github.com/cnrancher/autok3s/cmd/common"
"github.com/cnrancher/autok3s/pkg/providers"
"github.com/cnrancher/autok3s/pkg/utils"

"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -33,7 +34,7 @@ func DeleteCommand() *cobra.Command {
dp = reg
}

deleteCmd.Flags().AddFlagSet(dp.GetCredentialFlags(deleteCmd))
deleteCmd.Flags().AddFlagSet(utils.ConvertFlags(deleteCmd, dp.GetCredentialFlags()))
deleteCmd.Flags().AddFlagSet(dp.GetDeleteFlags(deleteCmd))
joinCmd.Example = dp.GetUsageExample("delete")
}
Expand Down
3 changes: 2 additions & 1 deletion cmd/join.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"github.com/cnrancher/autok3s/cmd/common"
"github.com/cnrancher/autok3s/pkg/providers"
"github.com/cnrancher/autok3s/pkg/types"
"github.com/cnrancher/autok3s/pkg/utils"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)
Expand Down Expand Up @@ -44,7 +45,7 @@ func JoinCommand() *cobra.Command {
joinCmd.Flags().StringVar(&jSSH.Password, "ssh-password", jSSH.Password, "SSH login password")
joinCmd.Flags().BoolVar(&jSSH.SSHAgentAuth, "ssh-agent", jSSH.SSHAgentAuth, "Enable ssh agent")

joinCmd.Flags().AddFlagSet(jp.GetCredentialFlags(joinCmd))
joinCmd.Flags().AddFlagSet(utils.ConvertFlags(joinCmd, jp.GetCredentialFlags()))
joinCmd.Flags().AddFlagSet(jp.GetJoinFlags(joinCmd))
joinCmd.Example = jp.GetUsageExample("join")
}
Expand Down
23 changes: 5 additions & 18 deletions cmd/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,9 @@ func listCluster() {
if err != nil {
logrus.Fatalf("failed to unmarshal state file, msg: %v\n", err)
}

var (
p providers.Provider
filters []*types.ClusterInfo
clusterList []*types.Cluster
)

var p providers.Provider
kubeCfg := fmt.Sprintf("%s/%s", common.CfgPath, common.KubeCfgFile)
filters := []*types.ClusterInfo{}
for _, r := range result {
p, err = c.GetProviderByState(r)
if err != nil {
Expand All @@ -79,20 +74,12 @@ func listCluster() {
if err := cluster.OverwriteCfg(r.Name); err != nil {
logrus.Errorf("failed to remove unexist cluster %s from kube config", r.Name)
}
if err := cluster.DeleteState(r.Name, r.Provider); err != nil {
logrus.Errorf("failed to remove unexist cluster %s from state: %v", r.Name, err)
}
continue
}

filters = append(filters, p.GetCluster(kubeCfg))
clusterList = append(clusterList, &types.Cluster{
Metadata: r.Metadata,
Options: r.Options,
Status: r.Status,
})
}

// remove useless clusters from .state.
if err := cluster.FilterState(clusterList); err != nil {
logrus.Errorf("failed to remove useless clusters\n")
}

for _, f := range filters {
Expand Down
5 changes: 3 additions & 2 deletions cmd/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,13 @@ var (
}

bindPort = "8080"
bindAddress = "0.0.0.0"
bindAddress = "127.0.0.1"
)

func init() {
// only support localhost for now
serveCmd.Flags().StringVar(&bindPort, "bind-port", bindPort, "HTTP/HTTPS bind port")
serveCmd.Flags().StringVar(&bindAddress, "bind-address", bindAddress, "HTTP/HTTPS bind address")
//serveCmd.Flags().StringVar(&bindAddress, "bind-address", bindAddress, "HTTP/HTTPS bind address")
}

func ServeCommand() *cobra.Command {
Expand Down
3 changes: 2 additions & 1 deletion cmd/ssh.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"github.com/cnrancher/autok3s/cmd/common"
"github.com/cnrancher/autok3s/pkg/providers"
"github.com/cnrancher/autok3s/pkg/types"
"github.com/cnrancher/autok3s/pkg/utils"

"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -43,7 +44,7 @@ func SSHCommand() *cobra.Command {
sshCmd.Flags().StringVar(&sSSH.Password, "ssh-password", sSSH.Password, "SSH login password")
sshCmd.Flags().BoolVar(&sSSH.SSHAgentAuth, "ssh-agent", sSSH.SSHAgentAuth, "Enable ssh agent")

sshCmd.Flags().AddFlagSet(sp.GetCredentialFlags(sshCmd))
sshCmd.Flags().AddFlagSet(utils.ConvertFlags(sshCmd, sp.GetCredentialFlags()))
sshCmd.Flags().AddFlagSet(sp.GetSSHFlags(sshCmd))
sshCmd.Example = sp.GetUsageExample("ssh")
}
Expand Down

0 comments on commit 06d3c89

Please sign in to comment.