Browse Source

etcdctl v3: adds the --once option to the lease keep-alive command

Fixes: #8719
marco 8 years ago
parent
commit
cb188d0b26
1 changed files with 17 additions and 2 deletions
  1. 17 2
      etcdctl/ctlv3/command/lease_command.go

+ 17 - 2
etcdctl/ctlv3/command/lease_command.go

@@ -150,15 +150,21 @@ func leaseListCommandFunc(cmd *cobra.Command, args []string) {
 	display.Leases(*resp)
 	display.Leases(*resp)
 }
 }
 
 
+var (
+	leaseKeepAliveOnce bool
+)
+
 // NewLeaseKeepAliveCommand returns the cobra command for "lease keep-alive".
 // NewLeaseKeepAliveCommand returns the cobra command for "lease keep-alive".
 func NewLeaseKeepAliveCommand() *cobra.Command {
 func NewLeaseKeepAliveCommand() *cobra.Command {
 	lc := &cobra.Command{
 	lc := &cobra.Command{
-		Use:   "keep-alive <leaseID>",
+		Use:   "keep-alive [options] <leaseID>",
 		Short: "Keeps leases alive (renew)",
 		Short: "Keeps leases alive (renew)",
 
 
 		Run: leaseKeepAliveCommandFunc,
 		Run: leaseKeepAliveCommandFunc,
 	}
 	}
 
 
+	lc.Flags().BoolVar(&leaseKeepAliveOnce, "once", false, "Resets the keep-alive time to its original value and exits immediately")
+
 	return lc
 	return lc
 }
 }
 
 
@@ -169,11 +175,20 @@ func leaseKeepAliveCommandFunc(cmd *cobra.Command, args []string) {
 	}
 	}
 
 
 	id := leaseFromArgs(args[0])
 	id := leaseFromArgs(args[0])
+	
+	if leaseKeepAliveOnce {
+		respc, kerr := mustClientFromCmd(cmd).KeepAliveOnce(context.TODO(), id)
+		if kerr != nil {
+			ExitWithError(ExitBadConnection, kerr)
+		}
+		display.KeepAlive(*respc)
+		return
+	}
+
 	respc, kerr := mustClientFromCmd(cmd).KeepAlive(context.TODO(), id)
 	respc, kerr := mustClientFromCmd(cmd).KeepAlive(context.TODO(), id)
 	if kerr != nil {
 	if kerr != nil {
 		ExitWithError(ExitBadConnection, kerr)
 		ExitWithError(ExitBadConnection, kerr)
 	}
 	}
-
 	for resp := range respc {
 	for resp := range respc {
 		display.KeepAlive(*resp)
 		display.KeepAlive(*resp)
 	}
 	}