Skip to content

Commit 18a31f8

Browse files
committed
Add support for only one ready pod per service
1 parent 482f3f2 commit 18a31f8

File tree

6 files changed

+1590
-64
lines changed

6 files changed

+1590
-64
lines changed

cmd/wait.go

+8-2
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,15 @@ func wait(cmd *cobra.Command, args []string) error {
9090

9191
log.Printf("Starting with namespaces: %v", namespaces)
9292

93+
nsConfigs := map[string]cache.Config{}
94+
95+
for _, ns := range namespaces {
96+
nsConfigs[ns] = cache.Config{}
97+
}
98+
9399
opts := cache.Options{
94-
Namespaces: namespaces,
95-
SyncPeriod: WaitForConfigFlags.SyncPeriod,
100+
DefaultNamespaces: nsConfigs,
101+
SyncPeriod: WaitForConfigFlags.SyncPeriod,
96102
}
97103

98104
conf, err := KubernetesConfigFlags.ToRESTConfig()

flags/flags.go

+13-7
Original file line numberDiff line numberDiff line change
@@ -25,19 +25,21 @@ import (
2525
)
2626

2727
type ConfigFlags struct {
28-
PrintVersion *bool
29-
PrintTree *bool
30-
PrintCollapsedTree *bool
28+
PrintVersion *bool
29+
PrintTree *bool
30+
PrintCollapsedTree *bool
31+
OnlyOnePerServiceRequired *bool
3132

3233
Timeout *time.Duration
3334
SyncPeriod *time.Duration
3435
}
3536

3637
func NewConfigFlags() *ConfigFlags {
3738
return &ConfigFlags{
38-
PrintVersion: utilpointer.Bool(false),
39-
PrintTree: utilpointer.Bool(true),
40-
PrintCollapsedTree: utilpointer.Bool(true),
39+
PrintVersion: utilpointer.Bool(false),
40+
PrintTree: utilpointer.Bool(true),
41+
PrintCollapsedTree: utilpointer.Bool(true),
42+
OnlyOnePerServiceRequired: utilpointer.Bool(false),
4143

4244
Timeout: utilpointer.Duration(time.Duration(600 * time.Second)),
4345
SyncPeriod: utilpointer.Duration(time.Duration(90 * time.Second)),
@@ -49,10 +51,14 @@ func (f *ConfigFlags) AddFlags(flags *pflag.FlagSet) {
4951
flags.DurationVarP(f.Timeout, "timeout", "t", *f.Timeout, "The length of time to wait before ending watch, zero means never. Any other values should contain a corresponding time unit (e.g. 1s, 2m, 3h)")
5052
}
5153

52-
if f.Timeout != nil {
54+
if f.SyncPeriod != nil {
5355
flags.DurationVar(f.SyncPeriod, "sync-period", *f.SyncPeriod, "The length of time to pass to the cache to initiate a sync. (e.g. 1s, 2m, 3h)")
5456
}
5557

58+
if f.OnlyOnePerServiceRequired != nil {
59+
flags.BoolVar(f.OnlyOnePerServiceRequired, "only-one-per-service-required", *f.OnlyOnePerServiceRequired, "When true a service is ready when at least one pod is ready. When false all pods must be ready.")
60+
}
61+
5662
if f.PrintVersion != nil {
5763
flags.BoolVarP(f.PrintVersion, "version", "v", *f.PrintVersion, "Display version info")
5864
}

go.mod

+53-45
Original file line numberDiff line numberDiff line change
@@ -1,78 +1,86 @@
11
module github.com/erayan/k8s-wait-for-multi
22

3-
go 1.20
3+
go 1.21
4+
5+
toolchain go1.21.5
46

57
require (
6-
github.com/spf13/cobra v1.7.0
8+
github.com/spf13/cobra v1.8.0
79
github.com/spf13/pflag v1.0.5
810
github.com/xlab/treeprint v1.2.0
9-
k8s.io/api v0.27.3
10-
k8s.io/apimachinery v0.27.3
11-
k8s.io/cli-runtime v0.27.3
12-
k8s.io/client-go v0.27.3
13-
k8s.io/kubectl v0.27.3
14-
k8s.io/utils v0.0.0-20230209194617-a36077c30491
15-
sigs.k8s.io/controller-runtime v0.15.0
11+
k8s.io/api v0.29.0
12+
k8s.io/apimachinery v0.29.0
13+
k8s.io/cli-runtime v0.29.0
14+
k8s.io/client-go v0.29.0
15+
k8s.io/kubectl v0.29.0
16+
k8s.io/utils v0.0.0-20240102154912-e7106e64919e
17+
sigs.k8s.io/controller-runtime v0.16.3
1618
)
1719

1820
require (
19-
github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 // indirect
21+
github.com/Azure/go-ansiterm v0.0.0-20230124172434-306776ec8161 // indirect
2022
github.com/MakeNowJust/heredoc v1.0.0 // indirect
2123
github.com/chai2010/gettext-go v1.0.2 // indirect
2224
github.com/davecgh/go-spew v1.1.1 // indirect
23-
github.com/emicklei/go-restful/v3 v3.9.0 // indirect
24-
github.com/evanphx/json-patch v4.12.0+incompatible // indirect
25-
github.com/evanphx/json-patch/v5 v5.6.0 // indirect
26-
github.com/exponent-io/jsonpath v0.0.0-20151013193312-d6023ce2651d // indirect
27-
github.com/fvbommel/sortorder v1.0.1 // indirect
28-
github.com/go-errors/errors v1.4.2 // indirect
29-
github.com/go-logr/logr v1.2.4 // indirect
30-
github.com/go-openapi/jsonpointer v0.19.6 // indirect
31-
github.com/go-openapi/jsonreference v0.20.1 // indirect
32-
github.com/go-openapi/swag v0.22.3 // indirect
25+
github.com/emicklei/go-restful/v3 v3.11.1 // indirect
26+
github.com/evanphx/json-patch v5.7.0+incompatible // indirect
27+
github.com/evanphx/json-patch/v5 v5.7.0 // indirect
28+
github.com/exponent-io/jsonpath v0.0.0-20210407135951-1de76d718b3f // indirect
29+
github.com/fvbommel/sortorder v1.1.0 // indirect
30+
github.com/go-errors/errors v1.5.1 // indirect
31+
github.com/go-logr/logr v1.4.1 // indirect
32+
github.com/go-openapi/jsonpointer v0.20.2 // indirect
33+
github.com/go-openapi/jsonreference v0.20.4 // indirect
34+
github.com/go-openapi/swag v0.22.7 // indirect
3335
github.com/gogo/protobuf v1.3.2 // indirect
3436
github.com/golang/protobuf v1.5.3 // indirect
35-
github.com/google/btree v1.0.1 // indirect
36-
github.com/google/gnostic v0.5.7-v3refs // indirect
37-
github.com/google/go-cmp v0.5.9 // indirect
38-
github.com/google/gofuzz v1.1.0 // indirect
37+
github.com/google/btree v1.1.2 // indirect
38+
github.com/google/gnostic v0.7.0 // indirect
39+
github.com/google/gnostic-models v0.6.9-0.20230804172637-c7be7c783f49 // indirect
40+
github.com/google/go-cmp v0.6.0 // indirect
41+
github.com/google/gofuzz v1.2.0 // indirect
3942
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 // indirect
40-
github.com/google/uuid v1.3.0 // indirect
41-
github.com/gregjones/httpcache v0.0.0-20180305231024-9cad4c3443a7 // indirect
42-
github.com/imdario/mergo v0.3.6 // indirect
43+
github.com/google/uuid v1.5.0 // indirect
44+
github.com/gorilla/websocket v1.5.1 // indirect
45+
github.com/gregjones/httpcache v0.0.0-20190611155906-901d90724c79 // indirect
46+
github.com/imdario/mergo v0.3.16 // indirect
4347
github.com/inconshreveable/mousetrap v1.1.0 // indirect
4448
github.com/josharian/intern v1.0.0 // indirect
4549
github.com/json-iterator/go v1.1.12 // indirect
4650
github.com/liggitt/tabwriter v0.0.0-20181228230101-89fcab3d43de // indirect
4751
github.com/mailru/easyjson v0.7.7 // indirect
48-
github.com/mitchellh/go-wordwrap v1.0.0 // indirect
52+
github.com/mitchellh/go-wordwrap v1.0.1 // indirect
4953
github.com/moby/spdystream v0.2.0 // indirect
50-
github.com/moby/term v0.0.0-20221205130635-1aeaba878587 // indirect
54+
github.com/moby/term v0.5.0 // indirect
5155
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
5256
github.com/modern-go/reflect2 v1.0.2 // indirect
5357
github.com/monochromegane/go-gitignore v0.0.0-20200626010858-205db1a8cc00 // indirect
5458
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
59+
github.com/mxk/go-flowrate v0.0.0-20140419014527-cca7078d478f // indirect
5560
github.com/peterbourgon/diskv v2.0.1+incompatible // indirect
5661
github.com/pkg/errors v0.9.1 // indirect
5762
github.com/russross/blackfriday/v2 v2.1.0 // indirect
58-
go.starlark.net v0.0.0-20200306205701-8dd3e2ee1dd5 // indirect
59-
golang.org/x/net v0.10.0 // indirect
60-
golang.org/x/oauth2 v0.5.0 // indirect
61-
golang.org/x/sys v0.8.0 // indirect
62-
golang.org/x/term v0.8.0 // indirect
63-
golang.org/x/text v0.9.0 // indirect
64-
golang.org/x/time v0.3.0 // indirect
65-
google.golang.org/appengine v1.6.7 // indirect
66-
google.golang.org/protobuf v1.30.0 // indirect
63+
go.starlark.net v0.0.0-20231121155337-90ade8b19d09 // indirect
64+
golang.org/x/exp v0.0.0-20240103183307-be819d1f06fc // indirect
65+
golang.org/x/net v0.19.0 // indirect
66+
golang.org/x/oauth2 v0.15.0 // indirect
67+
golang.org/x/sync v0.6.0 // indirect
68+
golang.org/x/sys v0.16.0 // indirect
69+
golang.org/x/term v0.16.0 // indirect
70+
golang.org/x/text v0.14.0 // indirect
71+
golang.org/x/time v0.5.0 // indirect
72+
google.golang.org/appengine v1.6.8 // indirect
73+
google.golang.org/protobuf v1.32.0 // indirect
74+
gopkg.in/evanphx/json-patch.v5 v5.7.0 // indirect
6775
gopkg.in/inf.v0 v0.9.1 // indirect
6876
gopkg.in/yaml.v2 v2.4.0 // indirect
6977
gopkg.in/yaml.v3 v3.0.1 // indirect
70-
k8s.io/component-base v0.27.3 // indirect
71-
k8s.io/klog/v2 v2.90.1 // indirect
72-
k8s.io/kube-openapi v0.0.0-20230501164219-8b0f38b5fd1f // indirect
78+
k8s.io/component-base v0.29.0 // indirect
79+
k8s.io/klog/v2 v2.110.1 // indirect
80+
k8s.io/kube-openapi v0.0.0-20240105020646-a37d4de58910 // indirect
7381
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
74-
sigs.k8s.io/kustomize/api v0.13.2 // indirect
75-
sigs.k8s.io/kustomize/kyaml v0.14.1 // indirect
76-
sigs.k8s.io/structured-merge-diff/v4 v4.2.3 // indirect
77-
sigs.k8s.io/yaml v1.3.0 // indirect
82+
sigs.k8s.io/kustomize/api v0.16.0 // indirect
83+
sigs.k8s.io/kustomize/kyaml v0.16.0 // indirect
84+
sigs.k8s.io/structured-merge-diff/v4 v4.4.1 // indirect
85+
sigs.k8s.io/yaml v1.4.0 // indirect
7886
)

0 commit comments

Comments
 (0)