-
Notifications
You must be signed in to change notification settings - Fork 0
/
wait.go
64 lines (53 loc) · 1.84 KB
/
wait.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: 2021-Present The Jackal Authors
// Package tools contains the CLI commands for Jackal.
package tools
import (
"time"
"github.com/racer159/jackal/src/config/lang"
"github.com/racer159/jackal/src/pkg/message"
"github.com/racer159/jackal/src/pkg/utils"
"github.com/spf13/cobra"
// Import to initialize client auth plugins.
_ "k8s.io/client-go/plugin/pkg/client/auth"
)
var (
waitTimeout string
waitNamespace string
)
var waitForCmd = &cobra.Command{
Use: "wait-for { KIND | PROTOCOL } { NAME | SELECTOR | URI } { CONDITION | HTTP_CODE }",
Aliases: []string{"w", "wait"},
Short: lang.CmdToolsWaitForShort,
Long: lang.CmdToolsWaitForLong,
Example: lang.CmdToolsWaitForExample,
Args: cobra.MinimumNArgs(1),
Run: func(_ *cobra.Command, args []string) {
// Parse the timeout string
timeout, err := time.ParseDuration(waitTimeout)
if err != nil {
message.Fatalf(err, lang.CmdToolsWaitForErrTimeoutString, waitTimeout)
}
kind := args[0]
// identifier is optional to allow for commands like `jackal tools wait-for storageclass` without specifying a name.
identifier := ""
if len(args) > 1 {
identifier = args[1]
}
// Condition is optional, default to "exists".
condition := ""
if len(args) > 2 {
condition = args[2]
}
// Execute the wait command.
if err := utils.ExecuteWait(waitTimeout, waitNamespace, condition, kind, identifier, timeout); err != nil {
message.Fatal(err, err.Error())
}
},
}
func init() {
toolsCmd.AddCommand(waitForCmd)
waitForCmd.Flags().StringVar(&waitTimeout, "timeout", "5m", lang.CmdToolsWaitForFlagTimeout)
waitForCmd.Flags().StringVarP(&waitNamespace, "namespace", "n", "", lang.CmdToolsWaitForFlagNamespace)
waitForCmd.Flags().BoolVar(&message.NoProgress, "no-progress", false, lang.RootCmdFlagNoProgress)
}