Skip to content

Commit 7631b4f

Browse files
improve unified setup file
1 parent 81a7e2b commit 7631b4f

File tree

10 files changed

+567
-1013
lines changed

10 files changed

+567
-1013
lines changed

tests/@setup/README.md

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ This tool replaces 22+ setup scripts scattered across Bash, Python, and TypeScri
1111
- **Mock Services**: AWS S3 (CloudServer) and Azure (Azurite) mock deployments
1212
- **Test Buckets**: Automated creation across AWS, Azure, and Ring providers
1313
- **Storage Locations**: Management API configuration for all storage backends
14-
- **Keycloak Setup**: Realm, users, and role configuration
1514
- **DNS Configuration**: CoreDNS rewrite rules for test domains
1615
- **RBAC Permissions**: Service account cluster-admin permissions
1716

@@ -52,7 +51,7 @@ zenko-setup all --namespace=my-namespace --subdomain=test.local
5251

5352
Skip specific components:
5453
```bash
55-
zenko-setup all --skip-mocks --skip-keycloak
54+
zenko-setup all --skip-mocks
5655
```
5756

5857
### Individual Components
@@ -68,9 +67,6 @@ zenko-setup buckets --provider=aws
6867
# Storage locations
6968
zenko-setup locations
7069

71-
# Keycloak realm and users
72-
zenko-setup keycloak
73-
7470
# DNS configuration
7571
zenko-setup dns
7672

tests/@setup/package.json

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,16 @@
2323
"author": "Scality",
2424
"license": "Apache-2.0",
2525
"dependencies": {
26-
"@aws-sdk/client-iam": "^3.400.0",
27-
"@aws-sdk/client-s3": "^3.400.0",
28-
"@azure/storage-blob": "^12.15.0",
29-
"@azure/storage-queue": "^12.15.0",
30-
"@kubernetes/client-node": "^0.20.0",
31-
"axios": "^1.5.0",
32-
"commander": "^11.0.0",
33-
"dotenv": "^16.3.1",
26+
"@aws-sdk/client-iam": "^3.888.0",
27+
"@aws-sdk/client-s3": "^3.888.0",
28+
"@azure/storage-blob": "^12.28.0",
29+
"@azure/storage-queue": "^12.27.0",
30+
"@kubernetes/client-node": "^1.3.0",
31+
"axios": "^1.12.2",
32+
"commander": "^14.0.1",
33+
"dotenv": "^17.2.2",
3434
"werelogs": "scality/werelogs#8.2.2",
35-
"yaml": "^2.3.2"
35+
"yaml": "^2.8.1"
3636
},
3737
"devDependencies": {
3838
"@eslint/compat": "^1.3.2",

tests/@setup/src/buckets.ts

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,17 @@ async function setupAWSBuckets(k8s: KubernetesClient, options: BucketsOptions):
3030
logger.info('Creating AWS test buckets');
3131

3232
// Get AWS credentials from mock service
33-
const awsSecret = await k8s.coreApi.readNamespacedSecret('aws-mock-credentials', options.namespace);
33+
const awsSecret = await k8s.coreApi.readNamespacedSecret({
34+
name: 'aws-mock-credentials',
35+
namespace: options.namespace,
36+
});
3437
const awsConfig = {
3538
credentials: {
36-
accessKeyId: Buffer.from(awsSecret.data!['aws-access-key-id'], 'base64').toString(),
37-
secretAccessKey: Buffer.from(awsSecret.data!['aws-secret-access-key'], 'base64').toString()
38-
},
39-
region: Buffer.from(awsSecret.data!['aws-region'], 'base64').toString(),
40-
endpoint: Buffer.from(awsSecret.data!['aws-endpoint'], 'base64').toString(),
39+
accessKeyId: Buffer.from(awsSecret.data!['aws-access-key-id'], 'base64').toString(),
40+
secretAccessKey: Buffer.from(awsSecret.data!['aws-secret-access-key'], 'base64').toString()
41+
},
42+
region: Buffer.from(awsSecret.data!['aws-region'], 'base64').toString(),
43+
endpoint: Buffer.from(awsSecret.data!['aws-endpoint'], 'base64').toString(),
4144
forcePathStyle: true
4245
};
4346

@@ -104,7 +107,10 @@ async function setupAzureBuckets(k8s: KubernetesClient, options: BucketsOptions)
104107
logger.info('Creating Azure test containers and queues');
105108

106109
// Get Azure credentials from mock service
107-
const azureSecret = await k8s.coreApi.readNamespacedSecret('azure-mock-credentials', options.namespace);
110+
const azureSecret = await k8s.coreApi.readNamespacedSecret({
111+
name: 'azure-mock-credentials',
112+
namespace: options.namespace,
113+
});
108114
const accountName = Buffer.from(azureSecret.data!['account-name'], 'base64').toString();
109115
const accountKey = Buffer.from(azureSecret.data!['account-key'], 'base64').toString();
110116
const blobEndpoint = Buffer.from(azureSecret.data!['blob-endpoint'], 'base64').toString();

tests/@setup/src/cli.ts

Lines changed: 21 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import { Command } from 'commander';
44
import { setupMocks } from './mocks';
55
import { setupBuckets } from './buckets';
66
import { setupLocations } from './locations';
7-
import { setupKeycloak } from './keycloak';
87
import { setupDNS } from './dns';
98
import { setupRBAC } from './rbac';
109
import { logger } from './utils/logger';
@@ -88,18 +87,6 @@ program
8887
});
8988
});
9089

