Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Validation: don't expect bastion nodes to join #4775

Merged
merged 1 commit into from Mar 24, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 13 additions & 5 deletions pkg/validation/validate_cluster.go
Expand Up @@ -219,11 +219,19 @@ func (v *ValidationCluster) validateNodes(cloudGroups map[string]*cloudinstances
node := member.Node

if node == nil {
v.addError(&ValidationError{
Kind: "Machine",
Name: member.ID,
Message: fmt.Sprintf("machine %q has not yet joined cluster", member.ID),
})
nodeExpectedToJoin := true
if cloudGroup.InstanceGroup.Spec.Role == kops.InstanceGroupRoleBastion {
// bastion nodes don't join the cluster
nodeExpectedToJoin = false
}

if nodeExpectedToJoin {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why don't we have?

if cloudGroup.InstanceGroup.Spec.Role != kops.InstanceGroupRoleBastion {
    v.addError(&ValidationError{
	Kind:    "Machine",
	Name:    member.ID,
	Message: fmt.Sprintf("machine %q has not yet joined cluster", member.ID),
	})
}

Confused why we have an extra if ...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because we expect more roles in future, and I find this code to be more self-descriptive (at the expense of being longer, admittedly)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes more flexiable ... k

v.addError(&ValidationError{
Kind: "Machine",
Name: member.ID,
Message: fmt.Sprintf("machine %q has not yet joined cluster", member.ID),
})
}
continue
}

Expand Down
46 changes: 46 additions & 0 deletions pkg/validation/validate_cluster_test.go
Expand Up @@ -184,3 +184,49 @@ func makePodList(pods []map[string]string) *v1.PodList {
}
return &list
}

func Test_ValidateBastionNodes(t *testing.T) {
groups := make(map[string]*cloudinstances.CloudInstanceGroup)
groups["ig1"] = &cloudinstances.CloudInstanceGroup{
InstanceGroup: &kopsapi.InstanceGroup{
ObjectMeta: metav1.ObjectMeta{
Name: "ig1",
},
Spec: kopsapi.InstanceGroupSpec{
Role: kopsapi.InstanceGroupRoleNode,
},
},
Ready: []*cloudinstances.CloudInstanceGroupMember{
{
ID: "i-00001",
Node: nil,
},
},
}

// When an instancegroup's nodes are not ready, that is an error
{
v := &ValidationCluster{}
groups["ig1"].InstanceGroup.Spec.Role = kopsapi.InstanceGroupRoleNode
v.validateNodes(groups)
if len(v.Failures) != 1 {
printDebug(t, v)
t.Fatal("Nodes are expected to join cluster")
} else if v.Failures[0].Message != "machine \"i-00001\" has not yet joined cluster" {
printDebug(t, v)
t.Fatalf("unexpected validation failure: %+v", v.Failures[0])
}
}

// Except for a bastion instancegroup - those are not expected to join as nodes
{
v := &ValidationCluster{}
groups["ig1"].InstanceGroup.Spec.Role = kopsapi.InstanceGroupRoleBastion
v.validateNodes(groups)
if len(v.Failures) != 0 {
printDebug(t, v)
t.Fatal("Bastion nodes are not expected to join cluster")
}
}

}