Skip to content

Commit

Permalink
fix delete clusterFile (#65)
Browse files Browse the repository at this point in the history
* fix login;
fix delete clusterFile

* fix login;
fix delete clusterFile

* update
  • Loading branch information
bxy4543 committed May 12, 2021
1 parent 620df9a commit cfb28d6
Show file tree
Hide file tree
Showing 11 changed files with 49 additions and 52 deletions.
3 changes: 1 addition & 2 deletions apply/cloud_applier.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,9 @@ func (c *CloudApplier) Delete() error {
}
if err := utils.RemoveFileContent(common.EtcHosts, fmt.Sprintf("%s %s", host, common.APIServerDomain)); err != nil {
logger.Warn(err)
return nil
}

if err := utils.CleanFiles(common.DefaultKubeconfigDir, common.GetClusterWorkDir(c.ClusterDesired.Name), common.KubectlPath); err != nil {
if err := utils.CleanFiles(common.DefaultKubeconfigDir, common.GetClusterWorkDir(c.ClusterDesired.Name), common.TmpClusterfile, common.KubectlPath); err != nil {
logger.Warn(err)
return nil
}
Expand Down
10 changes: 7 additions & 3 deletions sealer/cmd/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ var buildConfig *BuildFlag

// buildCmd represents the build command
var buildCmd = &cobra.Command{
Use: "build",
Short: "cloud image local build command line",
Long: `sealer build -f Kubefile -t my-kubernetes:1.18.3 .`,
Use: "build",
Short: "cloud image local build command line",
Example: `sealer build -f Kubefile -t my-kubernetes:1.18.3 .`,
Run: func(cmd *cobra.Command, args []string) {
conf := &build.Config{}
builder := build.NewBuilder(conf, buildConfig.BuildType)
Expand All @@ -55,4 +55,8 @@ func init() {
buildCmd.Flags().StringVarP(&buildConfig.KubefileName, "kubefile", "f", "Kubefile", "kubefile filepath")
buildCmd.Flags().StringVarP(&buildConfig.ImageName, "imageName", "t", "", "cluster image name")
buildCmd.Flags().StringVarP(&buildConfig.Context, "context", "c", ".", "cluster image build context file path")
if err := buildCmd.MarkFlagRequired("imageName"); err != nil {
logger.Error("failed to init flag: %v", err)
os.Exit(1)
}
}
8 changes: 4 additions & 4 deletions sealer/cmd/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ import (

// deleteCmd represents the delete command
var deleteCmd = &cobra.Command{
Use: "delete",
Short: "delete a cluster",
Long: `sealer delete -f /root/.sealer/mycluster/Clusterfile
if provider is BARESERVER will delete kubernetes nodes, or if provider is ALI_CLOUD, will delete all the infra resources`,
Use: "delete",
Short: "delete a cluster",
Long: `if provider is BARESERVER will delete kubernetes nodes, or if provider is ALI_CLOUD, will delete all the infra resources`,
Example: `sealer delete -f /root/.sealer/mycluster/Clusterfile`,
Run: func(cmd *cobra.Command, args []string) {
if err := apply.NewApplierFromFile(clusterFile).Delete(); err != nil {
logger.Error(err)
Expand Down
6 changes: 3 additions & 3 deletions sealer/cmd/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ const (
)

var listCmd = &cobra.Command{
Use: "images",
Short: "list all cluster images",
Long: `sealer images`,
Use: "images",
Short: "list all cluster images",
Example: `sealer images`,
Run: func(cmd *cobra.Command, args []string) {
imageMetadataList, err := image.NewImageMetadataService().List()
if err != nil {
Expand Down
15 changes: 12 additions & 3 deletions sealer/cmd/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,10 @@ type LoginFlag struct {
var loginConfig *LoginFlag

var loginCmd = &cobra.Command{
Use: "login",
Short: "login image repositories",
Long: `sealer login registry.cn-qingdao.aliyuncs.com -u [username] -p [password]`,
Use: "login",
Short: "login image repositories",
Example: `sealer login registry.cn-qingdao.aliyuncs.com -u [username] -p [password]`,
Args: cobra.ExactArgs(1),
Run: func(cmd *cobra.Command, args []string) {
if len(args) == 0 {
logger.Error("enter the registry URL failed")
Expand All @@ -52,4 +53,12 @@ func init() {
rootCmd.AddCommand(loginCmd)
loginCmd.Flags().StringVarP(&loginConfig.RegistryUsername, "username", "u", "", "user name for login registry")
loginCmd.Flags().StringVarP(&loginConfig.RegistryPasswd, "passwd", "p", "", "password for login registry")
if err := loginCmd.MarkFlagRequired("username"); err != nil {
logger.Error("failed to init flag: %v", err)
os.Exit(1)
}
if err := loginCmd.MarkFlagRequired("passwd"); err != nil {
logger.Error("failed to init flag: %v", err)
os.Exit(1)
}
}
11 changes: 4 additions & 7 deletions sealer/cmd/pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,11 @@ import (

// pullCmd represents the pull command
var pullCmd = &cobra.Command{
Use: "pull",
Short: "pull cloud image to local",
Long: `sealer pull registry.cn-qingdao.aliyuncs.com/sealer-io/cloudrootfs:v1.16.9-alpha.5`,
Use: "pull",
Short: "pull cloud image to local",
Example: `sealer pull registry.cn-qingdao.aliyuncs.com/sealer-io/cloudrootfs:v1.16.9-alpha.5`,
Args: cobra.ExactArgs(1),
Run: func(cmd *cobra.Command, args []string) {
if len(args) == 0 {
logger.Error("enter the imageName")
os.Exit(1)
}
if err := image.NewImageService().Pull(args[0]); err != nil {
logger.Error(err)
os.Exit(1)
Expand Down
11 changes: 4 additions & 7 deletions sealer/cmd/push.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,11 @@ import (

// pushCmd represents the push command
var pushCmd = &cobra.Command{
Use: "push",
Short: "push cloud image to registry",
Long: `sealer push registry.cn-qingdao.aliyuncs.com/sealer-io/my-kuberentes-cluster-with-dashboard:latest`,
Use: "push",
Short: "push cloud image to registry",
Example: `sealer push registry.cn-qingdao.aliyuncs.com/sealer-io/my-kuberentes-cluster-with-dashboard:latest`,
Args: cobra.ExactArgs(1),
Run: func(cmd *cobra.Command, args []string) {
if len(args) == 0 {
logger.Error("enter the imageName")
os.Exit(1)
}
if err := image.NewImageService().Push(args[0]); err != nil {
logger.Error(err)
os.Exit(1)
Expand Down
11 changes: 4 additions & 7 deletions sealer/cmd/rmi.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,11 @@ import (

// rmiCmd represents the rmi command
var rmiCmd = &cobra.Command{
Use: "rmi",
Short: "rmi delete local image",
Long: `sealer rmi registry.cn-qingdao.aliyuncs.com/seadent/cloudrootfs:v1.16.9-alpha.5`,
Use: "rmi",
Short: "rmi delete local image",
Example: `sealer rmi registry.cn-qingdao.aliyuncs.com/sealer/cloudrootfs:v1.16.9-alpha.5`,
Args: cobra.ExactArgs(1),
Run: func(cmd *cobra.Command, args []string) {
if len(args) == 0 {
logger.Error("enter the imageName")
os.Exit(1)
}
if err := image.NewImageService().Delete(args[0]); err != nil {
logger.Error(err)
os.Exit(1)
Expand Down
9 changes: 3 additions & 6 deletions sealer/cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ var runArgs *common.RunArgs
var runCmd = &cobra.Command{
Use: "run",
Short: "run a cluster with images and arguments",
Long: `sealer run registry.cn-qingdao.aliyuncs.com/sealer-io/cloudrootfs:v1.16.9-alpha.7 --masters [arg] --nodes [arg]
examples:
Long: `sealer run registry.cn-qingdao.aliyuncs.com/sealer-io/cloudrootfs:v1.16.9-alpha.7 --masters [arg] --nodes [arg]`,
Example: `
create default cluster:
sealer run registry.cn-qingdao.aliyuncs.com/sealer-io/cloudrootfs:v1.16.9-alpha.7
Expand All @@ -30,11 +30,8 @@ create cluster to your baremetal server, appoint the iplist:
sealer run registry.cn-qingdao.aliyuncs.com/sealer-io/cloudrootfs:v1.16.9-alpha.7 --masters 192.168.0.2,192.168.0.3,192.168.0.4 \
--nodes 192.168.0.5,192.168.0.6,192.168.0.7
`,
Args: cobra.ExactArgs(1),
Run: func(cmd *cobra.Command, args []string) {
if len(args) == 0 {
logger.Error("cluster image name not found")
os.Exit(1)
}
applier, err := apply.NewApplierFromArgs(args[0], runArgs)
if err != nil {
logger.Error(err)
Expand Down
11 changes: 4 additions & 7 deletions sealer/cmd/tag.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,11 @@ import (
)

var tagCmd = &cobra.Command{
Use: "tag",
Short: "tag IMAGE[:TAG] TARGET_IMAGE[:TAG]",
Long: `sealer tag sealer/cloudrootfs:v1.16.9-alpha.6 registry.cn-qingdao.aliyuncs.com/sealer-io/cloudrootfs:v1.16.9-alpha.5`,
Use: "tag",
Short: "tag IMAGE[:TAG] TARGET_IMAGE[:TAG]",
Example: `sealer tag sealer/cloudrootfs:v1.16.9-alpha.6 registry.cn-qingdao.aliyuncs.com/sealer-io/cloudrootfs:v1.16.9-alpha.5`,
Args: cobra.ExactArgs(2),
Run: func(cmd *cobra.Command, args []string) {
if len(args) < 2 {
logger.Error("Enter imageName and target imageName")
os.Exit(1)
}
err := image.NewImageMetadataService().Tag(args[0], args[1])
if err != nil {
logger.Error(err)
Expand Down
6 changes: 3 additions & 3 deletions sealer/cmd/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ import (
var shortPrint bool

var versionCmd = &cobra.Command{
Use: "version",
Short: "version",
Long: `sealer version`,
Use: "version",
Short: "version",
Example: `sealer version`,
Run: func(cmd *cobra.Command, args []string) {
marshalled, err := json.Marshal(version.Get())
if err != nil {
Expand Down

0 comments on commit cfb28d6

Please sign in to comment.