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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion public/.evergreen.yml → .evergreen-kubectlplugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ functions:
- command: shell.exec
type: setup
params:
working_dir: src/github.com/mongodb/mongodb-kubernetes/public/tools/multicluster
working_dir: src/github.com/mongodb/mongodb-kubernetes
include_expansions_in_env:
- GRS_USERNAME
- GRS_PASSWORD
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -94,3 +94,6 @@ logs-debug/

docs/**/log/*
docs/**/test.sh.run.log

# goreleaser generated files
dist
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ before:
builds:
- env:
- CGO_ENABLED=0
main: ./cmd/kubectl-mongodb
goos:
- linux
- darwin
Expand All @@ -16,9 +17,9 @@ builds:
hooks:
# This will notarize Apple binaries and replace goreleaser bins with the notarized ones
post:
- cmd: ./kubectl_mac_notarize.sh
- cmd: ./scripts/release/kubectl-mongodb/kubectl_mac_notarize.sh
output: true
- cmd: ./sign.sh {{ .Path }}
- cmd: ./scripts/release/kubectl-mongodb/sign.sh {{ .Path }}
env:
- GRS_USERNAME={{ .Env.GRS_USERNAME }}
- GRS_PASSWORD={{ .Env.GRS_PASSWORD }}
Expand All @@ -27,7 +28,7 @@ builds:
- SIGNING_IMAGE_URI={{ .Env.SIGNING_IMAGE_URI }}
- ARTIFACTORY_USERNAME=mongodb-enterprise-kubernetes-operator
- ARTIFACTORY_PASSWORD={{ .Env.ARTIFACTORY_PASSWORD }}
- cmd: ./verify.sh {{ .Path }} && echo "VERIFIED OK"
- cmd: ./scripts/release/kubectl-mongodb/verify.sh {{ .Path }} && echo "VERIFIED OK"

archives:
- format: tar.gz
Expand Down
43 changes: 43 additions & 0 deletions cmd/kubectl-mongodb/LICENSE-THIRD-PARTY
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@

