Skip to content

[CLOUDP-332196] Move kubectl-mongodb plugin to cmd dir for atomic releases #271

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Jul 21, 2025

Conversation

viveksinghggits
Copy link
Contributor

@viveksinghggits viveksinghggits commented Jul 16, 2025

Summary

In the efforts towards atomic releases this PR tries to move the kubectl-mongodb plugin code from the directory public/tools/multicluster to the root of the project cmd/. This is to align the project with how other Go based projects are structured.
Apart from that this PR also moves the .goreleaser.yaml for the kubectl-mongodb plugin from public/tools/multicluster/.goreleaser.yaml directory to the root of the repo. This is also done in order to align how .goreleaser.yaml is kept in other Go based opensource projects.
This PR also moves the evergreen file that releases kubectl-mongodb plugin from the location public/.evergreen.yml to the root of the repo and is renamed to .evergreen-kubectlplugin.yml. This is to make sure the evergreen files are kept at the same location, i.e. the root of the repo.

Note on LICENSE-THIRD-PARTY

The licenses that are used by the third party go libraries that we use in our kubectl plugin, are documented in public docs at this link.
When we generated the file (LICENSE-THIRD-PARTY) after moving the kubectl-mongodb code to cmd/ directory, we can only see a new package added, that is sigs.k8s.io/yaml/goyaml this seems to be part of the module sigs.k8s.io/yaml which was already part of the LICENSE-THIRD-PARTY, that's why we don't need to re-publish the docs for third party licenses.

To generate the LICENSE-THIRD-PARTY, make precommit can be run after setting env var export MDB_UPDATE_LICENSES=true.

This PR also fixes https://jira.mongodb.org/browse/CLOUDP-332234

Proof of Work

Run goreleaser command locally and verify the binaries that are generated in the dist directory that they output the correct subcommands.

~/work/opensource/mongodb-kubernetes/dist/kubectl-mongodb_darwin_arm64_v8.0 (mongodb-kubectlplugin-refactor*) » ./kubectl-mongodb                             
This application is a tool to simplify maintenance tasks
of MongoDB resources in your kubernetes cluster.

Build: 1cd782d97de76ed25d6170a1d0aaa50382022c08, 2025-07-17T12:10:32Z

Usage:
  kubectl-mongodb [command]

Available Commands:
  completion   Generate the autocompletion script for the specified shell
  debug        Downloads all resources required for debugging and stores them into the disk
  help         Help about any command
  multicluster Manage MongoDB multicluster environments on k8s

Flags:
  -h, --help   help for kubectl-mongodb

Use "kubectl-mongodb [command] --help" for more information about a command.

Testing via evergreen:
Since we are experiencing some issues while testing the entire release process I am planning to merge this PR to master and then would test the release from master.

Jira: https://jira.mongodb.org/browse/CLOUDP-332196

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 checked for release_note changes?

Reminder (Please remove this when merging)

  • Please try to Approve or Reject Changes the PR, keep PRs in review as short as possible
  • Our Short Guide for PRs: Link
  • Remember the following Communication Standards - use comment prefixes for clarity:
    • blocking: Must be addressed before approval.
    • follow-up: Can be addressed in a later PR or ticket.
    • q: Clarifying question.
    • nit: Non-blocking suggestions.
    • note: Side-note, non-actionable. Example: Praise
    • --> no prefix is considered a question

@viveksinghggits viveksinghggits force-pushed the mongodb-kubectlplugin-refactor branch from 198327f to de60a3e Compare July 16, 2025 16:09
…ster

This commit moves the source code of mongodb kubectl plugin from `public/tools/multicluster`
to `cmd` directory. This is to align with how go code that ships a CLI is structured.

The command/subcommand building logic is moved to the `cmd` directory and and rest of the logic

The command/subcommand building logic is moved to the `cmd` directory and and rest of the logic
is moved to the new package `pkg/kubectl-mongodb`.

