|
| 1 | +/* |
| 2 | +Copyright 2024 The Kubernetes Authors. |
| 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 | +package main |
| 18 | + |
| 19 | +import ( |
| 20 | + "context" |
| 21 | + "fmt" |
| 22 | + "io" |
| 23 | + |
| 24 | + "k8s.io/kops/cmd/kops/util" |
| 25 | + "k8s.io/kops/pkg/apis/kops" |
| 26 | +) |
| 27 | + |
| 28 | +// ReconcileCluster updates the cluster to the desired state, including rolling updates where necessary. |
| 29 | +// To respect skew policy, it updates the control plane first, then updates the nodes. |
| 30 | +// "update" is probably now smart enough to automatically not update the control plane if it is already at the desired version, |
| 31 | +// but we do it explicitly here to be clearer / safer. |
| 32 | +func ReconcileCluster(ctx context.Context, f *util.Factory, out io.Writer, c *UpdateClusterOptions) error { |
| 33 | + fmt.Fprintf(out, "Updating control plane configuration\n") |
| 34 | + { |
| 35 | + opt := *c |
| 36 | + opt.Reconcile = false // Prevent infinite loop |
| 37 | + opt.InstanceGroupRoles = []string{ |
| 38 | + string(kops.InstanceGroupRoleAPIServer), |
| 39 | + string(kops.InstanceGroupRoleControlPlane), |
| 40 | + } |
| 41 | + if _, err := RunUpdateCluster(ctx, f, out, &opt); err != nil { |
| 42 | + return err |
| 43 | + } |
| 44 | + } |
| 45 | + |
| 46 | + fmt.Fprintf(out, "Doing rolling-update for control plane\n") |
| 47 | + { |
| 48 | + opt := &RollingUpdateOptions{} |
| 49 | + opt.InitDefaults() |
| 50 | + opt.ClusterName = c.ClusterName |
| 51 | + opt.InstanceGroupRoles = []string{ |
| 52 | + string(kops.InstanceGroupRoleAPIServer), |
| 53 | + string(kops.InstanceGroupRoleControlPlane), |
| 54 | + } |
| 55 | + opt.Yes = c.Yes |
| 56 | + if err := RunRollingUpdateCluster(ctx, f, out, opt); err != nil { |
| 57 | + return err |
| 58 | + } |
| 59 | + } |
| 60 | + |
| 61 | + fmt.Fprintf(out, "Updating node configuration\n") |
| 62 | + { |
| 63 | + opt := *c |
| 64 | + opt.Reconcile = false // Prevent infinite loop |
| 65 | + // Do all roles this time, though we only expect changes to node & bastion roles |
| 66 | + opt.InstanceGroupRoles = nil |
| 67 | + if _, err := RunUpdateCluster(ctx, f, out, &opt); err != nil { |
| 68 | + return err |
| 69 | + } |
| 70 | + } |
| 71 | + |
| 72 | + fmt.Fprintf(out, "Doing rolling-update for nodes\n") |
| 73 | + { |
| 74 | + opt := &RollingUpdateOptions{} |
| 75 | + opt.InitDefaults() |
| 76 | + opt.ClusterName = c.ClusterName |
| 77 | + // Do all roles this time, though we only expect changes to node & bastion roles |
| 78 | + opt.InstanceGroupRoles = nil |
| 79 | + opt.Yes = c.Yes |
| 80 | + if err := RunRollingUpdateCluster(ctx, f, out, opt); err != nil { |
| 81 | + return err |
| 82 | + } |
| 83 | + } |
| 84 | + |
| 85 | + return nil |
| 86 | +} |
0 commit comments