@@ -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
6262func 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+
129140func 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