Skip to content
This repository has been archived by the owner on Mar 4, 2024. It is now read-only.

Commit

Permalink
Merge branch 'main' into EVEREST-511
Browse files Browse the repository at this point in the history
  • Loading branch information
gen1us2k authored Oct 17, 2023
2 parents 47ca00d + 529d5e8 commit 8b55704
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 2 deletions.
7 changes: 7 additions & 0 deletions cli-tests/helpers/cliHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
22 changes: 22 additions & 0 deletions cli-tests/tests/flow/all-operators.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,5 +71,27 @@ 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 -o yaml');

await out.outContains(
'name: DISABLE_TELEMETRY\n value: "false"',
);

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',
]);
// check that the telemetry IS disabled
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"',
);
});
});
});
28 changes: 26 additions & 2 deletions pkg/kubernetes/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ const (

defaultAPIURIPath = "/api"
defaultAPIsURIPath = "/apis"

disableTelemetryEnvVar = "DISABLE_TELEMETRY"
)

// Each level has 2 spaces for PrefixWriter.
Expand Down Expand Up @@ -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,
Expand All @@ -1084,16 +1091,33 @@ func (c *Client) CreateSubscriptionForCatalog(ctx context.Context, namespace, na
Channel: channel,
StartingCSV: startingCSV,
InstallPlanApproval: approval,
Config: &v1alpha1.SubscriptionConfig{
Env: []corev1.EnvVar{
{
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
}
Expand Down

0 comments on commit 8b55704

Please sign in to comment.