feature(main): sealos run repeat exec (#952)

* feature(main): sealos run repeat exec

* feature(main): sealos run repeat exec
This commit is contained in:
cuisongliu
2022-04-26 16:58:32 +08:00
committed by GitHub
parent 8e34fd9225
commit dd00fbf2a4
4 changed files with 30 additions and 22 deletions
@@ -17,6 +17,8 @@ package applydrivers
import (
"fmt"
"github.com/fanux/sealos/pkg/utils/strings"
"github.com/fanux/sealos/pkg/apply/processor"
"github.com/fanux/sealos/pkg/utils/logger"
"github.com/fanux/sealos/pkg/utils/yaml"
@@ -83,9 +85,24 @@ func (c *Applier) initCluster() error {
return nil
}
func diffImages(spec, curr *v2.Cluster) []string {
pullImages := make([]string, 0)
for _, img := range spec.Spec.Image {
if strings.NotIn(img, curr.Spec.Image) {
pullImages = append(pullImages, img)
}
}
return pullImages
}
func (c *Applier) installApp() error {
installProcessor, err := processor.NewInstallProcessor(c.ClusterFile)
err := c.ClusterFile.Process()
if err != nil {
return err
}
current := c.ClusterFile.GetCluster()
pullImages := diffImages(c.ClusterDesired, current)
installProcessor, err := processor.NewInstallProcessor(c.ClusterFile, pullImages)
if err != nil {
return err
}
+1 -1
View File
@@ -135,7 +135,7 @@ func (c *CreateProcessor) Join(cluster *v2.Cluster) error {
}
func (c *CreateProcessor) RunGuest(cluster *v2.Cluster) error {
return c.Guest.Apply(cluster)
return c.Guest.Apply(cluster, nil)
}
func NewCreateProcessor(clusterFile clusterfile.Interface) (Interface, error) {
+8 -17
View File
@@ -17,7 +17,6 @@ package processor
import (
"context"
"github.com/fanux/sealos/pkg/utils/strings"
"golang.org/x/sync/errgroup"
"github.com/fanux/sealos/pkg/clusterfile"
@@ -36,6 +35,7 @@ type InstallProcessor struct {
ClusterManager types.ClusterService
RegistryManager types.RegistryService
Guest guest.Interface
pullImages []string
imageList types.ImageListOCIV1
cManifestList types.ClusterManifestList
}
@@ -67,34 +67,23 @@ func (c *InstallProcessor) GetPipeLine() ([]func(cluster *v2.Cluster) error, err
return todoList, nil
}
func diffImages(spec, curr *v2.Cluster) []string {
pullImages := make([]string, 0)
for _, img := range spec.Spec.Image {
if strings.NotIn(img, curr.Spec.Image) {
pullImages = append(pullImages, img)
}
}
return pullImages
}
func (c *InstallProcessor) ChangeCluster(cluster *v2.Cluster) error {
err := c.ClusterFile.Process()
if err != nil {
return err
}
current := c.ClusterFile.GetCluster()
pullImages := diffImages(cluster, current)
err = c.RegistryManager.Pull(pullImages...)
err = c.RegistryManager.Pull(c.pullImages...)
if err != nil {
return err
}
img, err := c.ImageManager.Inspect(pullImages...)
img, err := c.ImageManager.Inspect(c.pullImages...)
if err != nil {
return err
}
//TODO if app image is ok
c.imageList = img
c.cManifestList, err = c.ClusterManager.Create(cluster.Name, len(current.Spec.Image), pullImages...)
c.cManifestList, err = c.ClusterManager.Create(cluster.Name, len(current.Spec.Image), c.pullImages...)
return err
}
@@ -121,10 +110,11 @@ func (c *InstallProcessor) MountRootfs(cluster *v2.Cluster) error {
}
func (c *InstallProcessor) RunGuest(cluster *v2.Cluster) error {
return c.Guest.Apply(cluster)
images := c.pullImages
return c.Guest.Apply(cluster, images)
}
func NewInstallProcessor(clusterFile clusterfile.Interface) (Interface, error) {
func NewInstallProcessor(clusterFile clusterfile.Interface, images []string) (Interface, error) {
imgSvc, err := image.NewImageService()
if err != nil {
return nil, err
@@ -151,5 +141,6 @@ func NewInstallProcessor(clusterFile clusterfile.Interface) (Interface, error) {
ClusterManager: clusterSvc,
RegistryManager: registrySvc,
Guest: gs,
pullImages: images,
}, nil
}
+3 -3
View File
@@ -30,7 +30,7 @@ import (
)
type Interface interface {
Apply(cluster *v2.Cluster) error
Apply(cluster *v2.Cluster, images []string) error
Delete(cluster *v2.Cluster) error
}
@@ -46,9 +46,9 @@ func NewGuestManager() (Interface, error) {
return &Default{imageService: is}, nil
}
func (d *Default) Apply(cluster *v2.Cluster) error {
func (d *Default) Apply(cluster *v2.Cluster, images []string) error {
clusterRootfs := runtime.GetContantData(cluster.Name).RootFSPath()
img, err := d.imageService.Inspect(cluster.Spec.Image...)
img, err := d.imageService.Inspect(images...)
if err != nil {
return fmt.Errorf("get cluster image failed, %s", err)
}