Skip to content

Commit ae097a7

Browse files
author
Christopher Brandt
committed
feat(kubernetesEngine): add tke service
1 parent f50abf9 commit ae097a7

20 files changed

Lines changed: 266 additions & 11 deletions

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,3 +70,4 @@ CloudGraph Tencent Provider will ask you what regions you would like to crawl an
7070
| vpnConnection | vpc, vpnGateway, customerGateway |
7171
| vpnGateway | vpc, vpnGatewayRoute, vpnConnection |
7272
| vpnGatewayRoute | vpnGateway |
73+
| kubernetesEngine | subnet, vpc |

src/enums/schemasMap.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ export default {
1313
[services.routeTable]: 'tencentRouteTable',
1414
[services.securityGroup]: 'tencentSecurityGroup',
1515
[services.securityGroupRule]: 'tencentSecurityGroupRule',
16+
[services.kubernetesEngine]: 'tencentKubernetesCluster',
1617
[services.subnet]: 'tencentSubnet',
1718
[services.vpc]: 'tencentVpc',
1819
[services.vpnConnection]: 'tencentVpnConnection',

src/enums/serviceAliases.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ export default {
55
customerGateway: 'customerGateways',
66
routeTable: 'routeTables',
77
securityGroup: 'securityGroups',
8+
kubernetesEngine: 'kubernetesClusters',
89
subnet: 'subnets',
910
vpc: 'vpcInstances',
1011
vpnConnection: 'vpnConnections',

src/enums/serviceMap.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import TencentSecurityGroup from '../services/securityGroup'
44
import TencentSecurityGroupRule from '../services/securityGroupRule'
55
import TencentCcn from '../services/ccn'
66
import TencentCcnAttachment from '../services/ccnAttachment'
7+
import TencentKubernetesEngine from '../services/kubernetesEngine'
78
import TencentSubnet from '../services/subnet'
89
import TencentVpc from '../services/vpc'
910
import TencentTag from '../services/tag'
@@ -29,6 +30,7 @@ export default {
2930
[services.routeTable]: TencentRouteTable,
3031
[services.securityGroup]: TencentSecurityGroup,
3132
[services.securityGroupRule]: TencentSecurityGroupRule,
33+
[services.kubernetesEngine]: TencentKubernetesEngine,
3234
[services.subnet]: TencentSubnet,
3335
[services.vpc]: TencentVpc,
3436
[services.vpnConnection]: TencentVpnConnection,

src/enums/services.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,11 @@ export default {
88
routeTable: 'routeTable',
99
securityGroup: 'securityGroup',
1010
securityGroupRule: 'securityGroupRule',
11+
kubernetesEngine: 'kubernetesEngine',
1112
subnet: 'subnet',
1213
vpc: 'vpc',
1314
vpnConnection: 'vpnConnection',
1415
vpnGateway: 'vpnGateway',
1516
vpnGatewayRoute: 'vpnGatewayRoute',
17+
tag: 'tag'
1618
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
import * as tencentcloud from 'tencentcloud-sdk-nodejs'
2+
import { Cluster } from 'tencentcloud-sdk-nodejs/tencentcloud/services/tke/v20180525/tke_models'
3+
import { ClientConfig } from 'tencentcloud-sdk-nodejs/tencentcloud/common/interface'
4+
import CloudGraph from '@cloudgraph/sdk'
5+
import groupBy from 'lodash/groupBy'
6+
import isEmpty from 'lodash/isEmpty'
7+
import loggerText from '../../properties/logger'
8+
import { TencentServiceInput } from '../../types'
9+
import { initTestEndpoint, generateTencentErrorLog } from '../../utils'
10+
11+
const lt = { ...loggerText }
12+
const { logger } = CloudGraph
13+
const serviceName = 'KubernetesEngine'
14+
const apiEndpoint = initTestEndpoint(serviceName)
15+
16+
export interface RawTencentKubernetesEngine extends Cluster {
17+
id: string
18+
region: string
19+
subnets: string[]
20+
}
21+
22+
export default async ({
23+
regions,
24+
config,
25+
}: TencentServiceInput): Promise<{
26+
[region: string]: RawTencentKubernetesEngine[]
27+
}> =>
28+
new Promise(async resolve => {
29+
const clusterList: RawTencentKubernetesEngine[] = []
30+
31+
for (const region of regions.split(',')) {
32+
/**
33+
* Get all clusters
34+
*/
35+
try {
36+
const TkeClient = tencentcloud.tke.v20180525.Client
37+
const clientConfig: ClientConfig = { credential: config, region, profile: { httpProfile: { endpoint: apiEndpoint } } }
38+
const tke = new TkeClient(clientConfig)
39+
const response = await tke.DescribeClusters(null)
40+
41+
if (response && !isEmpty(response.Clusters)) {
42+
for (const instance of response.Clusters) {
43+
clusterList.push({
44+
id: instance.ClusterId,
45+
...instance,
46+
subnets: instance.ClusterNetworkSettings?.Subnets?.map(subnet => subnet),
47+
region,
48+
})
49+
}
50+
}
51+
52+
} catch (error) {
53+
generateTencentErrorLog(serviceName, 'tke:DescribeClusters', error)
54+
}
55+
}
56+
57+
logger.debug(lt.foundResources(serviceName, clusterList.length))
58+
resolve(groupBy(clusterList, 'region'))
59+
})
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
import cuid from 'cuid'
2+
import { TencentKubernetesCluster } from '../../types/generated'
3+
import { RawTencentKubernetesEngine } from './data'
4+
5+
export default ({
6+
service,
7+
account,
8+
region,
9+
}: {
10+
service: RawTencentKubernetesEngine
11+
account: string
12+
region: string
13+
}): TencentKubernetesCluster => {
14+
const {
15+
id,
16+
ClusterName: name,
17+
ClusterDescription: clusterDescription,
18+
ClusterVersion: clusterVersion,
19+
ClusterOs: clusterOs,
20+
ClusterType: clusterType,
21+
ClusterNetworkSettings,
22+
ClusterNodeNum: clusterNodeNum,
23+
ProjectId: projectId,
24+
TagSpecification,
25+
ClusterStatus: clusterStatus,
26+
Property: property,
27+
ClusterMaterNodeNum: clusterMaterNodeNum,
28+
ImageId: imageId,
29+
OsCustomizeType: osCustomizeType,
30+
ContainerRuntime: containerRuntime,
31+
CreatedTime: createdTime,
32+
DeletionProtection: deletionProtection,
33+
EnableExternalNode: enableExternalNode,
34+
ClusterLevel: clusterLevel,
35+
AutoUpgradeClusterLevel: autoUpgradeClusterLevel,
36+
} = service
37+
38+
const Tags = []
39+
TagSpecification?.map(spec => {
40+
Tags.push(spec.Tags)
41+
})
42+
43+
return {
44+
id,
45+
region,
46+
name,
47+
clusterDescription,
48+
clusterVersion,
49+
clusterOs,
50+
clusterType,
51+
clusterNetworkSettings: {
52+
clusterCIDR: ClusterNetworkSettings?.ClusterCIDR,
53+
ignoreClusterCIDRConflict: ClusterNetworkSettings?.IgnoreClusterCIDRConflict,
54+
maxNodePodNum: ClusterNetworkSettings?.MaxNodePodNum,
55+
maxClusterServiceNum: ClusterNetworkSettings?.MaxClusterServiceNum,
56+
ipvs: ClusterNetworkSettings?.Ipvs,
57+
vpcId: ClusterNetworkSettings?.VpcId,
58+
cni: ClusterNetworkSettings?.Cni,
59+
kubeProxyMode: ClusterNetworkSettings?.KubeProxyMode,
60+
serviceCIDR: ClusterNetworkSettings?.ServiceCIDR,
61+
subnets: ClusterNetworkSettings?.Subnets,
62+
},
63+
clusterNodeNum,
64+
projectId,
65+
tags: Tags.map(tag => ({
66+
id: cuid(),
67+
key: tag.Key,
68+
value: tag.Value,
69+
})),
70+
clusterStatus,
71+
property,
72+
clusterMaterNodeNum,
73+
imageId,
74+
osCustomizeType,
75+
containerRuntime,
76+
createdTime,
77+
deletionProtection,
78+
enableExternalNode,
79+
clusterLevel,
80+
autoUpgradeClusterLevel,
81+
}
82+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { Service } from '@cloudgraph/sdk'
2+
import BaseService from '../base'
3+
import format from './format'
4+
import getData from './data'
5+
import { getMutation } from '../../utils'
6+
import services from '../../enums/services'
7+
import schemasMap from '../../enums/schemasMap'
8+
9+
10+
export default class TencentKubernetesEngine extends BaseService implements Service {
11+
format = format.bind(this)
12+
13+
getData = getData.bind(this)
14+
15+
mutation = getMutation(schemasMap[services.kubernetesEngine])
16+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
type tencentKubernetesCluster implements tencentBaseService @key(fields: "id") {
2+
name: String @search(by: [hash, regexp])
3+
clusterDescription: String @search(by: [hash, regexp])
4+
clusterVersion: String @search(by: [hash, regexp])
5+
clusterOs: String @search(by: [hash, regexp])
6+
clusterType: String @search(by: [hash, regexp])
7+
clusterNetworkSettings: tencentKubernetesClusterNetworkSettings
8+
clusterNodeNum: Int @search
9+
projectId: Int @search
10+
tags: [tencentRawTag]
11+
clusterStatus: String @search(by: [hash, regexp])
12+
property: String @search(by: [hash, regexp])
13+
clusterMaterNodeNum: Int @search
14+
imageId: String @search(by: [hash, regexp])
15+
osCustomizeType: String @search(by: [hash, regexp])
16+
containerRuntime: String @search(by: [hash, regexp])
17+
createdTime: String @search(by: [hash, regexp])
18+
deletionProtection: Boolean @search
19+
enableExternalNode: Boolean @search
20+
clusterLevel: String @search(by: [hash, regexp])
21+
autoUpgradeClusterLevel: Boolean @search
22+
subnets: [tencentSubnet] @hasInverse(field: kubernetesClusters)
23+
vpcInstances: [tencentVpc] @hasInverse(field: kubernetesClusters)
24+
}
25+
26+
type tencentKubernetesClusterNetworkSettings
27+
@generate(
28+
query: { get: false, query: true, aggregate: false }
29+
mutation: { add: false, delete: false }
30+
subscription: false
31+
) {
32+
clusterCIDR: String @search(by: [hash, regexp])
33+
ignoreClusterCIDRConflict: Boolean @search
34+
maxNodePodNum: Int @search
35+
maxClusterServiceNum: Int @search
36+
ipvs: Boolean @search
37+
vpcId: String @search(by: [hash, regexp])
38+
cni: Boolean @search
39+
kubeProxyMode: String @search(by: [hash, regexp])
40+
serviceCIDR: String @search(by: [hash, regexp])
41+
subnets: [String] @search(by: [hash, regexp])
42+
}

src/services/subnet/data.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { initTestEndpoint, generateTencentErrorLog } from '../../utils'
1010

1111
const lt = { ...loggerText }
1212
const { logger } = CloudGraph
13-
export const serviceName = 'Subnet'
13+
const serviceName = 'Subnet'
1414
const apiEndpoint = initTestEndpoint(serviceName)
1515

1616
export interface RawTencentSubnet extends Subnet {

0 commit comments

Comments
 (0)