diff --git a/plugins/inputs/kube_inventory/daemonset.go b/plugins/inputs/kube_inventory/daemonset.go index c365d169c..e169c8f27 100644 --- a/plugins/inputs/kube_inventory/daemonset.go +++ b/plugins/inputs/kube_inventory/daemonset.go @@ -40,7 +40,8 @@ func (ki *KubernetesInventory) gatherDaemonSet(d v1.DaemonSet, acc telegraf.Accu } } - if d.GetCreationTimestamp().Second() != 0 { + creationTs := d.GetCreationTimestamp() + if !creationTs.IsZero() { fields["created"] = d.GetCreationTimestamp().UnixNano() } diff --git a/plugins/inputs/kube_inventory/endpoint.go b/plugins/inputs/kube_inventory/endpoint.go index 89cbf6587..1eb86eea1 100644 --- a/plugins/inputs/kube_inventory/endpoint.go +++ b/plugins/inputs/kube_inventory/endpoint.go @@ -20,7 +20,8 @@ func collectEndpoints(ctx context.Context, acc telegraf.Accumulator, ki *Kuberne } func (ki *KubernetesInventory) gatherEndpoint(e corev1.Endpoints, acc telegraf.Accumulator) { - if e.GetCreationTimestamp().Second() == 0 && e.GetCreationTimestamp().Nanosecond() == 0 { + creationTs := e.GetCreationTimestamp() + if creationTs.IsZero() { return } diff --git a/plugins/inputs/kube_inventory/ingress.go b/plugins/inputs/kube_inventory/ingress.go index 6fd424dc0..f8a966bc1 100644 --- a/plugins/inputs/kube_inventory/ingress.go +++ b/plugins/inputs/kube_inventory/ingress.go @@ -20,7 +20,8 @@ func collectIngress(ctx context.Context, acc telegraf.Accumulator, ki *Kubernete } func (ki *KubernetesInventory) gatherIngress(i netv1.Ingress, acc telegraf.Accumulator) { - if i.GetCreationTimestamp().Second() == 0 && i.GetCreationTimestamp().Nanosecond() == 0 { + creationTs := i.GetCreationTimestamp() + if creationTs.IsZero() { return } diff --git a/plugins/inputs/kube_inventory/pod.go b/plugins/inputs/kube_inventory/pod.go index ebd3ae43a..ab4e5dd28 100644 --- a/plugins/inputs/kube_inventory/pod.go +++ b/plugins/inputs/kube_inventory/pod.go @@ -20,7 +20,8 @@ func collectPods(ctx context.Context, acc telegraf.Accumulator, ki *KubernetesIn } func (ki *KubernetesInventory) gatherPod(p corev1.Pod, acc telegraf.Accumulator) { - if p.GetCreationTimestamp().Second() == 0 && p.GetCreationTimestamp().Nanosecond() == 0 { + creationTs := p.GetCreationTimestamp() + if creationTs.IsZero() { return } diff --git a/plugins/inputs/kube_inventory/pod_test.go b/plugins/inputs/kube_inventory/pod_test.go index 31600b101..962805a67 100644 --- a/plugins/inputs/kube_inventory/pod_test.go +++ b/plugins/inputs/kube_inventory/pod_test.go @@ -20,7 +20,7 @@ func TestPod(t *testing.T) { selectExclude := []string{} now := time.Now() started := time.Date(now.Year(), now.Month(), now.Day(), now.Hour()-1, 1, 36, 0, now.Location()) - created := time.Date(now.Year(), now.Month(), now.Day(), now.Hour()-2, 1, 36, 0, now.Location()) + created := time.Date(now.Year(), now.Month(), now.Day(), now.Hour()-2, 1, 0, 0, now.Location()) cond1 := time.Date(now.Year(), 7, 5, 7, 53, 29, 0, now.Location()) cond2 := time.Date(now.Year(), 7, 5, 7, 53, 31, 0, now.Location()) diff --git a/plugins/inputs/kube_inventory/service.go b/plugins/inputs/kube_inventory/service.go index c2a7b7077..d58918860 100644 --- a/plugins/inputs/kube_inventory/service.go +++ b/plugins/inputs/kube_inventory/service.go @@ -20,7 +20,8 @@ func collectServices(ctx context.Context, acc telegraf.Accumulator, ki *Kubernet } func (ki *KubernetesInventory) gatherService(s corev1.Service, acc telegraf.Accumulator) { - if s.GetCreationTimestamp().Second() == 0 && s.GetCreationTimestamp().Nanosecond() == 0 { + creationTs := s.GetCreationTimestamp() + if creationTs.IsZero() { return }