Skip to content

Commit 58e6c83

Browse files
committed
Add kubectl dba adopt milvus: adopt a running Milvus in place
Adopting a Distributed Milvus 2.6 that runs from a Helm chart was a manual procedure: gather the effective config, write three Secrets and a staged Milvus, diff the rendered config, then scale each role by hand. The new command group does it: - plan RELEASE: read-only. Finds the release's workloads (by app.kubernetes.io/instance and the component label, or --workload), merges the mounted config files in Milvus' load order, finds the client Service and the MilvusVersion for the running image, and checks the WAL (Woodpecker on object storage), etcd, object storage and the root password, logging in to a running proxy through a port-forward (Milvus applies a root password only on first start). --output-dir writes the objects for review. - run RELEASE: creates the Secrets, a state ConfigMap <name>-adopt and the Milvus with every role at 0 (orphan-on-delete, DoNotTerminate, external etcd with the current root path, autoOps off, write check off), removes a chart Service on a name KubeDB needs headless, and stops if the config the operator rendered differs from the running one on storage, etcd root path, WAL, security or ports. Then hands the roles over, overlap (default; one QueryNode at a time) or stop-start, recording each one; re-running resumes. - status RELEASE: where each role runs. - rollback RELEASE: deletes the Milvus with orphan-on-delete, moves each role back to the chart starting the chart's pods first, restores the client Service's selector, labels and ports, and with --cleanup deletes what KubeDB left and recreates the removed chart Services. --name covers a Milvus adopted by hand. Several workloads of one role become node groups (e.g. QueryNodes on two GPU pools). Tested end to end on a cluster running the upstream chart 5.0.19 (Milvus 2.6.15): hand-adoption rollback, plan, overlap run, state rollback, stop-start run killed and resumed; data bit-exact after each. Signed-off-by: sabnaj <sabnaj@appscode.com>
1 parent 2fea701 commit 58e6c83

13 files changed

Lines changed: 3691 additions & 0 deletions

‎pkg/adopt/adopt.go‎

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
Copyright AppsCode Inc. and Contributors
3+
Licensed under the AppsCode Community License 1.0.0 (the "License");
4+
you may not use this file except in compliance with the License.
5+
You may obtain a copy of the License at
6+
https://github.com/appscode/licenses/raw/1.0.0/AppsCode-Community-1.0.0.md
7+
Unless required by applicable law or agreed to in writing, software
8+
distributed under the License is distributed on an "AS IS" BASIS,
9+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10+
See the License for the specific language governing permissions and
11+
limitations under the License.
12+
*/
13+
14+
// Package adopt implements `kubectl dba adopt`, which brings a database that
15+
// already runs in Kubernetes (for example from a Helm chart) under KubeDB in
16+
// place: the data stays where it is and the workloads change hands one role at
17+
// a time.
18+
package adopt
19+
20+
import (
21+
"github.com/spf13/cobra"
22+
cmdutil "k8s.io/kubectl/pkg/cmd/util"
23+
"k8s.io/kubectl/pkg/util/i18n"
24+
"k8s.io/kubectl/pkg/util/templates"
25+
)
26+
27+
// NewCmdAdopt returns the `adopt` command group.
28+
func NewCmdAdopt(f cmdutil.Factory) *cobra.Command {
29+
cmd := &cobra.Command{
30+
Use: "adopt",
31+
Short: i18n.T("Bring a running database under KubeDB in place, without moving its data"),
32+
Long: templates.LongDesc(`
33+
Take over a database that already runs in Kubernetes, for example one
34+
installed by a Helm chart. The data stays in its current storage, the
35+
credentials stay the same, and clients keep their address; only the
36+
workloads change hands, one role at a time.`),
37+
Run: func(cmd *cobra.Command, args []string) {},
38+
DisableFlagsInUseLine: true,
39+
DisableAutoGenTag: true,
40+
}
41+
cmd.AddCommand(NewCmdMilvus(f))
42+
return cmd
43+
}

‎pkg/adopt/findings.go‎

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/*
2+
Copyright AppsCode Inc. and Contributors
3+
Licensed under the AppsCode Community License 1.0.0 (the "License");
4+
you may not use this file except in compliance with the License.
5+
You may obtain a copy of the License at
6+
https://github.com/appscode/licenses/raw/1.0.0/AppsCode-Community-1.0.0.md
7+
Unless required by applicable law or agreed to in writing, software
8+
distributed under the License is distributed on an "AS IS" BASIS,
9+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10+
See the License for the specific language governing permissions and
11+
limitations under the License.
12+
*/
13+
14+
package adopt
15+
16+
import (
17+
"fmt"
18+
"io"
19+
)
20+
21+
const (
22+
levelError = "ERROR"
23+
levelWarn = "WARN"
24+
levelInfo = "OK"
25+
)
26+
27+
type finding struct {
28+
Level string
29+
Msg string
30+
}
31+
32+
// findings are the results of the pre-flight checks. An ERROR blocks the
33+
// adoption; a WARN needs a look before the handover.
34+
type findings []finding
35+
36+
func (f *findings) errorf(format string, a ...any) {
37+
*f = append(*f, finding{levelError, fmt.Sprintf(format, a...)})
38+
}
39+
40+
func (f *findings) warnf(format string, a ...any) {
41+
*f = append(*f, finding{levelWarn, fmt.Sprintf(format, a...)})
42+
}
43+
44+
func (f *findings) infof(format string, a ...any) {
45+
*f = append(*f, finding{levelInfo, fmt.Sprintf(format, a...)})
46+
}
47+
48+
func (f findings) hasErrors() bool {
49+
for _, x := range f {
50+
if x.Level == levelError {
51+
return true
52+
}
53+
}
54+
return false
55+
}
56+
57+
func (f findings) print(w io.Writer) {
58+
for _, x := range f {
59+
_, _ = fmt.Fprintf(w, " [%-5s] %s\n", x.Level, x.Msg)
60+
}
61+
}

0 commit comments

Comments
 (0)