github.com/SUSE/skuba@v1.4.17/pkg/skuba/actions/addon/upgrade/plan.go (about) 1 /* 2 * Copyright (c) 2019 SUSE LLC. 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 * 16 */ 17 18 package addons 19 20 import ( 21 "fmt" 22 23 "github.com/pkg/errors" 24 clientset "k8s.io/client-go/kubernetes" 25 26 "github.com/SUSE/skuba/internal/pkg/skuba/addons" 27 "github.com/SUSE/skuba/internal/pkg/skuba/kubeadm" 28 "github.com/SUSE/skuba/internal/pkg/skuba/kubernetes" 29 "github.com/SUSE/skuba/internal/pkg/skuba/upgrade/addon" 30 ) 31 32 func Plan(client clientset.Interface) error { 33 currentClusterVersion, err := kubeadm.GetCurrentClusterVersion(client) 34 if err != nil { 35 return err 36 } 37 clusterConfiguration, err := kubeadm.GetClusterConfiguration(client) 38 if err != nil { 39 return errors.Wrap(err, "Could not fetch cluster configuration") 40 } 41 42 addonConfiguration := addons.AddonConfiguration{ 43 ClusterVersion: currentClusterVersion, 44 ControlPlane: clusterConfiguration.ControlPlaneEndpoint, 45 ClusterName: clusterConfiguration.ClusterName, 46 } 47 48 // check local addons cluster folder configuration is up-to-date 49 match, err := addons.CheckLocalAddonsBaseManifests(addonConfiguration) 50 if err != nil { 51 return err 52 } 53 if !match { 54 fmt.Println("Current local addons cluster folder configuration is out-of-date.") 55 fmt.Println("Please run \"skuba addon refresh localconfig\" before you perform addon upgrade.") 56 return nil 57 } 58 59 currentVersion := currentClusterVersion.String() 60 latestVersion := kubernetes.LatestVersion().String() 61 allNodesVersioningInfo, err := kubernetes.AllNodesVersioningInfo(client) 62 if err != nil { 63 return err 64 } 65 allNodesMatchClusterVersion := kubernetes.AllNodesTolerateClusterVersionWithVersioningInfo(allNodesVersioningInfo, currentClusterVersion) 66 fmt.Printf("Current Kubernetes cluster version: %s\n", currentVersion) 67 fmt.Printf("Latest Kubernetes version: %s\n", latestVersion) 68 fmt.Println() 69 70 if !allNodesMatchClusterVersion { 71 return errors.Errorf("Not all nodes match clusterVersion %s", currentVersion) 72 } 73 74 updatedAddons, err := addon.UpdatedAddons(client, currentClusterVersion) 75 if err != nil { 76 return err 77 } 78 if addon.HasAddonUpdate(updatedAddons) { 79 fmt.Printf("Addon upgrades for %s:\n", currentVersion) 80 addon.PrintAddonUpdates(updatedAddons) 81 82 dryRun := true 83 if err := addons.DeployAddons(client, addonConfiguration, dryRun); err != nil { 84 return errors.Wrap(err, "Failed to plan addons") 85 } 86 } else { 87 fmt.Printf("Congratulations! Addons for %s are already at the latest version available\n", currentVersion) 88 } 89 90 return nil 91 }