Skip to content

Commit 555bc50

Browse files
committed
Initial change to add more KCP roles.
Added helper functions for subroles. Code does not add new functionality. It is making the API changes in preperation for multiple sub-roles within a role. A few key test fixes. Added canonicalization of the Instance Group Sub Resources.
1 parent 7a0fb7e commit 555bc50

107 files changed

Lines changed: 1484 additions & 630 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

cmd/kops-controller/pkg/server/node_config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ func (s *Server) buildInstanceGroupFromCAPI(ctx context.Context, capiMachine *cl
141141
// "machineType": "", // Should not matter
142142
// "subnets": // Should not matter
143143
ig.Spec.Zones = []string{failureDomain}
144-
ig.Spec.Role = "Node" // TODO: Support other roles?
144+
ig.Spec.Role = kops.InstanceGroupSubRoleNode.Role() // TODO: Support other roles?
145145

146146
log.Info("built InstanceGroup from CAPI Machine", "instanceGroup", ig)
147147
return ig, nil

cmd/kops/create_cluster.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -585,10 +585,10 @@ func RunCreateCluster(ctx context.Context, f *util.Factory, out io.Writer, c *Cr
585585
var controlPlanes []*api.InstanceGroup
586586
var nodes []*api.InstanceGroup
587587
for _, ig := range instanceGroups {
588-
switch ig.Spec.Role {
589-
case api.InstanceGroupRoleControlPlane:
588+
switch {
589+
case ig.Spec.Role.HasControlPlane():
590590
controlPlanes = append(controlPlanes, ig)
591-
case api.InstanceGroupRoleNode:
591+
case ig.Spec.Role.HasNode():
592592
nodes = append(nodes, ig)
593593
}
594594
}

cmd/kops/create_instancegroup.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ var (
8383
// NewCmdCreateInstanceGroup create a new cobra command object for creating a instancegroup.
8484
func NewCmdCreateInstanceGroup(f *util.Factory, out io.Writer) *cobra.Command {
8585
options := &CreateInstanceGroupOptions{
86-
Role: kopsapi.InstanceGroupRoleNode.ToLowerString(),
86+
Role: kopsapi.InstanceGroupSubRoleNode.Role().ToLowerString(),
8787
Edit: true,
8888
}
8989

@@ -124,12 +124,15 @@ func NewCmdCreateInstanceGroup(f *util.Factory, out io.Writer) *cobra.Command {
124124
},
125125
}
126126

127-
allRoles := make([]string, 0, len(kopsapi.AllInstanceGroupRoles))
128-
for _, r := range kopsapi.AllInstanceGroupRoles {
129-
if r == kopsapi.InstanceGroupRoleAPIServer && !featureflag.APIServerNodes.Enabled() {
127+
allRoles := make([]string, 0, len(kopsapi.AllInstanceGroupSubRoles))
128+
for _, subrole := range kopsapi.AllInstanceGroupSubRoles {
129+
role := subrole.Role()
130+
if role.HasAPIServer() && !featureflag.APIServerNodes.Enabled() {
130131
continue
131132
}
132-
allRoles = append(allRoles, r.ToLowerString())
133+
// TODO: Can we GA the APIServerNodes feature flag?
134+
// TODO: Do we need feature flag for the new roles and multi role support?
135+
allRoles = append(allRoles, role.ToLowerString())
133136
}
134137

135138
cmd.Flags().StringVar(&options.Role, "role", options.Role, "Type of instance group to create ("+strings.Join(allRoles, ",")+")")

cmd/kops/delete_instancegroup.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ func NewCmdDeleteInstanceGroup(f *util.Factory, out io.Writer) *cobra.Command {
8484

8585
return nil
8686
},
87-
ValidArgsFunction: completeInstanceGroup(f, nil, &[]string{kops.InstanceGroupRoleControlPlane.ToLowerString()}),
87+
ValidArgsFunction: completeInstanceGroup(f, nil, &[]string{kops.InstanceGroupSubRoleControlPlane.Role().ToLowerString()}),
8888
RunE: func(cmd *cobra.Command, args []string) error {
8989
ctx := cmd.Context()
9090

@@ -147,15 +147,15 @@ func RunDeleteInstanceGroup(ctx context.Context, f *util.Factory, out io.Writer,
147147

148148
fmt.Fprintf(out, "InstanceGroup %q found for deletion\n", groupName)
149149

150-
if group.Spec.Role == kops.InstanceGroupRoleControlPlane {
150+
if group.Spec.Role.HasControlPlane() {
151151
groups, err := clientset.InstanceGroupsFor(cluster).List(ctx, metav1.ListOptions{})
152152
if err != nil {
153153
return fmt.Errorf("listing InstanceGroups: %v", err)
154154
}
155155

156156
onlyMaster := true
157157
for _, ig := range groups.Items {
158-
if ig.Name != groupName && ig.Spec.Role == kops.InstanceGroupRoleControlPlane {
158+
if ig.Name != groupName && ig.Spec.Role.HasControlPlane() {
159159
onlyMaster = false
160160
break
161161
}

cmd/kops/reconcile_cluster.go

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,12 @@ func RunReconcileCluster(ctx context.Context, f *util.Factory, out io.Writer, op
139139
{
140140
opt := *c
141141
opt.InstanceGroupRoles = []string{
142-
string(kops.InstanceGroupRoleAPIServer),
143-
string(kops.InstanceGroupRoleControlPlane),
142+
string(kops.InstanceGroupSubRoleAPIServer.Role()),
143+
string(kops.InstanceGroupSubRoleControlPlane.Role()),
144+
string(kops.InstanceGroupSubRoleEtcd.Role()),
145+
string(kops.InstanceGroupSubRoleScheduler.Role()),
146+
string(kops.InstanceGroupSubRoleCloudControllerManager.Role()),
147+
string(kops.InstanceGroupSubRoleKubeControllerManager.Role()),
144148
}
145149
opt.Prune = false // Do not prune until after the last rolling update
146150
if _, err := RunCoreUpdateCluster(ctx, f, out, &opt); err != nil {
@@ -160,7 +164,7 @@ func RunReconcileCluster(ctx context.Context, f *util.Factory, out io.Writer, op
160164

161165
// filter the instance group to only include the control plane
162166
opt.filterInstanceGroups = func(ig *kops.InstanceGroup) bool {
163-
return ig.Spec.Role == kops.InstanceGroupRoleAPIServer || ig.Spec.Role == kops.InstanceGroupRoleControlPlane
167+
return ig.Spec.Role.IsControlPlaneType()
164168
}
165169

166170
// Ignore all pods, we just want to check the control plane is responding
@@ -180,8 +184,12 @@ func RunReconcileCluster(ctx context.Context, f *util.Factory, out io.Writer, op
180184
opt.ClusterName = c.ClusterName
181185
opt.CreateKubecfgOptions = options.CreateKubecfgOptions
182186
opt.InstanceGroupRoles = []string{
183-
string(kops.InstanceGroupRoleAPIServer),
184-
string(kops.InstanceGroupRoleControlPlane),
187+
string(kops.InstanceGroupSubRoleAPIServer.Role()),
188+
string(kops.InstanceGroupSubRoleControlPlane.Role()),
189+
string(kops.InstanceGroupSubRoleEtcd.Role()),
190+
string(kops.InstanceGroupSubRoleScheduler.Role()),
191+
string(kops.InstanceGroupSubRoleCloudControllerManager.Role()),
192+
string(kops.InstanceGroupSubRoleKubeControllerManager.Role()),
185193
}
186194
opt.Yes = c.Yes
187195
if err := RunRollingUpdateCluster(ctx, f, out, opt); err != nil {

cmd/kops/rolling-update_cluster.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -189,9 +189,9 @@ func NewCmdRollingUpdateCluster(f *util.Factory, out io.Writer) *cobra.Command {
189189
},
190190
}
191191

192-
allRoles := make([]string, 0, len(kopsapi.AllInstanceGroupRoles))
193-
for _, r := range kopsapi.AllInstanceGroupRoles {
194-
allRoles = append(allRoles, r.ToLowerString())
192+
allRoles := make([]string, 0, len(kopsapi.AllInstanceGroupSubRoles))
193+
for _, subrole := range kopsapi.AllInstanceGroupSubRoles {
194+
allRoles = append(allRoles, subrole.ToLowerString())
195195
}
196196

197197
cmd.Flags().BoolVarP(&options.Yes, "yes", "y", options.Yes, "Perform rolling update immediately; without --yes rolling-update executes a dry-run")
@@ -280,7 +280,7 @@ func RunRollingUpdateCluster(ctx context.Context, f *util.Factory, out io.Writer
280280
return err
281281
}
282282

283-
countByRole := make(map[kopsapi.InstanceGroupRole]int32)
283+
countByRole := make(map[kopsapi.InstanceGroupSubRole]int32)
284284
var instanceGroups []*kopsapi.InstanceGroup
285285
for i := range list.Items {
286286
instanceGroup := &list.Items[i]
@@ -290,9 +290,11 @@ func RunRollingUpdateCluster(ctx context.Context, f *util.Factory, out io.Writer
290290
if instanceGroup.Spec.MinSize != nil {
291291
minSize = *instanceGroup.Spec.MinSize
292292
}
293-
countByRole[instanceGroup.Spec.Role] = countByRole[instanceGroup.Spec.Role] + minSize
293+
for _, subrole := range instanceGroup.Spec.Role.SubRoles() {
294+
countByRole[subrole] = countByRole[subrole] + minSize
295+
}
294296
}
295-
if countByRole[kopsapi.InstanceGroupRoleAPIServer]+countByRole[kopsapi.InstanceGroupRoleControlPlane] <= 1 {
297+
if countByRole[kopsapi.InstanceGroupSubRoleAPIServer]+countByRole[kopsapi.InstanceGroupSubRoleControlPlane] <= 1 {
296298
options.DeregisterControlPlaneNodes = false
297299
}
298300

cmd/kops/toolbox_instance-selector.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -494,7 +494,7 @@ func validateAllPrivateOrPublicSubnets(userSubnets []string) error {
494494
func createInstanceGroup(groupName, clusterName string, subnets []string) *kops.InstanceGroup {
495495
ig := &kops.InstanceGroup{}
496496
ig.ObjectMeta.Name = groupName
497-
ig.Spec.Role = kops.InstanceGroupRoleNode
497+
ig.Spec.Role = kops.InstanceGroupSubRoleNode.Role()
498498
ig.Spec.Subnets = subnets
499499
ig.ObjectMeta.Labels = make(map[string]string)
500500
ig.ObjectMeta.Labels[kops.LabelClusterName] = clusterName

cmd/kops/toolbox_instance-selector_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,8 @@ func TestValidateUserSubnetsWithClusterSubnets(t *testing.T) {
143143
func TestCreateInstanceGroup(t *testing.T) {
144144
zones := []string{"us-east-2a", "us-east-2b", "us-east-2c"}
145145
actualIG := createInstanceGroup("testGroup", "clusterTest", zones)
146-
if actualIG.Spec.Role != kops.InstanceGroupRoleNode {
147-
t.Fatalf("instance group should have the \"%s\" role but got %s", kops.InstanceGroupRoleNode, actualIG.Spec.Role)
146+
if !actualIG.Spec.Role.HasNode() {
147+
t.Fatalf("instance group should have the \"%s\" sub-role but got %s", kops.InstanceGroupSubRoleNode, actualIG.Spec.Role)
148148
}
149149
if !reflect.DeepEqual(actualIG.Spec.Subnets, zones) {
150150
t.Fatalf("instance group should have all the zones passed in but got %s", actualIG.Spec.Subnets)

cmd/kops/update_cluster.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -141,9 +141,9 @@ func NewCmdUpdateCluster(f *util.Factory, out io.Writer) *cobra.Command {
141141
options := &UpdateClusterOptions{}
142142
options.InitDefaults()
143143

144-
allRoles := make([]string, 0, len(kops.AllInstanceGroupRoles))
145-
for _, r := range kops.AllInstanceGroupRoles {
146-
allRoles = append(allRoles, r.ToLowerString())
144+
allRoles := make([]string, 0, len(kops.AllInstanceGroupSubRoles))
145+
for _, subrole := range kops.AllInstanceGroupSubRoles {
146+
allRoles = append(allRoles, subrole.ToLowerString())
147147
}
148148

149149
cmd := &cobra.Command{
@@ -510,7 +510,7 @@ func parseLifecycle(lifecycle string) (fi.Lifecycle, error) {
510510

511511
func usesBastion(instanceGroups []*kops.InstanceGroup) bool {
512512
for _, ig := range instanceGroups {
513-
if ig.Spec.Role == kops.InstanceGroupRoleBastion {
513+
if ig.Spec.Role.HasBastion() {
514514
return true
515515
}
516516
}

examples/kops-api-example/up.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ func up(vfsContext *vfs.VFSContext, ctx context.Context) error {
8686
ig := &api.InstanceGroup{}
8787
ig.ObjectMeta.Name = "master"
8888
ig.Spec = api.InstanceGroupSpec{
89-
Role: api.InstanceGroupRoleControlPlane,
89+
Role: api.InstanceGroupSubRoleControlPlane.Role(),
9090
Subnets: masterZones,
9191
}
9292
_, err := clientset.InstanceGroupsFor(cluster).Create(ctx, ig, metav1.CreateOptions{})
@@ -100,7 +100,7 @@ func up(vfsContext *vfs.VFSContext, ctx context.Context) error {
100100
ig := &api.InstanceGroup{}
101101
ig.ObjectMeta.Name = "nodes"
102102
ig.Spec = api.InstanceGroupSpec{
103-
Role: api.InstanceGroupRoleNode,
103+
Role: api.InstanceGroupSubRoleNode.Role(),
104104
Subnets: nodeZones,
105105
}
106106

0 commit comments

Comments
 (0)