Skip to content

Vendor k8s label selection, remove apimachinery fork - #562

Merged
xenoscopic merged 3 commits into
masterfrom
vendor-apimachinery
Apr 22, 2026
Merged

Vendor k8s label selection, remove apimachinery fork#562
xenoscopic merged 3 commits into
masterfrom
vendor-apimachinery

Conversation

@xenoscopic

@xenoscopic xenoscopic commented Apr 22, 2026

Copy link
Copy Markdown
Contributor

Summary

Vendor the subset of k8s.io/apimachinery used for Kubernetes-style
label selection into pkg/selection/internal/third_party/apimachinery/,
eliminating the mutagen-io/apimachinery fork and its replace
directive in go.mod.

The fork existed solely to strip the klog dependency, which bloated
agent binaries and spawned goroutines on init(). By vendoring only the
packages Mutagen actually uses, we get the same benefit permanently
without maintaining a fork.

Originally extracted from kubernetes/apimachinery at
f916759cb6b8
(tag v0.21.3), via mutagen-io/apimachinery v0.21.3-mutagen1.

Commit structure

  1. test: expand label selection test coverage -- 56 new tests
    for pkg/selection public API (parsing, matching, key/value
    validation, key extraction). Runs against the fork to establish
    baseline.
  2. deps: vendor k8s label selection, remove apimachinery fork --
    Vendored code + original k8s test files. Same tests pass against
    vendored code.

Vendored packages

Package Source + Tests Purpose
labels 4 + 2 files Selector parsing and label matching
selection 1 file Operator enum
util/errors 1 file Aggregate error type
util/sets 3 files String set (other types omitted)
util/validation 1 + 1 files Name and label value validation
util/validation/field 2 + 2 files Error types and field paths

Each file carries the full Apache 2.0 license header and extraction
provenance, following the existing pattern in
pkg/filesystem/watching/internal/third_party/.

What's removed

  • k8s.io/apimachinery require line from go.mod
  • replace k8s.io/apimachinery => github.com/mutagen-io/apimachinery
  • 187 lines of transitive k8s dependency hashes from go.sum

Test plan

  • go test ./pkg/selection/... passes (56 Mutagen-level tests +
    vendored k8s tests for labels, validation, and field packages)
  • go build ./cmd/... ./pkg/... passes
  • go vet ./cmd/... ./pkg/... passes clean
  • CI passes on all platforms

Add comprehensive tests for the pkg/selection public API:

- TestParseLabelSelector: 21 subtests covering equality,
  inequality, set-based (in/notin), existence/non-existence,
  multiple requirements, and invalid selector syntax.
- TestLabelSelectorMatches: 28 subtests covering matching
  behavior for all selector types against various label sets
  including nil, empty, matching, non-matching, and extra keys.
- TestEnsureLabelKeyValid: 12 cases including qualified keys,
  boundary lengths, and invalid characters.
- TestEnsureLabelValueValid: 10 cases including empty values,
  boundary lengths, and invalid formats.
- TestExtractAndSortLabelKeys: 5 subtests for nil, empty,
  single, multiple, and special-character keys.

Remove placeholder TODO comments from test files.

Signed-off-by: Jacob Howard <jacob@mutagen.io>
@xenoscopic
xenoscopic force-pushed the vendor-apimachinery branch from dce3e98 to 0e3f6ae Compare April 22, 2026 10:35
Vendor the subset of k8s.io/apimachinery used for Kubernetes-
style label selection into pkg/selection/internal/third_party/
apimachinery. This eliminates the mutagen-io/apimachinery fork
(and its replace directive in go.mod), which existed solely to
strip the klog dependency and its init-time goroutines from
the Mutagen agent binary.

Vendored from kubernetes/apimachinery at revision:
kubernetes/apimachinery@f916759
(tag v0.21.3, via mutagen-io/apimachinery v0.21.3-mutagen1)

Vendored packages:
- pkg/labels: selector parsing and label matching
- pkg/selection: operator enum
- pkg/util/errors: aggregate error type
- pkg/util/sets: string set (other set types omitted)
- pkg/util/validation: name and label value validation
- pkg/util/validation/field: error types and field paths

Includes original k8s test files for labels, validation, and
field packages. Each vendored file carries the full Apache 2.0
license header and extraction provenance.

Two test cases in validation_test.go were adjusted for Go 1.17+
behavior (leading zeros in IPv4 octets now rejected).

Removes 187 lines of transitive k8s dependency hashes from
go.sum.

Signed-off-by: Jacob Howard <jacob@mutagen.io>
@xenoscopic
xenoscopic force-pushed the vendor-apimachinery branch from 0e3f6ae to e778e78 Compare April 22, 2026 10:39
Signed-off-by: Jacob Howard <jacob@mutagen.io>
@xenoscopic
xenoscopic merged commit 6ccfeaa into master Apr 22, 2026
7 checks passed
@xenoscopic
xenoscopic deleted the vendor-apimachinery branch April 22, 2026 11:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant