SKUNK-212: move all shared packages + dissolve MCO api/v1 types (PR 1/4)#1107
Open
MaciejKaras wants to merge 22 commits into
Open
SKUNK-212: move all shared packages + dissolve MCO api/v1 types (PR 1/4)#1107MaciejKaras wants to merge 22 commits into
MaciejKaras wants to merge 22 commits into
Conversation
3 tasks
MaciejKaras
commented
May 13, 2026
Contributor
MCK 1.8.1 Release NotesBug Fixes
|
…kube/service Resolve the name collision between Enterprise pkg/kube/service (helpers: DeleteServiceIfItExists, Merge, CreateOrUpdateService) and MCO's mongodb-community-operator/pkg/kube/service (primitives: Getter, Updater, Creator, Deleter, GetDeleter, GetUpdateCreator interfaces, plus the Builder DSL in service_builder.go). Enterprise's package previously imported MCO's package as a dependency (an outside->MCO violation in production code). After this commit, both sets of declarations live in a single pkg/kube/service package at repo root, the MCO copy is deleted, and the mekoService alias used in five Enterprise files is replaced by bare service.* references. Foundation step for the mongodb-community-operator decoupling (spec: docs/design/decouple-mdb-community-investigation.md, cluster 1).
Relocate the following packages from mongodb-community-operator/pkg/util/ to pkg/util/ at repo root: - constants - contains (intra-package import to constants also updated) - envvar - apierrors - scale All 5 are pure leaves (no transitive MCO dependencies among themselves outside this batch). Behaviour-preserving refactor - code unchanged, only import paths rewritten. Foundation step for the mongodb-community-operator decoupling (spec: docs/design/decouple-mdb-community-investigation.md, cluster 5).
Relocate the following packages from mongodb-community-operator/pkg/kube/ to pkg/kube/ at repo root: - annotations - configmap - lifecycle - pod - probes - resourcerequirements - persistentvolumeclaim All 7 are pure leaves (zero MCO imports). Behaviour-preserving refactor - code unchanged, only import paths rewritten. Foundation step for the mongodb-community-operator decoupling (spec: docs/design/decouple-mdb-community-investigation.md, cluster 1).
Relocate the following packages from mongodb-community-operator/pkg/ to pkg/ at repo root: - kube/secret - kube/container - kube/client - kube/podtemplatespec - util/merge These five have intra-batch dependencies (e.g. kube/client uses kube/secret; kube/podtemplatespec uses kube/container and util/merge). The batched move keeps the build green at every commit boundary. One transient outside->MCO import remains after this commit and is deliberately deferred to Plan 2 (move pkg/automationconfig): pkg/util/merge -> mongodb-community-operator/pkg/automationconfig Foundation step for the mongodb-community-operator decoupling (spec: docs/design/decouple-mdb-community-investigation.md, cluster 1+5).
Rename lifecyle.go -> lifecycle.go. Pure rename, byte-identical content; Go cares about the package name, not the filename, so no consumer updates are needed. Follow-up to the mongodb-community-operator decoupling refactor (spec: docs/design/decouple-mdb-community-investigation.md).
GetUpdater (Getter + Updater) was inherited verbatim from MCO when pkg/kube/service was merged into root. It has zero consumers in the repo today. Drop it. Note: GetUpdateCreateDeleter is also inherited but IS consumed (by pkg/kube/client/client.go:31 which embeds it in the Client interface), so it is kept. Follow-up to the mongodb-community-operator decoupling refactor (spec: docs/design/decouple-mdb-community-investigation.md).
The two packages had overlapping responsibilities (both wrapped os.LookupEnv).
Consolidate the three envvar functions into env and delete the envvar package:
- envvar.MergeWithOverride(existing, desired []corev1.EnvVar) []corev1.EnvVar
-> env.MergeWithOverride (added verbatim; 2 call sites)
- envvar.GetEnvOrDefault(name, default string) string
-> env.ReadOrDefault (functionally equivalent for non-empty defaults;
additionally treats FOO="" as missing, which is the safer behaviour;
17 call sites)
- envvar.ReadBool(name string) bool
-> env.ReadBoolOrDefault(name, false) (uses strconv.ParseBool; semantically
equivalent for "true"/"false" values; differs only on integer-like
booleans like "1", which no current consumer uses; 11 call sites)
Footprint: 30 call sites across 14 Go files updated to import pkg/util/env
instead of pkg/util/envvar. pkg/util/envvar deleted.
Follow-up to the mongodb-community-operator decoupling refactor
(spec: docs/design/decouple-mdb-community-investigation.md, cluster 5).
The test previously lived in pkg/kube/container/container_test.go but exclusively exercised env.MergeWithOverride. Relocate it next to the function it tests so it lives in the package it covers. Renamed TestMergeEnvs -> TestMergeWithOverride to match the function name. Drop the now-unused pkg/util/env import from container_test.go. Follow-up to the mongodb-community-operator decoupling refactor.
…ild context PR #1088 (mongodb-community-operator decoupling foundation) relocated several pkg/kube/* and pkg/util/* packages from inside the mongodb-community-operator/ tree to repo root. The mongodb-community-operator/cmd/versionhook binary transitively imports those relocated packages (via mongodb-community-operator/pkg/agent and its dependencies). The Dockerfiles that build the version-upgrade-hook image, and the init-database image (which also builds the versionhook binary), only copy mongodb-community-operator/ into the Docker build context. As a result `go build` cannot resolve the now-root pkg/ imports and the two CI tasks fail with "no matching versions for query 'latest'". Add `COPY pkg ./pkg` to both Dockerfiles so the moved packages are present at build time. The readinessprobe image is unaffected — the readiness cmd has zero root-pkg dependencies.
Relocate the following packages from mongodb-community-operator/pkg/ to
pkg/ at repo root in a single batched commit:
- automationconfig (with its generated zz_generated.deepcopy.go)
- authentication/scramcredentials (transitive dep of automationconfig;
also has one outside-MCO test consumer in mongodbopsmanager_controller_test.go)
- util/versions (transitive dep of automationconfig; pure leaf, no other
outside-MCO consumers)
Batching is required because automationconfig imports both scramcredentials
and util/versions; moving only automationconfig would create two new
outside->MCO edges. All three packages are pure leaves outside this batch
(no further MCO deps).
This clears the single documented Plan-1 residual: pkg/util/merge/
merge_automationconfigs{,_test}.go now import pkg/automationconfig at root.
Behaviour-preserving refactor; full short-mode test suite identical to the
post-Plan-1 baseline.
Pure-leaf package (no MCO transitive deps) — only moved the one directory. Sweeps 32 outside-MCO importers in api/v1/, controllers/, and pkg/. Spec: docs/design/decouple-mdb-community-investigation.md cluster 3.
… decoupling) Relocates three shared packages from mongodb-community-operator/pkg/ to root pkg/: - pkg/agent: readiness/health polling helpers + agent flags; moved wholesale, no code changes. 1 Enterprise importer + 2 MCO-internal importers updated. - pkg/mongot: mongot YAML config types; moved wholesale, no code changes. 3 Enterprise importers updated. - pkg/tls (MCO): TLS secret management (EnsureTLSSecret, TLSConfigurableResource, OperatorSecretFileName). The root pkg/tls already exists (Enterprise TLS mode helpers); no symbol conflicts exist, so the MCO content was added as pkg/tls/tls_secret.go within the same package. 1 Enterprise importer updated. No transitive MCO subpackage deps discovered (all three packages are pure leaves). Path-normalised test diff vs Plan 3 baseline is empty (74 ok / 0 FAIL). Spec: docs/design/decouple-mdb-community-investigation.md clusters 9, 10, 11. Stacked on Plan 3 (PR #1090, branch decuple-plan-3-api-common).
Move Prometheus, AutomationConfigOverride (+OverrideReplicaSet, OverrideProcess), MongodConfiguration (+MapWrapper, NewMongodConfiguration), and LogLevel from mongodb-community-operator/api/v1 to api/v1/common. Update all external callers (api/v1/mdb, api/v1/om, api/v1/mdbmulti, controllers/operator/*, controllers/om/) to import from api/v1/common. MCO internal callers updated to use common.X directly (no aliases). Regenerate deepcopy via make generate.
… level Drop the api/v1/common sub-package entirely; redistribute its types across api/v1/wrap.go, persistence.go, prometheus.go, mongod_config.go, and automationconfig_override.go (package v1). Update all callers throughout the repo to use the api/v1 import directly.
…icaSet description
appdb_construction_test.go had conflicting v1 aliases (k8s apps/v1 and root api/v1); rename k8s alias to appsv1 and update callers. mongodbcommunity_types_test.go referenced NewMongodConfiguration, SecretKeyReference, MapWrapper bare — these moved to root api/v1 in Plan 9; add rootv1 import alias and qualify the calls.
api/v1/common was deleted in Plan 9 (types moved to root api/v1). Three controller test files still imported it but never used common.*, causing golangci-lint typecheck failures.
277aef5 to
ef393c3
Compare
3 tasks
3 tasks
…erator/pkg/agent Move replica_set_port_manager, agenthealth back into the MCO boundary; delete agentflags (unused dead code). pkg/agent now contains only agent_readiness, which is genuinely shared between the MCO and Enterprise AppDB controllers. replica_set_port_manager imports pkg/agent as plain "agent" for the PodState type; replica_set_controller uses mcoagent alias for the MCO package alongside the shared agent import for readiness calls.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Foundation step of the MCO decoupling effort. Hard constraint: nothing outside
mongodb-community-operator/may import anything under it. This PR lays the groundwork — relocating all shared packages that root-level code was consuming from inside the MCO boundary, and dissolving the four spec types that lived inside MCO'sapi/v1.Part A — shared package moves
kube / util leaf packages (
mongodb-community-operator/pkg/→ repo root):pkg/util/{apierrors, constants, contains, scale, merge, env, envvar→env}pkg/kube/{annotations, configmap, lifecycle, pod, probes, resourcerequirements, persistentvolumeclaim, secret, container, client, podtemplatespec, service}pkg/kube/servicemerge: Both roots had apkg/kube/service. MCO's interfaces (Getter,Updater, etc.) and Enterprise's helpers merged into a single root package.pkg/util/envvar→pkg/util/env: 30 call sites consolidated;MergeWithOverrideadded topkg/util/env.automationconfig + transitive deps (Plan 2):
pkg/automationconfig,pkg/mdbversion,pkg/util/versionutilapi/v1/common+ agent/mongot/tls packages (Plans 3–4):api/v1/common,pkg/agent,pkg/mongot,pkg/tlspkg/agentscope correction: Onlyagent_readiness.gois genuinely shared (used by both the MCO replica set controller and the Enterprise AppDB controller). The remaining files are MCO-only and live inside the MCO boundary:mongodb-community-operator/pkg/agent/:agenthealth.go,replica_set_port_manager.goagentflags.godeleted (exported function was unused anywhere outside its own test)Part B — api/v1 type dissolution
Moves four shared spec types from
mongodb-community-operator/api/v1into rootapi/v1:Prometheus,AutomationConfigOverride(+ sub-types),MongodConfiguration(+MapWrapper),LogLeveldeepcopyregenerated. All import aliases standardised tov1 "github.com/mongodb/mongodb-kubernetes/api/v1".Pure behaviour-preserving refactor — no logic changes anywhere.
Proof of Work
CI passing is enough
Checklist
skip-changeloglabel if not needed