This commit also moves the `.goreleaser.yaml` to the root of the project because kubectl plugin
is now at the root of the project.
@viveksinghggits viveksinghggits force-pushed the mongodb-kubectlplugin-refactor branch from de60a3e to 02b94d0 Compare July 16, 2025 16:10
1. Since most of our evergreen config files are in root of the repo and now that kubectl plugin
is also moved to `cmd/` it makes sense to move the evergreen config file to the root of repo
with correct name.
2. Change the goreleaser config file to version 1. We upgraded it temporarily to  version 2
but CI complains that only version 1 is supported.
@viveksinghggits viveksinghggits force-pushed the mongodb-kubectlplugin-refactor branch from 94fab09 to 1884f19 Compare July 17, 2025 17:48
@viveksinghggits viveksinghggits marked this pull request as ready for review July 17, 2025 18:06
@viveksinghggits viveksinghggits requested a review from a team as a code owner July 17, 2025 18:06
viveksinghggits added a commit that referenced this pull request Jul 17, 2025
The evergreen function `build_multi_cluster_binary` is used to build the `kubectl-mongodb` plugin. And this function
gets used in the main `.evergreen.yml` file to build the `kubectl-mongodb` binary.
Since we moved the location of the source files for `kubectl-mongodb` plugin as part of [PR](#271),
this PR makes respective changes in the evergreen function so that it can properly build the `kubectl-mongodb` plugin from
the new location.
@MaciejKaras
Copy link
Collaborator

Thanks for very well documented PR!

Some general notes:

  • please add ticket number to PR title similar to other PRs, example
  • init_test_run/build_test_image task fails, it cannot build mcli for test usage
  • you need to run .githooks/pre-commit in order to fix linter issues

@viveksinghggits
Copy link
Contributor Author

Thank you for the feedback @MaciejKaras.

init_test_run/build_test_image task fails, it cannot build mcli for test usage

Right, we knew think is going to happen and I have raised the change as part of the other PR #275 which is based on this PR, to make things easy to review.

I will work on other comments.

@viveksinghggits viveksinghggits changed the title Move kubectl-mongodb plugin to cmd dir for atomic releases [CLOUDP-332196] Move kubectl-mongodb plugin to cmd dir for atomic releases Jul 18, 2025
Since we moved the code of `kubectl-mongodb` plugin to `cmd/` we needed
to move the licenses files to the new location.
This commit does that.
@viveksinghggits
Copy link
Contributor Author

@MaciejKaras can you please have a look into this PR again?

Copy link
Collaborator

@MaciejKaras MaciejKaras left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The refactor looks really good!

Please also check and update old multicluster usages in other files. Examples I found:

  • !/public/tools/multicluster/go.mod
  • public/tools/multicluster/vendor
  • files: [ "src/github.com/mongodb/mongodb-kubernetes/*.suite", "src/github.com/mongodb/mongodb-kubernetes/public/tools/multicluster/*.suite", "src/github.com/mongodb/mongodb-kubernetes/docker/mongodb-kubernetes-init-ops-manager/mmsconfiguration/*.suite" ]
  • ### Build the multi-cluster CLI image
    You can build a minimal image containing the CLI executable using the `Dockerfile` [provided in this repo](./../../tools/multicluster/Dockerfile).
    ``` shell
    git clone https://github.com/mongodb/mongodb-kubernetes
    cd mongodb-kubernetes/public/tools/multicluster
    docker build . -t "your-registry/multi-cluster-cli:latest"
    docker push "your-registry/multi-cluster-cli:latest"
    ```

@viveksinghggits
Copy link
Contributor Author

Hi @Julien-Ben,
Can you please have a look into this as well.

@viveksinghggits
Copy link
Contributor Author

The refactor looks really good!

Please also check and update old multicluster usages in other files. Examples I found:

  • !/public/tools/multicluster/go.mod
  • public/tools/multicluster/vendor
  • files: [ "src/github.com/mongodb/mongodb-kubernetes/*.suite", "src/github.com/mongodb/mongodb-kubernetes/public/tools/multicluster/*.suite", "src/github.com/mongodb/mongodb-kubernetes/docker/mongodb-kubernetes-init-ops-manager/mmsconfiguration/*.suite" ]
  • ### Build the multi-cluster CLI image
    You can build a minimal image containing the CLI executable using the `Dockerfile` [provided in this repo](./../../tools/multicluster/Dockerfile).
    ``` shell
    git clone https://github.com/mongodb/mongodb-kubernetes
    cd mongodb-kubernetes/public/tools/multicluster
    docker build . -t "your-registry/multi-cluster-cli:latest"
    docker push "your-registry/multi-cluster-cli:latest"
    ```

Thank you @MaciejKaras.
Those are good points, I am planning to raise those changes as part of a new PR.

Copy link
Collaborator

@Julien-Ben Julien-Ben left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work 👏

@viveksinghggits viveksinghggits merged commit 9a883c9 into master Jul 21, 2025
35 checks passed
@viveksinghggits viveksinghggits deleted the mongodb-kubectlplugin-refactor branch July 21, 2025 14:49
viveksinghggits added a commit that referenced this pull request Jul 21, 2025
…ngodb` (#280)

# Summary

Since we [moved](#271)
the code for kubectl plugin to the dir `cmd/`, we also need to move the
Dockerfile there. This PR does the same and moves the Dockerfile to the
`cmd/kubectl-mongodb` dir.

## Proof of Work

Go to the root of the repo and run the below command to build the image

```bash
~/work/opensource/mongodb-kubernetes (move-kplugin-dockerfile*) » docker build -t viveksinghggits/mongodb-mc-plugin:0.0.1 . -f cmd/kubectl-mongodb/Dockerfile    vivek.s@M-HYXVRF7WDG
[+] Building 11.5s (10/10) FINISHED                                                                                                                              docker:desktop-linux
 => [internal] load build definition from Dockerfile                                                                                                                             0.0s
 => => transferring dockerfile: 309B                                                                                                                                             0.0s
 => [internal] load metadata for docker.io/library/golang:1.24                                                                                                                   0.7s
 => [internal] load .dockerignore                                                                                                                                                0.0s
 => => transferring context: 1.16kB                                                                                                                                              0.0s
 => [builder 1/4] FROM docker.io/library/golang:1.24@sha256:14fd8a55e59a560704e5fc44970b301d00d344e45d6b914dda228e09f359a088                                                     0.0s
 => => resolve docker.io/library/golang:1.24@sha256:14fd8a55e59a560704e5fc44970b301d00d344e45d6b914dda228e09f359a088                                                             0.0s
 => [internal] load build context                                                                                                                                                0.1s
 => => transferring context: 172.97kB                                                                                                                                            0.1s
 => CACHED [builder 2/4] WORKDIR /go/src                                                                                                                                         0.0s
 => [builder 3/4] ADD . .                                                                                                                                                        0.2s
 => [builder 4/4] RUN CGO_ENABLED=0 go build -a -buildvcs=false -o /go/bin/mongodb-multicluster                                                                                 10.4s
 => CACHED [stage-1 1/1] COPY --from=builder /go/bin/mongodb-multicluster /go/bin/mongodb-multicluster                                                                           0.0s
 => exporting to image                                                                                                                                                           0.0s
 => => exporting layers                                                                                                                                                          0.0s
 => => exporting manifest sha256:f0d3ef2864de3f81ec287382c66a76897419bddb5337a4e2fb9b56b7e3ca14dc                                                                                0.0s
 => => exporting config sha256:ce9089ec4e89d1b2c2b3dd5edeb4053eaae95c62a3182e7c015dd4d63ecf6be2                                                                                  0.0s
 => => exporting attestation manifest sha256:19f49f2aebd733e6a259441c81d0fef424c6af4fadf6f86e8032e77b7f1f3d51                                                                    0.0s
 => => exporting manifest list sha256:1574999c4354dbe1915980c0baf9aab438cbc59c7b909e34bf73b84ec98945e9                                                                           0.0s
 => => naming to docker.io/viveksinghggits/mongodb-mc-plugin:0.0.1                                                                                                               0.0s
 => => unpacking to docker.io/viveksinghggits/mongodb-mc-plugin:0.0.1                                                                                                            0.0s
```

## Checklist
- [x] Have you linked a jira ticket and/or is the ticket in the title?
- [x] Have you checked whether your jira ticket required DOCSP changes?
- [x] Have you checked for release_note changes?
viveksinghggits added a commit that referenced this pull request Jul 22, 2025
# Summary

As part of [the
PR](#271) we moved the
kubectl-mongodb code from `public/tools/multicluster` to
`cmd/kubectl-mongodb`.
This PR, tries to move the license file from `public/tools/multicluster`
to `cmd/kubectl-mongodb`.
The next [PR](#281) in
this chain are going to actually remove the `public/tools` directory
entirely.

## Proof of Work

NA

## Checklist
- [x] Have you linked a jira ticket and/or is the ticket in the title?
- [x] Have you checked whether your jira ticket required DOCSP changes?
- [x] Have you checked for release_note changes?
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.

3 participants