From d5c276447436792caaf3f0f25f036139076a525e Mon Sep 17 00:00:00 2001 From: Carlos Salguero Date: Thu, 26 May 2022 11:26:41 -0300 Subject: [PATCH 1/5] PMM-9965 Remove VM operator --- go.mod | 2 +- go.sum | 2 ++ services/dbaas/dbaas_client.go | 7 +++++ services/management/dbaas/deps.go | 2 ++ .../management/dbaas/kubernetes_server.go | 6 ++++ .../dbaas/kubernetes_server_test.go | 2 ++ .../dbaas/mock_dbaas_client_test.go | 30 +++++++++++++++++++ 7 files changed, 50 insertions(+), 1 deletion(-) diff --git a/go.mod b/go.mod index 8f9adca656..311e3a82cc 100644 --- a/go.mod +++ b/go.mod @@ -34,7 +34,7 @@ require ( github.com/hashicorp/go-version v1.4.0 github.com/lib/pq v1.10.6 github.com/minio/minio-go/v7 v7.0.26 - github.com/percona-platform/dbaas-api v0.0.0-20220110092915-5aacd784d472 + github.com/percona-platform/dbaas-api v0.0.0-20220525210215-cc4aa3b918e0 github.com/percona-platform/saas v0.0.0-20220427162947-f9d246ad0f16 github.com/percona/pmm v0.0.0-20220520150831-23069cdf1bb8 github.com/percona/promconfig v0.2.4-0.20211110115058-98687f586f54 diff --git a/go.sum b/go.sum index f5c3350c14..062b7b9a82 100644 --- a/go.sum +++ b/go.sum @@ -466,6 +466,8 @@ github.com/percona-lab/crypto v0.0.0-20220413143500-70ef7e9f1813 h1:Jb/t6zDMQMwt github.com/percona-lab/crypto v0.0.0-20220413143500-70ef7e9f1813/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= github.com/percona-platform/dbaas-api v0.0.0-20220110092915-5aacd784d472 h1:Henk22VMEBX2jwxAW/pHmiJ9s/w8uwRD4ErPidAS9Vs= github.com/percona-platform/dbaas-api v0.0.0-20220110092915-5aacd784d472/go.mod h1:WZZ3Hi+lAWCaGWmsrfkkvRQPkIa8n1OZ0s8Su+vbgus= +github.com/percona-platform/dbaas-api v0.0.0-20220525210215-cc4aa3b918e0 h1:R5bHvc6hHCV6bNUl26Yt8Th75ThPpv9JaWZHSLkl+0E= +github.com/percona-platform/dbaas-api v0.0.0-20220525210215-cc4aa3b918e0/go.mod h1:VsQuyV8PabFGg0gkc40vmBcnmxrkl/PCvuissmlztJM= github.com/percona-platform/saas v0.0.0-20220427162947-f9d246ad0f16 h1:0fx16uGtl4MwrBwm9/VSoNEhjL0cXYxS0quEhLthGcc= github.com/percona-platform/saas v0.0.0-20220427162947-f9d246ad0f16/go.mod h1:gFUwaFp6Ugu5qsBwiOVJYbDlzgZ77tmXdXGO7tG5xVI= github.com/percona/pmm v0.0.0-20220520150831-23069cdf1bb8 h1:P5iuV4GRUIviRg/5/FM6ZOKdiBPdwUPbrHld/epM3hk= diff --git a/services/dbaas/dbaas_client.go b/services/dbaas/dbaas_client.go index b89a723bf3..ebad7c092d 100644 --- a/services/dbaas/dbaas_client.go +++ b/services/dbaas/dbaas_client.go @@ -237,3 +237,10 @@ func (c *Client) StartMonitoring(ctx context.Context, in *controllerv1beta1.Star defer c.connM.RUnlock() return c.kubernetesClient.StartMonitoring(ctx, in, opts...) } + +// StartMonitoring sets up victoria metrics operator to monitor kubernetes cluster. +func (c *Client) StopMonitoring(ctx context.Context, in *controllerv1beta1.StopMonitoringRequest, opts ...grpc.CallOption) (*controllerv1beta1.StopMonitoringResponse, error) { + c.connM.RLock() + defer c.connM.RUnlock() + return c.kubernetesClient.StopMonitoring(ctx, in, opts...) +} diff --git a/services/management/dbaas/deps.go b/services/management/dbaas/deps.go index 25a9a18950..52d5c2a1cf 100644 --- a/services/management/dbaas/deps.go +++ b/services/management/dbaas/deps.go @@ -66,6 +66,8 @@ type dbaasClient interface { InstallPSMDBOperator(ctx context.Context, in *controllerv1beta1.InstallPSMDBOperatorRequest, opts ...grpc.CallOption) (*controllerv1beta1.InstallPSMDBOperatorResponse, error) // StartMonitoring sets up victoria metrics operator to monitor kubernetes cluster. StartMonitoring(ctx context.Context, in *controllerv1beta1.StartMonitoringRequest, opts ...grpc.CallOption) (*controllerv1beta1.StartMonitoringResponse, error) + // StopMonitoring removes victoria metrics operator from the cluster. + StopMonitoring(ctx context.Context, in *controllerv1beta1.StopMonitoringRequest, opts ...grpc.CallOption) (*controllerv1beta1.StopMonitoringResponse, error) } type versionService interface { diff --git a/services/management/dbaas/kubernetes_server.go b/services/management/dbaas/kubernetes_server.go index b00796434e..5832af6e41 100644 --- a/services/management/dbaas/kubernetes_server.go +++ b/services/management/dbaas/kubernetes_server.go @@ -357,6 +357,12 @@ func (k kubernetesServer) UnregisterKubernetesCluster(ctx context.Context, req * return models.RemoveKubernetesCluster(t.Querier, req.KubernetesClusterName) } + _, err = k.dbaasClient.StopMonitoring(ctx, &dbaascontrollerv1beta1.StopMonitoringRequest{ + KubeAuth: &dbaascontrollerv1beta1.KubeAuth{ + Kubeconfig: kubernetesCluster.KubeConfig, + }, + }) + pxcClusters, err := k.dbaasClient.ListPXCClusters(ctx, &dbaascontrollerv1beta1.ListPXCClustersRequest{ KubeAuth: &dbaascontrollerv1beta1.KubeAuth{ diff --git a/services/management/dbaas/kubernetes_server_test.go b/services/management/dbaas/kubernetes_server_test.go index 0121b4f410..3d47a6303a 100644 --- a/services/management/dbaas/kubernetes_server_test.go +++ b/services/management/dbaas/kubernetes_server_test.go @@ -76,6 +76,8 @@ func TestKubernetesServer(t *testing.T) { dc.On("InstallPXCOperator", mock.Anything, mock.Anything).Return(&controllerv1beta1.InstallPXCOperatorResponse{}, nil) + dc.On("StopMonitoring", mock.Anything, mock.Anything).Return(&controllerv1beta1.StopMonitoringResponse{}, nil) + kubernetesClusterName := "test-cluster" registerKubernetesClusterResponse, err := ks.RegisterKubernetesCluster(ctx, &dbaasv1beta1.RegisterKubernetesClusterRequest{ KubernetesClusterName: kubernetesClusterName, diff --git a/services/management/dbaas/mock_dbaas_client_test.go b/services/management/dbaas/mock_dbaas_client_test.go index 8c570cca85..515945f9de 100644 --- a/services/management/dbaas/mock_dbaas_client_test.go +++ b/services/management/dbaas/mock_dbaas_client_test.go @@ -488,6 +488,36 @@ func (_m *mockDbaasClient) StartMonitoring(ctx context.Context, in *controllerv1 return r0, r1 } +// StopMonitoring provides a mock function with given fields: ctx, in, opts +func (_m *mockDbaasClient) StopMonitoring(ctx context.Context, in *controllerv1beta1.StopMonitoringRequest, opts ...grpc.CallOption) (*controllerv1beta1.StopMonitoringResponse, error) { + _va := make([]interface{}, len(opts)) + for _i := range opts { + _va[_i] = opts[_i] + } + var _ca []interface{} + _ca = append(_ca, ctx, in) + _ca = append(_ca, _va...) + ret := _m.Called(_ca...) + + var r0 *controllerv1beta1.StopMonitoringResponse + if rf, ok := ret.Get(0).(func(context.Context, *controllerv1beta1.StopMonitoringRequest, ...grpc.CallOption) *controllerv1beta1.StopMonitoringResponse); ok { + r0 = rf(ctx, in, opts...) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*controllerv1beta1.StopMonitoringResponse) + } + } + + var r1 error + if rf, ok := ret.Get(1).(func(context.Context, *controllerv1beta1.StopMonitoringRequest, ...grpc.CallOption) error); ok { + r1 = rf(ctx, in, opts...) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + // UpdatePSMDBCluster provides a mock function with given fields: ctx, in, opts func (_m *mockDbaasClient) UpdatePSMDBCluster(ctx context.Context, in *controllerv1beta1.UpdatePSMDBClusterRequest, opts ...grpc.CallOption) (*controllerv1beta1.UpdatePSMDBClusterResponse, error) { _va := make([]interface{}, len(opts)) From b4507c7d8293c97ab3832baa5c7fc9fc02ff0fdc Mon Sep 17 00:00:00 2001 From: Carlos Salguero Date: Thu, 2 Jun 2022 07:18:11 -0300 Subject: [PATCH 2/5] Fixes for CR --- services/management/dbaas/kubernetes_server.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/services/management/dbaas/kubernetes_server.go b/services/management/dbaas/kubernetes_server.go index 5832af6e41..c18354973f 100644 --- a/services/management/dbaas/kubernetes_server.go +++ b/services/management/dbaas/kubernetes_server.go @@ -363,6 +363,10 @@ func (k kubernetesServer) UnregisterKubernetesCluster(ctx context.Context, req * }, }) + if err != nil { + return errors.Wrap(err, "cannot stop monitoring") + } + pxcClusters, err := k.dbaasClient.ListPXCClusters(ctx, &dbaascontrollerv1beta1.ListPXCClustersRequest{ KubeAuth: &dbaascontrollerv1beta1.KubeAuth{ From 2e50bd30c7c3d51a979a636478bd12d48882ad51 Mon Sep 17 00:00:00 2001 From: Carlos Salguero Date: Thu, 2 Jun 2022 07:29:34 -0300 Subject: [PATCH 3/5] Updated deps --- go.mod | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/go.mod b/go.mod index a4e892c322..23f4017024 100644 --- a/go.mod +++ b/go.mod @@ -34,7 +34,7 @@ require ( github.com/hashicorp/go-version v1.4.0 github.com/lib/pq v1.10.6 github.com/minio/minio-go/v7 v7.0.27 - github.com/percona-platform/dbaas-api v0.0.0-20220110092915-5aacd784d472 + github.com/percona-platform/dbaas-api v0.0.0-20220525210215-cc4aa3b918e0 github.com/percona-platform/saas v0.0.0-20220427162947-f9d246ad0f16 github.com/percona/pmm v0.0.0-20220520150831-23069cdf1bb8 github.com/percona/promconfig v0.2.4-0.20211110115058-98687f586f54 From 5b1e0100c5ed7a624abd7979fa4992f1a97c9cae Mon Sep 17 00:00:00 2001 From: Carlos Salguero Date: Thu, 2 Jun 2022 09:46:00 -0300 Subject: [PATCH 4/5] Stop monitoring errors are just logged Errors are just logged and won't prevent the methos execution until the end. --- services/management/dbaas/kubernetes_server.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/management/dbaas/kubernetes_server.go b/services/management/dbaas/kubernetes_server.go index c18354973f..6f4204409f 100644 --- a/services/management/dbaas/kubernetes_server.go +++ b/services/management/dbaas/kubernetes_server.go @@ -364,7 +364,7 @@ func (k kubernetesServer) UnregisterKubernetesCluster(ctx context.Context, req * }) if err != nil { - return errors.Wrap(err, "cannot stop monitoring") + k.l.Warnf("cannot stop monitoring: %s", err) } pxcClusters, err := k.dbaasClient.ListPXCClusters(ctx, From 7f1679015667aff86d5e8a8d22e5a8d6dfd5168e Mon Sep 17 00:00:00 2001 From: Carlos Salguero Date: Mon, 6 Jun 2022 08:54:22 -0300 Subject: [PATCH 5/5] Updated comment --- services/dbaas/dbaas_client.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/dbaas/dbaas_client.go b/services/dbaas/dbaas_client.go index ebad7c092d..f1e0d5486c 100644 --- a/services/dbaas/dbaas_client.go +++ b/services/dbaas/dbaas_client.go @@ -238,7 +238,7 @@ func (c *Client) StartMonitoring(ctx context.Context, in *controllerv1beta1.Star return c.kubernetesClient.StartMonitoring(ctx, in, opts...) } -// StartMonitoring sets up victoria metrics operator to monitor kubernetes cluster. +// StopMonitoring removes victoria metrics operator from the kubernetes cluster. func (c *Client) StopMonitoring(ctx context.Context, in *controllerv1beta1.StopMonitoringRequest, opts ...grpc.CallOption) (*controllerv1beta1.StopMonitoringResponse, error) { c.connM.RLock() defer c.connM.RUnlock()