Skip to content

Commit

Permalink
resolve conflict (#1910)
Browse files Browse the repository at this point in the history
  • Loading branch information
Stevent-fei authored Dec 16, 2022
1 parent bae3392 commit 92521b9
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 155 deletions.
2 changes: 1 addition & 1 deletion cmd/sealer/cmd/cluster/apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ func NewApplyCmd() *cobra.Command {

if extension.Type == v12.AppInstaller {
logrus.Infof("start to install application: %s", imageName)
return installApplication(imageName, []string{}, extension, infraDriver, imageEngine, applyMode)
return installApplication(imageName, nil, extension, infraDriver, imageEngine, applyMode)
}

client := utils.GetClusterClient()
Expand Down
2 changes: 1 addition & 1 deletion cmd/sealer/cmd/cluster/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ import "github.com/spf13/cobra"

func NewClusterCommands() []*cobra.Command {
var clusterCommands []*cobra.Command
clusterCommands = append(clusterCommands, NewDeleteCmd(), NewJoinCmd(), NewRunCmd(), NewRunAPPCmd(), NewCertCmd(), NewScaleUpCmd(), NewApplyCmd())
clusterCommands = append(clusterCommands, NewDeleteCmd(), NewJoinCmd(), NewRunCmd(), NewCertCmd(), NewScaleUpCmd(), NewApplyCmd())
return clusterCommands
}
139 changes: 0 additions & 139 deletions cmd/sealer/cmd/cluster/run-app.go

This file was deleted.

92 changes: 86 additions & 6 deletions cmd/sealer/cmd/cluster/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"github.com/sealerio/sealer/common"
clusterruntime "github.com/sealerio/sealer/pkg/cluster-runtime"
"github.com/sealerio/sealer/pkg/clusterfile"
v12 "github.com/sealerio/sealer/pkg/define/image/v1"
imagecommon "github.com/sealerio/sealer/pkg/define/options"
"github.com/sealerio/sealer/pkg/imagedistributor"
"github.com/sealerio/sealer/pkg/imageengine"
Expand All @@ -46,6 +47,9 @@ run cluster by Clusterfile:
run cluster by CLI flags:
sealer run registry.cn-qingdao.aliyuncs.com/sealer-io/kubernetes:v1.22.4 -m 172.28.80.01 -n 172.28.80.02 -p Sealer123
run app image:
sealer run localhost/nginx:v1
`

func NewRunCmd() *cobra.Command {
Expand Down Expand Up @@ -73,6 +77,43 @@ func NewRunCmd() *cobra.Command {
clusterFile = runFlags.ClusterFile
applyMode = runFlags.Mode
)
imageEngine, err := imageengine.NewImageEngine(imagecommon.EngineGlobalConfigurations{})
if err != nil {
return err
}

extension, err := imageEngine.GetSealerImageExtension(&imagecommon.GetImageAnnoOptions{ImageNameOrID: args[0]})
if err != nil {
return fmt.Errorf("failed to get cluster image extension: %s", err)
}

if extension.Type == v12.AppInstaller {
logrus.Infof("start to install app image: %s", args[0])
cf, err := clusterfile.NewClusterFile(nil)
if err != nil {
return err
}

cluster := cf.GetCluster()
infraDriver, err := infradriver.NewInfraDriver(&cluster)
if err != nil {
return err
}

if err := imageEngine.Pull(&imagecommon.PullOptions{
Quiet: false,
PullPolicy: "missing",
Image: args[0],
Platform: "local",
}); err != nil {
return err
}
return installApplication(args[0], runFlags.LaunchCmds, extension, infraDriver, imageEngine, applyMode)
}

if len(runFlags.LaunchCmds) > 0 {
return fmt.Errorf("this command parameter (--cmds) is only available to application images")
}

if runFlags.Masters == "" && clusterFile == "" {
return fmt.Errorf("you must input master ip Or use Clusterfile")
Expand Down Expand Up @@ -119,11 +160,6 @@ func NewRunCmd() *cobra.Command {
return err
}

imageEngine, err := imageengine.NewImageEngine(imagecommon.EngineGlobalConfigurations{})
if err != nil {
return err
}

return createNewCluster(infraDriver, imageEngine, cf, applyMode)
},
}
Expand All @@ -138,10 +174,10 @@ func NewRunCmd() *cobra.Command {
runCmd.Flags().StringVar(&runFlags.Pk, "pk", filepath.Join(common.GetHomeDir(), ".ssh", "id_rsa"), "set baremetal server private key")
runCmd.Flags().StringVar(&runFlags.PkPassword, "pk-passwd", "", "set baremetal server private key password")
runCmd.Flags().StringSliceVar(&runFlags.CMDArgs, "cmd-args", []string{}, "set args for image cmd instruction")
runCmd.Flags().StringSliceVar(&runFlags.LaunchCmds, "cmds", []string{}, "override default LaunchCmds of clusterimage")
runCmd.Flags().StringSliceVarP(&runFlags.CustomEnv, "env", "e", []string{}, "set custom environment variables")
runCmd.Flags().StringVarP(&runFlags.ClusterFile, "Clusterfile", "f", "", "Clusterfile path to run a Kubernetes cluster")
runCmd.Flags().StringVar(&runFlags.Mode, "mode", common.ApplyModeApply, "load images to the specified registry in advance")

//err := runCmd.RegisterFlagCompletionFunc("provider", func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
// return strings.ContainPartial([]string{common.BAREMETAL, common.AliCloud, common.CONTAINER}, toComplete), cobra.ShellCompDirectiveNoFileComp
//})
Expand Down Expand Up @@ -272,3 +308,47 @@ func loadToRegistry(infraDriver infradriver.InfraDriver, distributor imagedistri
logrus.Infof("load image success")
return nil
}

func installApplication(appImageName string, launchCmds []string, extension v12.ImageExtension,
infraDriver infradriver.InfraDriver, imageEngine imageengine.Interface, mode string) error {
clusterHosts := infraDriver.GetHostIPList()

clusterHostsPlatform, err := infraDriver.GetHostsPlatform(clusterHosts)
if err != nil {
return err
}

imageMounter, err := imagedistributor.NewImageMounter(imageEngine, clusterHostsPlatform)
if err != nil {
return err
}

imageMountInfo, err := imageMounter.Mount(appImageName)
if err != nil {
return err
}

defer func() {
err = imageMounter.Umount(appImageName, imageMountInfo)
if err != nil {
logrus.Errorf("failed to umount cluster image: %v", err)
}
}()

distributor, err := imagedistributor.NewScpDistributor(imageMountInfo, infraDriver, nil)
if err != nil {
return err
}

if mode == common.ApplyModeLoadImage {
return loadToRegistry(infraDriver, distributor)
}

installer := clusterruntime.NewAppInstaller(infraDriver, distributor, extension)
err = installer.Install(infraDriver.GetHostIPListByRole(common.MASTER)[0], launchCmds)
if err != nil {
return err
}

return nil
}
12 changes: 4 additions & 8 deletions cmd/sealer/cmd/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,14 @@ type Flags struct {
CMDArgs []string
Mode string
ClusterFile string
// override default LaunchCmds of clusterimage
LaunchCmds []string
// maybe we can support to override default LaunchArgs of clusterimage to render LaunchCmds.
LaunchArgs []string
}

type ApplyFlags struct {
ClusterFile string
ApplyMode string
ForceDelete bool
}

type APPFlags struct {
// override default LaunchCmds of clusterimage
LaunchCmds []string
// maybe we can support to override default LaunchArgs of clusterimage to render LaunchCmds.
LaunchArgs []string
ApplyMode string
}

0 comments on commit 92521b9

Please sign in to comment.