Skip to content

Commit

Permalink
fix root to $HOME in sealos
Browse files Browse the repository at this point in the history
Signed-off-by: oldthreefeng <[email protected]>
  • Loading branch information
oldthreefeng committed Jan 5, 2021
1 parent a15e341 commit 2c3b8a7
Show file tree
Hide file tree
Showing 11 changed files with 55 additions and 104 deletions.
11 changes: 10 additions & 1 deletion cert/kube_certs.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,21 @@ import (
)

var (
SealosConfigDir = "/root/.sealos"
SealosConfigDir = getSealosCertDir()
KubernetesDir = "/etc/kubernetes"
KubeDefaultCertPath = "/etc/kubernetes/pki"
kubeDefaultCertEtcdPath = "/etc/kubernetes/pki/etcd"
)

func getSealosCertDir() string {
home, err := os.UserHomeDir()
if err != nil {
fmt.Println(err)
os.Exit(1)
}
return home + "/.sealos"
}

func CaList(CertPath, CertEtcdPath string) []Config {
return []Config{
{
Expand Down
6 changes: 3 additions & 3 deletions cmd/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ func init() {
// Here you will define your flags and configuration settings.
initCmd.Flags().StringVar(&install.SSHConfig.User, "user", "root", "servers user name for ssh")
initCmd.Flags().StringVar(&install.SSHConfig.Password, "passwd", "", "password for ssh")
initCmd.Flags().StringVar(&install.SSHConfig.PkFile, "pk", "/root/.ssh/id_rsa", "private key for ssh")
initCmd.Flags().StringVar(&install.SSHConfig.PkFile, "pk", getUserHome() + "/.ssh/id_rsa", "private key for ssh")
initCmd.Flags().StringVar(&install.SSHConfig.PkPassword, "pk-passwd", "", "private key password for ssh")

initCmd.Flags().StringVar(&install.KubeadmFile, "kubeadm-config", "", "kubeadm-config.yaml template file")
Expand Down Expand Up @@ -138,8 +138,8 @@ func init() {
initCmd.Flags().IntVar(&install.Vlog, "vlog", 0, "kubeadm log level")

// 不像用户暴露
// initCmd.Flags().StringVar(&install.CertPath, "cert-path", "/root/.sealos/pki", "cert file path")
// initCmd.Flags().StringVar(&install.CertEtcdPath, "cert-etcd-path", "/root/.sealos/pki/etcd", "etcd cert file path")
// initCmd.Flags().StringVar(&install.CertPath, "cert-path", getUserHome() + "/.sealos/pki", "cert file path")
// initCmd.Flags().StringVar(&install.CertEtcdPath, "cert-etcd-path", getUserHome() + "/.sealos/pki/etcd", "etcd cert file path")
}

func NewInitGenerateCmd() *cobra.Command {
Expand Down
2 changes: 1 addition & 1 deletion cmd/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func init() {
rootCmd.AddCommand(installCmd)

installCmd.Flags().StringVar(&AppURL, "pkg-url", "", "http://store.lameleg.com/prometheus.tar.gz download offline plugins package url, or file localtion ex. /root/prometheus.tar.gz")
installCmd.Flags().StringVarP(&install.WorkDir, "workdir", "w", "/root", "workdir for install package home ex. sealos install --pkg-url dashboard.tar --workdir /data")
installCmd.Flags().StringVarP(&install.WorkDir, "workdir", "w", getUserHome(), "workdir for install package home ex. sealos install --pkg-url dashboard.tar --workdir /data")
installCmd.Flags().StringVarP(&install.PackageConfig, "pkg-config", "c", "", `packageConfig for install package config ex. sealos install --pkg-url dashboard.tar -c config`)
installCmd.Flags().StringVarP(&install.Values, "values", "f", "", "values for install package values.yaml , you know what you did .ex. sealos install --pkg-url dashboard.tar -f values.yaml")
}
17 changes: 11 additions & 6 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,10 @@ func init() {
// initConfig reads in config file and ENV variables if set.
func initConfig() {
// Find home directory.
home, err := homedir.Dir()
if err != nil {
fmt.Println(err)
os.Exit(1)
}
home := getUserHome()
logFile := fmt.Sprintf("%s/.sealos/sealos.log", home)
if !install.FileExist(home + "/.sealos") {
err = os.MkdirAll(home + "/.sealos",os.ModePerm)
err := os.MkdirAll(home + "/.sealos",os.ModePerm)
if err != nil {
fmt.Println("create default sealos config dir failed, please create it by your self mkdir -p /root/.sealos && touch /root/.sealos/config.yaml")
}
Expand All @@ -82,3 +78,12 @@ func initConfig() {
logger.Cfg(6, logFile)
}
}

func getUserHome() string {
home, err := homedir.Dir()
if err != nil {
fmt.Println(err)
os.Exit(1)
}
return home
}
12 changes: 4 additions & 8 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,17 @@ go 1.13
require (
github.com/aliyun/aliyun-oss-go-sdk v2.1.4+incompatible
github.com/baiyubin/aliyun-sts-go-sdk v0.0.0-20180326062324-cfa1a18b161f // indirect
github.com/coreos/go-semver v0.3.0 // indirect
github.com/dustin/go-humanize v1.0.0 // indirect
github.com/fanux/lvscare v0.0.0-00010101000000-000000000000
github.com/fanux/sealgate v0.0.5
github.com/fsnotify/fsnotify v1.4.9 // indirect
github.com/ghodss/yaml v1.0.0
github.com/magiconair/properties v1.8.4 // indirect
github.com/gorilla/websocket v1.4.2 // indirect
github.com/mitchellh/go-homedir v1.1.0
github.com/mitchellh/mapstructure v1.3.3 // indirect
github.com/pelletier/go-toml v1.8.1 // indirect
github.com/pkg/errors v0.9.1
github.com/pkg/sftp v1.11.0
github.com/satori/go.uuid v1.2.0 // indirect
github.com/spf13/afero v1.4.0 // indirect
github.com/spf13/cast v1.3.1 // indirect
github.com/spf13/cobra v1.0.0
github.com/spf13/jwalterweatherman v1.1.0 // indirect
github.com/spf13/viper v1.7.1
github.com/vishvananda/netlink v1.1.0
github.com/wangle201210/githubapi v0.0.0-20200804144924-cde7bbdc36ab
github.com/wonderivan/logger v1.0.0
Expand All @@ -30,6 +24,8 @@ require (
go.uber.org/zap v1.13.0
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9
golang.org/x/sys v0.0.0-20200923182605-d9f96fdee20d // indirect
golang.org/x/text v0.3.3 // indirect
google.golang.org/appengine v1.6.1 // indirect
gopkg.in/ini.v1 v1.61.0 // indirect
gopkg.in/yaml.v2 v2.3.0
k8s.io/api v0.18.0
Expand Down
Loading

0 comments on commit 2c3b8a7

Please sign in to comment.