Skip to content

Commit b2a52d6

Browse files
authored
Merge branch 'master' into modernize_readme
2 parents 22eb9a7 + 09f7ece commit b2a52d6

File tree

27 files changed

+644
-2738
lines changed

27 files changed

+644
-2738
lines changed

go.mod

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ require (
3737
github.com/urfave/cli/v2 v2.27.5
3838
github.com/vbauerster/mpb/v8 v8.9.1
3939
github.com/vishvananda/netlink v1.3.0
40-
go.githedgehog.com/fabric v0.61.0
40+
go.githedgehog.com/fabric v0.61.1
4141
golang.org/x/crypto v0.32.0
4242
golang.org/x/sync v0.10.0
4343
golang.org/x/term v0.28.0
@@ -164,7 +164,7 @@ require (
164164
github.com/go-playground/universal-translator v0.18.1 // indirect
165165
github.com/go-task/slim-sprig/v3 v3.0.0 // indirect
166166
github.com/gogo/protobuf v1.3.2 // indirect
167-
github.com/golang/glog v1.2.2 // indirect
167+
github.com/golang/glog v1.2.4 // indirect
168168
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
169169
github.com/golang/protobuf v1.5.4 // indirect
170170
github.com/google/gnostic-models v0.6.8 // indirect
@@ -239,11 +239,11 @@ require (
239239
github.com/nwaples/rardecode/v2 v2.0.0-beta.4.0.20241112120701-034e449c6e78 // indirect
240240
github.com/oklog/ulid v1.3.1 // indirect
241241
github.com/olekukonko/tablewriter v0.0.5 // indirect
242-
github.com/openconfig/gnmi v0.11.0 // indirect
242+
github.com/openconfig/gnmi v0.12.0 // indirect
243243
github.com/openconfig/gnmic v0.32.0 // indirect
244-
github.com/openconfig/goyang v1.4.5 // indirect
244+
github.com/openconfig/goyang v1.6.0 // indirect
245245
github.com/openconfig/grpctunnel v0.1.0 // indirect
246-
github.com/openconfig/ygot v0.29.19 // indirect
246+
github.com/openconfig/ygot v0.29.20 // indirect
247247
github.com/opencontainers/go-digest v1.0.0 // indirect
248248
github.com/opencontainers/runtime-spec v1.2.0 // indirect
249249
github.com/opencontainers/selinux v1.11.1 // indirect
@@ -321,8 +321,8 @@ require (
321321
google.golang.org/api v0.198.0 // indirect
322322
google.golang.org/genproto v0.0.0-20240903143218-8af14fe29dc1 // indirect
323323
google.golang.org/genproto/googleapis/api v0.0.0-20240827150818-7e3bb234dfed // indirect
324-
google.golang.org/genproto/googleapis/rpc v0.0.0-20240903143218-8af14fe29dc1 // indirect
325-
google.golang.org/grpc v1.67.0 // indirect
324+
google.golang.org/genproto/googleapis/rpc v0.0.0-20241007155032-5fefd90f89a9 // indirect
325+
google.golang.org/grpc v1.67.1 // indirect
326326
google.golang.org/protobuf v1.36.1 // indirect
327327
gopkg.in/evanphx/json-patch.v4 v4.12.0 // indirect
328328
gopkg.in/inf.v0 v0.9.1 // indirect

go.sum

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -353,8 +353,8 @@ github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7a
353353
github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q=
354354
github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q=
355355
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
356-
github.com/golang/glog v1.2.2 h1:1+mZ9upx1Dh6FmUTFR1naJ77miKiXgALjWOZ3NVFPmY=
357-
github.com/golang/glog v1.2.2/go.mod h1:6AhwSGph0fcJtXVM/PEHPqZlFeoLxhs7/t5UDAwmO+w=
356+
github.com/golang/glog v1.2.4 h1:CNNw5U8lSiiBk7druxtSHHTsRWcxKoac6kZKm2peBBc=
357+
github.com/golang/glog v1.2.4/go.mod h1:6AhwSGph0fcJtXVM/PEHPqZlFeoLxhs7/t5UDAwmO+w=
358358
github.com/golang/groupcache v0.0.0-20190702054246-869f871628b6/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
359359
github.com/golang/groupcache v0.0.0-20191227052852-215e87163ea7/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
360360
github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
@@ -659,19 +659,19 @@ github.com/onsi/ginkgo/v2 v2.22.2/go.mod h1:oeMosUL+8LtarXBHu/c0bx2D/K9zyQ6uX3cT
659659
github.com/onsi/gomega v1.36.2 h1:koNYke6TVk6ZmnyHrCXba/T/MoLBXFjeC1PtvYgw0A8=
660660
github.com/onsi/gomega v1.36.2/go.mod h1:DdwyADRjrc825LhMEkD76cHR5+pUnjhUN8GlHlRPHzY=
661661
github.com/openconfig/gnmi v0.10.0/go.mod h1:Y9os75GmSkhHw2wX8sMsxfI7qRGAEcDh8NTa5a8vj6E=
662-
github.com/openconfig/gnmi v0.11.0 h1:H7pLIb/o3xObu3+x0Fv9DCK7TH3FUh7mNwbYe+34hFw=
663-
github.com/openconfig/gnmi v0.11.0/go.mod h1:9oJSQPPCpNvfMRj8e4ZoLVAw4wL8HyxXbiDlyuexCGU=
662+
github.com/openconfig/gnmi v0.12.0 h1:aPkmcX9pdcz6QqsBsXXg5UQooqhnmlHD3JtdtvtzmaU=
663+
github.com/openconfig/gnmi v0.12.0/go.mod h1:5a/cIOZevJLfJgd1qWkgYROE8xfgEbaSJXpdD8xk/LQ=
664664
github.com/openconfig/gnmic v0.32.0 h1:gZU9fqVa0ayUIt1kOI2wxEGQvNn3DSA6SX/njOJWYV4=
665665
github.com/openconfig/gnmic v0.32.0/go.mod h1:QUQxVCmKYY5lbmqSIXAv2GAofFR6q5w6T6bM8U7b9F0=
666666
github.com/openconfig/goyang v0.0.0-20200115183954-d0a48929f0ea/go.mod h1:dhXaV0JgHJzdrHi2l+w0fZrwArtXL7jEFoiqLEdmkvU=
667-
github.com/openconfig/goyang v1.4.5 h1:+s3p3MeiPQ/QNsC5DL3MXhCp5cv4dag3vlGKCtszsRU=
668-
github.com/openconfig/goyang v1.4.5/go.mod h1:sdNZi/wdTZyLNBNfgLzmmbi7kISm7FskMDKKzMY+x1M=
667+
github.com/openconfig/goyang v1.6.0 h1:JjnPbLY1/y28VyTO67LsEV0TaLWNiZyDcsppGq4F4is=
668+
github.com/openconfig/goyang v1.6.0/go.mod h1:sdNZi/wdTZyLNBNfgLzmmbi7kISm7FskMDKKzMY+x1M=
669669
github.com/openconfig/grpctunnel v0.0.0-20220819142823-6f5422b8ca70/go.mod h1:OmTWe7RyZj2CIzIgy4ovEBzCLBJzRvWSZmn7u02U9gU=
670670
github.com/openconfig/grpctunnel v0.1.0 h1:EN99qtlExZczgQgp5ANnHRC/Rs62cAG+Tz2BQ5m/maM=
671671
github.com/openconfig/grpctunnel v0.1.0/go.mod h1:G04Pdu0pml98tdvXrvLaU+EBo3PxYfI9MYqpvdaEHLo=
672672
github.com/openconfig/ygot v0.6.0/go.mod h1:o30svNf7O0xK+R35tlx95odkDmZWS9JyWWQSmIhqwAs=
673-
github.com/openconfig/ygot v0.29.19 h1:3bbAWbCBVjyjHgeROvT38LQ7pAxcjtm7C2vNVj/rvEE=
674-
github.com/openconfig/ygot v0.29.19/go.mod h1:8/FXt4tc5wSfYDEJbGGumxmxwJ55Xuv12oO/jCyEins=
673+
github.com/openconfig/ygot v0.29.20 h1:XHLpwCN91QuKc2LAvnEqtCmH8OuxgLlErDhrdl2mJw8=
674+
github.com/openconfig/ygot v0.29.20/go.mod h1:K8HbrPm/v8/emtGQ9+RsJXx6UPKC5JzS/FqK7pN+tMo=
675675
github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8Oi/yOhh5U=
676676
github.com/opencontainers/go-digest v1.0.0/go.mod h1:0JzlMkj0TRzQZfJkVvzbP0HBR3IKzErnv2BNG4W4MAM=
677677
github.com/opencontainers/image-spec v1.1.0 h1:8SG7/vwALn54lVB/0yZ/MMwhFrPYtpEHQb2IpWsCzug=
@@ -872,8 +872,8 @@ github.com/zealic/xignore v0.3.3 h1:EpLXUgZY/JEzFkTc+Y/VYypzXtNz+MSOMVCGW5Q4CKQ=
872872
github.com/zealic/xignore v0.3.3/go.mod h1:lhS8V7fuSOtJOKsvKI7WfsZE276/7AYEqokv3UiqEAU=
873873
go.etcd.io/bbolt v1.3.11 h1:yGEzV1wPz2yVCLsD8ZAiGHhHVlczyC9d1rP43/VCRJ0=
874874
go.etcd.io/bbolt v1.3.11/go.mod h1:dksAq7YMXoljX0xu6VF5DMZGbhYYoLUalEiSySYAS4I=
875-
go.githedgehog.com/fabric v0.61.0 h1:1Mk6Z9VIs9M0el+Ji/6vXyfTvnOdhA33/v4BTIdvpNs=
876-
go.githedgehog.com/fabric v0.61.0/go.mod h1:FK/xKBScNxkeUGBcb033/tGhHZx/99zM0uuciqqsDZo=
875+
go.githedgehog.com/fabric v0.61.1 h1:NsI/ghTkHLuwXppzK6bhvEuEAlx/Huk24+0nViUgPMk=
876+
go.githedgehog.com/fabric v0.61.1/go.mod h1:n7jiGJW2LnZnxPVqLBvZWzMZ52WNnYJuD37Y+NDlmG0=
877877
go.githedgehog.com/fabric-bcm-ygot v0.2.0-4.4.0 h1:vxflsKB6+aIrXGeuWxagL82Eze8N2eGJzQ9bCazvcPU=
878878
go.githedgehog.com/fabric-bcm-ygot v0.2.0-4.4.0/go.mod h1:P/rTRtJedD3Pw72xgXYLPZAP8RpK2YmUR15qHGHxQWE=
879879
go.mongodb.org/mongo-driver v1.14.0 h1:P98w8egYRjYe3XDjxhYJagTokP/H6HzlsnojRgZRd80=
@@ -1196,8 +1196,8 @@ google.golang.org/genproto v0.0.0-20240903143218-8af14fe29dc1 h1:BulPr26Jqjnd4eY
11961196
google.golang.org/genproto v0.0.0-20240903143218-8af14fe29dc1/go.mod h1:hL97c3SYopEHblzpxRL4lSs523++l8DYxGM1FQiYmb4=
11971197
google.golang.org/genproto/googleapis/api v0.0.0-20240827150818-7e3bb234dfed h1:3RgNmBoI9MZhsj3QxC+AP/qQhNwpCLOvYDYYsFrhFt0=
11981198
google.golang.org/genproto/googleapis/api v0.0.0-20240827150818-7e3bb234dfed/go.mod h1:OCdP9MfskevB/rbYvHTsXTtKC+3bHWajPdoKgjcYkfo=
1199-
google.golang.org/genproto/googleapis/rpc v0.0.0-20240903143218-8af14fe29dc1 h1:pPJltXNxVzT4pK9yD8vR9X75DaWYYmLGMsEvBfFQZzQ=
1200-
google.golang.org/genproto/googleapis/rpc v0.0.0-20240903143218-8af14fe29dc1/go.mod h1:UqMtugtsSgubUsoxbuAoiCXvqvErP7Gf0so0mK9tHxU=
1199+
google.golang.org/genproto/googleapis/rpc v0.0.0-20241007155032-5fefd90f89a9 h1:QCqS/PdaHTSWGvupk2F/ehwHtGc0/GYkT+3GAcR1CCc=
1200+
google.golang.org/genproto/googleapis/rpc v0.0.0-20241007155032-5fefd90f89a9/go.mod h1:GX3210XPVPUjJbTUbvwI8f2IpZDMZuPJWDzDuebbviI=
12011201
google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c=
12021202
google.golang.org/grpc v1.20.1/go.mod h1:10oTOabMzJvdu6/UiuZezV6QK5dSlG84ov/aaiqXj38=
12031203
google.golang.org/grpc v1.21.1/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM=
@@ -1211,8 +1211,8 @@ google.golang.org/grpc v1.33.2/go.mod h1:JMHMWHQWaTccqQQlmk3MJZS+GWXOdAesneDmEnv
12111211
google.golang.org/grpc v1.36.0/go.mod h1:qjiiYl8FncCW8feJPdyg3v6XW24KsRHe+dy9BAGRRjU=
12121212
google.golang.org/grpc v1.39.1/go.mod h1:PImNr+rS9TWYb2O4/emRugxiyHZ5JyHW5F+RPnDzfrE=
12131213
google.golang.org/grpc v1.40.0/go.mod h1:ogyxbiOoUXAkP+4+xa6PZSE9DZgIHtSpzjDTB9KAK34=
1214-
google.golang.org/grpc v1.67.0 h1:IdH9y6PF5MPSdAntIcpjQ+tXO41pcQsfZV2RxtQgVcw=
1215-
google.golang.org/grpc v1.67.0/go.mod h1:1gLDyUQU7CTLJI90u3nXZ9ekeghjeM7pTDZlqFNg2AA=
1214+
google.golang.org/grpc v1.67.1 h1:zWnc1Vrcno+lHZCOofnIMvycFcc0QRGIzm9dhnDX68E=
1215+
google.golang.org/grpc v1.67.1/go.mod h1:1gLDyUQU7CTLJI90u3nXZ9ekeghjeM7pTDZlqFNg2AA=
12161216
google.golang.org/grpc/cmd/protoc-gen-go-grpc v1.1.0/go.mod h1:6Kw0yEErY5E/yWrBtf03jp27GLLJujG4z/JK95pnjjw=
12171217
google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8=
12181218
google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0=

pkg/fab/versions.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import (
1313

1414
var (
1515
FabricatorVersion = meta.Version(version.Version)
16-
FabricVersion = meta.Version("v0.61.0")
16+
FabricVersion = meta.Version("v0.61.1")
1717
)
1818

1919
var Versions = fabapi.Versions{

pkg/hhfab/testing.go

Lines changed: 66 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ func (c *Config) Wait(ctx context.Context, vlab *VLAB) error {
5959
}
6060

6161
slog.Info("Waiting for all switches ready")
62-
if err := waitSwitchesReady(ctx, kube, 0); err != nil {
62+
if err := WaitSwitchesReady(ctx, kube, 0, 30*time.Minute); err != nil {
6363
return fmt.Errorf("waiting for switches ready: %w", err)
6464
}
6565

@@ -80,6 +80,40 @@ type SetupVPCsOpts struct {
8080
InterfaceMTU uint16
8181
}
8282

83+
func CreateOrUpdateVpc(ctx context.Context, kube client.Client, vpc *vpcapi.VPC) (bool, error) {
84+
var changed bool
85+
some := &vpcapi.VPC{ObjectMeta: metav1.ObjectMeta{Name: vpc.Name, Namespace: vpc.Namespace}}
86+
res, err := ctrlutil.CreateOrUpdate(ctx, kube, some, func() error {
87+
some.Spec = vpc.Spec
88+
some.Default()
89+
90+
return nil
91+
})
92+
if err != nil {
93+
return changed, fmt.Errorf("creating or updating VPC %q: %w", vpc.Name, err)
94+
}
95+
96+
switch res {
97+
case ctrlutil.OperationResultCreated:
98+
slog.Info("Created", "vpc", vpc.Name, "subnets", len(vpc.Spec.Subnets))
99+
changed = true
100+
case ctrlutil.OperationResultUpdated:
101+
slog.Info("Updated", "vpc", vpc.Name, "subnets", len(vpc.Spec.Subnets))
102+
changed = true
103+
}
104+
105+
return changed, nil
106+
}
107+
108+
func GetKubeClient(ctx context.Context, workDir string) (client.Client, error) {
109+
kubeconfig := filepath.Join(workDir, VLABDir, VLABKubeConfig)
110+
return kubeutil.NewClient(ctx, kubeconfig,
111+
wiringapi.SchemeBuilder,
112+
vpcapi.SchemeBuilder,
113+
agentapi.SchemeBuilder,
114+
)
115+
}
116+
83117
func (c *Config) SetupVPCs(ctx context.Context, vlab *VLAB, opts SetupVPCsOpts) error {
84118
ctx, cancel := context.WithTimeout(ctx, 30*time.Minute)
85119
defer cancel()
@@ -308,7 +342,7 @@ func (c *Config) SetupVPCs(ctx context.Context, vlab *VLAB, opts SetupVPCsOpts)
308342

309343
if opts.WaitSwitchesReady {
310344
slog.Info("Waiting for switches ready before configuring VPCs and VPCAttachments")
311-
if err := waitSwitchesReady(ctx, kube, 0); err != nil {
345+
if err := WaitSwitchesReady(ctx, kube, 0, 30*time.Minute); err != nil {
312346
return fmt.Errorf("waiting for switches ready: %w", err)
313347
}
314348
}
@@ -346,25 +380,11 @@ func (c *Config) SetupVPCs(ctx context.Context, vlab *VLAB, opts SetupVPCsOpts)
346380
}
347381

348382
for _, vpc := range vpcs {
349-
some := &vpcapi.VPC{ObjectMeta: metav1.ObjectMeta{Name: vpc.Name, Namespace: vpc.Namespace}}
350-
res, err := ctrlutil.CreateOrUpdate(ctx, kube, some, func() error {
351-
some.Spec = vpc.Spec
352-
some.Default()
353-
354-
return nil
355-
})
383+
iterChanged, err := CreateOrUpdateVpc(ctx, kube, vpc)
356384
if err != nil {
357-
return fmt.Errorf("creating or updating VPC %q: %w", vpc.Name, err)
358-
}
359-
360-
switch res {
361-
case ctrlutil.OperationResultCreated:
362-
slog.Info("Created", "vpc", vpc.Name, "subnets", len(vpc.Spec.Subnets))
363-
changed = true
364-
case ctrlutil.OperationResultUpdated:
365-
slog.Info("Updated", "vpc", vpc.Name, "subnets", len(vpc.Spec.Subnets))
366-
changed = true
385+
return fmt.Errorf("creating or updating vpc %q: %w", vpc.Name, err)
367386
}
387+
changed = changed || iterChanged
368388
}
369389

370390
for _, attach := range attaches {
@@ -399,7 +419,7 @@ func (c *Config) SetupVPCs(ctx context.Context, vlab *VLAB, opts SetupVPCsOpts)
399419
case <-time.After(15 * time.Second):
400420
}
401421

402-
if err := waitSwitchesReady(ctx, kube, 0); err != nil {
422+
if err := WaitSwitchesReady(ctx, kube, 0, 30*time.Minute); err != nil {
403423
return fmt.Errorf("waiting for switches ready: %w", err)
404424
}
405425
}
@@ -507,7 +527,7 @@ func (c *Config) SetupPeerings(ctx context.Context, vlab *VLAB, opts SetupPeerin
507527

508528
if opts.WaitSwitchesReady {
509529
slog.Info("Waiting for switches ready before configuring VPC and External Peerings")
510-
if err := waitSwitchesReady(ctx, kube, 0); err != nil {
530+
if err := WaitSwitchesReady(ctx, kube, 0, 30*time.Minute); err != nil {
511531
return fmt.Errorf("waiting for switches ready: %w", err)
512532
}
513533
}
@@ -712,7 +732,16 @@ func (c *Config) SetupPeerings(ctx context.Context, vlab *VLAB, opts SetupPeerin
712732
}
713733
}
714734

715-
changed := false
735+
if err := DoSetupPeerings(ctx, kube, vpcPeerings, externalPeerings, opts.WaitSwitchesReady); err != nil {
736+
return err
737+
}
738+
slog.Info("VPC and External Peerings setup complete", "took", time.Since(start))
739+
740+
return nil
741+
}
742+
743+
func DoSetupPeerings(ctx context.Context, kube client.Client, vpcPeerings map[string]*vpcapi.VPCPeeringSpec, externalPeerings map[string]*vpcapi.ExternalPeeringSpec, waitReady bool) error {
744+
var changed bool
716745

717746
vpcPeeringList := &vpcapi.VPCPeeringList{}
718747
if err := kube.List(ctx, vpcPeeringList); err != nil {
@@ -810,7 +839,7 @@ func (c *Config) SetupPeerings(ctx context.Context, vlab *VLAB, opts SetupPeerin
810839
}
811840
}
812841

813-
if changed && opts.WaitSwitchesReady {
842+
if changed && waitReady {
814843
slog.Info("Waiting for switches ready after configuring VPC and External Peerings")
815844

816845
// TODO remove it when we can actually know that changes to VPC/VPCAttachment are reflected in agents
@@ -820,13 +849,11 @@ func (c *Config) SetupPeerings(ctx context.Context, vlab *VLAB, opts SetupPeerin
820849
case <-time.After(15 * time.Second):
821850
}
822851

823-
if err := waitSwitchesReady(ctx, kube, 0); err != nil {
852+
if err := WaitSwitchesReady(ctx, kube, 0, 30*time.Minute); err != nil {
824853
return fmt.Errorf("waiting for switches ready: %w", err)
825854
}
826855
}
827856

828-
slog.Info("VPC and External Peerings setup complete", "took", time.Since(start))
829-
830857
return nil
831858
}
832859

@@ -899,7 +926,7 @@ func (c *Config) TestConnectivity(ctx context.Context, vlab *VLAB, opts TestConn
899926
if opts.WaitSwitchesReady {
900927
slog.Info("Waiting for switches ready before testing connectivity")
901928

902-
if err := waitSwitchesReady(ctx, kube, 30*time.Second); err != nil {
929+
if err := WaitSwitchesReady(ctx, kube, 30*time.Second, 30*time.Minute); err != nil {
903930
return fmt.Errorf("waiting for switches ready: %w", err)
904931
}
905932
}
@@ -1123,13 +1150,19 @@ func (c *Config) TestConnectivity(ctx context.Context, vlab *VLAB, opts TestConn
11231150
return nil
11241151
}
11251152

1126-
func waitSwitchesReady(ctx context.Context, kube client.Reader, appliedFor time.Duration) error {
1127-
ctx, cancel := context.WithTimeout(ctx, 30*time.Minute)
1128-
defer cancel()
1153+
func WaitSwitchesReady(ctx context.Context, kube client.Reader, appliedFor time.Duration, timeout time.Duration) error {
1154+
var waitCtx context.Context
1155+
var cancel context.CancelFunc
1156+
if timeout > 0 {
1157+
waitCtx, cancel = context.WithTimeout(ctx, timeout)
1158+
defer cancel()
1159+
} else {
1160+
waitCtx = ctx
1161+
}
11291162

11301163
for {
11311164
switches := &wiringapi.SwitchList{}
1132-
if err := kube.List(ctx, switches); err != nil {
1165+
if err := kube.List(waitCtx, switches); err != nil {
11331166
return fmt.Errorf("listing switches: %w", err)
11341167
}
11351168

@@ -1145,7 +1178,7 @@ func waitSwitchesReady(ctx context.Context, kube client.Reader, appliedFor time.
11451178
updated := false
11461179

11471180
ag := &agentapi.Agent{}
1148-
err := kube.Get(ctx, client.ObjectKey{Name: sw.Name, Namespace: sw.Namespace}, ag)
1181+
err := kube.Get(waitCtx, client.ObjectKey{Name: sw.Name, Namespace: sw.Namespace}, ag)
11491182
if err != nil && !apierrors.IsNotFound(err) {
11501183
return fmt.Errorf("getting agent %q: %w", sw.Name, err)
11511184
}
@@ -1499,7 +1532,7 @@ func (c *Config) Inspect(ctx context.Context, vlab *VLAB, opts InspectOpts) erro
14991532
fail := false
15001533

15011534
slog.Info("Waiting for switches ready before inspecting")
1502-
if err := waitSwitchesReady(ctx, kube, opts.WaitAppliedFor); err != nil {
1535+
if err := WaitSwitchesReady(ctx, kube, opts.WaitAppliedFor, 30*time.Minute); err != nil {
15031536
slog.Error("Failed to wait for switches ready", "err", err)
15041537
fail = true
15051538
}

vendor/github.com/golang/glog/glog.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)