Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bugfix: fix apply #2116

Merged
merged 1 commit into from
Mar 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 21 additions & 17 deletions cmd/sealer/cmd/cluster/apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ func NewApplyCmd() *cobra.Command {

// NOTE: in some scenarios, we do not need to prepare the app file repeatedly,
// such as the cluster and the apps in the same image
var ignorePrepareAppMaterials bool
var skipPrepareAppMaterials bool
// ensure that the cluster reaches the final state firstly
if imageSpec.ImageExtension.Type == imagev1.KubeInstaller {
client := utils.GetClusterClient()
Expand All @@ -127,25 +127,26 @@ func NewApplyCmd() *cobra.Command {
return applyClusterWithNew(cf, applyMode, imageEngine, imageSpec)
Copy link
Member

@kakaZhou719 kakaZhou719 Mar 16, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

applyClusterFileWithNew ? clusterfile contains app and cluster. so maybe it is better for us to use apply clusterfile ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in fact, it‘s just the part relevant to the cluster.

And as for what you said about the app, that's really unreasonable. And I have added a comment TODO: decouple the cluster installation and application installation, and we should fix it in a separate PR.

}

if err := applyClusterWithExisted(cf, client, imageEngine, imageSpec); err != nil {
clusterUpdated, err := applyClusterWithExisted(cf, client, imageEngine, imageSpec)
if err != nil {
return err
}
// NOTE: we should continue to apply application after the cluster is applied successfully
// And it's not needed to prepare the app file repeatedly
ignorePrepareAppMaterials = true
skipPrepareAppMaterials = clusterUpdated
}

// install application
app := utils.ConstructApplication(cf.GetApplication(), desiredCluster.Spec.CMD, desiredCluster.Spec.APPNames)
return runApplicationImage(&RunApplicationImageRequest{
ImageName: imageName,
Application: app,
Envs: desiredCluster.Spec.Env,
ImageEngine: imageEngine,
Extension: imageSpec.ImageExtension,
Configs: cf.GetConfigs(),
RunMode: applyMode,
IgnorePrepareAppMaterials: ignorePrepareAppMaterials,
ImageName: imageName,
Application: app,
Envs: desiredCluster.Spec.Env,
ImageEngine: imageEngine,
Extension: imageSpec.ImageExtension,
Configs: cf.GetConfigs(),
RunMode: applyMode,
SkipPrepareAppMaterials: skipPrepareAppMaterials,
})
},
}
Expand Down Expand Up @@ -193,31 +194,34 @@ func applyClusterWithNew(cf clusterfile.Interface, applyMode string,
}

func applyClusterWithExisted(cf clusterfile.Interface, client *k8s.Client,
imageEngine imageengine.Interface, imageSpec *imagev1.ImageSpec) error {
imageEngine imageengine.Interface, imageSpec *imagev1.ImageSpec) (bool, error) {
desiredCluster := cf.GetCluster()
currentCluster, err := utils.GetCurrentCluster(client)
if err != nil {
return errors.Wrap(err, "failed to get current cluster")
return false, errors.Wrap(err, "failed to get current cluster")
}

mj, md := strings.Diff(currentCluster.GetMasterIPList(), desiredCluster.GetMasterIPList())
nj, nd := strings.Diff(currentCluster.GetNodeIPList(), desiredCluster.GetNodeIPList())
if len(mj) == 0 && len(md) == 0 && len(nj) == 0 && len(nd) == 0 {
logrus.Infof("No need scale, completed")
return nil
return false, nil
}

if len(md) > 0 || len(nd) > 0 {
logrus.Warnf("scale down not supported: %v, %v, skip them", md, nd)
}
if len(md) > 0 {
return fmt.Errorf("make sure all masters' ip exist in your clusterfile: %s", applyFlags.ClusterFile)
return false, fmt.Errorf("make sure all masters' ip exist in your clusterfile: %s", applyFlags.ClusterFile)
}

infraDriver, err := infradriver.NewInfraDriver(&desiredCluster)
if err != nil {
return err
return false, err
}

return scaleUpCluster(imageSpec.Name, mj, nj, infraDriver, imageEngine, cf)
if err := scaleUpCluster(imageSpec.Name, mj, nj, infraDriver, imageEngine, cf); err != nil {
return false, err
}
return true, nil
}
21 changes: 12 additions & 9 deletions cmd/sealer/cmd/cluster/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -385,14 +385,14 @@ func loadToRegistry(infraDriver infradriver.InfraDriver, distributor imagedistri
}

type RunApplicationImageRequest struct {
ImageName string
Application *v2.Application
Envs []string
ImageEngine imageengine.Interface
Extension imagev1.ImageExtension
Configs []v1.Config
RunMode string
IgnorePrepareAppMaterials bool
ImageName string
Application *v2.Application
Envs []string
ImageEngine imageengine.Interface
Extension imagev1.ImageExtension
Configs []v1.Config
RunMode string
SkipPrepareAppMaterials bool
}

func runApplicationImage(request *RunApplicationImageRequest) error {
Expand All @@ -415,12 +415,15 @@ func runApplicationImage(request *RunApplicationImageRequest) error {
}
infraDriver.AddClusterEnv(request.Envs)

if !request.IgnorePrepareAppMaterials {
if !request.SkipPrepareAppMaterials {
if err := prepareMaterials(infraDriver, request.ImageEngine, v2App,
request.ImageName, request.RunMode, request.Configs); err != nil {
return err
}
}
if request.RunMode == common.ApplyModeLoadImage {
return nil
}

if err = v2App.Launch(infraDriver); err != nil {
return err
Expand Down
1 change: 1 addition & 0 deletions cmd/sealer/cmd/cluster/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
"github.com/sealerio/sealer/pkg/imagedistributor"
"github.com/sealerio/sealer/pkg/imageengine"
"github.com/sealerio/sealer/pkg/infradriver"

"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"sigs.k8s.io/yaml"
Expand Down
3 changes: 3 additions & 0 deletions pkg/imageengine/buildah/inspect.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package buildah

import (
"fmt"
"sort"
"strings"

"github.com/containers/buildah"
Expand Down Expand Up @@ -134,10 +135,12 @@ func handleImageLabelOutput(labels map[string]string) map[string]string {
}

if len(supportedCNI) != 0 {
sort.Strings(supportedCNI)
supportedCNIJSON, _ := json.Marshal(supportedCNI)
result[command.LabelSupportedKubeCNIAlpha] = string(supportedCNIJSON)
}
if len(supportedCSI) != 0 {
sort.Strings(supportedCSI)
supportedCSIJSON, _ := json.Marshal(supportedCSI)
result[command.LabelSupportedKubeCSIAlpha] = string(supportedCSIJSON)
}
Expand Down