Skip to content

Commit

Permalink
bugfix: fix apply
Browse files Browse the repository at this point in the history
Signed-off-by: 煜星 <[email protected]>
  • Loading branch information
starnop committed Mar 16, 2023
1 parent a2ea705 commit 9be5901
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 8 deletions.
20 changes: 12 additions & 8 deletions cmd/sealer/cmd/cluster/apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,12 +127,13 @@ func NewApplyCmd() *cobra.Command {
return applyClusterWithNew(cf, applyMode, imageEngine, imageSpec)
}

if err := applyClusterWithExisted(cf, client, imageEngine, imageSpec); err != nil {
updated, 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
ignorePrepareAppMaterials = updated
}

// install application
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
}
3 changes: 3 additions & 0 deletions cmd/sealer/cmd/cluster/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,9 @@ func runApplicationImage(request *RunApplicationImageRequest) error {
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

0 comments on commit 9be5901

Please sign in to comment.