forked from labring/sealos
-
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.
Merge pull request labring#481 from oldthreefeng/upgrade_kubernetes_b…
…y_sealos WIP: add upgrade kubernetes cmd
- Loading branch information
Showing
17 changed files
with
2,358 additions
and
92 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
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,67 @@ | ||
/* | ||
Copyright © 2020 NAME HERE <EMAIL ADDRESS> | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
"github.com/fanux/sealos/install" | ||
"github.com/spf13/cobra" | ||
"github.com/wonderivan/logger" | ||
"os" | ||
) | ||
|
||
func init() { | ||
rootCmd.AddCommand(NewUpgradeCmd()) | ||
} | ||
|
||
var ( | ||
newVersion string | ||
newPkgUrl string | ||
) | ||
|
||
func NewUpgradeCmd() *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "upgrade", | ||
Short: "upgrade your kubernetes version by sealos", | ||
Run: UpgradeCmdFunc, | ||
PreRun: PreRunUpgradeCmdFunc, | ||
} | ||
cmd.Flags().StringVar(&newVersion, "version", "", "upgrade version for kubernetes version") | ||
cmd.Flags().StringVar(&newPkgUrl, "pkg-url", "", "http://store.lameleg.com/kube1.14.1.tar.gz download offline package url, or file location ex. /root/kube1.14.1.tar.gz") | ||
cmd.Flags().BoolVarP(&force, "force", "f", false, "upgrade need interactive to confirm") | ||
return cmd | ||
} | ||
|
||
func UpgradeCmdFunc(cmd *cobra.Command, args []string) { | ||
if !force { | ||
prompt := fmt.Sprintf("upgrade cmd will upgrade your kubernetes cluster immediately \n" + | ||
"Are you sure you want to proceed with the upgrade? (y/n)?") | ||
result := install.Confirm(prompt) | ||
if !result { | ||
logger.Info("upgrade is skip, Exit") | ||
os.Exit(-1) | ||
} | ||
} | ||
u := install.NewUpgrade(newVersion, newPkgUrl) | ||
u.SetUP() | ||
} | ||
|
||
func PreRunUpgradeCmdFunc(cmd *cobra.Command, args []string) { | ||
if err := install.ExitUpgradeCase(newVersion, newPkgUrl) ; err != nil { | ||
logger.Error("PreRun error: ", err) | ||
os.Exit(1) | ||
} | ||
} |
Large diffs are not rendered by default.
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
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
Oops, something went wrong.