mirror of
				https://github.com/optim-enterprises-bv/kubernetes.git
				synced 2025-11-03 19:58:17 +00:00 
			
		
		
		
	simplify code and add unit test for NotReady taint
This commit is contained in:
		@@ -81,32 +81,34 @@ var (
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	nodeConditionToTaintKeyStatusMap = map[v1.NodeConditionType]struct {
 | 
			
		||||
		TaintKey string
 | 
			
		||||
		Status   v1.ConditionStatus
 | 
			
		||||
		taintKey string
 | 
			
		||||
		// noScheduleStatus is the condition under which the node should be tainted as not schedulable for this
 | 
			
		||||
		// NodeConditionType
 | 
			
		||||
		noScheduleStatus v1.ConditionStatus
 | 
			
		||||
	}{
 | 
			
		||||
		v1.NodeReady: {
 | 
			
		||||
			TaintKey: algorithm.TaintNodeNotReady,
 | 
			
		||||
			Status:   v1.ConditionFalse,
 | 
			
		||||
			taintKey:         algorithm.TaintNodeNotReady,
 | 
			
		||||
			noScheduleStatus: v1.ConditionFalse,
 | 
			
		||||
		},
 | 
			
		||||
		v1.NodeMemoryPressure: {
 | 
			
		||||
			TaintKey: algorithm.TaintNodeMemoryPressure,
 | 
			
		||||
			Status:   v1.ConditionTrue,
 | 
			
		||||
			taintKey:         algorithm.TaintNodeMemoryPressure,
 | 
			
		||||
			noScheduleStatus: v1.ConditionTrue,
 | 
			
		||||
		},
 | 
			
		||||
		v1.NodeOutOfDisk: {
 | 
			
		||||
			TaintKey: algorithm.TaintNodeOutOfDisk,
 | 
			
		||||
			Status:   v1.ConditionTrue,
 | 
			
		||||
			taintKey:         algorithm.TaintNodeOutOfDisk,
 | 
			
		||||
			noScheduleStatus: v1.ConditionTrue,
 | 
			
		||||
		},
 | 
			
		||||
		v1.NodeDiskPressure: {
 | 
			
		||||
			TaintKey: algorithm.TaintNodeDiskPressure,
 | 
			
		||||
			Status:   v1.ConditionTrue,
 | 
			
		||||
			taintKey:         algorithm.TaintNodeDiskPressure,
 | 
			
		||||
			noScheduleStatus: v1.ConditionTrue,
 | 
			
		||||
		},
 | 
			
		||||
		v1.NodeNetworkUnavailable: {
 | 
			
		||||
			TaintKey: algorithm.TaintNodeNetworkUnavailable,
 | 
			
		||||
			Status:   v1.ConditionTrue,
 | 
			
		||||
			taintKey:         algorithm.TaintNodeNetworkUnavailable,
 | 
			
		||||
			noScheduleStatus: v1.ConditionTrue,
 | 
			
		||||
		},
 | 
			
		||||
		v1.NodePIDPressure: {
 | 
			
		||||
			TaintKey: algorithm.TaintNodePIDPressure,
 | 
			
		||||
			Status:   v1.ConditionTrue,
 | 
			
		||||
			taintKey:         algorithm.TaintNodePIDPressure,
 | 
			
		||||
			noScheduleStatus: v1.ConditionTrue,
 | 
			
		||||
		},
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
@@ -453,12 +455,12 @@ func (nc *Controller) doFixDeprecatedTaintKeyPass(node *v1.Node) error {
 | 
			
		||||
 | 
			
		||||
func (nc *Controller) doNoScheduleTaintingPass(node *v1.Node) error {
 | 
			
		||||
	// Map node's condition to Taints.
 | 
			
		||||
	taints := []v1.Taint{}
 | 
			
		||||
	var taints []v1.Taint
 | 
			
		||||
	for _, condition := range node.Status.Conditions {
 | 
			
		||||
		if taintKeyStatus, found := nodeConditionToTaintKeyStatusMap[condition.Type]; found {
 | 
			
		||||
			if condition.Status == taintKeyStatus.Status {
 | 
			
		||||
		if taint, found := nodeConditionToTaintKeyStatusMap[condition.Type]; found {
 | 
			
		||||
			if condition.Status == taint.noScheduleStatus {
 | 
			
		||||
				taints = append(taints, v1.Taint{
 | 
			
		||||
					Key:    taintKeyStatus.TaintKey,
 | 
			
		||||
					Key:    taint.taintKey,
 | 
			
		||||
					Effect: v1.TaintEffectNoSchedule,
 | 
			
		||||
				})
 | 
			
		||||
			}
 | 
			
		||||
 
 | 
			
		||||
@@ -2163,6 +2163,10 @@ func TestTaintsNodeByCondition(t *testing.T) {
 | 
			
		||||
		Key:    algorithm.TaintNodeNetworkUnavailable,
 | 
			
		||||
		Effect: v1.TaintEffectNoSchedule,
 | 
			
		||||
	}
 | 
			
		||||
	notReadyTaint := &v1.Taint{
 | 
			
		||||
		Key:    algorithm.TaintNodeNotReady,
 | 
			
		||||
		Effect: v1.TaintEffectNoSchedule,
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	tests := []struct {
 | 
			
		||||
		Name           string
 | 
			
		||||
@@ -2271,6 +2275,30 @@ func TestTaintsNodeByCondition(t *testing.T) {
 | 
			
		||||
			},
 | 
			
		||||
			ExpectedTaints: []*v1.Taint{networkUnavailableTaint},
 | 
			
		||||
		},
 | 
			
		||||
		{
 | 
			
		||||
			Name: "Ready is false",
 | 
			
		||||
			Node: &v1.Node{
 | 
			
		||||
				ObjectMeta: metav1.ObjectMeta{
 | 
			
		||||
					Name:              "node0",
 | 
			
		||||
					CreationTimestamp: metav1.Date(2012, 1, 1, 0, 0, 0, 0, time.UTC),
 | 
			
		||||
					Labels: map[string]string{
 | 
			
		||||
						kubeletapis.LabelZoneRegion:        "region1",
 | 
			
		||||
						kubeletapis.LabelZoneFailureDomain: "zone1",
 | 
			
		||||
					},
 | 
			
		||||
				},
 | 
			
		||||
				Status: v1.NodeStatus{
 | 
			
		||||
					Conditions: []v1.NodeCondition{
 | 
			
		||||
						{
 | 
			
		||||
							Type:               v1.NodeReady,
 | 
			
		||||
							Status:             v1.ConditionFalse,
 | 
			
		||||
							LastHeartbeatTime:  metav1.Date(2015, 1, 1, 12, 0, 0, 0, time.UTC),
 | 
			
		||||
							LastTransitionTime: metav1.Date(2015, 1, 1, 12, 0, 0, 0, time.UTC),
 | 
			
		||||
						},
 | 
			
		||||
					},
 | 
			
		||||
				},
 | 
			
		||||
			},
 | 
			
		||||
			ExpectedTaints: []*v1.Taint{notReadyTaint},
 | 
			
		||||
		},
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	for _, test := range tests {
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user