@@ -17,10 +17,14 @@ import (
17
17
"k8s.io/client-go/tools/remotecommand"
18
18
"k8s.io/metrics/pkg/apis/metrics"
19
19
metricsv1beta1api "k8s.io/metrics/pkg/apis/metrics/v1beta1"
20
+ "k8s.io/utils/ptr"
20
21
21
22
"github.com/containers/kubernetes-mcp-server/pkg/version"
22
23
)
23
24
25
+ // Default number of lines to retrieve from the end of the logs
26
+ const DefaultTailLines = int64 (100 )
27
+
24
28
type PodsTopOptions struct {
25
29
metav1.ListOptions
26
30
AllNamespaces bool
@@ -92,17 +96,26 @@ func (k *Kubernetes) PodsDelete(ctx context.Context, namespace, name string) (st
92
96
k .ResourcesDelete (ctx , & schema.GroupVersionKind {Group : "" , Version : "v1" , Kind : "Pod" }, namespace , name )
93
97
}
94
98
95
- func (k * Kubernetes ) PodsLog (ctx context.Context , namespace , name , container string , previous bool ) (string , error ) {
96
- tailLines := int64 (256 )
99
+ func (k * Kubernetes ) PodsLog (ctx context.Context , namespace , name , container string , previous bool , tail int64 ) (string , error ) {
97
100
pods , err := k .manager .accessControlClientSet .Pods (k .NamespaceOrDefault (namespace ))
98
101
if err != nil {
99
102
return "" , err
100
103
}
101
- req := pods . GetLogs ( name , & v1. PodLogOptions {
102
- TailLines : & tailLines ,
104
+
105
+ logOptions := & v1. PodLogOptions {
103
106
Container : container ,
104
107
Previous : previous ,
105
- })
108
+ }
109
+
110
+ // Only set tailLines if a value is provided (non-zero)
111
+ if tail > 0 {
112
+ logOptions .TailLines = & tail
113
+ } else {
114
+ // Default to DefaultTailLines lines when not specified
115
+ logOptions .TailLines = ptr .To (DefaultTailLines )
116
+ }
117
+
118
+ req := pods .GetLogs (name , logOptions )
106
119
res := req .Do (ctx )
107
120
if res .Error () != nil {
108
121
return "" , res .Error ()
0 commit comments