Skip to content

Commit d07d01d

Browse files
authored
feat(plugin): add configurable timeout flag for status command (cloudnative-pg#9201)
Add a new `--timeout` flag to the `kubectl cnpg status` command to allow users to configure the timeout for operations that access the pod filesystem (e.g., `du` for calculating cluster size, `cat` for reading configuration files). The timeout parameter: - Defaults to 10 seconds to maintain backward compatibility - Can be adjusted using `--timeout`/`-t` flag (e.g., `--timeout 45s`) - Is applied to all timeout-based operations in the status command This addresses issues with large clusters (e.g., >1TB) where filesystem operations may exceed the previous hardcoded 10-second timeout, causing "context deadline exceeded" errors. Closes cloudnative-pg#9164 Signed-off-by: Armando Ruocco <armando.ruocco@enterprisedb.com>
1 parent c78f5a7 commit d07d01d

File tree

3 files changed

+27
-9
lines changed

3 files changed

+27
-9
lines changed

docs/src/kubectl-plugin.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,13 @@ also view PostgreSQL configuration, HBA settings, and certificates.
360360

361361
The command also supports output in `yaml` and `json` format.
362362

363+
!!! Note
364+
The `status` command executes operations that access the pod filesystem,
365+
such as `du` to calculate cluster size and `cat` to read configuration files.
366+
For clusters with large data volumes (e.g., over 1TB), these operations may
367+
take longer than the default timeout of 10 seconds. You can adjust the timeout
368+
using the `--timeout` flag (e.g., `kubectl cnpg status sandbox --timeout 45s`).
369+
363370
### Promote
364371

365372
The meaning of this command is to `promote` a pod in the cluster to primary, so you

internal/cmd/plugin/status/cmd.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ package status
2222
import (
2323
"fmt"
2424
"strings"
25+
"time"
2526

2627
"github.com/spf13/cobra"
2728

@@ -47,15 +48,18 @@ func NewCmd() *cobra.Command {
4748

4849
verbose, _ := cmd.Flags().GetCount("verbose")
4950
output, _ := cmd.Flags().GetString("output")
51+
timeout, _ := cmd.Flags().GetDuration("timeout")
5052

51-
return Status(ctx, clusterName, verbose, plugin.OutputFormat(output))
53+
return Status(ctx, clusterName, verbose, plugin.OutputFormat(output), timeout)
5254
},
5355
}
5456

5557
statusCmd.Flags().CountP(
5658
"verbose", "v", "Increase verbosity to display more information")
5759
statusCmd.Flags().StringP(
5860
"output", "o", "text", "Output format. One of text|json")
61+
statusCmd.Flags().DurationP(
62+
"timeout", "t", 10*time.Second, "Timeout for operations that access pod filesystems (e.g., du, cat)")
5963

6064
return statusCmd
6165
}

internal/cmd/plugin/status/status.go

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ func Status(
111111
clusterName string,
112112
verbosity int,
113113
format plugin.OutputFormat,
114+
timeout time.Duration,
114115
) error {
115116
var cluster apiv1.Cluster
116117
var errs []error
@@ -134,12 +135,12 @@ func Status(
134135
}
135136
errs = append(errs, status.ErrorList...)
136137

137-
status.printBasicInfo(ctx, clientInterface)
138+
status.printBasicInfo(ctx, clientInterface, timeout)
138139
status.printHibernationInfo()
139140
status.printDemotionTokenInfo()
140141
status.printPromotionTokenInfo()
141142
if verbosity > 1 {
142-
errs = append(errs, status.printPostgresConfiguration(ctx, clientInterface)...)
143+
errs = append(errs, status.printPostgresConfiguration(ctx, clientInterface, timeout)...)
143144
status.printCertificatesStatus()
144145
}
145146
if !hibernated {
@@ -216,9 +217,11 @@ func listFencedInstances(fencedInstances *stringset.Data) string {
216217
return strings.Join(fencedInstances.ToList(), ", ")
217218
}
218219

219-
func (fullStatus *PostgresqlStatus) getClusterSize(ctx context.Context, client kubernetes.Interface) (string, error) {
220-
timeout := time.Second * 10
221-
220+
func (fullStatus *PostgresqlStatus) getClusterSize(
221+
ctx context.Context,
222+
client kubernetes.Interface,
223+
timeout time.Duration,
224+
) (string, error) {
222225
// Compute the disk space through `du`
223226
output, _, err := utils.ExecCommand(
224227
ctx,
@@ -238,10 +241,14 @@ func (fullStatus *PostgresqlStatus) getClusterSize(ctx context.Context, client k
238241
return size, nil
239242
}
240243

241-
func (fullStatus *PostgresqlStatus) printBasicInfo(ctx context.Context, k8sClient kubernetes.Interface) {
244+
func (fullStatus *PostgresqlStatus) printBasicInfo(
245+
ctx context.Context,
246+
k8sClient kubernetes.Interface,
247+
timeout time.Duration,
248+
) {
242249
summary := tabby.New()
243250

244-
clusterSize, clusterSizeErr := fullStatus.getClusterSize(ctx, k8sClient)
251+
clusterSize, clusterSizeErr := fullStatus.getClusterSize(ctx, k8sClient, timeout)
245252

246253
cluster := fullStatus.Cluster
247254

@@ -481,8 +488,8 @@ func (fullStatus *PostgresqlStatus) getStatus(cluster *apiv1.Cluster) string {
481488
func (fullStatus *PostgresqlStatus) printPostgresConfiguration(
482489
ctx context.Context,
483490
client kubernetes.Interface,
491+
timeout time.Duration,
484492
) []error {
485-
timeout := time.Second * 10
486493
var errs []error
487494

488495
// Read PostgreSQL configuration from custom.conf

0 commit comments

Comments
 (0)