Skip to content

Commit d1afbf7

Browse files
committed
Adding tags support in library
1 parent 5ea4b6b commit d1afbf7

File tree

6 files changed

+120
-3
lines changed

6 files changed

+120
-3
lines changed

dist/clusters.d.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,14 @@ export declare class ClusterVersion {
88
name: string;
99
version: string;
1010
}
11-
export declare function createCluster(vendorPortalApi: VendorPortalApi, clusterName: string, k8sDistribution: string, k8sVersion: string, clusterTTL: string, diskGib?: number, nodeCount?: number, instanceType?: string): Promise<Cluster>;
11+
interface tag {
12+
key: string;
13+
value: string;
14+
}
15+
export declare function createCluster(vendorPortalApi: VendorPortalApi, clusterName: string, k8sDistribution: string, k8sVersion: string, clusterTTL: string, diskGib?: number, nodeCount?: number, instanceType?: string, tags?: tag[]): Promise<Cluster>;
1216
export declare function pollForStatus(vendorPortalApi: VendorPortalApi, clusterId: string, expectedStatus: string, timeout?: number): Promise<Cluster>;
1317
export declare function getKubeconfig(vendorPortalApi: VendorPortalApi, clusterId: string): Promise<string>;
1418
export declare function removeCluster(vendorPortalApi: VendorPortalApi, clusterId: string): Promise<void>;
1519
export declare function upgradeCluster(vendorPortalApi: VendorPortalApi, clusterId: string, k8sVersion: string): Promise<Cluster>;
1620
export declare function getClusterVersions(vendorPortalApi: VendorPortalApi): Promise<ClusterVersion[]>;
21+
export {};

dist/clusters.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ exports.Cluster = Cluster;
77
class ClusterVersion {
88
}
99
exports.ClusterVersion = ClusterVersion;
10-
async function createCluster(vendorPortalApi, clusterName, k8sDistribution, k8sVersion, clusterTTL, diskGib, nodeCount, instanceType) {
10+
async function createCluster(vendorPortalApi, clusterName, k8sDistribution, k8sVersion, clusterTTL, diskGib, nodeCount, instanceType, tags) {
1111
const http = await vendorPortalApi.client();
1212
const reqBody = {
1313
"name": clusterName,
@@ -18,6 +18,9 @@ async function createCluster(vendorPortalApi, clusterName, k8sDistribution, k8sV
1818
"node_count": nodeCount,
1919
"instance_type": instanceType
2020
};
21+
if (tags) {
22+
reqBody['tags'] = tags;
23+
}
2124
const uri = `${vendorPortalApi.endpoint}/cluster`;
2225
const res = await http.post(uri, JSON.stringify(reqBody));
2326
if (res.message.statusCode != 201) {

dist/clusters.spec.js

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,49 @@ describe('ClusterService', () => {
3939
});
4040
});
4141
});
42+
describe('ClusterService with tags', () => {
43+
beforeAll(() => globalThis.provider.setup());
44+
afterEach(() => globalThis.provider.verify());
45+
afterAll(() => globalThis.provider.finalize());
46+
test('should return cluster with tags', () => {
47+
const expectedCluster = { cluster: { name: "cluster1", id: "1234abcd", status: "provisioning" } };
48+
const reqBody = {
49+
name: "cluster1",
50+
kubernetes_distribution: "kind",
51+
kubernetes_version: "v1.25.1",
52+
ttl: "10m",
53+
tags: [
54+
{
55+
key: "foo",
56+
value: "bar"
57+
}
58+
]
59+
};
60+
globalThis.provider.addInteraction({
61+
state: 'cluster created',
62+
uponReceiving: 'a request for creating a cluster',
63+
withRequest: {
64+
method: 'POST',
65+
path: '/cluster',
66+
body: reqBody,
67+
},
68+
willRespondWith: {
69+
status: 201,
70+
headers: { 'Content-Type': 'application/json' },
71+
body: expectedCluster
72+
}
73+
});
74+
const apiClient = new configuration_1.VendorPortalApi();
75+
apiClient.apiToken = "abcd1234";
76+
apiClient.endpoint = globalThis.provider.mockService.baseUrl;
77+
const tags = [{ key: "foo", value: "bar" }];
78+
return (0, clusters_1.createCluster)(apiClient, "cluster1", "kind", "v1.25.1", "10m", undefined, undefined, undefined, tags).then(cluster => {
79+
expect(cluster.name).toEqual(expectedCluster.cluster.name);
80+
expect(cluster.id).toEqual(expectedCluster.cluster.id);
81+
expect(cluster.status).toEqual(expectedCluster.cluster.status);
82+
});
83+
});
84+
});
4285
describe('upgradeCluster', () => {
4386
const mockServer = mockttp.getLocal();
4487
const apiClient = new configuration_1.VendorPortalApi();

pacts/npm_consumer-vp_service.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,12 @@
7373
"kubernetes_distribution": "kind",
7474
"kubernetes_version": "v1.25.1",
7575
"name": "cluster1",
76+
"tags": [
77+
{
78+
"key": "foo",
79+
"value": "bar"
80+
}
81+
],
7682
"ttl": "10m"
7783
},
7884
"headers": {

src/clusters.spec.ts

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,55 @@ describe('ClusterService', () => {
4343
});
4444
});
4545

