Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,10 @@ func (r *ReconcileHubLeader) reconcileHubLeader(ctx context.Context, nodepool *a
// Set match labels
matchLabels := make(map[string]string)
if nodepool.Spec.LeaderElectionStrategy == string(appsv1beta2.ElectionStrategyMark) {
// Add mark strategy match labels
matchLabels = nodepool.Spec.LeaderNodeLabelSelector
// Add mark strategy match labels safely without overwriting matchLabels with a potential nil map
for k, v := range nodepool.Spec.LeaderNodeLabelSelector {
matchLabels[k] = v
}
Comment thread
nishantbkl3345-ship-it marked this conversation as resolved.
Outdated
}
matchLabels[projectinfo.GetNodePoolLabel()] = nodepool.GetName()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,48 @@ func TestReconcile(t *testing.T) {
},
expectErr: false,
},
"mark election strategy with nil LeaderNodeLabelSelector": {
pool: &appsv1beta2.NodePool{
ObjectMeta: metav1.ObjectMeta{
Name: "hangzhou",
},
Spec: appsv1beta2.NodePoolSpec{
Type: appsv1beta2.Edge,
Labels: map[string]string{
"region": "hangzhou",
},
LeaderElectionStrategy: string(appsv1beta2.ElectionStrategyMark),
LeaderNodeLabelSelector: nil,
LeaderReplicas: 1,
EnableLeaderElection: true,
},
},
expectedNodePool: &appsv1beta2.NodePool{
ObjectMeta: metav1.ObjectMeta{
Name: "hangzhou",
},
Spec: appsv1beta2.NodePoolSpec{
Type: appsv1beta2.Edge,
Labels: map[string]string{
"region": "hangzhou",
},
LeaderElectionStrategy: string(appsv1beta2.ElectionStrategyMark),
LeaderNodeLabelSelector: nil,
EnableLeaderElection: true,
LeaderReplicas: 1,
},
Status: appsv1beta2.NodePoolStatus{
LeaderEndpoints: []appsv1beta2.Leader{
{
NodeName: "ready with internal IP",
Address: "10.0.0.1",
},
},
LeaderNum: 1,
},
},
expectErr: false,
},
"no potential leaders in hangzhou with mark strategy": {
pool: &appsv1beta2.NodePool{
ObjectMeta: metav1.ObjectMeta{
Expand Down