-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature(main): add patch package in run func (#949)
- Loading branch information
1 parent
2805329
commit 825469c
Showing
10 changed files
with
196 additions
and
30 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
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,155 @@ | ||
// Copyright © 2021 Alibaba Group Holding Ltd. | ||
// | ||
// 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 processor | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/fanux/sealos/pkg/utils/strings" | ||
"golang.org/x/sync/errgroup" | ||
|
||
"github.com/fanux/sealos/pkg/clusterfile" | ||
"github.com/fanux/sealos/pkg/config" | ||
"github.com/fanux/sealos/pkg/filesystem" | ||
"github.com/fanux/sealos/pkg/guest" | ||
"github.com/fanux/sealos/pkg/image" | ||
"github.com/fanux/sealos/pkg/image/types" | ||
v2 "github.com/fanux/sealos/pkg/types/v1beta1" | ||
"github.com/fanux/sealos/pkg/utils/contants" | ||
) | ||
|
||
type InstallProcessor struct { | ||
ClusterFile clusterfile.Interface | ||
ImageManager types.Service | ||
ClusterManager types.ClusterService | ||
RegistryManager types.RegistryService | ||
Guest guest.Interface | ||
imageList types.ImageListOCIV1 | ||
cManifestList types.ClusterManifestList | ||
} | ||
|
||
func (c *InstallProcessor) Execute(cluster *v2.Cluster) error { | ||
pipLine, err := c.GetPipeLine() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
for _, f := range pipLine { | ||
if err = f(cluster); err != nil { | ||
return err | ||
} | ||
} | ||
|
||
return nil | ||
} | ||
func (c *InstallProcessor) GetPipeLine() ([]func(cluster *v2.Cluster) error, error) { | ||
var todoList []func(cluster *v2.Cluster) error | ||
todoList = append(todoList, | ||
c.ChangeCluster, | ||
c.RunConfig, | ||
c.MountRootfs, | ||
//i.GetPhasePluginFunc(plugin.PhasePreGuest), | ||
c.RunGuest, | ||
//i.GetPhasePluginFunc(plugin.PhasePostInstall), | ||
) | ||
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...) | ||
if err != nil { | ||
return err | ||
} | ||
img, err := c.ImageManager.Inspect(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...) | ||
return err | ||
} | ||
|
||
func (c *InstallProcessor) RunConfig(cluster *v2.Cluster) error { | ||
eg, _ := errgroup.WithContext(context.Background()) | ||
for _, cManifest := range c.cManifestList { | ||
manifest := cManifest | ||
eg.Go(func() error { | ||
cfg := config.NewConfiguration(manifest.MountPoint, c.ClusterFile.GetConfigs()) | ||
return cfg.Dump(contants.Clusterfile(cluster.Name)) | ||
}) | ||
} | ||
return eg.Wait() | ||
} | ||
|
||
func (c *InstallProcessor) MountRootfs(cluster *v2.Cluster) error { | ||
hosts := append(cluster.GetMasterIPAndPortList(), cluster.GetNodeIPAndPortList()...) | ||
fs, err := filesystem.NewRootfsMounter(c.cManifestList, c.imageList) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return fs.MountRootfs(cluster, hosts, false) | ||
} | ||
|
||
func (c *InstallProcessor) RunGuest(cluster *v2.Cluster) error { | ||
return c.Guest.Apply(cluster) | ||
} | ||
|
||
func NewInstallProcessor(clusterFile clusterfile.Interface) (Interface, error) { | ||
imgSvc, err := image.NewImageService() | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
clusterSvc, err := image.NewClusterService() | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
registrySvc, err := image.NewRegistryService() | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
gs, err := guest.NewGuestManager() | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return &InstallProcessor{ | ||
ClusterFile: clusterFile, | ||
ImageManager: imgSvc, | ||
ClusterManager: clusterSvc, | ||
RegistryManager: registrySvc, | ||
Guest: gs, | ||
}, nil | ||
} |
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
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