91-
program
92-
.command('keycloak')
93-
.description('Setup Keycloak realm, users, and roles')
94-
.action(async () => {
95-
const globalOptions = program.opts();
96-
await setupKeycloak({
97-
namespace: globalOptions.namespace || 'default',
98-
instanceId: globalOptions.instanceId,
99-
dryRun: globalOptions.dryRun,
100-
});
101-
});
102-
10390
program
10491
.command('dns')
10592
.description('Configure CoreDNS for test domains')
@@ -125,7 +112,7 @@ program
125112

126113
async function runSetup(options: any) {
127114
try {
128-
logger.info('🚀 Starting Zenko test environment setup');
115+
logger.info('🚀 Starting Zenko test environment setup');
129116

130117
const tasks = [];
131118

@@ -178,39 +165,29 @@ async function runSetup(options: any) {
178165
});
179166
}
180167

181-
if (options.keycloak) {
182-
tasks.push({
183-
name: 'Keycloak', fn: () => setupKeycloak({
184-
namespace: options.namespace || 'default',
185-
instanceId: options.instanceId,
186-
dryRun: options.dryRun,
187-
})
188-
});
189-
}
190-
191168
for (const task of tasks) {
192-
logger.info(`📝 Setting up ${task.name}...`);
193-
194-
if (options.dryRun) {
195-
logger.info(` [DRY RUN] Would execute ${task.name} setup`);
196-
continue;
197-
}
198-
199-
try {
200-
await task.fn();
201-
logger.info(` ✅ ${task.name} setup completed`);
202-
} catch (error) {
203-
logger.error(` ❌ ${task.name} setup failed`, { error: error instanceof Error ? error.message : String(error) });
204-
throw error;
205-
}
169+
logger.info(`📝 Setting up ${task.name}...`);
170+
171+
if (options.dryRun) {
172+
logger.info(` [DRY RUN] Would execute ${task.name} setup`);
173+
continue;
174+
}
175+
176+
try {
177+
await task.fn();
178+
logger.info(` ✅ ${task.name} setup completed`);
179+
} catch (error) {
180+
logger.error(` ❌ ${task.name} setup failed`, { error: error instanceof Error ? error.message : String(error) });
181+
throw error;
182+
}
206183
}
207184

208-
logger.info('🎉 Zenko test environment setup completed successfully!');
209-
210-
} catch (error) {
211-
logger.error('💥 Setup failed', { error: error instanceof Error ? error.message : String(error) });
212-
process.exit(1);
213-
}
185+
logger.info('🎉 Zenko test environment setup completed successfully!');
186+
187+
} catch (error) {
188+
logger.error('💥 Setup failed', { error: error instanceof Error ? error.message : String(error) });
189+
process.exit(1);
190+
}
214191
}
215192

216193
program.parse();

tests/@setup/src/dns.ts

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@ export async function setupDNS(options: DNSOptions): Promise<void> {
1515
// Get the current CoreDNS ConfigMap
1616
let coreDnsConfigMap;
1717
try {
18-
coreDnsConfigMap = await k8s.coreApi.readNamespacedConfigMap('coredns', 'kube-system');
18+
coreDnsConfigMap = await k8s.coreApi.readNamespacedConfigMap({
19+
name: 'coredns',
20+
namespace: 'kube-system',
21+
});
1922
} catch (error: any) {
2023
if (error.response?.statusCode === 404) {
2124
logger.warn('CoreDNS ConfigMap not found, attempting to find alternative');
@@ -27,7 +30,10 @@ export async function setupDNS(options: DNSOptions): Promise<void> {
2730

2831
for (const alt of alternatives) {
2932
try {
30-
coreDnsConfigMap = await k8s.coreApi.readNamespacedConfigMap(alt.name, alt.namespace);
33+
coreDnsConfigMap = await k8s.coreApi.readNamespacedConfigMap({
34+
name: alt.name,
35+
namespace: alt.namespace,
36+
});
3137
break;
3238
} catch (e) {
3339
continue;
@@ -61,14 +67,18 @@ export async function setupDNS(options: DNSOptions): Promise<void> {
6167

6268
// Update the ConfigMap
6369
const updatedConfigMap = {
64-
...coreDnsConfigMap.body,
70+
...coreDnsConfigMap,
6571
data: {
6672
...coreDnsConfigMap.data,
6773
'Corefile': newCorefile
6874
}
6975
};
7076

71-
await k8s.coreApi.replaceNamespacedConfigMap('coredns', 'kube-system', updatedConfigMap);
77+
await k8s.coreApi.replaceNamespacedConfigMap({
78+
name: 'coredns',
79+
namespace: 'kube-system',
80+
body: updatedConfigMap,
81+
});
7282

7383
// Restart CoreDNS deployment to pick up changes
7484
await restartCoreDNS(k8s);
@@ -176,15 +186,22 @@ function addRewriteRules(currentCorefile: string, rewriteRules: string, subdomai
176186
async function restartCoreDNS(k8s: KubernetesClient): Promise<void> {
177187
try {
178188
// Get CoreDNS deployment
179-
const deployment = await k8s.appsApi.readNamespacedDeployment('coredns', 'kube-system');
189+
const deployment = await k8s.appsApi.readNamespacedDeployment({
190+
name: 'coredns',
191+
namespace: 'kube-system',
192+
});
180193

181194
// Add/update restart annotation to trigger rolling restart
182195
const annotations = deployment.spec?.template.metadata?.annotations || {};
183196
annotations['kubectl.kubernetes.io/restartedAt'] = new Date().toISOString();
184197

185198
deployment.spec!.template.metadata!.annotations = annotations;
186199

187-
await k8s.appsApi.replaceNamespacedDeployment('coredns', 'kube-system', deployment.body);
200+
await k8s.appsApi.replaceNamespacedDeployment({
201+
name: 'coredns',
202+
namespace: 'kube-system',
203+
body: deployment,
204+
});
188205

189206
logger.debug('CoreDNS deployment restart triggered');
190207

0 commit comments

Comments
 (0)