github.com/alibaba/sealer@v0.8.6-0.20220430115802-37a2bdaa8173/apply/processor/upgrade.go (about) 1 // Copyright © 2021 Alibaba Group Holding Ltd. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package processor 16 17 import ( 18 "github.com/alibaba/sealer/pkg/filesystem/cloudfilesystem" 19 v2 "github.com/alibaba/sealer/types/api/v2" 20 21 "github.com/alibaba/sealer/common" 22 "github.com/alibaba/sealer/pkg/filesystem" 23 "github.com/alibaba/sealer/pkg/runtime" 24 "github.com/alibaba/sealer/utils" 25 ) 26 27 type UpgradeProcessor struct { 28 fileSystem cloudfilesystem.Interface 29 Runtime runtime.Interface 30 } 31 32 // Execute :according to the different of desired cluster to upgrade cluster. 33 func (u UpgradeProcessor) Execute(cluster *v2.Cluster) error { 34 err := u.MountRootfs(cluster) 35 if err != nil { 36 return err 37 } 38 err = u.Upgrade() 39 if err != nil { 40 return err 41 } 42 43 return nil 44 } 45 46 func (u UpgradeProcessor) MountRootfs(cluster *v2.Cluster) error { 47 //some hosts already mounted when scaled cluster. 48 hosts := append(cluster.GetMasterIPList(), cluster.GetNodeIPList()...) 49 regConfig := runtime.GetRegistryConfig(common.DefaultTheClusterRootfsDir(cluster.Name), cluster.GetMaster0IP()) 50 if utils.NotInIPList(regConfig.IP, hosts) { 51 hosts = append(hosts, regConfig.IP) 52 } 53 return u.fileSystem.MountRootfs(cluster, hosts, false) 54 } 55 56 func (u UpgradeProcessor) Upgrade() error { 57 return u.Runtime.Upgrade() 58 } 59 60 func NewUpgradeProcessor(rootfs string, rt runtime.Interface) (Interface, error) { 61 // only do upgrade here. cancel scale action. 62 fs, err := filesystem.NewFilesystem(rootfs) 63 if err != nil { 64 return nil, err 65 } 66 67 return UpgradeProcessor{ 68 fileSystem: fs, 69 Runtime: rt, 70 }, nil 71 }