github.com/davecgh/go-spew/spew,v1.1.1,https://github.com/davecgh/go-spew/blob/v1.1.1/LICENSE,ISC
github.com/emicklei/go-restful/v3,v3.11.0,https://github.com/emicklei/go-restful/blob/v3.11.0/LICENSE,MIT
github.com/ghodss/yaml,v1.0.0,https://github.com/ghodss/yaml/blob/v1.0.0/LICENSE,MIT
github.com/go-logr/logr,v1.4.2,https://github.com/go-logr/logr/blob/v1.4.2/LICENSE,Apache-2.0
github.com/go-openapi/jsonpointer,v0.19.6,https://github.com/go-openapi/jsonpointer/blob/v0.19.6/LICENSE,Apache-2.0
github.com/go-openapi/jsonreference,v0.20.2,https://github.com/go-openapi/jsonreference/blob/v0.20.2/LICENSE,Apache-2.0
github.com/go-openapi/swag,v0.22.3,https://github.com/go-openapi/swag/blob/v0.22.3/LICENSE,Apache-2.0
github.com/gogo/protobuf,v1.3.2,https://github.com/gogo/protobuf/blob/v1.3.2/LICENSE,BSD-3-Clause
github.com/golang/protobuf,v1.5.4,https://github.com/golang/protobuf/blob/v1.5.4/LICENSE,BSD-3-Clause
github.com/google/gnostic-models,v0.6.8,https://github.com/google/gnostic-models/blob/v0.6.8/LICENSE,Apache-2.0
github.com/google/gofuzz,v1.2.0,https://github.com/google/gofuzz/blob/v1.2.0/LICENSE,Apache-2.0
github.com/google/uuid,v1.6.0,https://github.com/google/uuid/blob/v1.6.0/LICENSE,BSD-3-Clause
github.com/gorilla/websocket,v1.5.0,https://github.com/gorilla/websocket/blob/v1.5.0/LICENSE,BSD-2-Clause
github.com/imdario/mergo,v0.3.15,https://github.com/imdario/mergo/blob/v0.3.15/LICENSE,BSD-3-Clause
github.com/josharian/intern,v1.0.0,https://github.com/josharian/intern/blob/v1.0.0/license.md,MIT
github.com/json-iterator/go,v1.1.12,https://github.com/json-iterator/go/blob/v1.1.12/LICENSE,MIT
github.com/mailru/easyjson,v0.7.7,https://github.com/mailru/easyjson/blob/v0.7.7/LICENSE,MIT
github.com/moby/spdystream,v0.2.0,https://github.com/moby/spdystream/blob/v0.2.0/LICENSE,Apache-2.0
github.com/modern-go/concurrent,v0.0.0-20180306012644-bacd9c7ef1dd,https://github.com/modern-go/concurrent/blob/bacd9c7ef1dd/LICENSE,Apache-2.0
github.com/modern-go/reflect2,v1.0.2,https://github.com/modern-go/reflect2/blob/v1.0.2/LICENSE,Apache-2.0
github.com/munnerz/goautoneg,v0.0.0-20191010083416-a7dc8b61c822,https://github.com/munnerz/goautoneg/blob/a7dc8b61c822/LICENSE,BSD-3-Clause
github.com/mxk/go-flowrate/flowrate,v0.0.0-20140419014527-cca7078d478f,https://github.com/mxk/go-flowrate/blob/cca7078d478f/LICENSE,BSD-3-Clause
github.com/spf13/cobra,v1.7.0,https://github.com/spf13/cobra/blob/v1.7.0/LICENSE.txt,Apache-2.0
github.com/spf13/pflag,v1.0.5,https://github.com/spf13/pflag/blob/v1.0.5/LICENSE,BSD-3-Clause
google.golang.org/protobuf,v1.36.5,https://github.com/protocolbuffers/protobuf-go/blob/v1.36.5/LICENSE,BSD-3-Clause
gopkg.in/inf.v0,v0.9.1,https://github.com/go-inf/inf/blob/v0.9.1/LICENSE,BSD-3-Clause
gopkg.in/yaml.v2,v2.4.0,https://github.com/go-yaml/yaml/blob/v2.4.0/LICENSE,Apache-2.0
gopkg.in/yaml.v3,v3.0.1,https://github.com/go-yaml/yaml/blob/v3.0.1/LICENSE,MIT
k8s.io/api,v0.30.10,https://github.com/kubernetes/api/blob/v0.30.10/LICENSE,Apache-2.0
k8s.io/apimachinery/pkg,v0.30.10,https://github.com/kubernetes/apimachinery/blob/v0.30.10/LICENSE,Apache-2.0
k8s.io/apimachinery/third_party/forked/golang,v0.30.10,https://github.com/kubernetes/apimachinery/blob/v0.30.10/third_party/forked/golang/LICENSE,BSD-3-Clause
k8s.io/client-go,v0.30.10,https://github.com/kubernetes/client-go/blob/v0.30.10/LICENSE,Apache-2.0
k8s.io/klog/v2,v2.130.1,https://github.com/kubernetes/klog/blob/v2.130.1/LICENSE,Apache-2.0
k8s.io/kube-openapi/pkg,v0.0.0-20240228011516-70dd3763d340,https://github.com/kubernetes/kube-openapi/blob/70dd3763d340/LICENSE,Apache-2.0
k8s.io/kube-openapi/pkg/internal/third_party/go-json-experiment/json,v0.0.0-20240228011516-70dd3763d340,https://github.com/kubernetes/kube-openapi/blob/70dd3763d340/pkg/internal/third_party/go-json-experiment/json/LICENSE,BSD-3-Clause
k8s.io/kube-openapi/pkg/validation/spec,v0.0.0-20240228011516-70dd3763d340,https://github.com/kubernetes/kube-openapi/blob/70dd3763d340/pkg/validation/spec/LICENSE,Apache-2.0
k8s.io/utils,v0.0.0-20240502163921-fe8a2dddb1d0,https://github.com/kubernetes/utils/blob/fe8a2dddb1d0/LICENSE,Apache-2.0
k8s.io/utils/internal/third_party/forked/golang/net,v0.0.0-20240502163921-fe8a2dddb1d0,https://github.com/kubernetes/utils/blob/fe8a2dddb1d0/internal/third_party/forked/golang/LICENSE,BSD-3-Clause
sigs.k8s.io/json,v0.0.0-20221116044647-bc3834ca7abd,https://github.com/kubernetes-sigs/json/blob/bc3834ca7abd/LICENSE,Apache-2.0
sigs.k8s.io/structured-merge-diff/v4,v4.4.1,https://github.com/kubernetes-sigs/structured-merge-diff/blob/v4.4.1/LICENSE,Apache-2.0
sigs.k8s.io/yaml,v1.4.0,https://github.com/kubernetes-sigs/yaml/blob/v1.4.0/LICENSE,Apache-2.0
sigs.k8s.io/yaml/goyaml.v2,v1.4.0,https://github.com/kubernetes-sigs/yaml/blob/v1.4.0/goyaml.v2/LICENSE,Apache-2.0
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package cmd
package debug

import (
"fmt"
"os"
"strings"

"github.com/spf13/cobra"
"k8s.io/client-go/tools/clientcmd"

"github.com/mongodb/mongodb-kubernetes/multi/pkg/common"
"github.com/mongodb/mongodb-kubernetes/multi/pkg/debug"
"github.com/spf13/cobra"
"github.com/mongodb/mongodb-kubernetes/pkg/kubectl-mongodb/common"
"github.com/mongodb/mongodb-kubernetes/pkg/kubectl-mongodb/debug"
)

