Skip to content

Commit 294d0b9

Browse files
committed
Introduce --reconcile flag to kOps
Kubernetes 1.31 now stops nodes joining a cluster if the minor version of the node is greater than the minor version of the control plane. The addition of the instance-group-roles flag to update means that we can now update / rolling-update the control plane first. However, we must now issue four commands: * Update control plane * Rolling update control plane * Update nodes * Rolling update nodes This adds a flag to automate this process. It is implemented by executing those 4 steps in sequence.
1 parent 3a8a13f commit 294d0b9

File tree

3 files changed

+100
-0
lines changed

3 files changed

+100
-0
lines changed

cmd/kops/reconcile_cluster.go

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
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+
func ReconcileCluster(ctx context.Context, f *util.Factory, out io.Writer, c *UpdateClusterOptions) error {
29+
fmt.Fprintf(out, "Updating control plane configuration\n")
30+
{
31+
opt := *c
32+
opt.Reconcile = false // Prevent infinite loop
33+
opt.InstanceGroupRoles = []string{
34+
string(kops.InstanceGroupRoleAPIServer),
35+
string(kops.InstanceGroupRoleControlPlane),
36+
}
37+
if _, err := RunUpdateCluster(ctx, f, out, &opt); err != nil {
38+
return err
39+
}
40+
}
41+
42+
fmt.Fprintf(out, "Doing rolling-update for control plane\n")
43+
{
44+
opt := &RollingUpdateOptions{}
45+
opt.InitDefaults()
46+
opt.ClusterName = c.ClusterName
47+
opt.InstanceGroupRoles = []string{
48+
string(kops.InstanceGroupRoleAPIServer),
49+
string(kops.InstanceGroupRoleControlPlane),
50+
}
51+
opt.Yes = c.Yes
52+
if err := RunRollingUpdateCluster(ctx, f, out, opt); err != nil {
53+
return err
54+
}
55+
}
56+
57+
fmt.Fprintf(out, "Updating node configuration\n")
58+
{
59+
opt := *c
60+
opt.Reconcile = false // Prevent infinite loop
61+
// TODO: or just do all roles?
62+
opt.InstanceGroupRoles = []string{
63+
string(kops.InstanceGroupRoleBastion),
64+
string(kops.InstanceGroupRoleNode),
65+
}
66+
if _, err := RunUpdateCluster(ctx, f, out, &opt); err != nil {
67+
return err
68+
}
69+
}
70+
71+
fmt.Fprintf(out, "Doing rolling-update for nodes\n")
72+
{
73+
opt := &RollingUpdateOptions{}
74+
opt.InitDefaults()
75+
opt.ClusterName = c.ClusterName
76+
// TODO: or just do all roles?
77+
opt.InstanceGroupRoles = []string{
78+
string(kops.InstanceGroupRoleBastion),
79+
string(kops.InstanceGroupRoleNode),
80+
}
81+
opt.Yes = c.Yes
82+
if err := RunRollingUpdateCluster(ctx, f, out, opt); err != nil {
83+
return err
84+
}
85+
}
86+
87+
return nil
88+
}

cmd/kops/update_cluster.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,9 @@ type UpdateClusterOptions struct {
103103
// The goal is that the cluster can keep running even during more disruptive
104104
// infrastructure changes.
105105
Prune bool
106+
107+
// Reconcile is true if we should reconcile the cluster by rolling the control plane and nodes sequentially
108+
Reconcile bool
106109
}
107110

108111
func (o *UpdateClusterOptions) InitDefaults() {
@@ -117,6 +120,7 @@ func (o *UpdateClusterOptions) InitDefaults() {
117120
o.CreateKubecfg = true
118121

119122
o.Prune = false
123+
o.Reconcile = false
120124

121125
o.RunTasksOptions.InitDefaults()
122126
}
@@ -193,6 +197,13 @@ type UpdateClusterResults struct {
193197
}
194198

195199
func RunUpdateCluster(ctx context.Context, f *util.Factory, out io.Writer, c *UpdateClusterOptions) (*UpdateClusterResults, error) {
200+
if c.Reconcile {
201+
if !c.Yes {
202+
return nil, fmt.Errorf("--reconcile is only supported with --yes")
203+
}
204+
return nil, ReconcileCluster(ctx, f, out, c)
205+
}
206+
196207
results := &UpdateClusterResults{}
197208

198209
isDryrun := false

docs/cli/kops_update_cluster.md

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)