Skip to content
Open
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
43 changes: 43 additions & 0 deletions pkg/adopt/adopt.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
Copyright AppsCode Inc. and Contributors
Licensed under the AppsCode Community License 1.0.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
https://github.com/appscode/licenses/raw/1.0.0/AppsCode-Community-1.0.0.md
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

// Package adopt implements `kubectl dba adopt`, which brings a database that
// already runs in Kubernetes (for example from a Helm chart) under KubeDB in
// place: the data stays where it is and the workloads change hands one role at
// a time.
package adopt

import (
"github.com/spf13/cobra"
cmdutil "k8s.io/kubectl/pkg/cmd/util"
"k8s.io/kubectl/pkg/util/i18n"
"k8s.io/kubectl/pkg/util/templates"
)

// NewCmdAdopt returns the `adopt` command group.
func NewCmdAdopt(f cmdutil.Factory) *cobra.Command {
cmd := &cobra.Command{
Use: "adopt",
Short: i18n.T("Bring a running database under KubeDB in place, without moving its data"),
Long: templates.LongDesc(`
Take over a database that already runs in Kubernetes, for example one
installed by a Helm chart. The data stays in its current storage, the
credentials stay the same, and clients keep their address; only the
workloads change hands, one role at a time.`),
Run: func(cmd *cobra.Command, args []string) {},
DisableFlagsInUseLine: true,
DisableAutoGenTag: true,
}
cmd.AddCommand(NewCmdMilvus(f))
return cmd
}
61 changes: 61 additions & 0 deletions pkg/adopt/findings.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
Copyright AppsCode Inc. and Contributors
Licensed under the AppsCode Community License 1.0.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
https://github.com/appscode/licenses/raw/1.0.0/AppsCode-Community-1.0.0.md
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package adopt

import (
"fmt"
"io"
)

const (
levelError = "ERROR"
levelWarn = "WARN"
levelInfo = "OK"
)

type finding struct {
Level string
Msg string
}

// findings are the results of the pre-flight checks. An ERROR blocks the
// adoption; a WARN needs a look before the handover.
type findings []finding

func (f *findings) errorf(format string, a ...any) {
*f = append(*f, finding{levelError, fmt.Sprintf(format, a...)})
}

func (f *findings) warnf(format string, a ...any) {
*f = append(*f, finding{levelWarn, fmt.Sprintf(format, a...)})
}

func (f *findings) infof(format string, a ...any) {
*f = append(*f, finding{levelInfo, fmt.Sprintf(format, a...)})
}

func (f findings) hasErrors() bool {
for _, x := range f {
if x.Level == levelError {
return true
}
}
return false
}

func (f findings) print(w io.Writer) {
for _, x := range f {
_, _ = fmt.Fprintf(w, " [%-5s] %s\n", x.Level, x.Msg)
}
}
Loading
Loading