Skip to content

SKUNK-212: move all shared packages + dissolve MCO api/v1 types (PR 1/4)#1107

Open
MaciejKaras wants to merge 22 commits into
masterfrom
decuple-1-shared-packages
Open

SKUNK-212: move all shared packages + dissolve MCO api/v1 types (PR 1/4)#1107
MaciejKaras wants to merge 22 commits into
masterfrom
decuple-1-shared-packages

Conversation

@MaciejKaras
Copy link
Copy Markdown
Collaborator

@MaciejKaras MaciejKaras commented May 13, 2026

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's api/v1.

image

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/service merge: Both roots had a pkg/kube/service. MCO's interfaces (Getter, Updater, etc.) and Enterprise's helpers merged into a single root package.

pkg/util/envvarpkg/util/env: 30 call sites consolidated; MergeWithOverride added to pkg/util/env.

automationconfig + transitive deps (Plan 2): pkg/automationconfig, pkg/mdbversion, pkg/util/versionutil

api/v1/common + agent/mongot/tls packages (Plans 3–4): api/v1/common, pkg/agent, pkg/mongot, pkg/tls

pkg/agent scope correction: Only agent_readiness.go is 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.go
  • agentflags.go deleted (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/v1 into root api/v1:

  • Prometheus, AutomationConfigOverride (+ sub-types), MongodConfiguration (+ MapWrapper), LogLevel

deepcopy regenerated. All import aliases standardised to v1 "github.com/mongodb/mongodb-kubernetes/api/v1".

Pure behaviour-preserving refactor — no logic changes anywhere.

Proof of Work

CI passing is enough

Checklist

  • Have you linked a jira ticket and/or is the ticket in the title?
  • Have you checked whether your jira ticket required DOCSP changes?
  • Have you added changelog file?

@MaciejKaras MaciejKaras added the skip-changelog Use this label in Pull Request to not require new changelog entry file label May 13, 2026
Comment thread .idea/pySourceRootDetection.xml Outdated
@MaciejKaras MaciejKaras changed the base branch from decuple-mdb-community to master May 13, 2026 11:58
@MaciejKaras MaciejKaras changed the title refactor(decouple): move all shared packages + dissolve MCO api/v1 types (PR 1/4) SKUNK-212: move all shared packages + dissolve MCO api/v1 types (PR 1/4) May 13, 2026
@github-actions
Copy link
Copy Markdown
Contributor

⚠️ (this preview might not be accurate if the PR is not rebased on current master branch)

MCK 1.8.1 Release Notes

Bug Fixes

  • MongoDBOpsManager, AppDB: In multi-cluster AppDB topology, fixed a bug where the per-cluster spec.applicationDatabase.clusterSpecList[i].statefulSet override was silently ignored.

…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.
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.
…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.
@MaciejKaras MaciejKaras requested a review from lucian-tosa May 14, 2026 12:09
@MaciejKaras MaciejKaras marked this pull request as ready for review May 14, 2026 12:09
@MaciejKaras MaciejKaras requested review from a team, m1kola, mircea-cosbuc and roothorp as code owners May 14, 2026 12:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

skip-changelog Use this label in Pull Request to not require new changelog entry file

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant