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

Omit timeAdded from taint when empty #43016

Merged
merged 2 commits into from
Sep 23, 2017
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
4 changes: 2 additions & 2 deletions cmd/kubeadm/app/phases/markmaster/markmaster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func TestMarkMaster(t *testing.T) {
"master label and taint missing",
"",
nil,
"{\"metadata\":{\"labels\":{\"node-role.kubernetes.io/master\":\"\"}},\"spec\":{\"taints\":[{\"effect\":\"NoSchedule\",\"key\":\"node-role.kubernetes.io/master\",\"timeAdded\":null}]}}",
"{\"metadata\":{\"labels\":{\"node-role.kubernetes.io/master\":\"\"}},\"spec\":{\"taints\":[{\"effect\":\"NoSchedule\",\"key\":\"node-role.kubernetes.io/master\"}]}}",
},
{
"master label missing",
Expand All @@ -61,7 +61,7 @@ func TestMarkMaster(t *testing.T) {
"master taint missing",
kubeadmconstants.LabelNodeRoleMaster,
nil,
"{\"spec\":{\"taints\":[{\"effect\":\"NoSchedule\",\"key\":\"node-role.kubernetes.io/master\",\"timeAdded\":null}]}}",
"{\"spec\":{\"taints\":[{\"effect\":\"NoSchedule\",\"key\":\"node-role.kubernetes.io/master\"}]}}",
},
{
"nothing missing",
Expand Down
2 changes: 1 addition & 1 deletion pkg/api/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -2229,7 +2229,7 @@ type Taint struct {
// TimeAdded represents the time at which the taint was added.
// It is only written for NoExecute taints.
// +optional
TimeAdded metav1.Time
TimeAdded *metav1.Time
}

type TaintEffect string
Expand Down
4 changes: 2 additions & 2 deletions pkg/api/v1/zz_generated.conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -5101,7 +5101,7 @@ func autoConvert_v1_Taint_To_api_Taint(in *v1.Taint, out *api.Taint, s conversio
out.Key = in.Key
out.Value = in.Value
out.Effect = api.TaintEffect(in.Effect)
out.TimeAdded = in.TimeAdded
out.TimeAdded = (*meta_v1.Time)(unsafe.Pointer(in.TimeAdded))
return nil
}

Expand All @@ -5114,7 +5114,7 @@ func autoConvert_api_Taint_To_v1_Taint(in *api.Taint, out *v1.Taint, s conversio
out.Key = in.Key
out.Value = in.Value
out.Effect = v1.TaintEffect(in.Effect)
out.TimeAdded = in.TimeAdded
out.TimeAdded = (*meta_v1.Time)(unsafe.Pointer(in.TimeAdded))
return nil
}

Expand Down
10 changes: 9 additions & 1 deletion pkg/api/zz_generated.deepcopy.go
Original file line number Diff line number Diff line change
Expand Up @@ -5903,7 +5903,15 @@ func (in *TCPSocketAction) DeepCopy() *TCPSocketAction {
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *Taint) DeepCopyInto(out *Taint) {
*out = *in
in.TimeAdded.DeepCopyInto(&out.TimeAdded)
if in.TimeAdded != nil {
in, out := &in.TimeAdded, &out.TimeAdded
if *in == nil {
*out = nil
} else {
*out = new(v1.Time)
(*in).DeepCopyInto(*out)
}
}
return
}

Expand Down
9 changes: 7 additions & 2 deletions pkg/controller/daemon/daemon_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,17 +63,22 @@ var (
noExecuteTaints = []v1.Taint{{Key: "dedicated", Value: "user1", Effect: "NoExecute"}}
)

func nowPointer() *metav1.Time {
now := metav1.Now()
return &now
}

var (
nodeNotReady = []v1.Taint{{
Key: algorithm.TaintNodeNotReady,
Effect: v1.TaintEffectNoExecute,
TimeAdded: metav1.Now(),
TimeAdded: nowPointer(),
}}

nodeUnreachable = []v1.Taint{{
Key: algorithm.TaintNodeUnreachable,
Effect: v1.TaintEffectNoExecute,
TimeAdded: metav1.Now(),
TimeAdded: nowPointer(),
}}
)

Expand Down
3 changes: 2 additions & 1 deletion pkg/controller/node/scheduler/taint_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,12 @@ import (
var timeForControllerToProgress = 500 * time.Millisecond

func createNoExecuteTaint(index int) v1.Taint {
now := metav1.Now()
return v1.Taint{
Key: "testTaint" + fmt.Sprintf("%v", index),
Value: "test" + fmt.Sprintf("%v", index),
Effect: v1.TaintEffectNoExecute,
TimeAdded: metav1.Now(),
TimeAdded: &now,
}
}

Expand Down
3 changes: 2 additions & 1 deletion pkg/controller/node/util/controller_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,8 @@ func RecordNodeStatusChange(recorder record.EventRecorder, node *v1.Node, newSta
// otherwise.
func SwapNodeControllerTaint(kubeClient clientset.Interface, taintsToAdd, taintsToRemove []*v1.Taint, node *v1.Node) bool {
for _, taintToAdd := range taintsToAdd {
taintToAdd.TimeAdded = metav1.Now()
now := metav1.Now()
taintToAdd.TimeAdded = &now
}

err := controller.AddOrUpdateTaintOnNode(kubeClient, node.Name, taintsToAdd...)
Expand Down
1,399 changes: 703 additions & 696 deletions staging/src/k8s.io/api/core/v1/generated.pb.go

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion staging/src/k8s.io/api/core/v1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -2466,7 +2466,7 @@ type Taint struct {
// TimeAdded represents the time at which the taint was added.
// It is only written for NoExecute taints.
// +optional
TimeAdded metav1.Time `json:"timeAdded,omitempty" protobuf:"bytes,4,opt,name=timeAdded"`
TimeAdded *metav1.Time `json:"timeAdded,omitempty" protobuf:"bytes,4,opt,name=timeAdded"`
Copy link
Contributor

Choose a reason for hiding this comment

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

Isn't it a breaking API change in beta type?

Copy link
Member Author

Choose a reason for hiding this comment

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

wire serialization remains compatible.

the old version encoded zero values to:

  • json: timeAdded: null
  • proto: 0x22 tag with zero length value

the new version omits zero values from the wire format

the new version successfully decodes zero values from the old version

the old version treats missing values as the zero value when decoding

}

type TaintEffect string
Expand Down
10 changes: 9 additions & 1 deletion staging/src/k8s.io/api/core/v1/zz_generated.deepcopy.go
Original file line number Diff line number Diff line change
Expand Up @@ -5905,7 +5905,15 @@ func (in *TCPSocketAction) DeepCopy() *TCPSocketAction {
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *Taint) DeepCopyInto(out *Taint) {
*out = *in
in.TimeAdded.DeepCopyInto(&out.TimeAdded)
if in.TimeAdded != nil {
in, out := &in.TimeAdded, &out.TimeAdded
if *in == nil {
*out = nil
} else {
*out = new(meta_v1.Time)
(*in).DeepCopyInto(*out)
}
}
return
}

Expand Down
3 changes: 2 additions & 1 deletion test/e2e/scheduling/taints_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,12 @@ import (
)

func getTestTaint() v1.Taint {
now := metav1.Now()
return v1.Taint{
Key: "kubernetes.io/e2e-evict-taint-key",
Value: "evictTaintVal",
Effect: v1.TaintEffectNoExecute,
TimeAdded: metav1.Now(),
TimeAdded: &now,
}
}

Expand Down