From 843fdded46dcfa268b208453aa98633e204b40f7 Mon Sep 17 00:00:00 2001 From: Sergey Kanzhelev Date: Tue, 17 Mar 2026 23:10:45 +0000 Subject: [PATCH] Eliminate k8s.io/apimachinery from cri-client --- pkg/kubelet/kuberuntime/kuberuntime_logs.go | 15 ++- .../k8s.io/cri-client/.import-restrictions | 17 +++ staging/src/k8s.io/cri-client/go.mod | 23 +--- staging/src/k8s.io/cri-client/go.sum | 43 ------- .../k8s.io/cri-client/pkg/fake/endpoint.go | 2 +- .../src/k8s.io/cri-client/pkg/logs/logs.go | 81 ++++++------ .../k8s.io/cri-client/pkg/logs/logs_test.go | 115 +++++++----------- 7 files changed, 117 insertions(+), 179 deletions(-) create mode 100644 staging/src/k8s.io/cri-client/.import-restrictions diff --git a/pkg/kubelet/kuberuntime/kuberuntime_logs.go b/pkg/kubelet/kuberuntime/kuberuntime_logs.go index 8e88601605a..3123e6bc4bd 100644 --- a/pkg/kubelet/kuberuntime/kuberuntime_logs.go +++ b/pkg/kubelet/kuberuntime/kuberuntime_logs.go @@ -30,6 +30,19 @@ import ( // just pass in empty string "". func (m *kubeGenericRuntimeManager) ReadLogs(ctx context.Context, path, containerID string, apiOpts *v1.PodLogOptions, stdout, stderr io.Writer) error { // Convert v1.PodLogOptions into internal log options. - opts := logs.NewLogOptions(apiOpts, time.Now()) + now := time.Now() + opts := &logs.LogOptions{ + TailLines: apiOpts.TailLines, + LimitBytes: apiOpts.LimitBytes, + Follow: apiOpts.Follow, + Timestamp: apiOpts.Timestamps, + } + if apiOpts.SinceSeconds != nil { + opts.Since = now.Add(-time.Duration(*apiOpts.SinceSeconds) * time.Second) + } + if apiOpts.SinceTime != nil && apiOpts.SinceTime.After(opts.Since) { + opts.Since = apiOpts.SinceTime.Time + } + return logs.ReadLogs(ctx, path, containerID, opts, m.runtimeService, stdout, stderr) } diff --git a/staging/src/k8s.io/cri-client/.import-restrictions b/staging/src/k8s.io/cri-client/.import-restrictions new file mode 100644 index 00000000000..a3083cffeeb --- /dev/null +++ b/staging/src/k8s.io/cri-client/.import-restrictions @@ -0,0 +1,17 @@ +rules: + # prevent import of k8s.io/kubernetes + - selectorRegexp: k8s[.]io/kubernetes + forbiddenPrefixes: + - '' + # prevent import of k8s.io/apimachinery + - selectorRegexp: k8s[.]io/apimachinery + forbiddenPrefixes: + - '' + # prevent import of k8s.io/api + - selectorRegexp: k8s[.]io/api + forbiddenPrefixes: + - '' + # prevent import of k8s.io/client-go + - selectorRegexp: k8s[.]io/client-go + forbiddenPrefixes: + - '' diff --git a/staging/src/k8s.io/cri-client/go.mod b/staging/src/k8s.io/cri-client/go.mod index d625109a456..9a15c49cedf 100644 --- a/staging/src/k8s.io/cri-client/go.mod +++ b/staging/src/k8s.io/cri-client/go.mod @@ -15,9 +15,6 @@ require ( go.opentelemetry.io/otel/trace v1.40.0 golang.org/x/sys v0.40.0 google.golang.org/grpc v1.78.0 - k8s.io/api v0.0.0 - k8s.io/apimachinery v0.0.0 - k8s.io/client-go v0.0.0 k8s.io/component-base v0.0.0 k8s.io/cri-api v0.0.0 k8s.io/klog/v2 v2.140.0 @@ -30,22 +27,11 @@ require ( github.com/cenkalti/backoff/v5 v5.0.3 // indirect github.com/cespare/xxhash/v2 v2.3.0 // indirect github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect - github.com/emicklei/go-restful/v3 v3.13.0 // indirect github.com/felixge/httpsnoop v1.0.4 // indirect - github.com/fxamacker/cbor/v2 v2.9.0 // indirect github.com/go-logr/logr v1.4.3 // indirect github.com/go-logr/stdr v1.2.2 // indirect - github.com/go-openapi/jsonpointer v0.21.0 // indirect - github.com/go-openapi/jsonreference v0.20.2 // indirect - github.com/go-openapi/swag v0.23.0 // indirect - github.com/google/gnostic-models v0.7.0 // indirect github.com/google/uuid v1.6.0 // indirect github.com/grpc-ecosystem/grpc-gateway/v2 v2.27.7 // indirect - github.com/josharian/intern v1.0.0 // indirect - github.com/json-iterator/go v1.1.12 // indirect - github.com/mailru/easyjson v0.7.7 // indirect - github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect - github.com/modern-go/reflect2 v1.0.3-0.20250322232337-35a7c28c31ee // indirect github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect github.com/prometheus/client_golang v1.23.2 // indirect @@ -53,7 +39,6 @@ require ( github.com/prometheus/common v0.67.5 // indirect github.com/prometheus/procfs v0.19.2 // indirect github.com/spf13/pflag v1.0.9 // indirect - github.com/x448/float16 v0.8.4 // indirect go.opentelemetry.io/auto/sdk v1.2.1 // indirect go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.65.0 // indirect go.opentelemetry.io/otel v1.40.0 // indirect @@ -62,7 +47,6 @@ require ( go.opentelemetry.io/otel/metric v1.40.0 // indirect go.opentelemetry.io/proto/otlp v1.9.0 // indirect go.yaml.in/yaml/v2 v2.4.3 // indirect - go.yaml.in/yaml/v3 v3.0.4 // indirect golang.org/x/net v0.49.0 // indirect golang.org/x/oauth2 v0.34.0 // indirect golang.org/x/text v0.33.0 // indirect @@ -70,12 +54,9 @@ require ( google.golang.org/genproto/googleapis/api v0.0.0-20260128011058-8636f8732409 // indirect google.golang.org/genproto/googleapis/rpc v0.0.0-20260128011058-8636f8732409 // indirect google.golang.org/protobuf v1.36.12-0.20260120151049-f2248ac996af // indirect - gopkg.in/inf.v0 v0.9.1 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect - k8s.io/kube-openapi v0.0.0-20260317180543-43fb72c5454a // indirect - sigs.k8s.io/json v0.0.0-20250730193827-2d320260d730 // indirect - sigs.k8s.io/randfill v1.0.0 // indirect - sigs.k8s.io/structured-merge-diff/v6 v6.3.2 // indirect + k8s.io/apimachinery v0.0.0 // indirect + k8s.io/client-go v0.0.0 // indirect ) replace ( diff --git a/staging/src/k8s.io/cri-client/go.sum b/staging/src/k8s.io/cri-client/go.sum index 3f2e1d7f9ba..ea5c9a25574 100644 --- a/staging/src/k8s.io/cri-client/go.sum +++ b/staging/src/k8s.io/cri-client/go.sum @@ -4,7 +4,6 @@ github.com/Azure/go-ansiterm v0.0.0-20230124172434-306776ec8161/go.mod h1:xomTg6 github.com/GoogleCloudPlatform/opentelemetry-operations-go/detectors/gcp v1.30.0/go.mod h1:P4WPRUkOhJC13W//jWpyfJNDAIpvRbAUIYLX/4jtlE0= github.com/Microsoft/go-winio v0.6.2 h1:F2VQgta7ecxGYO8k3ZZz3RS8fVIXVxONVUPlNERoyfY= github.com/Microsoft/go-winio v0.6.2/go.mod h1:yd8OoFMLzJbo9gZq8j5qaps8bJ9aShtEA8Ipt1oGCvU= -github.com/NYTimes/gziphandler v1.1.1/go.mod h1:n/CVRwUEOgIxrgPvAQhUUr9oeUtvrhMomdKFjzJNB0c= github.com/alecthomas/kingpin/v2 v2.4.0/go.mod h1:0gyi0zQnjuFk8xrkNKamJoyUo382HRL7ATRpFZCw6tE= github.com/alecthomas/units v0.0.0-20240927000941-0f3dac36c52b/go.mod h1:fvzegU4vN3H1qMT+8wDmzjAcDONcgo2/SZ/TyfdUOFs= github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY= @@ -17,12 +16,8 @@ github.com/cenkalti/backoff/v5 v5.0.3/go.mod h1:rkhZdG3JZukswDf7f0cwqPNk4K0sa+F9 github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs= github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= github.com/cncf/xds/go v0.0.0-20251022180443-0feb69152e9f/go.mod h1:HlzOvOjVBOfTGSRXRyY0OiCS/3J1akRGQQpRO/7zyF4= -github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= -github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM= github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/emicklei/go-restful/v3 v3.13.0 h1:C4Bl2xDndpU6nJ4bc1jXd+uTmYPVUwkD6bFY/oTyCes= github.com/emicklei/go-restful/v3 v3.13.0/go.mod h1:6n3XBCmQQb25CM2LCACGz8ukIrRry+4bhvbpWn3mrbc= github.com/envoyproxy/go-control-plane v0.13.5-0.20251024222203-75eaa193e329/go.mod h1:Alz8LEClvR7xKsrq3qzoc4N0guvVNSS8KmSChGYr9hs= github.com/envoyproxy/go-control-plane/envoy v1.35.0/go.mod h1:09qwbGVuSWWAyN5t/b3iyVfz5+z8QWGrzkoqm/8SbEs= @@ -32,7 +27,6 @@ github.com/felixge/httpsnoop v1.0.4 h1:NFTV2Zj1bL4mc9sqWACXbQFVBBg2W3GPvqp8/ESS2 github.com/felixge/httpsnoop v1.0.4/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U= github.com/fsnotify/fsnotify v1.9.0 h1:2Ml+OJNzbYCTzsxtv8vKSFD9PbJjmhYF14k/jKC7S9k= github.com/fsnotify/fsnotify v1.9.0/go.mod h1:8jBTzvmWwFyi3Pb8djgCCO5IBqzKJ/Jwo8TRcHyHii0= -github.com/fxamacker/cbor/v2 v2.9.0 h1:NpKPmjDBgUfBms6tr6JZkTHtfFGcMKsw3eGcmD/sapM= github.com/fxamacker/cbor/v2 v2.9.0/go.mod h1:vM4b+DJCtHn+zz7h3FFp/hDAI9WNWCsZj23V5ytsSxQ= github.com/go-jose/go-jose/v4 v4.1.3/go.mod h1:x4oUasVrzR7071A4TnHLGSPpNOm2a21K9Kf04k1rs08= github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= @@ -41,56 +35,39 @@ github.com/go-logr/logr v1.4.3/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ4 github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag= github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE= github.com/go-logr/zapr v1.3.0/go.mod h1:YKepepNBd1u/oyhd/yQmtjVXmm9uML4IXUgMOwR8/Gg= -github.com/go-openapi/jsonpointer v0.19.6/go.mod h1:osyAmYz/mB/C3I+WsTTSgw1ONzaLJoLCyoi6/zppojs= -github.com/go-openapi/jsonpointer v0.21.0 h1:YgdVicSA9vH5RiHs9TZW5oyafXZFc6+2Vc1rr/O9oNQ= github.com/go-openapi/jsonpointer v0.21.0/go.mod h1:IUyH9l/+uyhIYQ/PXVA41Rexl+kOkAPDdXEYns6fzUY= -github.com/go-openapi/jsonreference v0.20.2 h1:3sVjiK66+uXK/6oQ8xgcRKcFgQ5KXa2KvnJRumpMGbE= github.com/go-openapi/jsonreference v0.20.2/go.mod h1:Bl1zwGIM8/wsvqjsOQLJ/SH+En5Ap4rVB5KVcIDZG2k= -github.com/go-openapi/swag v0.22.3/go.mod h1:UzaqsxGiab7freDnrUUra0MwWfN/q7tE4j+VcZ0yl14= -github.com/go-openapi/swag v0.23.0 h1:vsEVJDUo2hPJ2tu0/Xc+4noaxyEffXNIs3cOULZ+GrE= github.com/go-openapi/swag v0.23.0/go.mod h1:esZ8ITTYEsH1V2trKHjAN8Ai7xHb8RV+YSZ577vPjgQ= github.com/golang-jwt/jwt/v5 v5.3.0/go.mod h1:fxCRLWMO43lRc8nhHWY6LGqRcf+1gQWArsqaEUEa5bE= github.com/golang/glog v1.2.5/go.mod h1:6AhwSGph0fcJtXVM/PEHPqZlFeoLxhs7/t5UDAwmO+w= github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek= github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps= github.com/google/btree v1.1.3/go.mod h1:qOPhT0dTNdNzV6Z/lhRX0YXUafgPLFUh+gZMl761Gm4= -github.com/google/gnostic-models v0.7.0 h1:qwTtogB15McXDaNqTZdzPJRHvaVJlAl+HVQnLmJEJxo= github.com/google/gnostic-models v0.7.0/go.mod h1:whL5G0m6dmc5cPxKc5bdKdEN3UjI7OUGxBlw57miDrQ= github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8= github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU= -github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/gorilla/websocket v1.5.4-0.20250319132907-e064f32e3674/go.mod h1:r4w70xmWCQKmi1ONH4KIaBptdivuRPyosB9RmPlGEwA= github.com/grpc-ecosystem/grpc-gateway/v2 v2.27.7 h1:X+2YciYSxvMQK0UZ7sg45ZVabVZBeBuvMkmuI2V3Fak= github.com/grpc-ecosystem/grpc-gateway/v2 v2.27.7/go.mod h1:lW34nIZuQ8UDPdkon5fmfp2l3+ZkQ2me/+oecHYLOII= github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw= -github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY= github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y= github.com/jpillora/backoff v1.0.0/go.mod h1:J/6gKK9jxlEcS3zixgDgUAsiuZ7yrSoa/FX5e0EB2j4= -github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM= github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo= github.com/julienschmidt/httprouter v1.3.0/go.mod h1:JR6WtHb+2LUe8TCKY3cZOxFyyO8IZAc4RVcycCCAKdM= github.com/klauspost/compress v1.18.0 h1:c/Cqfb0r+Yi+JtIEq73FWXVkRonBlf0CRNYc8Zttxdo= github.com/klauspost/compress v1.18.0/go.mod h1:2Pp+KzxcywXVXMr50+X0Q/Lsb43OQHYWRCY2AiWywWQ= -github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= -github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= -github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc= github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw= -github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0= github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc= github.com/moby/spdystream v0.5.0/go.mod h1:xBAYlnt/ay+11ShkdFKNAG7LsyK/tmNBVvVOwrfMgdI= github.com/moby/term v0.5.0/go.mod h1:8FzsFHVUBGZdbDsJw/ot+X+d5HLUbvklYLJ9uGfcI3Y= -github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= -github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg= github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= -github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk= -github.com/modern-go/reflect2 v1.0.3-0.20250322232337-35a7c28c31ee h1:W5t00kpgFdJifH4BDsTlE89Zl93FEloxaWZfGcifgq8= github.com/modern-go/reflect2 v1.0.3-0.20250322232337-35a7c28c31ee/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk= github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq1c1nUAm88MOHcQC9l5mIlSMApZMrHA= github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ= @@ -98,7 +75,6 @@ github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f/go.mod h1:qRW github.com/mxk/go-flowrate v0.0.0-20140419014527-cca7078d478f/go.mod h1:ZdcZmHo+o7JKHSa8/e818NopupXU1YMK5fe1lsApnBw= github.com/peterbourgon/diskv v2.0.1+incompatible/go.mod h1:uqqh8zWWbv1HBMNONnaR/tNboyR3/BZd58JJSHlUSCU= github.com/planetscale/vtprotobuf v0.6.1-0.20240319094008-0393e58bdf10/go.mod h1:t/avpk3KcrXxUnYOhZhMXJlSEyie6gQbtLq5NM3loB8= -github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U= github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/prometheus/client_golang v1.23.2 h1:Je96obch5RDVy3FDMndoUsjAhG5Edi49h0RJWRi/o0o= @@ -117,17 +93,9 @@ github.com/spf13/cobra v1.10.2/go.mod h1:7C1pvHqHw5A4vrJfjNwvOdzYu0Gml16OCs2GRiT github.com/spf13/pflag v1.0.9 h1:9exaQaMOCwffKiiiYk6/BndUBv+iRViNW+4lEMi0PvY= github.com/spf13/pflag v1.0.9/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= github.com/spiffe/go-spiffe/v2 v2.6.0/go.mod h1:gm2SeUoMZEtpnzPNs2Csc0D/gX33k1xIx7lEzqblHEs= -github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= -github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA= -github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= -github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= -github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U= github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U= -github.com/x448/float16 v0.8.4 h1:qLwI1I70+NjRFUR3zs1JPUCgaCXSh3SW62uAKT1mSBM= github.com/x448/float16 v0.8.4/go.mod h1:14CWIYCyZA/cWjXOioeEpHeN/83MdbZDRQHoFcYsOfg= github.com/xhit/go-str2duration/v2 v2.1.0/go.mod h1:ohY8p+0f07DiV6Em5LKB0s2YpLtXVyJfNt1+BlmyAsU= go.opentelemetry.io/auto/sdk v1.2.1 h1:jXsnJ4Lmnqd11kwkBV2LgLoFMZKizbCi5fNZ/ipaZ64= @@ -159,7 +127,6 @@ go.uber.org/multierr v1.11.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN8 go.uber.org/zap v1.27.1/go.mod h1:GB2qFLM7cTU87MWRP2mPIjqfIDnGu+VIO4V/SdhGo2E= go.yaml.in/yaml/v2 v2.4.3 h1:6gvOSjQoTB3vt1l+CU+tSyi/HOjfOjRLJ4YwYZGwRO0= go.yaml.in/yaml/v2 v2.4.3/go.mod h1:zSxWcmIDjOzPXpjlTTbAsKokqkDNAVtZO0WOMiT90s8= -go.yaml.in/yaml/v3 v3.0.4 h1:tfq32ie2Jv2UxXFdLJdh3jXuOzWiL1fo0bu/FbuKpbc= go.yaml.in/yaml/v3 v3.0.4/go.mod h1:DhzuOOF2ATzADvBadXxruRBLzYTpT36CKvDb3+aBEFg= golang.org/x/crypto v0.47.0/go.mod h1:ff3Y9VzzKbwSSEzWqJsJVBnWmRwRSHt/6Op5n9bQc4A= golang.org/x/mod v0.31.0/go.mod h1:43JraMp9cGx1Rx3AqioxrbrhNsLl2l/iNAvuBkrezpg= @@ -176,8 +143,6 @@ golang.org/x/text v0.33.0/go.mod h1:LuMebE6+rBincTi9+xWTY8TztLzKHc/9C1uBCG27+q8= golang.org/x/time v0.14.0 h1:MRx4UaLrDotUKUdCIqzPC48t1Y9hANFKIRpNx+Te8PI= golang.org/x/time v0.14.0/go.mod h1:eL/Oa2bBBK0TkX57Fyni+NgnyQQN4LitPmob2Hjnqw4= golang.org/x/tools v0.40.0/go.mod h1:Ik/tzLRlbscWpqqMRjyWYDisX8bG13FrdXp3o4Sr9lc= -golang.org/x/tools/go/expect v0.1.0-deprecated/go.mod h1:eihoPOH+FgIqa3FpoTwguz/bVUSGBlGQU67vpBeOrBY= -golang.org/x/tools/go/packages/packagestest v0.1.1-deprecated/go.mod h1:RVAQXBGNv1ib0J382/DPCRS/BPnsGebyM1Gj5VSDpG8= gonum.org/v1/gonum v0.16.0 h1:5+ul4Swaf3ESvrOnidPp4GZbzf0mxVQpDCYUQE7OJfk= gonum.org/v1/gonum v0.16.0/go.mod h1:fef3am4MQ93R2HHpKnLk4/Tbh/s0+wqD5nfa6Pnwy4E= google.golang.org/genproto/googleapis/api v0.0.0-20260128011058-8636f8732409 h1:merA0rdPeUV3YIIfHHcH4qBkiQAc1nfCKSI7lB4cV2M= @@ -192,23 +157,15 @@ gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8 gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= gopkg.in/evanphx/json-patch.v4 v4.13.0/go.mod h1:p8EYWUEYMpynmqDbY58zCKCFZw8pRWMG4EsWvDvM72M= -gopkg.in/inf.v0 v0.9.1 h1:73M5CoZyi3ZLMOyDlQh031Cx6N9NDJ2Vvfl76EDAgDc= gopkg.in/inf.v0 v0.9.1/go.mod h1:cWUDdTG/fYaXco+Dcufb5Vnc6Gp2YChqWtbxRZE0mXw= -gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= -k8s.io/gengo/v2 v2.0.0-20250604051438-85fd79dbfd9f/go.mod h1:EJykeLsmFC60UQbYJezXkEsG2FLrt0GPNkU5iK5GWxU= k8s.io/klog/v2 v2.140.0 h1:Tf+J3AH7xnUzZyVVXhTgGhEKnFqye14aadWv7bzXdzc= k8s.io/klog/v2 v2.140.0/go.mod h1:o+/RWfJ6PwpnFn7OyAG3QnO47BFsymfEfrz6XyYSSp0= -k8s.io/kube-openapi v0.0.0-20260317180543-43fb72c5454a h1:xCeOEAOoGYl2jnJoHkC3hkbPJgdATINPMAxaynU2Ovg= k8s.io/kube-openapi v0.0.0-20260317180543-43fb72c5454a/go.mod h1:uGBT7iTA6c6MvqUvSXIaYZo9ukscABYi2btjhvgKGZ0= k8s.io/utils v0.0.0-20260210185600-b8788abfbbc2 h1:AZYQSJemyQB5eRxqcPky+/7EdBj0xi3g0ZcxxJ7vbWU= k8s.io/utils v0.0.0-20260210185600-b8788abfbbc2/go.mod h1:xDxuJ0whA3d0I4mf/C4ppKHxXynQ+fxnkmQH0vTHnuk= -sigs.k8s.io/json v0.0.0-20250730193827-2d320260d730 h1:IpInykpT6ceI+QxKBbEflcR5EXP7sU1kvOlxwZh5txg= sigs.k8s.io/json v0.0.0-20250730193827-2d320260d730/go.mod h1:mdzfpAEoE6DHQEN0uh9ZbOCuHbLK5wOm7dK4ctXE9Tg= -sigs.k8s.io/randfill v1.0.0 h1:JfjMILfT8A6RbawdsK2JXGBR5AQVfd+9TbzrlneTyrU= sigs.k8s.io/randfill v1.0.0/go.mod h1:XeLlZ/jmk4i1HRopwe7/aU3H5n1zNUcX6TM94b3QxOY= -sigs.k8s.io/structured-merge-diff/v6 v6.3.2 h1:kwVWMx5yS1CrnFWA/2QHyRVJ8jM6dBA80uLmm0wJkk8= sigs.k8s.io/structured-merge-diff/v6 v6.3.2/go.mod h1:M3W8sfWvn2HhQDIbGWj3S099YozAsymCo/wrT5ohRUE= -sigs.k8s.io/yaml v1.6.0 h1:G8fkbMSAFqgEFgh4b1wmtzDnioxFCUgTZhlbj5P9QYs= sigs.k8s.io/yaml v1.6.0/go.mod h1:796bPqUfzR/0jLAl6XjHl3Ck7MiyVv8dbTdyT3/pMf4= diff --git a/staging/src/k8s.io/cri-client/pkg/fake/endpoint.go b/staging/src/k8s.io/cri-client/pkg/fake/endpoint.go index 956c2079f4f..85b6610d73e 100644 --- a/staging/src/k8s.io/cri-client/pkg/fake/endpoint.go +++ b/staging/src/k8s.io/cri-client/pkg/fake/endpoint.go @@ -20,7 +20,7 @@ package fake import ( "fmt" - "k8s.io/apimachinery/pkg/util/rand" + "math/rand" ) const ( diff --git a/staging/src/k8s.io/cri-client/pkg/logs/logs.go b/staging/src/k8s.io/cri-client/pkg/logs/logs.go index bcef4031731..ffa3bb37e62 100644 --- a/staging/src/k8s.io/cri-client/pkg/logs/logs.go +++ b/staging/src/k8s.io/cri-client/pkg/logs/logs.go @@ -33,7 +33,6 @@ import ( "google.golang.org/grpc/codes" "google.golang.org/grpc/status" - v1 "k8s.io/api/core/v1" internalapi "k8s.io/cri-api/pkg/apis" runtimeapi "k8s.io/cri-api/pkg/apis/runtime/v1" "k8s.io/klog/v2" @@ -88,34 +87,28 @@ func (l *logMessage) reset() { // LogOptions is the CRI internal type of all log options. type LogOptions struct { - tail int64 - bytes int64 - since time.Time - follow bool - timestamp bool -} - -// NewLogOptions convert the v1.PodLogOptions to CRI internal LogOptions. -func NewLogOptions(apiOpts *v1.PodLogOptions, now time.Time) *LogOptions { - opts := &LogOptions{ - tail: -1, // -1 by default which means read all logs. - bytes: -1, // -1 by default which means read all logs. - follow: apiOpts.Follow, - timestamp: apiOpts.Timestamps, - } - if apiOpts.TailLines != nil { - opts.tail = *apiOpts.TailLines - } - if apiOpts.LimitBytes != nil { - opts.bytes = *apiOpts.LimitBytes - } - if apiOpts.SinceSeconds != nil { - opts.since = now.Add(-time.Duration(*apiOpts.SinceSeconds) * time.Second) - } - if apiOpts.SinceTime != nil && apiOpts.SinceTime.After(opts.since) { - opts.since = apiOpts.SinceTime.Time - } - return opts + // TailLines is the number of lines to show from the end of the logs. + // If it is nil, it means all log lines will be shown. + // If it is 0, no log lines will be shown. + // This corresponds to the TailLines field in v1.PodLogOptions. + TailLines *int64 + // LimitBytes is the maximum number of bytes to read from the logs. + // If it is nil, it means all bytes will be read. + // If it is 0, no bytes will be read. + // This corresponds to the LimitBytes field in v1.PodLogOptions. + LimitBytes *int64 + // Since is the absolute time from which to show logs. + // Only logs with a timestamp after this time will be returned. + // This can be derived from either SinceSeconds or SinceTime in v1.PodLogOptions. + Since time.Time + // Follow indicates whether the logs should be followed. + // If true, the read will continue until the container is stopped or the context is cancelled. + // This corresponds to the Follow field in v1.PodLogOptions. + Follow bool + // Timestamp indicates whether to include timestamps in the log output. + // If true, each log line will be prefixed with its RFC3339 timestamp. + // This corresponds to the Timestamps field in v1.PodLogOptions. + Timestamp bool } // parseFunc is a function parsing one log line to the internal log type. @@ -235,20 +228,20 @@ func newLogWriter(stdout io.Writer, stderr io.Writer, opts *LogOptions) *logWrit opts: opts, remain: math.MaxInt64, // initialize it as infinity } - if opts.bytes >= 0 { - w.remain = opts.bytes + if opts.LimitBytes != nil { + w.remain = *opts.LimitBytes } return w } // writeLogs writes logs into stdout, stderr. func (w *logWriter) write(msg *logMessage, addPrefix bool) error { - if msg.timestamp.Before(w.opts.since) { + if msg.timestamp.Before(w.opts.Since) { // Skip the line because it's older than since return nil } line := msg.log - if w.opts.timestamp && addPrefix { + if w.opts.Timestamp && addPrefix { prefix := append([]byte(msg.timestamp.Format(timeFormatOut)), delimiter[0]) line = append(prefix, line...) } @@ -308,16 +301,20 @@ func ReadLogs(ctx context.Context, path, containerID string, opts *LogOptions, r defer f.Close() // Search start point based on tail line. - start, err := findTailLineStartIndex(f, opts.tail) + var tail int64 = -1 + if opts.TailLines != nil { + tail = *opts.TailLines + } + start, err := findTailLineStartIndex(f, tail) if err != nil { - return fmt.Errorf("failed to tail %d lines of log file %q: %v", opts.tail, path, err) + return fmt.Errorf("failed to tail %d lines of log file %q: %w", tail, path, err) } if _, err := f.Seek(start, io.SeekStart); err != nil { - return fmt.Errorf("failed to seek %d in log file %q: %v", start, path, err) + return fmt.Errorf("failed to seek %d in log file %q: %w", start, path, err) } - limitedMode := (opts.tail >= 0) && (!opts.follow) - limitedNum := opts.tail + limitedMode := (opts.TailLines != nil) && (!opts.Follow) + limitedNum := tail // Start parsing the logs. r := bufio.NewReader(f) // Do not create watcher here because it is not needed if `Follow` is false. @@ -342,7 +339,7 @@ func ReadLogs(ctx context.Context, path, containerID string, opts *LogOptions, r if err != io.EOF { // This is an real error return fmt.Errorf("failed to read log file %q: %v", path, err) } - if opts.follow { + if opts.Follow { // The container is not running, we got to the end of the log. if !found { return nil @@ -410,7 +407,11 @@ func ReadLogs(ctx context.Context, path, containerID string, opts *LogOptions, r // Write the log line into the stream. if err := writer.write(msg, isNewLine); err != nil { if err == errMaximumWrite { - logger.V(2).Info("Finished parsing log file, hit bytes limit", "path", path, "limit", opts.bytes) + var bytes int64 = -1 + if opts.LimitBytes != nil { + bytes = *opts.LimitBytes + } + logger.V(2).Info("Finished parsing log file, hit bytes limit", "path", path, "limit", bytes) return nil } logger.Error(err, "Failed when writing line to log file", "path", path, "line", msg) diff --git a/staging/src/k8s.io/cri-client/pkg/logs/logs_test.go b/staging/src/k8s.io/cri-client/pkg/logs/logs_test.go index a109644250a..9578f67f70f 100644 --- a/staging/src/k8s.io/cri-client/pkg/logs/logs_test.go +++ b/staging/src/k8s.io/cri-client/pkg/logs/logs_test.go @@ -31,138 +31,104 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - v1 "k8s.io/api/core/v1" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - utiltesting "k8s.io/client-go/util/testing" runtimeapi "k8s.io/cri-api/pkg/apis/runtime/v1" apitesting "k8s.io/cri-api/pkg/apis/testing" "k8s.io/utils/ptr" ) -func TestLogOptions(t *testing.T) { - var ( - line = int64(8) - bytes = int64(64) - timestamp = metav1.Now() - sinceseconds = int64(10) - ) - for c, test := range []struct { - apiOpts *v1.PodLogOptions - expect *LogOptions - }{ - { // empty options - apiOpts: &v1.PodLogOptions{}, - expect: &LogOptions{tail: -1, bytes: -1}, - }, - { // test tail lines - apiOpts: &v1.PodLogOptions{TailLines: &line}, - expect: &LogOptions{tail: line, bytes: -1}, - }, - { // test limit bytes - apiOpts: &v1.PodLogOptions{LimitBytes: &bytes}, - expect: &LogOptions{tail: -1, bytes: bytes}, - }, - { // test since timestamp - apiOpts: &v1.PodLogOptions{SinceTime: ×tamp}, - expect: &LogOptions{tail: -1, bytes: -1, since: timestamp.Time}, - }, - { // test since seconds - apiOpts: &v1.PodLogOptions{SinceSeconds: &sinceseconds}, - expect: &LogOptions{tail: -1, bytes: -1, since: timestamp.Add(-10 * time.Second)}, - }, - } { - t.Logf("TestCase #%d: %+v", c, test) - opts := NewLogOptions(test.apiOpts, timestamp.Time) - assert.Equal(t, test.expect, opts) - } -} - func TestReadLogs(t *testing.T) { file, err := os.CreateTemp("", "TestFollowLogs") if err != nil { t.Fatalf("unable to create temp file") } - defer utiltesting.CloseAndRemove(t, file) + t.Cleanup(func() { + if err := file.Close(); err != nil { + t.Logf("failed to close file: %v", err) + } + if err := os.Remove(file.Name()); err != nil { + t.Logf("failed to remove file: %v", err) + } + }) file.WriteString(`{"log":"line1\n","stream":"stdout","time":"2020-09-27T11:18:01.00000000Z"}` + "\n") file.WriteString(`{"log":"line2\n","stream":"stdout","time":"2020-09-27T11:18:02.00000000Z"}` + "\n") file.WriteString(`{"log":"line3\n","stream":"stdout","time":"2020-09-27T11:18:03.00000000Z"}` + "\n") testCases := []struct { - name string - podLogOptions v1.PodLogOptions - expected string + name string + opts LogOptions + expected string }{ { - name: "default pod log options should output all lines", - podLogOptions: v1.PodLogOptions{}, - expected: "line1\nline2\nline3\n", + name: "default pod log options should output all lines", + opts: LogOptions{}, + expected: "line1\nline2\nline3\n", }, { name: "using TailLines 2 should output last 2 lines", - podLogOptions: v1.PodLogOptions{ + opts: LogOptions{ TailLines: ptr.To[int64](2), }, expected: "line2\nline3\n", }, { name: "using TailLines 4 should output all lines when the log has less than 4 lines", - podLogOptions: v1.PodLogOptions{ + opts: LogOptions{ TailLines: ptr.To[int64](4), }, expected: "line1\nline2\nline3\n", }, { name: "using TailLines 0 should output nothing", - podLogOptions: v1.PodLogOptions{ + opts: LogOptions{ TailLines: ptr.To[int64](0), }, expected: "", }, { name: "using LimitBytes 9 should output first 9 bytes", - podLogOptions: v1.PodLogOptions{ + opts: LogOptions{ LimitBytes: ptr.To[int64](9), }, expected: "line1\nlin", }, { name: "using LimitBytes 100 should output all bytes when the log has less than 100 bytes", - podLogOptions: v1.PodLogOptions{ + opts: LogOptions{ LimitBytes: ptr.To[int64](100), }, expected: "line1\nline2\nline3\n", }, { name: "using LimitBytes 0 should output nothing", - podLogOptions: v1.PodLogOptions{ + opts: LogOptions{ LimitBytes: ptr.To[int64](0), }, expected: "", }, { name: "using SinceTime should output lines with a time on or after the specified time", - podLogOptions: v1.PodLogOptions{ - SinceTime: &metav1.Time{Time: time.Date(2020, time.Month(9), 27, 11, 18, 02, 0, time.UTC)}, + opts: LogOptions{ + Since: time.Date(2020, time.Month(9), 27, 11, 18, 02, 0, time.UTC), }, expected: "line2\nline3\n", }, { name: "using SinceTime now should output nothing", - podLogOptions: v1.PodLogOptions{ - SinceTime: &metav1.Time{Time: time.Now()}, + opts: LogOptions{ + Since: time.Now(), }, expected: "", }, { name: "using follow should output all log lines", - podLogOptions: v1.PodLogOptions{ + opts: LogOptions{ Follow: true, }, expected: "line1\nline2\nline3\n", }, { name: "using follow combined with TailLines 2 should output the last 2 lines", - podLogOptions: v1.PodLogOptions{ + opts: LogOptions{ Follow: true, TailLines: ptr.To[int64](2), }, @@ -170,9 +136,9 @@ func TestReadLogs(t *testing.T) { }, { name: "using follow combined with SinceTime should output lines with a time on or after the specified time", - podLogOptions: v1.PodLogOptions{ - Follow: true, - SinceTime: &metav1.Time{Time: time.Date(2020, time.Month(9), 27, 11, 18, 02, 0, time.UTC)}, + opts: LogOptions{ + Follow: true, + Since: time.Date(2020, time.Month(9), 27, 11, 18, 02, 0, time.UTC), }, expected: "line2\nline3\n", }, @@ -190,14 +156,13 @@ func TestReadLogs(t *testing.T) { }, } // If follow is specified, mark the container as exited or else ReadLogs will run indefinitely - if tc.podLogOptions.Follow { + if tc.opts.Follow { fakeRuntimeService.Containers[containerID].State = runtimeapi.ContainerState_CONTAINER_EXITED } - opts := NewLogOptions(&tc.podLogOptions, time.Now()) stdoutBuf := bytes.NewBuffer(nil) stderrBuf := bytes.NewBuffer(nil) - err = ReadLogs(context.TODO(), file.Name(), containerID, opts, fakeRuntimeService, stdoutBuf, stderrBuf) + err = ReadLogs(context.TODO(), file.Name(), containerID, &tc.opts, fakeRuntimeService, stdoutBuf, stderrBuf) if err != nil { t.Fatal(err.Error()) @@ -235,11 +200,10 @@ func TestReadRotatedLog(t *testing.T) { // Start to follow the container's log. fileName := file.Name() go func(ctx context.Context) { - podLogOptions := v1.PodLogOptions{ + opts := LogOptions{ Follow: true, } - opts := NewLogOptions(&podLogOptions, time.Now()) - _ = ReadLogs(ctx, fileName, containerID, opts, fakeRuntimeService, stdoutBuf, stderrBuf) + _ = ReadLogs(ctx, fileName, containerID, &opts, fakeRuntimeService, stdoutBuf, stderrBuf) }(ctx) // log in stdout @@ -412,7 +376,7 @@ func TestWriteLogs(t *testing.T) { } stdoutBuf := bytes.NewBuffer(nil) stderrBuf := bytes.NewBuffer(nil) - w := newLogWriter(stdoutBuf, stderrBuf, &LogOptions{since: test.since, timestamp: test.timestamp, bytes: -1}) + w := newLogWriter(stdoutBuf, stderrBuf, &LogOptions{Since: test.since, Timestamp: test.timestamp}) err := w.write(msg, true) assert.NoError(t, err) assert.Equal(t, test.expectStdout, stdoutBuf.String()) @@ -474,7 +438,7 @@ func TestWriteLogsWithBytesLimit(t *testing.T) { } stdoutBuf := bytes.NewBuffer(nil) stderrBuf := bytes.NewBuffer(nil) - w := newLogWriter(stdoutBuf, stderrBuf, &LogOptions{timestamp: test.timestamp, bytes: int64(test.bytes)}) + w := newLogWriter(stdoutBuf, stderrBuf, &LogOptions{Timestamp: test.timestamp, LimitBytes: ptr.To(int64(test.bytes))}) for i := 0; i < test.stdoutLines; i++ { msg.stream = runtimeapi.Stdout if err := w.write(msg, true); err != nil { @@ -521,7 +485,7 @@ func TestReadLogsLimitsWithTimestamps(t *testing.T) { var buf bytes.Buffer w := io.MultiWriter(&buf) - err = ReadLogs(context.Background(), tmpfile.Name(), "", &LogOptions{tail: -1, bytes: -1, timestamp: true}, nil, w, w) + err = ReadLogs(context.Background(), tmpfile.Name(), "", &LogOptions{Timestamp: true}, nil, w, w) assert.NoError(t, err) lineCount := 0 @@ -579,11 +543,16 @@ func TestOnlyStdoutStream(t *testing.T) { expectedStdout: "out1\nou", }, } + for name, tc := range testCases { t.Run(name, func(t *testing.T) { stdoutBuf := bytes.NewBuffer(nil) + var bytesPtr *int64 + if tc.limitBytes >= 0 { + bytesPtr = ptr.To(tc.limitBytes) + } w := newLogWriter(stdoutBuf, nil, &LogOptions{ - bytes: tc.limitBytes, + LimitBytes: bytesPtr, }) for _, msg := range msgs { err := w.write(msg, false)