From 84c5def62d8955bff08b5489a87850e81989f0f7 Mon Sep 17 00:00:00 2001 From: Oksana Grishchenko Date: Mon, 16 Oct 2023 12:22:54 +0200 Subject: [PATCH 01/10] EVEREST-504 telemetry opt-out --- pkg/kubernetes/client/client.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/pkg/kubernetes/client/client.go b/pkg/kubernetes/client/client.go index 04ef19e6..79e8cefa 100644 --- a/pkg/kubernetes/client/client.go +++ b/pkg/kubernetes/client/client.go @@ -1084,6 +1084,14 @@ func (c *Client) CreateSubscriptionForCatalog(ctx context.Context, namespace, na Channel: channel, StartingCSV: startingCSV, InstallPlanApproval: approval, + Config: &v1alpha1.SubscriptionConfig{ + Env: []corev1.EnvVar{ + { + Name: "DISABLE_TELEMETRY", + Value: "true", + }, + }, + }, }, } From 51a9bec854c499a8070faf8a678f1ba8c0a2c601 Mon Sep 17 00:00:00 2001 From: Oksana Grishchenko Date: Mon, 16 Oct 2023 14:41:17 +0200 Subject: [PATCH 02/10] EVEREST-504 patch --- pkg/kubernetes/client/client.go | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/pkg/kubernetes/client/client.go b/pkg/kubernetes/client/client.go index 79e8cefa..6a2c73ff 100644 --- a/pkg/kubernetes/client/client.go +++ b/pkg/kubernetes/client/client.go @@ -84,6 +84,8 @@ const ( defaultAPIURIPath = "/api" defaultAPIsURIPath = "/apis" + + disableTelemetryEnvVar = "DISABLE_TELEMETRY" ) // Each level has 2 spaces for PrefixWriter. @@ -1068,6 +1070,11 @@ func (c *Client) CreateSubscriptionForCatalog(ctx context.Context, namespace, na return nil, errors.Join(err, errors.New("cannot create an operator client instance")) } + disableTelemetry, ok := os.LookupEnv(disableTelemetryEnvVar) + if !ok || disableTelemetry != "true" { + disableTelemetry = "false" + } + subscription := &v1alpha1.Subscription{ TypeMeta: metav1.TypeMeta{ Kind: v1alpha1.SubscriptionKind, @@ -1087,21 +1094,30 @@ func (c *Client) CreateSubscriptionForCatalog(ctx context.Context, namespace, na Config: &v1alpha1.SubscriptionConfig{ Env: []corev1.EnvVar{ { - Name: "DISABLE_TELEMETRY", - Value: "true", + Name: disableTelemetryEnvVar, + Value: disableTelemetry, }, }, }, }, } - sub, err := operatorClient. OperatorsV1alpha1(). Subscriptions(namespace). Create(ctx, subscription, metav1.CreateOptions{}) if err != nil { if apierrors.IsAlreadyExists(err) { - return sub, nil + bytes, err := json.Marshal(subscription) + if err != nil { + return nil, err + } + + sub, err = operatorClient. + OperatorsV1alpha1(). + Subscriptions(namespace). + Patch(ctx, name, types.MergePatchType, bytes, metav1.PatchOptions{}) + + return sub, err } return sub, err } From 7a3269fbde6402b1323c0fd66382a9cb072c9456 Mon Sep 17 00:00:00 2001 From: Oksana Grishchenko Date: Mon, 16 Oct 2023 15:04:50 +0200 Subject: [PATCH 03/10] go mod tidy --- go.mod | 1 - go.sum | 1 - 2 files changed, 2 deletions(-) diff --git a/go.mod b/go.mod index 3ab79b7d..fe1a96a8 100644 --- a/go.mod +++ b/go.mod @@ -16,7 +16,6 @@ require ( go.uber.org/zap v1.26.0 golang.org/x/sync v0.4.0 gopkg.in/yaml.v3 v3.0.1 - gotest.tools v2.2.0+incompatible k8s.io/api v0.28.2 k8s.io/apiextensions-apiserver v0.28.2 k8s.io/apimachinery v0.28.2 diff --git a/go.sum b/go.sum index f214c104..5426c828 100644 --- a/go.sum +++ b/go.sum @@ -1427,7 +1427,6 @@ gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C 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= gotest.tools v2.2.0+incompatible/go.mod h1:DsYFclhRJ6vuDpmuTbkuFWG+y2sxOXAzmJt81HFBacw= gotest.tools/v3 v3.0.2/go.mod h1:3SzNCllyD9/Y+b5r9JIKQ474KzkZyqLqEfYqMsX94Bk= honnef.co/go/tools v0.0.0-20180728063816-88497007e858/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= From eaa1c21f803b2c5cfe095cc0948e1d4853bad3ef Mon Sep 17 00:00:00 2001 From: Oksana Grishchenko Date: Mon, 16 Oct 2023 15:12:00 +0200 Subject: [PATCH 04/10] go mod tidy --- go.mod | 1 + go.sum | 1 + 2 files changed, 2 insertions(+) diff --git a/go.mod b/go.mod index fe1a96a8..3ab79b7d 100644 --- a/go.mod +++ b/go.mod @@ -16,6 +16,7 @@ require ( go.uber.org/zap v1.26.0 golang.org/x/sync v0.4.0 gopkg.in/yaml.v3 v3.0.1 + gotest.tools v2.2.0+incompatible k8s.io/api v0.28.2 k8s.io/apiextensions-apiserver v0.28.2 k8s.io/apimachinery v0.28.2 diff --git a/go.sum b/go.sum index 5426c828..f214c104 100644 --- a/go.sum +++ b/go.sum @@ -1427,6 +1427,7 @@ gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C 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= gotest.tools v2.2.0+incompatible/go.mod h1:DsYFclhRJ6vuDpmuTbkuFWG+y2sxOXAzmJt81HFBacw= gotest.tools/v3 v3.0.2/go.mod h1:3SzNCllyD9/Y+b5r9JIKQ474KzkZyqLqEfYqMsX94Bk= honnef.co/go/tools v0.0.0-20180728063816-88497007e858/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= From cac160c8193e02c57b5dd970e9360d66b8ef25b6 Mon Sep 17 00:00:00 2001 From: Oksana Grishchenko Date: Mon, 16 Oct 2023 16:23:23 +0200 Subject: [PATCH 05/10] add test --- cli-tests/tests/flow/all-operators.spec.ts | 26 ++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/cli-tests/tests/flow/all-operators.spec.ts b/cli-tests/tests/flow/all-operators.spec.ts index d7a24475..9bb8c117 100644 --- a/cli-tests/tests/flow/all-operators.spec.ts +++ b/cli-tests/tests/flow/all-operators.spec.ts @@ -71,5 +71,31 @@ test.describe('Everest CLI install operators', async () => { ]); }); await verifyClusterResources(); + await test.step('disable telemetry', async () => { + // check that the telemetry IS NOT disabled by default + let out = await cli.exec('kubectl get deployments/percona-xtradb-cluster-operator --namespace=percona-everest'); + + await out.outContainsNormalizedMany([ + `- name: DISABLE_TELEMETRY + value: "false"`, + ]); + + await cli.exec('export DISABLE_TELEMETRY=true'); + out = await cli.everestExecSkipWizard(`install operators --backup.enable=0 --monitoring.enable=0 --name=${clusterName}`); + await out.assertSuccess(); + await out.outErrContainsNormalizedMany([ + 'percona-xtradb-cluster-operator operator has been installed', + 'percona-server-mongodb-operator operator has been installed', + 'percona-postgresql-operator operator has been installed', + 'everest-operator operator has been installed', + 'Connected Kubernetes cluster to Everest', + ]); + // check that the telemetry IS disabled + out = await cli.exec('kubectl get deployments/percona-xtradb-cluster-operator --namespace=percona-everest'); + await out.outContainsNormalizedMany([ + `- name: DISABLE_TELEMETRY + value: "true"`, + ]); + }); }); }); From 4d05b5c65cf7ec6982bf0ad3baab09cbf4a11cd2 Mon Sep 17 00:00:00 2001 From: Oksana Grishchenko Date: Mon, 16 Oct 2023 16:44:38 +0200 Subject: [PATCH 06/10] fix test --- cli-tests/tests/flow/all-operators.spec.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cli-tests/tests/flow/all-operators.spec.ts b/cli-tests/tests/flow/all-operators.spec.ts index 9bb8c117..927283b0 100644 --- a/cli-tests/tests/flow/all-operators.spec.ts +++ b/cli-tests/tests/flow/all-operators.spec.ts @@ -73,7 +73,7 @@ test.describe('Everest CLI install operators', async () => { await verifyClusterResources(); await test.step('disable telemetry', async () => { // check that the telemetry IS NOT disabled by default - let out = await cli.exec('kubectl get deployments/percona-xtradb-cluster-operator --namespace=percona-everest'); + let out = await cli.exec('kubectl get deployments/percona-xtradb-cluster-operator --namespace=percona-everest -o yaml'); await out.outContainsNormalizedMany([ `- name: DISABLE_TELEMETRY From bd3363db8e2bd35d907c34fd6ef7b83dd3f0619f Mon Sep 17 00:00:00 2001 From: Oksana Grishchenko Date: Tue, 17 Oct 2023 10:17:25 +0200 Subject: [PATCH 07/10] fix test --- cli-tests/tests/flow/all-operators.spec.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cli-tests/tests/flow/all-operators.spec.ts b/cli-tests/tests/flow/all-operators.spec.ts index 927283b0..aefa4cfc 100644 --- a/cli-tests/tests/flow/all-operators.spec.ts +++ b/cli-tests/tests/flow/all-operators.spec.ts @@ -77,7 +77,7 @@ test.describe('Everest CLI install operators', async () => { await out.outContainsNormalizedMany([ `- name: DISABLE_TELEMETRY - value: "false"`, + value: "false"`, ]); await cli.exec('export DISABLE_TELEMETRY=true'); @@ -94,7 +94,7 @@ test.describe('Everest CLI install operators', async () => { out = await cli.exec('kubectl get deployments/percona-xtradb-cluster-operator --namespace=percona-everest'); await out.outContainsNormalizedMany([ `- name: DISABLE_TELEMETRY - value: "true"`, + value: "true"`, ]); }); }); From a195a0924f527bb851cf6cd79c7ac5bf4c2af828 Mon Sep 17 00:00:00 2001 From: Oksana Grishchenko Date: Tue, 17 Oct 2023 11:41:38 +0200 Subject: [PATCH 08/10] fix test --- cli-tests/tests/flow/all-operators.spec.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cli-tests/tests/flow/all-operators.spec.ts b/cli-tests/tests/flow/all-operators.spec.ts index aefa4cfc..a6f65f95 100644 --- a/cli-tests/tests/flow/all-operators.spec.ts +++ b/cli-tests/tests/flow/all-operators.spec.ts @@ -77,7 +77,7 @@ test.describe('Everest CLI install operators', async () => { await out.outContainsNormalizedMany([ `- name: DISABLE_TELEMETRY - value: "false"`, + value: \\"false\\"`, ]); await cli.exec('export DISABLE_TELEMETRY=true'); @@ -94,7 +94,7 @@ test.describe('Everest CLI install operators', async () => { out = await cli.exec('kubectl get deployments/percona-xtradb-cluster-operator --namespace=percona-everest'); await out.outContainsNormalizedMany([ `- name: DISABLE_TELEMETRY - value: "true"`, + value: \\"true\\"`, ]); }); }); From a79128b96a9bd6b0f6c1c2a96e34a5aa12442e57 Mon Sep 17 00:00:00 2001 From: Oksana Grishchenko Date: Tue, 17 Oct 2023 16:38:52 +0200 Subject: [PATCH 09/10] fix test --- cli-tests/helpers/cliHelper.ts | 7 +++++++ cli-tests/tests/flow/all-operators.spec.ts | 20 ++++++++------------ 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/cli-tests/helpers/cliHelper.ts b/cli-tests/helpers/cliHelper.ts index 6dfe35f1..28f29bb4 100644 --- a/cli-tests/helpers/cliHelper.ts +++ b/cli-tests/helpers/cliHelper.ts @@ -64,6 +64,13 @@ export class CliHelper { }); } + async everestExecSkipWizardWithEnv(command, env: string) { + // eslint-disable-next-line @typescript-eslint/no-unsafe-return + return test.step(`Run "${command}" command with env variables`, async () => { + return this.execute(`${env} ${this.pathToBinary} ${command} --skip-wizard`); + }); + } + /** * Silent Shell(sh) exec() wrapper to return handy {@link Output} object. * Provides no logs to skip huge outputs. diff --git a/cli-tests/tests/flow/all-operators.spec.ts b/cli-tests/tests/flow/all-operators.spec.ts index a6f65f95..0bc93151 100644 --- a/cli-tests/tests/flow/all-operators.spec.ts +++ b/cli-tests/tests/flow/all-operators.spec.ts @@ -75,27 +75,23 @@ test.describe('Everest CLI install operators', async () => { // check that the telemetry IS NOT disabled by default let out = await cli.exec('kubectl get deployments/percona-xtradb-cluster-operator --namespace=percona-everest -o yaml'); - await out.outContainsNormalizedMany([ - `- name: DISABLE_TELEMETRY - value: \\"false\\"`, - ]); + await out.outContains( + 'name: DISABLE_TELEMETRY\n value: "true"', + ); - await cli.exec('export DISABLE_TELEMETRY=true'); - out = await cli.everestExecSkipWizard(`install operators --backup.enable=0 --monitoring.enable=0 --name=${clusterName}`); + out = await cli.everestExecSkipWizardWithEnv('install operators --backup.enable=0 --monitoring.enable=0 --name=aaa', 'DISABLE_TELEMETRY=true'); await out.assertSuccess(); await out.outErrContainsNormalizedMany([ 'percona-xtradb-cluster-operator operator has been installed', 'percona-server-mongodb-operator operator has been installed', 'percona-postgresql-operator operator has been installed', 'everest-operator operator has been installed', - 'Connected Kubernetes cluster to Everest', ]); // check that the telemetry IS disabled - out = await cli.exec('kubectl get deployments/percona-xtradb-cluster-operator --namespace=percona-everest'); - await out.outContainsNormalizedMany([ - `- name: DISABLE_TELEMETRY - value: \\"true\\"`, - ]); + out = await cli.exec('kubectl get deployments/percona-xtradb-cluster-operator --namespace=percona-everest -o yaml'); + await out.outContains( + 'name: DISABLE_TELEMETRY\n value: "true"', + ); }); }); }); From 4230c0544e8f830013d7add0e020901d2bb3b2d6 Mon Sep 17 00:00:00 2001 From: Oksana Grishchenko Date: Tue, 17 Oct 2023 16:45:13 +0200 Subject: [PATCH 10/10] fix test --- cli-tests/tests/flow/all-operators.spec.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cli-tests/tests/flow/all-operators.spec.ts b/cli-tests/tests/flow/all-operators.spec.ts index 0bc93151..4e5a5a15 100644 --- a/cli-tests/tests/flow/all-operators.spec.ts +++ b/cli-tests/tests/flow/all-operators.spec.ts @@ -76,7 +76,7 @@ test.describe('Everest CLI install operators', async () => { let out = await cli.exec('kubectl get deployments/percona-xtradb-cluster-operator --namespace=percona-everest -o yaml'); await out.outContains( - 'name: DISABLE_TELEMETRY\n value: "true"', + 'name: DISABLE_TELEMETRY\n value: "false"', ); out = await cli.everestExecSkipWizardWithEnv('install operators --backup.enable=0 --monitoring.enable=0 --name=aaa', 'DISABLE_TELEMETRY=true');