Skip to content

Commit 966ed75

Browse files
authored
[Feature] [DP] Add Timeout (#1970)
1 parent 3c4c4c4 commit 966ed75

File tree

2 files changed

+26
-20
lines changed

2 files changed

+26
-20
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
- (Feature) (Platform) Gateway UpToDate Condition
1818
- (Documentation) Update Supported Kubernetes Versions
1919
- (Feature) (Platform) Inventory Improvement
20+
- (Feature) (DP) Add Timeout
2021

2122
## [1.3.0](https://github.com/arangodb/kube-arangodb/tree/1.3.0) (2025-08-01)
2223
- (Feature) (Platform) Storage Debug

cmd/admin.go

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,8 @@ import (
2929
"net"
3030
goHttp "net/http"
3131
"os"
32-
"os/signal"
3332
"strconv"
34-
"syscall"
33+
"time"
3534

3635
"github.com/spf13/cobra"
3736
core "k8s.io/api/core/v1"
@@ -57,10 +56,14 @@ const (
5756
ArgDeploymentName = "deployment-name"
5857
ArgMemberName = "member-name"
5958
ArgAcceptedCode = "accepted-code"
59+
ArgTimeout = "timeout"
6060
)
6161

6262
func init() {
6363
cmdMain.AddCommand(cmdAdmin)
64+
cmdAdminAgencyDump.PersistentFlags().DurationP(ArgTimeout, "t", time.Minute,
65+
"timeout of the request")
66+
6467
cmdAdmin.AddCommand(cmdAdminAgency)
6568
cmdAdmin.AddCommand(cmdAdminMember)
6669

@@ -126,6 +129,14 @@ var cmdAdminAgencyState = &cobra.Command{
126129
RunE: cmdAdminGetAgencyStateE,
127130
}
128131

132+
func extractTimeout(cmd *cobra.Command) (context.Context, context.CancelFunc) {
133+
if v, err := cmd.PersistentFlags().GetDuration(ArgTimeout); err == nil {
134+
return context.WithTimeout(cmd.Context(), v)
135+
}
136+
137+
return context.WithCancel(cmd.Context())
138+
}
139+
129140
func cmdGetAdminMemberRequestGetE(cmd *cobra.Command, args []string) error {
130141
deploymentName, err := cmd.Flags().GetString(ArgDeploymentName)
131142
if err != nil {
@@ -139,7 +150,10 @@ func cmdGetAdminMemberRequestGetE(cmd *cobra.Command, args []string) error {
139150
if err != nil {
140151
return err
141152
}
142-
ctx := getInterruptionContext()
153+
154+
ctx, c := extractTimeout(cmd)
155+
defer c()
156+
143157
d, certCA, auth, err := getDeploymentAndCredentials(ctx, deploymentName)
144158
if err != nil {
145159
logger.Err(err).Error("failed to create basic data for the connection")
@@ -175,7 +189,10 @@ func cmdAdminGetAgencyStateE(cmd *cobra.Command, _ []string) error {
175189
if err != nil {
176190
return err
177191
}
178-
ctx := getInterruptionContext()
192+
193+
ctx, c := extractTimeout(cmd)
194+
defer c()
195+
179196
d, certCA, auth, err := getDeploymentAndCredentials(ctx, deploymentName)
180197
if err != nil {
181198
logger.Err(err).Error("failed to create basic data for the connection")
@@ -220,7 +237,10 @@ func cmdAdminGetAgencyDumpE(cmd *cobra.Command, _ []string) error {
220237
if err != nil {
221238
return err
222239
}
223-
ctx := getInterruptionContext()
240+
241+
ctx, c := extractTimeout(cmd)
242+
defer c()
243+
224244
d, certCA, auth, err := getDeploymentAndCredentials(ctx, deploymentName)
225245
if err != nil {
226246
logger.Err(err).Error("failed to create basic data for the connection")
@@ -497,18 +517,3 @@ func getDeployment(ctx context.Context, namespace, deplName string) (api.ArangoD
497517

498518
return api.ArangoDeployment{}, errors.New(message)
499519
}
500-
501-
// getInterruptionContext returns context which will be cancelled when the process is interrupted.
502-
func getInterruptionContext() context.Context {
503-
c := make(chan os.Signal, 1)
504-
505-
signal.Notify(c, os.Interrupt, syscall.SIGTERM)
506-
ctx, cancel := context.WithCancel(context.Background())
507-
go func() {
508-
// Block until SIGTERM or SIGINT occurs.
509-
<-c
510-
cancel()
511-
}()
512-
513-
return ctx
514-
}

0 commit comments

Comments
 (0)