Skip to content

Commit 51f8ee0

Browse files
committed
integration: parse runtime image overrides via the shared helper
tsic's websocket-tagged override and tsric's prebuilt image both did their own strings.Cut into repo:tag. Route them through ParseImageRef alongside PrebuiltImage so there is one repository:tag parser, and drop tsic's now-unused errInvalidTailscaleImageFormat.
1 parent fb4bc55 commit 51f8ee0

3 files changed

Lines changed: 21 additions & 10 deletions

File tree

integration/integrationutil/util.go

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,25 @@ func PrebuiltImage(envVar string) (string, string, bool, error) {
3939
return "", "", false, nil
4040
}
4141

42+
repo, tag, err := ParseImageRef(image)
43+
if err != nil {
44+
return "", "", false, fmt.Errorf("%s=%w", envVar, err)
45+
}
46+
47+
return repo, tag, true, nil
48+
}
49+
50+
// ParseImageRef splits an already-resolved "repository:tag" image string into
51+
// its parts. Use it where the image comes from somewhere other than a single
52+
// knob (e.g. a websocket-tagged override chosen at runtime); for the common
53+
// read-a-knob case use [PrebuiltImage].
54+
func ParseImageRef(image string) (string, string, error) {
4255
repo, tag, found := strings.Cut(image, ":")
4356
if !found {
44-
return "", "", false, fmt.Errorf("%s=%q: %w", envVar, image, errInvalidImageFormat)
57+
return "", "", fmt.Errorf("%q: %w", image, errInvalidImageFormat)
4558
}
4659

47-
return repo, tag, true, nil
60+
return repo, tag, nil
4861
}
4962

5063
// PeerSyncTimeout returns the timeout for peer synchronization based on environment:

integration/tsic/tsic.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ var (
6666
errTailscaleWrongPeerCount = errors.New("wrong peer count")
6767
errTailscaleCannotUpWithoutAuthkey = errors.New("cannot up without authkey")
6868
errInvalidClientConfig = errors.New("verifiably invalid client config requested")
69-
errInvalidTailscaleImageFormat = errors.New("invalid HEADSCALE_INTEGRATION_TAILSCALE_IMAGE format, expected repository:tag")
7069
errTailscaleImageRequiredInCI = errors.New("HEADSCALE_INTEGRATION_TAILSCALE_IMAGE must be set in CI for HEAD version")
7170
errContainerNotInitialized = errors.New("container not initialized")
7271
errFQDNNotYetAvailable = errors.New("FQDN not yet available")
@@ -455,10 +454,9 @@ func New(
455454
if prebuiltImage != "" {
456455
log.Printf("Using pre-built tailscale image: %s", prebuiltImage) //nolint:gosec // G706: integration-only log of trusted env value
457456

458-
// Parse image into repository and tag
459-
repo, tag, ok := strings.Cut(prebuiltImage, ":")
460-
if !ok {
461-
return nil, errInvalidTailscaleImageFormat
457+
repo, tag, err := integrationutil.ParseImageRef(prebuiltImage)
458+
if err != nil {
459+
return nil, err
462460
}
463461

464462
tailscaleOptions.Repository = repo

integration/tsric/tsric.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -210,9 +210,9 @@ func New(
210210
if prebuiltImage := getPrebuiltImage(); prebuiltImage != "" {
211211
log.Printf("Using pre-built tailscale-rs image: %s", prebuiltImage)
212212

213-
repo, tag, ok := strings.Cut(prebuiltImage, ":")
214-
if !ok {
215-
return nil, fmt.Errorf("tsric: invalid image format %q, expected repository:tag", prebuiltImage) //nolint:err113
213+
repo, tag, err := integrationutil.ParseImageRef(prebuiltImage)
214+
if err != nil {
215+
return nil, fmt.Errorf("tsric: %w", err)
216216
}
217217

218218
runOptions.Repository = repo

0 commit comments

Comments
 (0)