Skip to content

Commit 1b700d9

Browse files
committed
WIP: annealing
1 parent b4306a3 commit 1b700d9

File tree

2 files changed

+84
-1
lines changed

2 files changed

+84
-1
lines changed

cmd/kops/anneal_cluster.go

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
package main
2+
3+
import (
4+
"context"
5+
"fmt"
6+
"io"
7+
8+
"k8s.io/kops/cmd/kops/util"
9+
"k8s.io/kops/pkg/apis/kops"
10+
)
11+
12+
func AnnealCluster(ctx context.Context, f *util.Factory, out io.Writer, c *UpdateClusterOptions) error {
13+
fmt.Fprintf(out, "Updating control plane configuration\n")
14+
{
15+
opt := *c
16+
opt.Anneal = false // Prevent infinite loop
17+
opt.InstanceGroupRoles = []string{
18+
string(kops.InstanceGroupRoleAPIServer),
19+
string(kops.InstanceGroupRoleControlPlane),
20+
}
21+
if _, err := RunUpdateCluster(ctx, f, out, &opt); err != nil {
22+
return err
23+
}
24+
}
25+
26+
fmt.Fprintf(out, "Doing rolling-update for control plane\n")
27+
{
28+
opt := &RollingUpdateOptions{}
29+
opt.InitDefaults()
30+
opt.ClusterName = c.ClusterName
31+
opt.InstanceGroupRoles = []string{
32+
string(kops.InstanceGroupRoleAPIServer),
33+
string(kops.InstanceGroupRoleControlPlane),
34+
}
35+
opt.Yes = c.Yes
36+
if err := RunRollingUpdateCluster(ctx, f, out, opt); err != nil {
37+
return err
38+
}
39+
}
40+
41+
fmt.Fprintf(out, "Updating node configuration\n")
42+
{
43+
opt := *c
44+
opt.Anneal = false // Prevent infinite loop
45+
// TODO: or just do all roles?
46+
opt.InstanceGroupRoles = []string{
47+
string(kops.InstanceGroupRoleBastion),
48+
string(kops.InstanceGroupRoleNode),
49+
}
50+
if _, err := RunUpdateCluster(ctx, f, out, &opt); err != nil {
51+
return err
52+
}
53+
}
54+
55+
fmt.Fprintf(out, "Doing rolling-update for nodes\n")
56+
{
57+
opt := &RollingUpdateOptions{}
58+
opt.InitDefaults()
59+
opt.ClusterName = c.ClusterName
60+
// TODO: or just do all roles?
61+
opt.InstanceGroupRoles = []string{
62+
string(kops.InstanceGroupRoleBastion),
63+
string(kops.InstanceGroupRoleNode),
64+
}
65+
opt.Yes = c.Yes
66+
if err := RunRollingUpdateCluster(ctx, f, out, opt); err != nil {
67+
return err
68+
}
69+
}
70+
71+
return nil
72+
}

cmd/kops/update_cluster.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,9 @@ type UpdateClusterOptions struct {
9696
// The goal is that the cluster can keep running even during more disruptive
9797
// infrastructure changes.
9898
Prune bool
99+
100+
// TODO
101+
Anneal bool
99102
}
100103

101104
func (o *UpdateClusterOptions) InitDefaults() {
@@ -108,6 +111,7 @@ func (o *UpdateClusterOptions) InitDefaults() {
108111
o.CreateKubecfg = true
109112

110113
o.Prune = false
114+
o.Anneal = false
111115

112116
o.RunTasksOptions.InitDefaults()
113117
}
@@ -163,7 +167,7 @@ func NewCmdUpdateCluster(f *util.Factory, out io.Writer) *cobra.Command {
163167
cmd.RegisterFlagCompletionFunc("lifecycle-overrides", completeLifecycleOverrides)
164168

165169
cmd.Flags().BoolVar(&options.Prune, "prune", options.Prune, "Delete old revisions of cloud resources that were needed during an upgrade")
166-
170+
cmd.Flags().BoolVar(&options.Anneal, "anneal", options.Anneal, "Anneal the cluster by rolling the control plane and nodes sequentially")
167171
return cmd
168172
}
169173

@@ -183,6 +187,13 @@ type UpdateClusterResults struct {
183187
}
184188

185189
func RunUpdateCluster(ctx context.Context, f *util.Factory, out io.Writer, c *UpdateClusterOptions) (*UpdateClusterResults, error) {
190+
if c.Anneal {
191+
if !c.Yes {
192+
return nil, fmt.Errorf("--anneal is only supported with --yes")
193+
}
194+
return nil, AnnealCluster(ctx, f, out, c)
195+
}
196+
186197
results := &UpdateClusterResults{}
187198

188199
isDryrun := false

0 commit comments

Comments
 (0)