type Flags struct {
Expand Down Expand Up @@ -39,18 +39,16 @@ func (f *Flags) ParseDebugFlags() error {
var debugFlags = &Flags{}

func init() {
rootCmd.AddCommand(debugCmd)

debugCmd.Flags().StringVar(&common.MemberClusters, "member-clusters", "", "Comma separated list of member clusters. [optional]")
debugCmd.Flags().StringVar(&debugFlags.CentralCluster, "central-cluster", "", "The central cluster the operator will be deployed in. [optional]")
debugCmd.Flags().StringVar(&debugFlags.MemberClusterNamespace, "member-cluster-namespace", "", "The namespace the member cluster resources will be deployed to. [optional]")
debugCmd.Flags().StringVar(&debugFlags.CentralClusterNamespace, "central-cluster-namespace", "", "The namespace the Operator will be deployed to. [optional]")
debugCmd.Flags().StringVar(&common.MemberClustersApiServers, "member-clusters-api-servers", "", "Comma separated list of api servers addresses. [optional, default will take addresses from KUBECONFIG env var]")
debugCmd.Flags().BoolVar(&debugFlags.Anonymize, "anonymize", true, "True if anonymization should be turned on")
debugCmd.Flags().BoolVar(&debugFlags.UseOwnerRef, "ownerRef", false, "True if the collection should be made with owner references (consider turning it on after CLOUDP-176772 is fixed)")
DebugCmd.Flags().StringVar(&common.MemberClusters, "member-clusters", "", "Comma separated list of member clusters. [optional]")
DebugCmd.Flags().StringVar(&debugFlags.CentralCluster, "central-cluster", "", "The central cluster the operator will be deployed in. [optional]")
DebugCmd.Flags().StringVar(&debugFlags.MemberClusterNamespace, "member-cluster-namespace", "", "The namespace the member cluster resources will be deployed to. [optional]")
DebugCmd.Flags().StringVar(&debugFlags.CentralClusterNamespace, "central-cluster-namespace", "", "The namespace the Operator will be deployed to. [optional]")
DebugCmd.Flags().StringVar(&common.MemberClustersApiServers, "member-clusters-api-servers", "", "Comma separated list of api servers addresses. [optional, default will take addresses from KUBECONFIG env var]")
DebugCmd.Flags().BoolVar(&debugFlags.Anonymize, "anonymize", true, "True if anonymization should be turned on")
DebugCmd.Flags().BoolVar(&debugFlags.UseOwnerRef, "ownerRef", false, "True if the collection should be made with owner references (consider turning it on after CLOUDP-176772 is fixed)")
}

var debugCmd = &cobra.Command{
var DebugCmd = &cobra.Command{
Use: "debug",
Short: "Downloads all resources required for debugging and stores them into the disk",
Long: `'debug' downloads all resources required for debugging and stores them into the disk.
Expand Down
12 changes: 12 additions & 0 deletions cmd/kubectl-mongodb/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package main

import (
"context"

"github.com/mongodb/mongodb-kubernetes/cmd/kubectl-mongodb/root"
)

func main() {
ctx := context.Background()
root.Execute(ctx)
}
21 changes: 21 additions & 0 deletions cmd/kubectl-mongodb/multicluster/multicluster.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package multicluster

import (
"github.com/spf13/cobra"

"github.com/mongodb/mongodb-kubernetes/cmd/kubectl-mongodb/multicluster/recover"
"github.com/mongodb/mongodb-kubernetes/cmd/kubectl-mongodb/multicluster/setup"
)

// MulticlusterCmd represents the multicluster command
var MulticlusterCmd = &cobra.Command{
Use: "multicluster",
Short: "Manage MongoDB multicluster environments on k8s",
Long: `'multicluster' is the toplevel command for managing
multicluster environments that hold MongoDB resources.`,
}

func init() {
MulticlusterCmd.AddCommand(setup.SetupCmd)
MulticlusterCmd.AddCommand(recover.RecoverCmd)
}
Original file line number Diff line number Diff line change
@@ -1,37 +1,35 @@
package cmd
package recover

import (
"fmt"
"os"
"slices"
"strings"

"github.com/mongodb/mongodb-kubernetes/multi/pkg/common"

"github.com/spf13/cobra"
"golang.org/x/xerrors"
"k8s.io/client-go/tools/clientcmd"

"github.com/mongodb/mongodb-kubernetes/pkg/kubectl-mongodb/common"
)

func init() {
multiclusterCmd.AddCommand(recoverCmd)

recoverCmd.Flags().StringVar(&common.MemberClusters, "member-clusters", "", "Comma separated list of member clusters. [required]")
recoverCmd.Flags().StringVar(&RecoverFlags.ServiceAccount, "service-account", "mongodb-kubernetes-operator-multi-cluster", "Name of the service account which should be used for the Operator to communicate with the member clusters. [optional, default: mongodb-kubernetes-operator-multi-cluster]")
recoverCmd.Flags().StringVar(&RecoverFlags.CentralCluster, "central-cluster", "", "The central cluster the operator will be deployed in. [required]")
recoverCmd.Flags().StringVar(&RecoverFlags.MemberClusterNamespace, "member-cluster-namespace", "", "The namespace the member cluster resources will be deployed to. [required]")
recoverCmd.Flags().StringVar(&RecoverFlags.CentralClusterNamespace, "central-cluster-namespace", "", "The namespace the Operator will be deployed to. [required]")
recoverCmd.Flags().BoolVar(&RecoverFlags.Cleanup, "cleanup", false, "Delete all previously created resources except for namespaces. [optional default: false]")
recoverCmd.Flags().BoolVar(&RecoverFlags.ClusterScoped, "cluster-scoped", false, "Create ClusterRole and ClusterRoleBindings for member clusters. [optional default: false]")
recoverCmd.Flags().StringVar(&RecoverFlags.OperatorName, "operator-name", common.DefaultOperatorName, "Name used to identify the deployment of the operator. [optional, default: mongodb-kubernetes-operator]")
recoverCmd.Flags().BoolVar(&RecoverFlags.InstallDatabaseRoles, "install-database-roles", false, "Install the ServiceAccounts and Roles required for running database workloads in the member clusters. [optional default: false]")
recoverCmd.Flags().StringVar(&RecoverFlags.SourceCluster, "source-cluster", "", "The source cluster for recovery. This has to be one of the healthy member cluster that is the source of truth for new cluster configuration. [required]")
recoverCmd.Flags().BoolVar(&RecoverFlags.CreateServiceAccountSecrets, "create-service-account-secrets", true, "Create service account token secrets. [optional default: true]")
recoverCmd.Flags().StringVar(&common.MemberClustersApiServers, "member-clusters-api-servers", "", "Comma separated list of api servers addresses. [optional, default will take addresses from KUBECONFIG env var]")
RecoverCmd.Flags().StringVar(&common.MemberClusters, "member-clusters", "", "Comma separated list of member clusters. [required]")
RecoverCmd.Flags().StringVar(&RecoverFlags.ServiceAccount, "service-account", "mongodb-kubernetes-operator-multi-cluster", "Name of the service account which should be used for the Operator to communicate with the member clusters. [optional, default: mongodb-kubernetes-operator-multi-cluster]")
RecoverCmd.Flags().StringVar(&RecoverFlags.CentralCluster, "central-cluster", "", "The central cluster the operator will be deployed in. [required]")
RecoverCmd.Flags().StringVar(&RecoverFlags.MemberClusterNamespace, "member-cluster-namespace", "", "The namespace the member cluster resources will be deployed to. [required]")
RecoverCmd.Flags().StringVar(&RecoverFlags.CentralClusterNamespace, "central-cluster-namespace", "", "The namespace the Operator will be deployed to. [required]")
RecoverCmd.Flags().BoolVar(&RecoverFlags.Cleanup, "cleanup", false, "Delete all previously created resources except for namespaces. [optional default: false]")
RecoverCmd.Flags().BoolVar(&RecoverFlags.ClusterScoped, "cluster-scoped", false, "Create ClusterRole and ClusterRoleBindings for member clusters. [optional default: false]")
RecoverCmd.Flags().StringVar(&RecoverFlags.OperatorName, "operator-name", common.DefaultOperatorName, "Name used to identify the deployment of the operator. [optional, default: mongodb-kubernetes-operator]")
RecoverCmd.Flags().BoolVar(&RecoverFlags.InstallDatabaseRoles, "install-database-roles", false, "Install the ServiceAccounts and Roles required for running database workloads in the member clusters. [optional default: false]")
RecoverCmd.Flags().StringVar(&RecoverFlags.SourceCluster, "source-cluster", "", "The source cluster for recovery. This has to be one of the healthy member cluster that is the source of truth for new cluster configuration. [required]")
RecoverCmd.Flags().BoolVar(&RecoverFlags.CreateServiceAccountSecrets, "create-service-account-secrets", true, "Create service account token secrets. [optional default: true]")
RecoverCmd.Flags().StringVar(&common.MemberClustersApiServers, "member-clusters-api-servers", "", "Comma separated list of api servers addresses. [optional, default will take addresses from KUBECONFIG env var]")
}

// recoverCmd represents the recover command
var recoverCmd = &cobra.Command{
// RecoverCmd represents the recover command
var RecoverCmd = &cobra.Command{
Use: "recover",
Short: "Recover the multicluster environment for MongoDB resources after a dataplane failure",
Long: `'recover' re-configures a failed multicluster environment to a enable the shuffling of dataplane
Expand Down
Loading