From 542b62c2cc586ab1c56171f14b69a7c789a7fbd0 Mon Sep 17 00:00:00 2001 From: Diogo Recharte Date: Thu, 8 Feb 2024 12:46:37 +0000 Subject: [PATCH] EVEREST-633 Remove namespace flag from token reset and deprecated code (#284) * EVEREST-633 remove namespace flag from token reset * EVEREST-633 Update percona-everest-backend go mod * EVEREST-633 remove deprecated code * EVEREST-633 Update everest-operator go mod --- commands/delete.go | 34 ----- commands/delete/mysql.go | 85 ----------- commands/list.go | 35 ----- commands/list/database_engines.go | 81 ----------- commands/list/versions.go | 85 ----------- commands/provision.go | 34 ----- commands/provision/mysql.go | 99 ------------- commands/root.go | 3 - commands/token/reset.go | 4 +- go.mod | 10 +- go.sum | 24 ---- pkg/delete/deps.go | 30 ---- pkg/delete/mysql.go | 85 ----------- pkg/everest/client/backup_storage.go | 41 ------ pkg/everest/client/client.go | 110 -------------- pkg/everest/client/database_cluster.go | 73 ---------- pkg/everest/client/database_engine.go | 42 ------ pkg/everest/client/kubernetes.go | 37 ----- pkg/everest/client/monitoring_instance.go | 76 ---------- pkg/list/database_engines.go | 107 -------------- pkg/list/deps.go | 27 ---- pkg/list/versions.go | 131 ----------------- pkg/output/command.go | 7 - pkg/provision/deps.go | 30 ---- pkg/provision/mysql.go | 166 ---------------------- 25 files changed, 4 insertions(+), 1452 deletions(-) delete mode 100644 commands/delete.go delete mode 100644 commands/delete/mysql.go delete mode 100644 commands/list.go delete mode 100644 commands/list/database_engines.go delete mode 100644 commands/list/versions.go delete mode 100644 commands/provision.go delete mode 100644 commands/provision/mysql.go delete mode 100644 pkg/delete/deps.go delete mode 100644 pkg/delete/mysql.go delete mode 100644 pkg/everest/client/backup_storage.go delete mode 100644 pkg/everest/client/client.go delete mode 100644 pkg/everest/client/database_cluster.go delete mode 100644 pkg/everest/client/database_engine.go delete mode 100644 pkg/everest/client/kubernetes.go delete mode 100644 pkg/everest/client/monitoring_instance.go delete mode 100644 pkg/list/database_engines.go delete mode 100644 pkg/list/deps.go delete mode 100644 pkg/list/versions.go delete mode 100644 pkg/provision/deps.go delete mode 100644 pkg/provision/mysql.go diff --git a/commands/delete.go b/commands/delete.go deleted file mode 100644 index ae16f198..00000000 --- a/commands/delete.go +++ /dev/null @@ -1,34 +0,0 @@ -// percona-everest-cli -// Copyright (C) 2023 Percona LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// 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 commands ... -package commands - -import ( - "github.com/spf13/cobra" - "go.uber.org/zap" - - "github.com/percona/percona-everest-cli/commands/delete" -) - -func newDeleteCmd(l *zap.SugaredLogger) *cobra.Command { //nolint:deadcode,unused - cmd := &cobra.Command{ - Use: "delete", - } - - cmd.AddCommand(delete.NewMySQLCmd(l)) - - return cmd -} diff --git a/commands/delete/mysql.go b/commands/delete/mysql.go deleted file mode 100644 index 9adf1d97..00000000 --- a/commands/delete/mysql.go +++ /dev/null @@ -1,85 +0,0 @@ -// percona-everest-cli -// Copyright (C) 2023 Percona LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// 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 delete provides delete sub-commands. -package delete //nolint:predeclared - -import ( - "fmt" - "os" - - "github.com/percona/percona-everest-backend/client" - "github.com/spf13/cobra" - "github.com/spf13/viper" - "go.uber.org/zap" - - "github.com/percona/percona-everest-cli/pkg/delete" - everestClient "github.com/percona/percona-everest-cli/pkg/everest/client" - "github.com/percona/percona-everest-cli/pkg/output" -) - -// NewMySQLCmd returns a new MySQL command. -func NewMySQLCmd(l *zap.SugaredLogger) *cobra.Command { - cmd := &cobra.Command{ - Use: "mysql", - Run: func(cmd *cobra.Command, args []string) { - initMySQLViperFlags(cmd) - - c, err := parseMySQLConfig() - if err != nil { - os.Exit(1) - } - - everestCl, err := client.NewClient(fmt.Sprintf("%s/v1", c.Everest.Endpoint)) - if err != nil { - l.Error(err) - os.Exit(1) - } - - everestClConnector := everestClient.NewEverest(everestCl) - command := delete.NewMySQL(*c, everestClConnector, l) - - if err := command.Run(cmd.Context()); err != nil { - output.PrintError(err, l) - os.Exit(1) - } - }, - } - - initMySQLFlags(cmd) - - return cmd -} - -func initMySQLFlags(cmd *cobra.Command) { - cmd.Flags().String("name", "", "Cluster name") - cmd.MarkFlagRequired("name") //nolint:errcheck,gosec - cmd.Flags().String("everest.endpoint", "http://127.0.0.1:8080", "Everest endpoint URL") - - cmd.Flags().BoolP("force", "f", false, "Do not prompt to confirm removal") -} - -func initMySQLViperFlags(cmd *cobra.Command) { - viper.BindPFlag("name", cmd.Flags().Lookup("name")) //nolint:errcheck,gosec - viper.BindPFlag("everest.endpoint", cmd.Flags().Lookup("everest.endpoint")) //nolint:errcheck,gosec - - viper.BindPFlag("force", cmd.Flags().Lookup("force")) //nolint:errcheck,gosec -} - -func parseMySQLConfig() (*delete.MySQLConfig, error) { - c := &delete.MySQLConfig{} - err := viper.Unmarshal(c) - return c, err -} diff --git a/commands/list.go b/commands/list.go deleted file mode 100644 index 0eabbbb4..00000000 --- a/commands/list.go +++ /dev/null @@ -1,35 +0,0 @@ -// percona-everest-cli -// Copyright (C) 2023 Percona LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// 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 commands ... -package commands - -import ( - "github.com/spf13/cobra" - "go.uber.org/zap" - - "github.com/percona/percona-everest-cli/commands/list" -) - -func newListCmd(l *zap.SugaredLogger) *cobra.Command { //nolint:deadcode,unused - cmd := &cobra.Command{ - Use: "list", - } - - cmd.AddCommand(list.NewDatabaseEnginesCmd(l)) - cmd.AddCommand(list.NewVersionsCmd(l)) - - return cmd -} diff --git a/commands/list/database_engines.go b/commands/list/database_engines.go deleted file mode 100644 index afdf6a16..00000000 --- a/commands/list/database_engines.go +++ /dev/null @@ -1,81 +0,0 @@ -// percona-everest-cli -// Copyright (C) 2023 Percona LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// 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 list holds logic for list commands. -package list - -import ( - "fmt" - "os" - - "github.com/percona/percona-everest-backend/client" - "github.com/spf13/cobra" - "github.com/spf13/viper" - "go.uber.org/zap" - - everestClient "github.com/percona/percona-everest-cli/pkg/everest/client" - "github.com/percona/percona-everest-cli/pkg/list" - "github.com/percona/percona-everest-cli/pkg/output" -) - -// NewDatabaseEnginesCmd returns a new database engines command. -func NewDatabaseEnginesCmd(l *zap.SugaredLogger) *cobra.Command { - cmd := &cobra.Command{ - Use: "databaseengines", - Aliases: []string{"databaseengine", "dbengines", "dbengine"}, - Run: func(cmd *cobra.Command, args []string) { - initDatabaseEnginesViperFlags(cmd) - - c, err := parseDatabaseEnginesConfig() - if err != nil { - os.Exit(1) - } - - everestCl, err := client.NewClient(fmt.Sprintf("%s/v1", c.Everest.Endpoint)) - if err != nil { - l.Error(err) - os.Exit(1) - } - - everestClConnector := everestClient.NewEverest(everestCl) - command := list.NewDatabaseEngines(*c, everestClConnector, l) - dbEngines, err := command.Run(cmd.Context()) - if err != nil { - output.PrintError(err, l) - os.Exit(1) - } - - output.PrintOutput(cmd, l, dbEngines) - }, - } - - initDatabaseEnginesFlags(cmd) - - return cmd -} - -func initDatabaseEnginesFlags(cmd *cobra.Command) { - cmd.Flags().String("everest.endpoint", "http://127.0.0.1:8080", "Everest endpoint URL") -} - -func initDatabaseEnginesViperFlags(cmd *cobra.Command) { - viper.BindPFlag("everest.endpoint", cmd.Flags().Lookup("everest.endpoint")) //nolint:errcheck,gosec -} - -func parseDatabaseEnginesConfig() (*list.DBEnginesConfig, error) { - c := &list.DBEnginesConfig{} - err := viper.Unmarshal(c) - return c, err -} diff --git a/commands/list/versions.go b/commands/list/versions.go deleted file mode 100644 index 97b3dfef..00000000 --- a/commands/list/versions.go +++ /dev/null @@ -1,85 +0,0 @@ -// percona-everest-cli -// Copyright (C) 2023 Percona LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// 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 list ... -package list - -import ( - "fmt" - "os" - - "github.com/percona/percona-everest-backend/client" - "github.com/spf13/cobra" - "github.com/spf13/viper" - "go.uber.org/zap" - - everestClient "github.com/percona/percona-everest-cli/pkg/everest/client" - "github.com/percona/percona-everest-cli/pkg/list" - "github.com/percona/percona-everest-cli/pkg/output" -) - -// NewVersionsCmd returns a new versions command. -func NewVersionsCmd(l *zap.SugaredLogger) *cobra.Command { - cmd := &cobra.Command{ - Use: "versions", - Aliases: []string{"version"}, - Run: func(cmd *cobra.Command, args []string) { - initVersionsViperFlags(cmd) - - c, err := parseVersionsConfig() - if err != nil { - os.Exit(1) - } - - everestCl, err := client.NewClient(fmt.Sprintf("%s/v1", c.Everest.Endpoint)) - if err != nil { - l.Error(err) - os.Exit(1) - } - - everestClConnector := everestClient.NewEverest(everestCl) - command := list.NewVersions(*c, everestClConnector, l) - res, err := command.Run(cmd.Context()) - if err != nil { - output.PrintError(err, l) - os.Exit(1) - } - - output.PrintOutput(cmd, l, res) - }, - } - - initVersionsFlags(cmd) - - return cmd -} - -func initVersionsFlags(cmd *cobra.Command) { - cmd.Flags().String("everest.endpoint", "http://127.0.0.1:8080", "Everest endpoint URL") - - cmd.Flags().String("type", "", "Filter by database engine type") -} - -func initVersionsViperFlags(cmd *cobra.Command) { - viper.BindPFlag("everest.endpoint", cmd.Flags().Lookup("everest.endpoint")) //nolint:errcheck,gosec - - viper.BindPFlag("type", cmd.Flags().Lookup("type")) //nolint:errcheck,gosec -} - -func parseVersionsConfig() (*list.VersionsConfig, error) { - c := &list.VersionsConfig{} - err := viper.Unmarshal(c) - return c, err -} diff --git a/commands/provision.go b/commands/provision.go deleted file mode 100644 index 13e6f779..00000000 --- a/commands/provision.go +++ /dev/null @@ -1,34 +0,0 @@ -// percona-everest-cli -// Copyright (C) 2023 Percona LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// 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 commands ... -package commands - -import ( - "github.com/spf13/cobra" - "go.uber.org/zap" - - "github.com/percona/percona-everest-cli/commands/provision" -) - -func newProvisionCmd(l *zap.SugaredLogger) *cobra.Command { //nolint:deadcode,unused - cmd := &cobra.Command{ - Use: "provision", - } - - cmd.AddCommand(provision.NewMySQLCmd(l)) - - return cmd -} diff --git a/commands/provision/mysql.go b/commands/provision/mysql.go deleted file mode 100644 index 497a7a93..00000000 --- a/commands/provision/mysql.go +++ /dev/null @@ -1,99 +0,0 @@ -// percona-everest-cli -// Copyright (C) 2023 Percona LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// 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 provision provides provision sub-commands. -package provision - -import ( - "fmt" - "os" - - "github.com/percona/percona-everest-backend/client" - "github.com/spf13/cobra" - "github.com/spf13/viper" - "go.uber.org/zap" - - everestClient "github.com/percona/percona-everest-cli/pkg/everest/client" - "github.com/percona/percona-everest-cli/pkg/output" - "github.com/percona/percona-everest-cli/pkg/provision" -) - -// NewMySQLCmd returns a new MySQL command. -func NewMySQLCmd(l *zap.SugaredLogger) *cobra.Command { - cmd := &cobra.Command{ - Use: "mysql", - Run: func(cmd *cobra.Command, args []string) { - initMySQLViperFlags(cmd) - - c, err := parseMySQLConfig() - if err != nil { - os.Exit(1) - } - - everestCl, err := client.NewClient(fmt.Sprintf("%s/v1", c.Everest.Endpoint)) - if err != nil { - l.Error(err) - os.Exit(1) - } - - everestClConnector := everestClient.NewEverest(everestCl) - command := provision.NewMySQL(*c, everestClConnector, l) - - if err := command.Run(cmd.Context()); err != nil { - output.PrintError(err, l) - os.Exit(1) - } - }, - } - - initMySQLFlags(cmd) - - return cmd -} - -func initMySQLFlags(cmd *cobra.Command) { - cmd.Flags().String("name", "", "Cluster name") - cmd.MarkFlagRequired("name") //nolint:errcheck,gosec - cmd.Flags().String("everest.endpoint", "http://127.0.0.1:8080", "Everest endpoint URL") - - cmd.Flags().String("db.version", "latest", "MySQL version") - - cmd.Flags().Int("nodes", 1, "Number of cluster nodes") - cmd.Flags().String("cpu", "1", "CPUs to assign to the cluster") - cmd.Flags().String("memory", "2G", "Memory to assign to the cluster (4G, 512M, etc.)") - cmd.Flags().String("disk", "15G", "MB of disk to assign to the cluster (8G, 500M, etc.)") - - cmd.Flags().Bool("external-access", false, "Make this cluster available outside of Kubernetes") -} - -func initMySQLViperFlags(cmd *cobra.Command) { - viper.BindPFlag("name", cmd.Flags().Lookup("name")) //nolint:errcheck,gosec - viper.BindPFlag("everest.endpoint", cmd.Flags().Lookup("everest.endpoint")) //nolint:errcheck,gosec - - viper.BindPFlag("db.version", cmd.Flags().Lookup("db.version")) //nolint:errcheck,gosec - - viper.BindPFlag("nodes", cmd.Flags().Lookup("nodes")) //nolint:errcheck,gosec - viper.BindPFlag("cpu", cmd.Flags().Lookup("cpu")) //nolint:errcheck,gosec - viper.BindPFlag("memory", cmd.Flags().Lookup("memory")) //nolint:errcheck,gosec - viper.BindPFlag("disk", cmd.Flags().Lookup("disk")) //nolint:errcheck,gosec - - viper.BindPFlag("external-access", cmd.Flags().Lookup("external-access")) //nolint:errcheck,gosec -} - -func parseMySQLConfig() (*provision.MySQLConfig, error) { - c := &provision.MySQLConfig{} - err := viper.Unmarshal(c) - return c, err -} diff --git a/commands/root.go b/commands/root.go index 7c87b2a5..6e27a6e4 100644 --- a/commands/root.go +++ b/commands/root.go @@ -37,9 +37,6 @@ func NewRootCmd(l *zap.SugaredLogger) *cobra.Command { rootCmd.PersistentFlags().Bool("json", false, "Set output type to JSON") rootCmd.AddCommand(newInstallCmd(l)) - // rootCmd.AddCommand(newProvisionCmd(l)) - // rootCmd.AddCommand(newListCmd(l)) - // rootCmd.AddCommand(newDeleteCmd(l)) rootCmd.AddCommand(newTokenCmd(l)) rootCmd.AddCommand(newVersionCmd(l)) rootCmd.AddCommand(newUpgradeCmd(l)) diff --git a/commands/token/reset.go b/commands/token/reset.go index 39dcc715..08519db8 100644 --- a/commands/token/reset.go +++ b/commands/token/reset.go @@ -23,6 +23,7 @@ import ( "github.com/spf13/viper" "go.uber.org/zap" + "github.com/percona/percona-everest-cli/pkg/install" "github.com/percona/percona-everest-cli/pkg/output" "github.com/percona/percona-everest-cli/pkg/token" ) @@ -39,6 +40,7 @@ func NewResetCmd(l *zap.SugaredLogger) *cobra.Command { os.Exit(1) } + c.Namespace = install.SystemNamespace command, err := token.NewReset(*c, l) if err != nil { output.PrintError(err, l) @@ -62,13 +64,11 @@ func NewResetCmd(l *zap.SugaredLogger) *cobra.Command { func initResetFlags(cmd *cobra.Command) { cmd.Flags().StringP("kubeconfig", "k", "~/.kube/config", "Path to a kubeconfig") - cmd.Flags().String("namespace", "percona-everest", "Namespace where Percona Everest is deployed") } func initResetViperFlags(cmd *cobra.Command) { viper.BindEnv("kubeconfig") //nolint:errcheck,gosec viper.BindPFlag("kubeconfig", cmd.Flags().Lookup("kubeconfig")) //nolint:errcheck,gosec - viper.BindPFlag("namespace", cmd.Flags().Lookup("namespace")) //nolint:errcheck,gosec } func parseResetConfig() (*token.ResetConfig, error) { diff --git a/go.mod b/go.mod index 33bb1be0..43a6db9e 100644 --- a/go.mod +++ b/go.mod @@ -10,7 +10,6 @@ require ( github.com/operator-framework/api v0.22.0 github.com/operator-framework/operator-lifecycle-manager v0.26.0 github.com/percona/everest-operator v0.6.0-dev1.0.20240207193854-cdd70b8eb1e6 - github.com/percona/percona-everest-backend v0.5.1-0.20240205094045-e23451782e1a github.com/spf13/cobra v1.8.0 github.com/spf13/viper v1.18.2 github.com/stretchr/testify v1.8.4 @@ -33,7 +32,6 @@ require ( github.com/Azure/azure-sdk-for-go/sdk/internal v1.5.1 // indirect github.com/Azure/azure-sdk-for-go/sdk/storage/azblob v1.2.1 // indirect github.com/antlr/antlr4/runtime/Go/antlr/v4 v4.0.0-20230305170008-8188dc5388df // indirect - github.com/apapsch/go-jsonmerge/v2 v2.0.0 // indirect github.com/aws/aws-sdk-go v1.50.9 // indirect github.com/blang/semver/v4 v4.0.0 // indirect github.com/bshuster-repo/logrus-logstash-hook v1.0.0 // indirect @@ -45,7 +43,6 @@ require ( github.com/evanphx/json-patch/v5 v5.7.0 // indirect github.com/flosch/pongo2/v6 v6.0.0 // indirect github.com/fsnotify/fsnotify v1.7.0 // indirect - github.com/getkin/kin-openapi v0.123.0 // indirect github.com/go-errors/errors v1.5.0 // indirect github.com/go-ini/ini v1.67.0 // indirect github.com/go-logr/logr v1.3.0 // indirect @@ -64,13 +61,13 @@ require ( github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 // indirect github.com/google/uuid v1.6.0 // indirect github.com/gorilla/handlers v1.5.1 // indirect + github.com/gorilla/mux v1.8.1 // indirect github.com/gorilla/websocket v1.5.0 // indirect github.com/h2non/filetype v1.1.1 // indirect github.com/h2non/go-is-svg v0.0.0-20160927212452-35e8c4b0612c // indirect github.com/hashicorp/hcl v1.0.1-vault-5 // indirect github.com/imdario/mergo v0.3.16 // indirect github.com/inconshreveable/mousetrap v1.1.0 // indirect - github.com/invopop/yaml v0.2.0 // indirect github.com/jessevdk/go-flags v1.5.0 // indirect github.com/jmespath/go-jmespath v0.4.0 // indirect github.com/josharian/intern v1.0.0 // indirect @@ -89,13 +86,11 @@ require ( github.com/moby/spdystream v0.2.0 // indirect github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect github.com/modern-go/reflect2 v1.0.2 // indirect - github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 // indirect github.com/mongodb/mongo-tools v0.0.0-20230720205640-fb74684da15f // indirect github.com/monochromegane/go-gitignore v0.0.0-20200626010858-205db1a8cc00 // indirect github.com/montanaflynn/stats v0.6.6 // indirect github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect github.com/mxk/go-flowrate v0.0.0-20140419014527-cca7078d478f // indirect - github.com/oapi-codegen/runtime v1.1.1 // indirect github.com/onsi/gomega v1.30.0 // indirect github.com/operator-framework/operator-registry v1.30.1 // indirect github.com/pelletier/go-toml/v2 v2.1.0 // indirect @@ -103,12 +98,12 @@ require ( github.com/percona/percona-postgresql-operator v0.0.0-20231220140959-ad5eef722609 // indirect github.com/percona/percona-server-mongodb-operator v1.15.0 // indirect github.com/percona/percona-xtradb-cluster-operator v1.13.0 // indirect - github.com/perimeterx/marshmallow v1.1.5 // indirect github.com/phayes/freeport v0.0.0-20220201140144-74d24b5ae9f5 // indirect github.com/pierrec/lz4 v2.6.1+incompatible // indirect github.com/pkg/errors v0.9.1 // indirect github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect github.com/prometheus/procfs v0.11.1 // indirect + github.com/rogpeppe/go-internal v1.12.0 // indirect github.com/sagikazarmark/locafero v0.4.0 // indirect github.com/sagikazarmark/slog-shim v0.1.0 // indirect github.com/sirupsen/logrus v1.9.3 // indirect @@ -119,7 +114,6 @@ require ( github.com/stoewer/go-strcase v1.2.0 // indirect github.com/stretchr/objx v0.5.0 // indirect github.com/subosito/gotenv v1.6.0 // indirect - github.com/ugorji/go/codec v1.2.12 // indirect github.com/xdg-go/pbkdf2 v1.0.0 // indirect github.com/xdg-go/scram v1.1.2 // indirect github.com/xdg-go/stringprep v1.0.4 // indirect diff --git a/go.sum b/go.sum index fd751f79..d581fe5c 100644 --- a/go.sum +++ b/go.sum @@ -42,7 +42,6 @@ github.com/PuerkitoBio/purell v1.1.0/go.mod h1:c11w/QuzBsJSee3cPx9rAFu61PvFxuPbt github.com/PuerkitoBio/purell v1.1.1/go.mod h1:c11w/QuzBsJSee3cPx9rAFu61PvFxuPbtSwDGJws/X0= github.com/PuerkitoBio/urlesc v0.0.0-20160726150825-5bd2802263f2/go.mod h1:uGdkoq3SwY9Y+13GIhn11/XLaGBb4BfwItxLd5jeuXE= github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578/go.mod h1:uGdkoq3SwY9Y+13GIhn11/XLaGBb4BfwItxLd5jeuXE= -github.com/RaveNoX/go-jsoncommentstrip v1.0.0/go.mod h1:78ihd09MekBnJnxpICcwzCMzGrKSKYe4AqU6PDYYpjk= github.com/Shopify/logrus-bugsnag v0.0.0-20171204204709-577dee27f20d h1:UrqY+r/OJnIp5u0s1SbQ8dVfLCZJsnvazdBP5hS4iRs= github.com/Shopify/logrus-bugsnag v0.0.0-20171204204709-577dee27f20d/go.mod h1:HI8ITrYtUY+O+ZhtlqUnD8+KwNPOyugEhfP9fdUIaEQ= github.com/adrg/xdg v0.4.0 h1:RzRqFcjH4nE5C6oTAxhBtoE2IRyjBSa62SCbyPidvls= @@ -54,8 +53,6 @@ github.com/alessio/shellescape v1.2.2/go.mod h1:PZAiSCk0LJaZkiCSkPv8qIobYglO3FPp github.com/andreyvit/diff v0.0.0-20170406064948-c7f18ee00883/go.mod h1:rCTlJbsFo29Kk6CurOXKm700vrz8f0KW0JNfpkRJY/8= github.com/antlr/antlr4/runtime/Go/antlr/v4 v4.0.0-20230305170008-8188dc5388df h1:7RFfzj4SSt6nnvCPbCqijJi1nWCd+TqAT3bYCStRC18= github.com/antlr/antlr4/runtime/Go/antlr/v4 v4.0.0-20230305170008-8188dc5388df/go.mod h1:pSwJ0fSY5KhvocuWSx4fz3BA8OrA1bQn+K1Eli3BRwM= -github.com/apapsch/go-jsonmerge/v2 v2.0.0 h1:axGnT1gRIfimI7gJifB699GoE/oq+F2MU7Dml6nw9rQ= -github.com/apapsch/go-jsonmerge/v2 v2.0.0/go.mod h1:lvDnEdqiQrp0O42VQGgmlKpxL1AP2+08jFMw88y4klk= github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8= github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5 h1:0CwZNZbxp69SHPdPJAN/hZIm0C4OItdklCFmMRWYpio= github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5/go.mod h1:wHh0iHkYZB8zMSxRWpUBQtwG5a7fFgvEO+odwuTv2gs= @@ -73,7 +70,6 @@ github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kB github.com/blang/semver v3.5.0+incompatible/go.mod h1:kRBLl5iJ+tD4TcOOxsy/0fnwebNt5EWlYSAyrTnjyyk= github.com/blang/semver/v4 v4.0.0 h1:1PFHFE6yCCTv8C1TeyNNarDzntLi7wMI5i/pzqYIsAM= github.com/blang/semver/v4 v4.0.0/go.mod h1:IbckMUScFkM3pff0VJDNKRiT6TG/YpiHIM2yvyW5YoQ= -github.com/bmatcuk/doublestar v1.1.1/go.mod h1:UD6OnuiIn0yFxxA2le/rnRU1G4RaI4UvFv1sNto9p6w= github.com/bshuster-repo/logrus-logstash-hook v1.0.0 h1:e+C0SB5R1pu//O4MQ3f9cFuPGoOVeF2fE4Og9otCc70= github.com/bshuster-repo/logrus-logstash-hook v1.0.0/go.mod h1:zsTqEiSzDgAa/8GZR7E1qaXrhYNDKBYy5/dWPTIflbk= github.com/bugsnag/bugsnag-go v1.5.3 h1:yeRUT3mUE13jL1tGwvoQsKdVbAsQx9AJ+fqahKveP04= @@ -186,8 +182,6 @@ github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nos github.com/fsnotify/fsnotify v1.7.0/go.mod h1:40Bi/Hjc2AVfZrqy+aj+yEI+/bRxZnMJyTJwOpGvigM= github.com/garyburd/redigo v1.6.0 h1:0VruCpn7yAIIu7pWVClQC8wxCJEcG3nyzpMSHKi1PQc= github.com/garyburd/redigo v1.6.0/go.mod h1:NR3MbYisc3/PwhQ00EMzDiPmrwpPxAn5GI05/YaO1SY= -github.com/getkin/kin-openapi v0.123.0 h1:zIik0mRwFNLyvtXK274Q6ut+dPh6nlxBp0x7mNrPhs8= -github.com/getkin/kin-openapi v0.123.0/go.mod h1:wb1aSZA/iWmorQP9KTAS/phLj/t17B5jT7+fS8ed9NM= github.com/ghodss/yaml v0.0.0-20150909031657-73d445a93680/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= github.com/ghodss/yaml v1.0.0 h1:wQHKEahhL6wmXdzwWG11gIVCkOv05bNOh+Rxn0yngAk= github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= @@ -264,8 +258,6 @@ github.com/go-sql-driver/mysql v1.7.1/go.mod h1:OXbVy3sEdcQ2Doequ6Z5BW6fXNQTmx+9 github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 h1:tfuBGBXKqDEevZMzYi5KSi8KkcZtzBcTgAUUtapy0OI= github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572/go.mod h1:9Pwr4B2jHnOSGXyyzV8ROjYa2ojvAY6HCGYYfMoC3Ls= -github.com/go-test/deep v1.1.0 h1:WOcxcdHcvdgThNXjw0t76K42FXTU7HpNQWHpA2HHNlg= -github.com/go-test/deep v1.1.0/go.mod h1:5C2ZWiW0ErCdrYzpqxLbTX7MG14M9iiw8DgHncVwcsE= github.com/gobuffalo/flect v0.2.0/go.mod h1:W3K3X9ksuZfir8f/LrfVtWmCDQFfayuylOJ7sz/Fj80= github.com/gofrs/uuid v3.3.0+incompatible h1:8K4tyRfvU1CYPgJsveYFQMhpFd/wXNM7iK6rR7UHz84= github.com/gofrs/uuid v3.3.0+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRxnplIgP/c0N/04lM= @@ -274,7 +266,6 @@ github.com/gogo/protobuf v1.2.1/go.mod h1:hp+jE20tsWTFYpLwKvXlhS1hjn+gTNwPg2I6zV github.com/gogo/protobuf v1.3.1/go.mod h1:SlYgWuQ5SjCEi6WLHjHCa1yvBfUnHcTbrrZtXPKa29o= github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q= github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q= -github.com/golang-jwt/jwt v3.2.2+incompatible h1:IfV12K8xAKAnZqdXVzCZ+TOjboZ2keLg81eXfW3O+oY= github.com/golang-jwt/jwt/v5 v5.0.0 h1:1n1XNM9hk7O9mnQoNBGolZvzebBQ7p93ULHRc28XJUE= github.com/golang-jwt/jwt/v5 v5.0.0/go.mod h1:pqrtFR0X4osieyHYxtmOUWsAWrfe1Q5UVIyoH402zdk= github.com/golang-migrate/migrate/v4 v4.16.1 h1:O+0C55RbMN66pWm5MjO6mw0px6usGpY0+bkSGW9zCo0= @@ -382,8 +373,6 @@ github.com/imdario/mergo v0.3.16/go.mod h1:WBLT9ZmE3lPoWsEzCh9LPo3TiwVN+ZKEjmz+h github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8= github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8= github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw= -github.com/invopop/yaml v0.2.0 h1:7zky/qH+O0DwAyoobXUqvVBwgBFRxKoQ/3FjcVpjTMY= -github.com/invopop/yaml v0.2.0/go.mod h1:2XuRLgs/ouIrW3XNzuNj7J3Nvu/Dig5MXvbCEdiBN3Q= github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI= github.com/jessevdk/go-flags v1.5.0 h1:1jKYvbxEjfUl0fmqTCOfonvskHHXMjBySTLW4y9LFvc= github.com/jessevdk/go-flags v1.5.0/go.mod h1:Fw0T6WPc1dYxT4mKEZRfG5kJhaTDP9pj1c2EWnYs/m4= @@ -403,7 +392,6 @@ github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHm github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU= github.com/jtolds/gls v4.20.0+incompatible h1:xdiiI2gbIgH/gLH7ADydsJ1uDOEzR8yvV7C0MuV77Wo= github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU= -github.com/juju/gnuflag v0.0.0-20171113085948-2ce1bb71843d/go.mod h1:2PavIy+JPciBPrBUjwbNvtwB6RQlve+hkpll6QSNmOE= github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w= github.com/kardianos/osext v0.0.0-20190222173326-2bc1f35cddc0 h1:iQTw/8FWTuc7uiaSepXwyf3o52HaUYcV+Tu66S3F5GA= github.com/kardianos/osext v0.0.0-20190222173326-2bc1f35cddc0/go.mod h1:1NbS8ALrpOvjt0rHPNLyCIeMtbizbir8U//inJ+zuB8= @@ -485,8 +473,6 @@ github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lN github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M= github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk= -github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 h1:RWengNIwukTxcDr9M+97sNutRR1RKhG96O6jWumTTnw= -github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826/go.mod h1:TaXosZuwdSHYgviHp1DAtfrULt5eUgsSMsZf+YrPgl8= github.com/mongodb/mongo-tools v0.0.0-20230720205640-fb74684da15f h1:vrP8tGvlgFyelOah/ndZgZfia5fXbNVIb37ldYYg+OM= github.com/mongodb/mongo-tools v0.0.0-20230720205640-fb74684da15f/go.mod h1:FjrtGjfqHbUZEkbw0lZ+GB/3rqQsZM9KCFYnO8xx2cU= github.com/monochromegane/go-gitignore v0.0.0-20200626010858-205db1a8cc00 h1:n6/2gBQ3RWajuToeY6ZtZTIKv2v7ThUy5KKusIT0yc0= @@ -503,8 +489,6 @@ github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRW github.com/mxk/go-flowrate v0.0.0-20140419014527-cca7078d478f h1:y5//uYreIhSUg3J1GEMiLbxo1LJaP8RfCpH6pymGZus= github.com/mxk/go-flowrate v0.0.0-20140419014527-cca7078d478f/go.mod h1:ZdcZmHo+o7JKHSa8/e818NopupXU1YMK5fe1lsApnBw= github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A= -github.com/oapi-codegen/runtime v1.1.1 h1:EXLHh0DXIJnWhdRPN2w4MXAzFyE4CskzhNLUmtpMYro= -github.com/oapi-codegen/runtime v1.1.1/go.mod h1:SK9X900oXmPWilYR5/WKPzt3Kqxn/uS/+lbpREv+eCg= github.com/oklog/ulid v1.3.1/go.mod h1:CirwcVhetQ6Lv90oh/F+FBtV6XMibvdAFo93nm5qn4U= github.com/olekukonko/tablewriter v0.0.0-20170122224234-a0225b3f23b5/go.mod h1:vsDQFd/mU46D+Z4whnwzcISnGGzXWMclvtLoiIKAKIo= github.com/onsi/ginkgo v0.0.0-20170829012221-11459a886d9c/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= @@ -543,16 +527,12 @@ github.com/percona/everest-operator v0.6.0-dev1.0.20240207193854-cdd70b8eb1e6 h1 github.com/percona/everest-operator v0.6.0-dev1.0.20240207193854-cdd70b8eb1e6/go.mod h1:45pGpvWrPy495qiQqxNuOJor4wif+vTTTJP4Qee8qZk= github.com/percona/percona-backup-mongodb v1.8.1-0.20230920143330-3b1c2e263901 h1:BDgsZRCjEuxl2/z4yWBqB0s8d20shuIDks7/RVdZiLs= github.com/percona/percona-backup-mongodb v1.8.1-0.20230920143330-3b1c2e263901/go.mod h1:fZRCMpUqkWlLVdRKqqaj001LoVP2eo6F0ZhoMPeXDng= -github.com/percona/percona-everest-backend v0.5.1-0.20240205094045-e23451782e1a h1:2CZcbM4NWnKq3/gE5OySzKMiJhjMwARa6tegJ2XIT48= -github.com/percona/percona-everest-backend v0.5.1-0.20240205094045-e23451782e1a/go.mod h1:Ql0t0eWcZV17MUTse4YYZIgXrSbLom8C96z30/bnyj0= github.com/percona/percona-postgresql-operator v0.0.0-20231220140959-ad5eef722609 h1:+UOK4gcHrRgqjo4smgfwT7/0apF6PhAJdQIdAV4ub/M= github.com/percona/percona-postgresql-operator v0.0.0-20231220140959-ad5eef722609/go.mod h1:znzhtSTF6moUOGNPzVpgfFEMaqIe/ijTSHY8BNDkiEA= github.com/percona/percona-server-mongodb-operator v1.15.0 h1:pcP9GMi9f05VFi8e/TQifBrR+cvOkYMiv1xAftkESBs= github.com/percona/percona-server-mongodb-operator v1.15.0/go.mod h1:D4HOWd6TXRg3kfJ3sgm1LkbMe0QheueGtGCyiUflwlE= github.com/percona/percona-xtradb-cluster-operator v1.13.0 h1:KhXkjK3hRCLdEtbcuc9ynKiY7fJ1IxRqZTLgd6R6xz0= github.com/percona/percona-xtradb-cluster-operator v1.13.0/go.mod h1:EuEh2c3STNlMTvuEMGeAkM6eDhKiIT5wtfcxBZLSjiA= -github.com/perimeterx/marshmallow v1.1.5 h1:a2LALqQ1BlHM8PZblsDdidgv1mWi1DgC2UmX50IvK2s= -github.com/perimeterx/marshmallow v1.1.5/go.mod h1:dsXbUu8CRzfYP5a87xpp0xq9S3u0Vchtcl8we9tYaXw= github.com/peterbourgon/diskv v2.0.1+incompatible/go.mod h1:uqqh8zWWbv1HBMNONnaR/tNboyR3/BZd58JJSHlUSCU= github.com/phayes/freeport v0.0.0-20220201140144-74d24b5ae9f5 h1:Ii+DKncOVM8Cu1Hc+ETb5K+23HdAMvESYE3ZJ5b5cMI= github.com/phayes/freeport v0.0.0-20220201140144-74d24b5ae9f5/go.mod h1:iIss55rKnNBTvrwdmkUpLnDpZoAHvWaiq5+iMmen4AE= @@ -639,7 +619,6 @@ github.com/spf13/viper v1.3.2/go.mod h1:ZiWeW+zYFKm7srdB9IoDzzZXaJaI5eL9QjNiN/DM github.com/spf13/viper v1.4.0/go.mod h1:PTJ7Z/lr49W6bUbkmS1V3by4uWynFiR9p7+dSq/yZzE= github.com/spf13/viper v1.18.2 h1:LUXCnvUvSM6FXAsj6nnfc8Q2tp1dIgUfY9Kc8GsSOiQ= github.com/spf13/viper v1.18.2/go.mod h1:EKmWIqdnk5lOcmR72yw6hS+8OPYcwD0jteitLMVB+yk= -github.com/spkg/bom v0.0.0-20160624110644-59b7046e48ad/go.mod h1:qLr4V1qq6nMqFKkMo8ZTx3f+BZEkzsRUY10Xsm2mwU0= github.com/stoewer/go-strcase v1.2.0 h1:Z2iHWqGXH00XYgqDmNgQbIBxf3wrNq0F3feEy0ainaU= github.com/stoewer/go-strcase v1.2.0/go.mod h1:IBiWB2sKIp3wVVQ3Y035++gc+knqhUQag1KpM8ahLw8= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= @@ -666,8 +645,6 @@ github.com/tmc/grpc-websocket-proxy v0.0.0-20170815181823-89b8d40f7ca8/go.mod h1 github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U= github.com/ugorji/go v1.1.4/go.mod h1:uQMGLiO92mf5W77hV/PUCpI3pbzQx3CRekS0kk+RGrc= github.com/ugorji/go/codec v0.0.0-20181204163529-d75b2dcb6bc8/go.mod h1:VFNgLljTbGfSG7qAOspJ7OScBnGdDN/yBr0sguwnwf0= -github.com/ugorji/go/codec v1.2.12 h1:9LC83zGrHhuUA9l16C9AHXAqEV/2wBQ4nkvumAE65EE= -github.com/ugorji/go/codec v1.2.12/go.mod h1:UNopzCgEMSXjBc6AOMqYvWC1ktqTAfzJZUZgYf6w6lg= github.com/urfave/cli v1.20.0/go.mod h1:70zkFmudgCuE/ngEzBv17Jvp/497gISqfk5gWijbERA= github.com/vektah/gqlparser v1.1.2/go.mod h1:1ycwN7Ij5njmMkPPAOaRFY4rET2Enx7IkVv3vaXspKw= github.com/xdg-go/pbkdf2 v1.0.0 h1:Su7DPu48wXMwC3bs7MCNG+z4FhcyEuz5dlvchbq0B0c= @@ -949,7 +926,6 @@ gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= gopkg.in/yaml.v3 v3.0.0-20190905181640-827449938966/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.0-20200121175148-a6ecf24a6d71/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= -gopkg.in/yaml.v3 v3.0.0/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gotest.tools v2.2.0+incompatible h1:VsBPFP1AI068pPrMxtb/S8Zkgf9xEmTLJjfM+P5UIEo= diff --git a/pkg/delete/deps.go b/pkg/delete/deps.go deleted file mode 100644 index b0a6fe10..00000000 --- a/pkg/delete/deps.go +++ /dev/null @@ -1,30 +0,0 @@ -// percona-everest-cli -// Copyright (C) 2023 Percona LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// 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 delete deletes database clusters. -package delete //nolint:predeclared - -import ( - "context" - - "github.com/percona/percona-everest-backend/client" -) - -type everestClientConnector interface { - DeleteDBCluster( - ctx context.Context, - name string, - ) (*client.IoK8sApimachineryPkgApisMetaV1StatusV2, error) -} diff --git a/pkg/delete/mysql.go b/pkg/delete/mysql.go deleted file mode 100644 index 022cb3e5..00000000 --- a/pkg/delete/mysql.go +++ /dev/null @@ -1,85 +0,0 @@ -// percona-everest-cli -// Copyright (C) 2023 Percona LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// 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 delete ... -package delete //nolint:predeclared - -import ( - "context" - "fmt" - - "github.com/AlecAivazis/survey/v2" - "go.uber.org/zap" -) - -// MySQL implements logic for the MySQL command. -type MySQL struct { - config MySQLConfig - everestClient everestClientConnector - l *zap.SugaredLogger -} - -// MySQLConfig stores configuration for the MySQL command. -type MySQLConfig struct { - Name string - - Everest struct { - // Endpoint stores URL to Everest. - Endpoint string - } - - // Force is true when we shall not prompt for removal. - Force bool -} - -// NewMySQL returns a new MySQL struct. -func NewMySQL(c MySQLConfig, everestClient everestClientConnector, l *zap.SugaredLogger) *MySQL { - cli := &MySQL{ - config: c, - everestClient: everestClient, - l: l.With("component", "delete/mysql"), - } - - return cli -} - -// Run runs the MySQL command. -func (m *MySQL) Run(ctx context.Context) error { - if !m.config.Force { - confirm := &survey.Confirm{ - Message: fmt.Sprintf("Are you sure you want to remove the %q database cluster?", m.config.Name), - } - prompt := false - err := survey.AskOne(confirm, &prompt) - if err != nil { - return err - } - - if !prompt { - m.l.Info("Exiting") - return nil - } - } - - m.l.Infof("Deleting %q cluster", m.config.Name) - _, err := m.everestClient.DeleteDBCluster(ctx, m.config.Name) - if err != nil { - return err - } - - m.l.Infof("Cluster %q successfully deleted", m.config.Name) - - return nil -} diff --git a/pkg/everest/client/backup_storage.go b/pkg/everest/client/backup_storage.go deleted file mode 100644 index a15fb346..00000000 --- a/pkg/everest/client/backup_storage.go +++ /dev/null @@ -1,41 +0,0 @@ -// percona-everest-cli -// Copyright (C) 2023 Percona LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// 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 client ... -package client - -import ( - "context" - "errors" - - "github.com/percona/percona-everest-backend/client" -) - -// CreateBackupStorage creates a new backup storage. -func (e *Everest) CreateBackupStorage( - ctx context.Context, - body client.CreateBackupStorageJSONRequestBody, -) (*client.BackupStorage, error) { - res := &client.BackupStorage{} - err := makeRequest( - ctx, e.cl.CreateBackupStorage, - body, res, errors.New("cannot create backup storage due to Everest error"), - ) - if err != nil { - return nil, err - } - - return res, nil -} diff --git a/pkg/everest/client/client.go b/pkg/everest/client/client.go deleted file mode 100644 index d77a9bee..00000000 --- a/pkg/everest/client/client.go +++ /dev/null @@ -1,110 +0,0 @@ -// percona-everest-cli -// Copyright (C) 2023 Percona LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// 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 client provides helpers to communicate with Everest API -package client - -import ( - "context" - "encoding/json" - "errors" - "fmt" - "io" - "net/http" - "net/url" - - "github.com/percona/percona-everest-backend/client" -) - -// Everest is a connector to the Everest API. -type Everest struct { - cl *client.Client -} - -// ErrEverest is an error coming from Everest where Everest provided an error message. -var ErrEverest = errors.New("") - -// NewEverest returns new Everest. -func NewEverest(everestClient *client.Client) *Everest { - return &Everest{ - cl: everestClient, - } -} - -// NewEverestFromURL returns a new Everest from a provided URL. -func NewEverestFromURL(rawURL, everestPwd string) (*Everest, error) { - u, err := url.Parse(rawURL) - if err != nil { - return nil, errors.Join(err, errors.New("could not parse Everest URL")) - } - everestCl, err := client.NewClient( - u.JoinPath("v1").String(), - client.WithRequestEditorFn(func(ctx context.Context, req *http.Request) error { - req.Header.Set("Cookie", fmt.Sprintf("everest_token=%s", everestPwd)) - return nil - }), - ) - if err != nil { - return nil, errors.Join(err, errors.New("could not initialize Everest client")) - } - return NewEverest(everestCl), nil -} - -// makeRequest calls arbitrary *client.Client method for API call and applies common logic for response handling. -// See methods in Everest struct for examples how to call. -func makeRequest[B interface{}, R interface{}]( - ctx context.Context, - fn func(context.Context, B, ...client.RequestEditorFn) (*http.Response, error), - body B, - ret R, - errorStatus error, -) error { - res, err := fn(ctx, body) - if err != nil { - return err - } - defer res.Body.Close() //nolint:errcheck - - if res.StatusCode < http.StatusOK || res.StatusCode >= http.StatusMultipleChoices { - return processErrorResponse(res, errorStatus) - } - err = json.NewDecoder(res.Body).Decode(ret) - if errors.Is(err, io.EOF) { - // In case the server returns no content, such as with the DELETE method, - // don't return an error. - return nil - } - - return err -} - -func processErrorResponse(res *http.Response, err error) error { - errMsg := client.Error{} - if err := json.NewDecoder(res.Body).Decode(&errMsg); err != nil { - return errors.Join(err, fmt.Errorf("could not decode Everest error response (status %d)", res.StatusCode)) - } - - msg := fmt.Sprintf("unknown error (status %d)", res.StatusCode) - if errMsg.Message != nil { - msg = fmt.Sprintf("%s (status %d)", *errMsg.Message, res.StatusCode) - return fmt.Errorf("%w%s: %w", ErrEverest, msg, err) - } - - if err != nil { - return errors.Join(err, errors.New(msg)) - } - - return errors.New("generic response error") -} diff --git a/pkg/everest/client/database_cluster.go b/pkg/everest/client/database_cluster.go deleted file mode 100644 index 36658373..00000000 --- a/pkg/everest/client/database_cluster.go +++ /dev/null @@ -1,73 +0,0 @@ -// percona-everest-cli -// Copyright (C) 2023 Percona LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// 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 client ... -package client - -import ( - "context" - "errors" - "net/http" - - "github.com/percona/percona-everest-backend/client" -) - -// CreateDBCluster creates a new database cluster. -func (e *Everest) CreateDBCluster( - ctx context.Context, - body client.CreateDatabaseClusterJSONRequestBody, -) (*client.DatabaseCluster, error) { - res := &client.DatabaseCluster{} - err := makeRequest( - ctx, - func( - ctx context.Context, - body client.CreateDatabaseClusterJSONRequestBody, - r ...client.RequestEditorFn, - ) (*http.Response, error) { - return e.cl.CreateDatabaseCluster(ctx, body, r...) - }, - body, res, errors.New("cannot create database cluster due to Everest error"), - ) - if err != nil { - return nil, err - } - - return res, nil -} - -// DeleteDBCluster deletes a database cluster. -func (e *Everest) DeleteDBCluster( - ctx context.Context, - name string, -) (*client.IoK8sApimachineryPkgApisMetaV1StatusV2, error) { - res := &client.IoK8sApimachineryPkgApisMetaV1StatusV2{} - err := makeRequest( - ctx, - func( - ctx context.Context, - _ struct{}, - r ...client.RequestEditorFn, - ) (*http.Response, error) { - return e.cl.DeleteDatabaseCluster(ctx, name, r...) - }, - struct{}{}, res, errors.New("cannot delete database cluster due to Everest error"), - ) - if err != nil { - return nil, err - } - - return res, nil -} diff --git a/pkg/everest/client/database_engine.go b/pkg/everest/client/database_engine.go deleted file mode 100644 index 1a4a0929..00000000 --- a/pkg/everest/client/database_engine.go +++ /dev/null @@ -1,42 +0,0 @@ -// percona-everest-cli -// Copyright (C) 2023 Percona LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// 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 client ... -package client - -import ( - "context" - "encoding/json" - "errors" - "net/http" - - "github.com/percona/percona-everest-backend/client" -) - -// ListDatabaseEngines lists database engines. -func (e *Everest) ListDatabaseEngines(ctx context.Context) (*client.DatabaseEngineList, error) { - ret := &client.DatabaseEngineList{} - res, err := e.cl.ListDatabaseEngines(ctx) - if err != nil { - return ret, errors.Join(err, errors.New("cannot list database engines due to Everest error")) - } - defer res.Body.Close() //nolint:errcheck - - if res.StatusCode < http.StatusOK || res.StatusCode >= http.StatusMultipleChoices { - return ret, processErrorResponse(res, errors.New("cannot list database engines due to Everest error")) - } - err = json.NewDecoder(res.Body).Decode(ret) - return ret, err -} diff --git a/pkg/everest/client/kubernetes.go b/pkg/everest/client/kubernetes.go deleted file mode 100644 index b57c799a..00000000 --- a/pkg/everest/client/kubernetes.go +++ /dev/null @@ -1,37 +0,0 @@ -// percona-everest-cli -// Copyright (C) 2023 Percona LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// 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 client ... -package client - -import ( - "context" - "errors" - - "github.com/percona/percona-everest-backend/client" -) - -// SetKubernetesClusterMonitoring configures Kubernetes cluster monitoring. -func (e *Everest) SetKubernetesClusterMonitoring( - ctx context.Context, - body client.SetKubernetesClusterMonitoringJSONRequestBody, -) error { - res := &struct{}{} - err := makeRequest( - ctx, e.cl.SetKubernetesClusterMonitoring, - body, res, errors.New("cannot configure Kubernetes cluster monitoring due to Everest error"), - ) - return err -} diff --git a/pkg/everest/client/monitoring_instance.go b/pkg/everest/client/monitoring_instance.go deleted file mode 100644 index b1c161e8..00000000 --- a/pkg/everest/client/monitoring_instance.go +++ /dev/null @@ -1,76 +0,0 @@ -// percona-everest-cli -// Copyright (C) 2023 Percona LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// 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 client ... -package client - -import ( - "context" - "errors" - "net/http" - - "github.com/percona/percona-everest-backend/client" -) - -// CreateMonitoringInstance creates a new monitoring instance. -func (e *Everest) CreateMonitoringInstance( - ctx context.Context, - body client.CreateMonitoringInstanceJSONRequestBody, -) (*client.MonitoringInstance, error) { - res := &client.MonitoringInstance{} - err := makeRequest( - ctx, e.cl.CreateMonitoringInstance, - body, res, errors.New("cannot create monitoring instance due to Everest error"), - ) - if err != nil { - return nil, err - } - - return res, nil -} - -// GetMonitoringInstance retrieves a monitoring instance by its name. -func (e *Everest) GetMonitoringInstance(ctx context.Context, name string) (*client.MonitoringInstance, error) { - res := &client.MonitoringInstance{} - err := makeRequest( - ctx, e.cl.GetMonitoringInstance, - name, res, errors.New("cannot retrieve monitoring instance due to Everest error"), - ) - if err != nil { - return nil, err - } - - return res, nil -} - -// ListMonitoringInstances lists monitoring instances. -func (e *Everest) ListMonitoringInstances(ctx context.Context) ([]client.MonitoringInstance, error) { - res := []client.MonitoringInstance{} - err := makeRequest( - ctx, func( - ctx context.Context, - _ struct{}, - r ...client.RequestEditorFn, - ) (*http.Response, error) { - return e.cl.ListMonitoringInstances(ctx, r...) - }, - struct{}{}, &res, errors.New("cannot list monitoring instances due to Everest error"), - ) - if err != nil { - return nil, err - } - - return res, nil -} diff --git a/pkg/list/database_engines.go b/pkg/list/database_engines.go deleted file mode 100644 index d6ecb5a3..00000000 --- a/pkg/list/database_engines.go +++ /dev/null @@ -1,107 +0,0 @@ -// percona-everest-cli -// Copyright (C) 2023 Percona LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// 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 list holds the main logic for list commands. -package list - -import ( - "context" - "fmt" - "strings" - - everestv1alpha1 "github.com/percona/everest-operator/api/v1alpha1" - "go.uber.org/zap" -) - -// DBEngines implements the main logic for commands. -type DBEngines struct { - config DBEnginesConfig - everestClient everestClientConnector - l *zap.SugaredLogger -} - -type ( - // DBEnginesConfig stores configuration for the database engines. - DBEnginesConfig struct { - Everest EverestConfig - } - - // EverestConfig stores config for Everest. - EverestConfig struct { - // Endpoint stores URL to Everest. - Endpoint string - } -) - -type ( - // DBEnginesList stores list of database engines. - DBEnginesList map[everestv1alpha1.EngineType]DBEngine - // DBEngine stores information about a database engine. - DBEngine struct { - Version string `json:"version"` - } -) - -// String returns string result of database engines list. -func (d DBEnginesList) String() string { - out := make([]string, 0, len(d)) - for engine, e := range d { - out = append(out, fmt.Sprintf("%s %s", engine, e.Version)) - } - - return strings.Join(out, "\n") -} - -// NewDatabaseEngines returns a new DBEngines struct. -func NewDatabaseEngines(c DBEnginesConfig, everestClient everestClientConnector, l *zap.SugaredLogger) *DBEngines { - cli := &DBEngines{ - config: c, - everestClient: everestClient, - l: l.With("component", "list/databaseengines"), - } - - return cli -} - -// Run runs the database engines list command. -func (d *DBEngines) Run(ctx context.Context) (DBEnginesList, error) { - dbEngines, err := d.everestClient.ListDatabaseEngines(ctx) - if err != nil { - return nil, err - } - - res := make(DBEnginesList) - - if dbEngines.Items == nil { - return res, nil - } - - for _, db := range *dbEngines.Items { - if db.Spec == nil { - continue - } - - if db.Status == nil { - continue - } - - e := everestv1alpha1.EngineType(db.Spec.Type) - res[e] = DBEngine{ - Version: *db.Status.OperatorVersion, - } - } - - return res, nil -} diff --git a/pkg/list/deps.go b/pkg/list/deps.go deleted file mode 100644 index 509d4124..00000000 --- a/pkg/list/deps.go +++ /dev/null @@ -1,27 +0,0 @@ -// percona-everest-cli -// Copyright (C) 2023 Percona LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// 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 list ... -package list - -import ( - "context" - - "github.com/percona/percona-everest-backend/client" -) - -type everestClientConnector interface { - ListDatabaseEngines(ctx context.Context) (*client.DatabaseEngineList, error) -} diff --git a/pkg/list/versions.go b/pkg/list/versions.go deleted file mode 100644 index 6785af1d..00000000 --- a/pkg/list/versions.go +++ /dev/null @@ -1,131 +0,0 @@ -// percona-everest-cli -// Copyright (C) 2023 Percona LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// 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 list holds the main logic for list commands. -package list - -import ( - "context" - "sort" - "strings" - - goversion "github.com/hashicorp/go-version" - everestv1alpha1 "github.com/percona/everest-operator/api/v1alpha1" - "github.com/percona/percona-everest-backend/client" - "go.uber.org/zap" -) - -// Versions implements the main logic for commands. -type Versions struct { - config VersionsConfig - everestClient everestClientConnector - l *zap.SugaredLogger -} - -type ( - // VersionsConfig stores configuration for the versions command. - VersionsConfig struct { - Everest EverestConfig - - // Type represents a database engine type. - Type string - } -) - -type ( - // VersionsList stores a list of versions per engine type. - VersionsList map[everestv1alpha1.EngineType]goversion.Collection -) - -// String returns string result of database engines list. -func (v VersionsList) String() string { - out := make([]string, 0, len(v)) - for engine, versions := range v { - out = append(out, "-----", string(engine), "-----") - - sort.Sort(sort.Reverse(versions)) - for _, ver := range versions { - out = append(out, ver.Original()) - } - } - - return strings.Join(out, "\n") -} - -// NewVersions returns a new Versions struct. -func NewVersions(c VersionsConfig, everestClient everestClientConnector, l *zap.SugaredLogger) *Versions { - cli := &Versions{ - config: c, - everestClient: everestClient, - l: l.With("component", "list/versions"), - } - - return cli -} - -// Run runs the versions list command. -func (v *Versions) Run(ctx context.Context) (VersionsList, error) { - dbEngines, err := v.everestClient.ListDatabaseEngines(ctx) - if err != nil { - return nil, err - } - - if dbEngines.Items == nil { - res := make(VersionsList) - return res, nil - } - - return v.parseVersions(*dbEngines.Items) -} - -func (v *Versions) parseVersions(items []client.DatabaseEngine) (VersionsList, error) { - res := make(VersionsList) - for _, db := range items { - if v.checkIfSkip(db) { - continue - } - - engineType := everestv1alpha1.EngineType(db.Spec.Type) - if _, ok := res[engineType]; !ok { - res[engineType] = make(goversion.Collection, 0, len(*db.Status.AvailableVersions.Engine)) - } - - for version := range *db.Status.AvailableVersions.Engine { - ver, err := goversion.NewVersion(version) - if err != nil { - return nil, err - } - res[engineType] = append(res[engineType], ver) - } - } - - return res, nil -} - -func (v *Versions) checkIfSkip(db client.DatabaseEngine) bool { - if db.Spec == nil { - return true - } - - if v.config.Type != "" && db.Spec.Type != v.config.Type { - return true - } - - if db.Status == nil || db.Status.AvailableVersions == nil || db.Status.AvailableVersions.Engine == nil { - return true - } - - return false -} diff --git a/pkg/output/command.go b/pkg/output/command.go index 9183b7d6..41ad646f 100644 --- a/pkg/output/command.go +++ b/pkg/output/command.go @@ -26,7 +26,6 @@ import ( "go.uber.org/zap" "github.com/percona/percona-everest-cli/commands/common" - everestClient "github.com/percona/percona-everest-cli/pkg/everest/client" ) // PrintOutput prints output as a string or json. @@ -52,12 +51,6 @@ func PrintOutput(cmd *cobra.Command, l *zap.SugaredLogger, output interface{}) { // PrintError formats and prints an error to logger. func PrintError(err error, l *zap.SugaredLogger) { - if errors.Is(err, everestClient.ErrEverest) { - l := l.WithOptions(zap.AddStacktrace(zap.DPanicLevel)) - l.Error(err) - return - } - if errors.Is(err, common.ErrExitWithError) { return } diff --git a/pkg/provision/deps.go b/pkg/provision/deps.go deleted file mode 100644 index 11a93dba..00000000 --- a/pkg/provision/deps.go +++ /dev/null @@ -1,30 +0,0 @@ -// percona-everest-cli -// Copyright (C) 2023 Percona LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// 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 provision provisions database clusters. -package provision - -import ( - "context" - - "github.com/percona/percona-everest-backend/client" -) - -type everestClientConnector interface { - CreateDBCluster( - ctx context.Context, - body client.CreateDatabaseClusterJSONRequestBody, - ) (*client.DatabaseCluster, error) -} diff --git a/pkg/provision/mysql.go b/pkg/provision/mysql.go deleted file mode 100644 index d5f26b54..00000000 --- a/pkg/provision/mysql.go +++ /dev/null @@ -1,166 +0,0 @@ -// percona-everest-cli -// Copyright (C) 2023 Percona LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// 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 provision ... -package provision - -import ( - "context" - "encoding/json" - "errors" - - everestv1alpha "github.com/percona/everest-operator/api/v1alpha1" - "github.com/percona/percona-everest-backend/client" - "go.uber.org/zap" - "k8s.io/apimachinery/pkg/api/resource" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" -) - -// MySQL implements logic for the MySQL command. -type MySQL struct { - config MySQLConfig - everestClient everestClientConnector - l *zap.SugaredLogger -} - -// MySQLConfig stores configuration for the MySQL command. -type MySQLConfig struct { - Name string - - Everest struct { - // Endpoint stores URL to Everest. - Endpoint string - } - - DB struct { - Version string - } - - Nodes int - CPU string - Memory string - Disk string - - ExternalAccess bool `mapstructure:"external-access"` -} - -// NewMySQL returns a new MySQL struct. -func NewMySQL(c MySQLConfig, everestClient everestClientConnector, l *zap.SugaredLogger) *MySQL { - cli := &MySQL{ - config: c, - everestClient: everestClient, - l: l.With("component", "provision/mysql"), - } - - return cli -} - -// Run runs the MySQL command. -func (m *MySQL) Run(ctx context.Context) error { - m.l.Info("Preparing cluster config") - body, err := m.prepareBody() - if err != nil { - return err - } - - m.l.Infof("Creating %q database cluster", m.config.Name) - _, err = m.everestClient.CreateDBCluster(ctx, *body) - if err != nil { - return err - } - - m.l.Infof("Database cluster %q has been scheduled to Kubernetes", m.config.Name) - - return nil -} - -func (m *MySQL) prepareBody() (*client.DatabaseCluster, error) { - cpu, err := resource.ParseQuantity(m.config.CPU) - if err != nil { - return nil, errors.Join(err, errors.New("cannot parse cpu")) - } - - memory, err := resource.ParseQuantity(m.config.Memory) - if err != nil { - return nil, errors.Join(err, errors.New("cannot parse memory")) - } - - disk, err := resource.ParseQuantity(m.config.Disk) - if err != nil { - return nil, errors.Join(err, errors.New("cannot parse disk storage")) - } - - replicas := int32(m.config.Nodes) - version := m.config.DB.Version - if m.config.DB.Version == "latest" { - // An empty string means the operator uses the latest version - version = "" - } - - payload := everestv1alpha.DatabaseCluster{ - TypeMeta: metav1.TypeMeta{ - APIVersion: "everest.percona.com/v1alpha1", - Kind: "DatabaseCluster", - }, - ObjectMeta: metav1.ObjectMeta{ - Name: m.config.Name, - }, - Spec: everestv1alpha.DatabaseClusterSpec{ - Engine: everestv1alpha.Engine{ - Type: everestv1alpha.DatabaseEnginePXC, - Replicas: replicas, - Version: version, - Storage: everestv1alpha.Storage{ - Size: disk, - }, - Resources: everestv1alpha.Resources{ - CPU: cpu, - Memory: memory, - }, - }, - Proxy: everestv1alpha.Proxy{ - Type: everestv1alpha.ProxyTypeHAProxy, - Replicas: &replicas, - Expose: everestv1alpha.Expose{ - Type: everestv1alpha.ExposeTypeInternal, - }, - }, - }, - } - - if m.config.ExternalAccess { - m.l.Debug("Enabling external access") - payload.Spec.Proxy.Expose.Type = everestv1alpha.ExposeTypeExternal - } - - return m.convertPayload(payload) -} - -func (m *MySQL) convertPayload(payload everestv1alpha.DatabaseCluster) (*client.DatabaseCluster, error) { - bodyJSON, err := json.Marshal(payload) - if err != nil { - return nil, errors.Join(err, errors.New("cannot marshal payload to json")) - } - - m.l.Debug(string(bodyJSON)) - - body := &client.DatabaseCluster{} - err = json.Unmarshal(bodyJSON, body) - if err != nil { - return nil, errors.Join(err, errors.New("cannot unmarshal payload back to json")) - } - - return body, nil -}