46+
describe('ClusterService with tags', () => {
47+
48+
beforeAll(() => globalThis.provider.setup());
49+
afterEach(() => globalThis.provider.verify());
50+
afterAll(() => globalThis.provider.finalize());
51+
52+
53+
test('should return cluster with tags', () => {
54+
const expectedCluster = { cluster: { name: "cluster1", id: "1234abcd", status: "provisioning" } }
55+
const reqBody = {
56+
name: "cluster1",
57+
kubernetes_distribution: "kind",
58+
kubernetes_version: "v1.25.1",
59+
ttl: "10m",
60+
tags: [
61+
{
62+
key: "foo",
63+
value: "bar"
64+
}
65+
]
66+
}
67+
globalThis.provider.addInteraction({
68+
state: 'cluster created',
69+
uponReceiving: 'a request for creating a cluster',
70+
withRequest: {
71+
method: 'POST',
72+
path: '/cluster',
73+
body: reqBody,
74+
},
75+
willRespondWith: {
76+
status: 201,
77+
headers: { 'Content-Type': 'application/json' },
78+
body: expectedCluster
79+
}
80+
});
81+
82+
const apiClient = new VendorPortalApi();
83+
apiClient.apiToken = "abcd1234";
84+
apiClient.endpoint = globalThis.provider.mockService.baseUrl;
85+
const tags = [{ key: "foo", value: "bar" }];
86+
87+
return createCluster(apiClient, "cluster1", "kind", "v1.25.1", "10m", undefined, undefined, undefined, tags).then(cluster => {
88+
expect(cluster.name).toEqual(expectedCluster.cluster.name);
89+
expect(cluster.id).toEqual(expectedCluster.cluster.id);
90+
expect(cluster.status).toEqual(expectedCluster.cluster.status);
91+
});
92+
});
93+
});
94+
4695
describe('upgradeCluster', () => {
4796
const mockServer = mockttp.getLocal()
4897
const apiClient = new VendorPortalApi();

src/clusters.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,14 @@ export class ClusterVersion {
1111
version: string;
1212
}
1313

14-
export async function createCluster(vendorPortalApi: VendorPortalApi, clusterName: string, k8sDistribution: string, k8sVersion: string, clusterTTL: string, diskGib?: number, nodeCount?: number, instanceType?: string): Promise<Cluster> {
14+
interface tag {
15+
key: string;
16+
value: string;
17+
}
18+
19+
20+
export async function createCluster(vendorPortalApi: VendorPortalApi, clusterName: string, k8sDistribution: string, k8sVersion: string,
21+
clusterTTL: string, diskGib?: number, nodeCount?: number, instanceType?: string, tags?: tag[]): Promise<Cluster> {
1522
const http = await vendorPortalApi.client();
1623

1724
const reqBody = {
@@ -24,6 +31,10 @@ export async function createCluster(vendorPortalApi: VendorPortalApi, clusterNam
2431
"instance_type": instanceType
2532
}
2633

34+
if (tags) {
35+
reqBody['tags'] = tags;
36+
}
37+
2738
const uri = `${vendorPortalApi.endpoint}/cluster`;
2839
const res = await http.post(uri, JSON.stringify(reqBody));
2940
if (res.message.statusCode != 201) {

0 commit comments

Comments
 (0)