fix(timezone): the timezone is standardized to UTC

Signed-off-by: cndoit18 <cndoit18@outlook.com>
This commit is contained in:
cndoit18 2021-06-03 13:43:11 +08:00
parent d541872f9a
commit 51717256f9
No known key found for this signature in database
GPG Key ID: A5E54CE7AC730381
9 changed files with 15 additions and 15 deletions

View File

@ -23,7 +23,7 @@ import (
"github.com/pkg/errors" "github.com/pkg/errors"
"k8s.io/api/core/v1" v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
bootstrapapi "k8s.io/cluster-bootstrap/token/api" bootstrapapi "k8s.io/cluster-bootstrap/token/api"
bootstraputil "k8s.io/cluster-bootstrap/token/util" bootstraputil "k8s.io/cluster-bootstrap/token/util"
@ -61,13 +61,13 @@ func encodeTokenSecretData(token *BootstrapToken, now time.Time) map[string][]by
if token.Expires != nil { if token.Expires != nil {
// Format the expiration date accordingly // Format the expiration date accordingly
// TODO: This maybe should be a helper function in bootstraputil? // TODO: This maybe should be a helper function in bootstraputil?
expirationString := token.Expires.Time.Format(time.RFC3339) expirationString := token.Expires.Time.UTC().Format(time.RFC3339)
data[bootstrapapi.BootstrapTokenExpirationKey] = []byte(expirationString) data[bootstrapapi.BootstrapTokenExpirationKey] = []byte(expirationString)
} else if token.TTL != nil && token.TTL.Duration > 0 { } else if token.TTL != nil && token.TTL.Duration > 0 {
// Only if .Expires is unset, TTL might have an effect // Only if .Expires is unset, TTL might have an effect
// Get the current time, add the specified duration, and format it accordingly // Get the current time, add the specified duration, and format it accordingly
expirationString := now.Add(token.TTL.Duration).Format(time.RFC3339) expirationString := now.Add(token.TTL.Duration).UTC().Format(time.RFC3339)
data[bootstrapapi.BootstrapTokenExpirationKey] = []byte(expirationString) data[bootstrapapi.BootstrapTokenExpirationKey] = []byte(expirationString)
} }

View File

@ -36,7 +36,7 @@ import (
"k8s.io/klog/v2" "k8s.io/klog/v2"
batchv1 "k8s.io/api/batch/v1" batchv1 "k8s.io/api/batch/v1"
"k8s.io/api/core/v1" v1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/errors" "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime"
@ -285,7 +285,7 @@ func syncOne(cj *batchv1.CronJob, js []batchv1.Job, now time.Time, jc jobControl
} }
if tooLate { if tooLate {
klog.V(4).Infof("Missed starting window for %s", nameForLog) klog.V(4).Infof("Missed starting window for %s", nameForLog)
recorder.Eventf(cj, v1.EventTypeWarning, "MissSchedule", "Missed scheduled time to start a job: %s", scheduledTime.Format(time.RFC1123Z)) recorder.Eventf(cj, v1.EventTypeWarning, "MissSchedule", "Missed scheduled time to start a job: %s", scheduledTime.UTC().Format(time.RFC1123Z))
// TODO: Since we don't set LastScheduleTime when not scheduling, we are going to keep noticing // TODO: Since we don't set LastScheduleTime when not scheduling, we are going to keep noticing
// the miss every cycle. In order to avoid sending multiple events, and to avoid processing // the miss every cycle. In order to avoid sending multiple events, and to avoid processing
// the cj again and again, we could set a Status.LastMissedTime when we notice a miss. // the cj again and again, we could set a Status.LastMissedTime when we notice a miss.

View File

@ -501,7 +501,7 @@ func (jm *ControllerV2) syncCronJob(
} }
if tooLate { if tooLate {
klog.V(4).InfoS("Missed starting window", "cronjob", klog.KRef(cj.GetNamespace(), cj.GetName())) klog.V(4).InfoS("Missed starting window", "cronjob", klog.KRef(cj.GetNamespace(), cj.GetName()))
jm.recorder.Eventf(cj, corev1.EventTypeWarning, "MissSchedule", "Missed scheduled time to start a job: %s", scheduledTime.Format(time.RFC1123Z)) jm.recorder.Eventf(cj, corev1.EventTypeWarning, "MissSchedule", "Missed scheduled time to start a job: %s", scheduledTime.UTC().Format(time.RFC1123Z))
// TODO: Since we don't set LastScheduleTime when not scheduling, we are going to keep noticing // TODO: Since we don't set LastScheduleTime when not scheduling, we are going to keep noticing
// the miss every cycle. In order to avoid sending multiple events, and to avoid processing // the miss every cycle. In order to avoid sending multiple events, and to avoid processing

View File

@ -529,7 +529,7 @@ func (e *Controller) syncService(key string) error {
if !endpointsLastChangeTriggerTime.IsZero() { if !endpointsLastChangeTriggerTime.IsZero() {
newEndpoints.Annotations[v1.EndpointsLastChangeTriggerTime] = newEndpoints.Annotations[v1.EndpointsLastChangeTriggerTime] =
endpointsLastChangeTriggerTime.Format(time.RFC3339Nano) endpointsLastChangeTriggerTime.UTC().Format(time.RFC3339Nano)
} else { // No new trigger time, clear the annotation. } else { // No new trigger time, clear the annotation.
delete(newEndpoints.Annotations, v1.EndpointsLastChangeTriggerTime) delete(newEndpoints.Annotations, v1.EndpointsLastChangeTriggerTime)
} }

View File

@ -235,7 +235,7 @@ func TestSyncServicePodSelection(t *testing.T) {
assert.Len(t, slices.Items, 1, "Expected 1 endpoint slices") assert.Len(t, slices.Items, 1, "Expected 1 endpoint slices")
slice := slices.Items[0] slice := slices.Items[0]
assert.Len(t, slice.Endpoints, 1, "Expected 1 endpoint in first slice") assert.Len(t, slice.Endpoints, 1, "Expected 1 endpoint in first slice")
assert.NotEmpty(t, slice.Annotations["endpoints.kubernetes.io/last-change-trigger-time"]) assert.NotEmpty(t, slice.Annotations[v1.EndpointsLastChangeTriggerTime])
endpoint := slice.Endpoints[0] endpoint := slice.Endpoints[0]
assert.EqualValues(t, endpoint.TargetRef, &v1.ObjectReference{Kind: "Pod", Namespace: ns, Name: pod1.Name}) assert.EqualValues(t, endpoint.TargetRef, &v1.ObjectReference{Kind: "Pod", Namespace: ns, Name: pod1.Name})
} }
@ -1064,7 +1064,7 @@ func TestSyncService(t *testing.T) {
// ensure all attributes of endpoint slice match expected state // ensure all attributes of endpoint slice match expected state
slice := sliceList.Items[0] slice := sliceList.Items[0]
assert.Equal(t, slice.Annotations["endpoints.kubernetes.io/last-change-trigger-time"], creationTimestamp.Format(time.RFC3339Nano)) assert.Equal(t, slice.Annotations[v1.EndpointsLastChangeTriggerTime], creationTimestamp.UTC().Format(time.RFC3339Nano))
assert.ElementsMatch(t, testcase.expectedEndpointPorts, slice.Ports) assert.ElementsMatch(t, testcase.expectedEndpointPorts, slice.Ports)
assert.ElementsMatch(t, testcase.expectedEndpoints, slice.Endpoints) assert.ElementsMatch(t, testcase.expectedEndpoints, slice.Endpoints)
}) })

View File

@ -390,7 +390,7 @@ func TestReconcile1Pod(t *testing.T) {
client := newClientset() client := newClientset()
setupMetrics() setupMetrics()
triggerTime := time.Now() triggerTime := time.Now().UTC()
r := newReconciler(client, []*corev1.Node{node1}, defaultMaxEndpointsPerSlice) r := newReconciler(client, []*corev1.Node{node1}, defaultMaxEndpointsPerSlice)
reconcileHelper(t, r, &testCase.service, []*corev1.Pod{pod1}, []*discovery.EndpointSlice{}, triggerTime) reconcileHelper(t, r, &testCase.service, []*corev1.Pod{pod1}, []*discovery.EndpointSlice{}, triggerTime)

View File

@ -223,7 +223,7 @@ func addTriggerTimeAnnotation(endpointSlice *discovery.EndpointSlice, triggerTim
} }
if !triggerTime.IsZero() { if !triggerTime.IsZero() {
endpointSlice.Annotations[corev1.EndpointsLastChangeTriggerTime] = triggerTime.Format(time.RFC3339Nano) endpointSlice.Annotations[corev1.EndpointsLastChangeTriggerTime] = triggerTime.UTC().Format(time.RFC3339Nano)
} else { // No new trigger time, clear the annotation. } else { // No new trigger time, clear the annotation.
delete(endpointSlice.Annotations, corev1.EndpointsLastChangeTriggerTime) delete(endpointSlice.Annotations, corev1.EndpointsLastChangeTriggerTime)
} }

View File

@ -23,7 +23,7 @@ import (
"errors" "errors"
"time" "time"
"k8s.io/api/core/v1" v1 "k8s.io/api/core/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors" apierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/wait" "k8s.io/apimachinery/pkg/util/wait"
@ -79,9 +79,9 @@ func addSecretExpiration(s *v1.Secret, expiration string) {
} }
// TimeStringFromNow returns the time as a string from now. // TimeStringFromNow returns the time as a string from now.
// e.g: 2019-12-03T14:30:40+08:00. // e.g: 2019-12-03T06:30:40Z.
func TimeStringFromNow(delta time.Duration) string { func TimeStringFromNow(delta time.Duration) string {
return time.Now().Add(delta).Format(time.RFC3339) return time.Now().Add(delta).UTC().Format(time.RFC3339)
} }
// WaitforSignedClusterInfoByBootStrapToken waits for signed cluster info by bootstrap token. // WaitforSignedClusterInfoByBootStrapToken waits for signed cluster info by bootstrap token.

View File

@ -72,7 +72,7 @@ func TestBootstrapTokenAuth(t *testing.T) {
bootstrapapi.BootstrapTokenUsageAuthentication: []byte("true"), bootstrapapi.BootstrapTokenUsageAuthentication: []byte("true"),
}, },
} }
tokenExpiredTime := time.Now().Add(-time.Hour).Format(time.RFC3339) tokenExpiredTime := time.Now().UTC().Add(-time.Hour).Format(time.RFC3339)
var expiredBootstrapToken = &corev1.Secret{ var expiredBootstrapToken = &corev1.Secret{
ObjectMeta: metav1.ObjectMeta{ ObjectMeta: metav1.ObjectMeta{
Namespace: metav1.NamespaceSystem, Namespace: metav1.NamespaceSystem,