From 7fb2c3c7d1b3636e5760bdcae87e3932e3b5a387 Mon Sep 17 00:00:00 2001 From: Qiyue Yao Date: Tue, 9 Nov 2021 12:07:15 -0800 Subject: [PATCH] Revert "Add startTime to the Traceflow Status (#2952)" This reverts commit f679f043babbee20a979e83cf67b750627db3342. --- build/yamls/antrea-aks.yml | 4 --- build/yamls/antrea-eks.yml | 4 --- build/yamls/antrea-gke.yml | 4 --- build/yamls/antrea-ipsec.yml | 4 --- build/yamls/antrea.yml | 4 --- build/yamls/base/crds.yml | 4 --- pkg/apis/crd/v1alpha1/types.go | 8 ------ .../crd/v1alpha1/zz_generated.deepcopy.go | 4 --- pkg/controller/traceflow/controller.go | 25 ++++--------------- 9 files changed, 5 insertions(+), 56 deletions(-) diff --git a/build/yamls/antrea-aks.yml b/build/yamls/antrea-aks.yml index 457cea07591..ec5ca5220ae 100644 --- a/build/yamls/antrea-aks.yml +++ b/build/yamls/antrea-aks.yml @@ -2954,8 +2954,6 @@ spec: type: integer type: object type: array - startTime: - type: string type: object required: - spec @@ -3134,8 +3132,6 @@ spec: type: integer type: object type: array - startTime: - type: string type: object required: - spec diff --git a/build/yamls/antrea-eks.yml b/build/yamls/antrea-eks.yml index dd5ede90368..f5287a050b1 100644 --- a/build/yamls/antrea-eks.yml +++ b/build/yamls/antrea-eks.yml @@ -2954,8 +2954,6 @@ spec: type: integer type: object type: array - startTime: - type: string type: object required: - spec @@ -3134,8 +3132,6 @@ spec: type: integer type: object type: array - startTime: - type: string type: object required: - spec diff --git a/build/yamls/antrea-gke.yml b/build/yamls/antrea-gke.yml index 356a1ccb0e4..ffefa909848 100644 --- a/build/yamls/antrea-gke.yml +++ b/build/yamls/antrea-gke.yml @@ -2954,8 +2954,6 @@ spec: type: integer type: object type: array - startTime: - type: string type: object required: - spec @@ -3134,8 +3132,6 @@ spec: type: integer type: object type: array - startTime: - type: string type: object required: - spec diff --git a/build/yamls/antrea-ipsec.yml b/build/yamls/antrea-ipsec.yml index 0b775ddbe99..8c34f7a667f 100644 --- a/build/yamls/antrea-ipsec.yml +++ b/build/yamls/antrea-ipsec.yml @@ -2954,8 +2954,6 @@ spec: type: integer type: object type: array - startTime: - type: string type: object required: - spec @@ -3134,8 +3132,6 @@ spec: type: integer type: object type: array - startTime: - type: string type: object required: - spec diff --git a/build/yamls/antrea.yml b/build/yamls/antrea.yml index 0b140458797..2bf664183dc 100644 --- a/build/yamls/antrea.yml +++ b/build/yamls/antrea.yml @@ -2954,8 +2954,6 @@ spec: type: integer type: object type: array - startTime: - type: string type: object required: - spec @@ -3134,8 +3132,6 @@ spec: type: integer type: object type: array - startTime: - type: string type: object required: - spec diff --git a/build/yamls/base/crds.yml b/build/yamls/base/crds.yml index 00ac35e194c..6d11d693984 100644 --- a/build/yamls/base/crds.yml +++ b/build/yamls/base/crds.yml @@ -560,8 +560,6 @@ spec: type: integer phase: type: string - startTime: - type: string results: type: array items: @@ -2026,8 +2024,6 @@ spec: type: integer phase: type: string - startTime: - type: string results: type: array items: diff --git a/pkg/apis/crd/v1alpha1/types.go b/pkg/apis/crd/v1alpha1/types.go index 68b50446060..851665d56c6 100644 --- a/pkg/apis/crd/v1alpha1/types.go +++ b/pkg/apis/crd/v1alpha1/types.go @@ -23,7 +23,6 @@ import ( type TraceflowPhase string const ( - // Pending is not used anymore Pending TraceflowPhase = "Pending" Running TraceflowPhase = "Running" Succeeded TraceflowPhase = "Succeeded" @@ -222,13 +221,6 @@ type TraceflowStatus struct { Phase TraceflowPhase `json:"phase,omitempty"` // Reason is a message indicating the reason of the traceflow's current phase. Reason string `json:"reason,omitempty"` - // StartTime is the time at which the Traceflow as started by the Antrea Controller. - // Before K8s v1.20, null values (field not set) are not pruned, and a CR where a - // metav1.Time field is not set would fail OpenAPI validation (type string). The - // recommendation seems to be to use a pointer instead, and the field will be omitted when - // serializing. - // See https://github.com/kubernetes/kubernetes/issues/86811 - StartTime *metav1.Time `json:"startTime,omitempty"` // DataplaneTag is a tag to identify a traceflow session across Nodes. DataplaneTag uint8 `json:"dataplaneTag,omitempty"` // Results is the collection of all observations on different nodes. diff --git a/pkg/apis/crd/v1alpha1/zz_generated.deepcopy.go b/pkg/apis/crd/v1alpha1/zz_generated.deepcopy.go index 5c38d6c7010..a2a892fd7df 100644 --- a/pkg/apis/crd/v1alpha1/zz_generated.deepcopy.go +++ b/pkg/apis/crd/v1alpha1/zz_generated.deepcopy.go @@ -732,10 +732,6 @@ func (in *TraceflowSpec) DeepCopy() *TraceflowSpec { // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *TraceflowStatus) DeepCopyInto(out *TraceflowStatus) { *out = *in - if in.StartTime != nil { - in, out := &in.StartTime, &out.StartTime - *out = (*in).DeepCopy() - } if in.Results != nil { in, out := &in.Results, &out.Results *out = make([]NodeResult, len(*in)) diff --git a/pkg/controller/traceflow/controller.go b/pkg/controller/traceflow/controller.go index ea0215d9c9b..7c5c958c489 100644 --- a/pkg/controller/traceflow/controller.go +++ b/pkg/controller/traceflow/controller.go @@ -289,7 +289,6 @@ func (c *Controller) startTraceflow(tf *crdv1alpha1.Traceflow) error { return err } -// checkTraceflowStatus is only called for Traceflows in the Running phase func (c *Controller) checkTraceflowStatus(tf *crdv1alpha1.Traceflow) error { succeeded := false if tf.Spec.LiveTraffic && tf.Spec.DroppedOnly { @@ -339,22 +338,12 @@ func (c *Controller) checkTraceflowStatus(tf *crdv1alpha1.Traceflow) error { return c.updateTraceflowStatus(tf, crdv1alpha1.Succeeded, "", 0) } - var timeout time.Duration - if tf.Spec.Timeout != 0 { - timeout = time.Duration(tf.Spec.Timeout) * time.Second - } else { - timeout = defaultTimeoutDuration - } - var startTime time.Time - if tf.Status.StartTime != nil { - startTime = tf.Status.StartTime.Time - } else { - // a fallback that should not be needed in general since we are in the Running phase - // when upgrading Antrea from a previous version, the field would be empty - klog.V(2).InfoS("StartTime field in Traceflow Status should not be empty", "Traceflow", klog.KObj(tf)) - startTime = tf.CreationTimestamp.Time + timeoutSeconds := int64(tf.Spec.Timeout) + if timeoutSeconds == 0 { + timeoutSeconds = int64(defaultTimeoutDuration.Seconds()) } - if startTime.Add(timeout).Before(time.Now()) { + // CreationTimestamp is of second accuracy. + if time.Now().Unix() > tf.CreationTimestamp.Unix()+timeoutSeconds { c.deallocateTagForTF(tf) return c.updateTraceflowStatus(tf, crdv1alpha1.Failed, traceflowTimeout, 0) } @@ -364,10 +353,6 @@ func (c *Controller) checkTraceflowStatus(tf *crdv1alpha1.Traceflow) error { func (c *Controller) updateTraceflowStatus(tf *crdv1alpha1.Traceflow, phase crdv1alpha1.TraceflowPhase, reason string, dataPlaneTag uint8) error { update := tf.DeepCopy() update.Status.Phase = phase - if phase == crdv1alpha1.Running && tf.Status.StartTime == nil { - t := metav1.Now() - update.Status.StartTime = &t - } update.Status.DataplaneTag = dataPlaneTag if reason != "" { update.Status.Reason = reason