Skip to content

Commit 9e5a798

Browse files
authored
Merge pull request #137 from cloudgraphdev/feature/EP-3169-update-cloudfront-and-eksCluster
feat(aws): Update cloudfront and eksCluster
2 parents b4d59ff + d7377ba commit 9e5a798

File tree

6 files changed

+81
-2
lines changed

6 files changed

+81
-2
lines changed

src/services/cloudfront/format.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ export default ({
134134
SmoothStreaming: smoothStreaming,
135135
TargetOriginId: targetOriginId,
136136
ViewerProtocolPolicy: viewerProtocolPolicy,
137+
CachePolicyId: cachePolicyId,
137138
} = cache
138139

139140
const forwardedValues = {
@@ -156,6 +157,7 @@ export default ({
156157
smoothStreaming: smoothStreaming ? t.yes : t.no,
157158
targetOriginId,
158159
viewerProtocolPolicy,
160+
cachePolicyId
159161
}
160162
}
161163

src/services/cloudfront/schema.graphql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ type awsCloudfrontCacheBehavior {
7979
smoothStreaming: String @search(by: [hash])
8080
targetOriginId: String @search(by: [hash])
8181
viewerProtocolPolicy: String @search(by: [hash])
82+
cachePolicyId: String @search(by: [hash])
8283
}
8384

8485
type awsCloudfrontCustomErrorResponse {

src/services/eksCluster/data.ts

Lines changed: 73 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import EKS, {
77
DescribeClusterRequest,
88
DescribeClusterResponse,
99
ListTagsForResourceResponse,
10+
ListNodegroupsRequest,
11+
ListNodegroupsResponse,
1012
} from 'aws-sdk/clients/eks'
1113
import CloudGraph from '@cloudgraph/sdk'
1214
import groupBy from 'lodash/groupBy'
@@ -23,8 +25,8 @@ const errorLog = new AwsErrorLog(serviceName)
2325
const endpoint = initTestEndpoint(serviceName)
2426
const MAX_ITEMS = 100
2527

26-
const listClustersForRegion = async ({
27-
eks,
28+
const listClustersForRegion = async ({
29+
eks,
2830
resolveRegion,
2931
}: {
3032
eks: EKS
@@ -123,9 +125,61 @@ const getResourceTags = async (eks: EKS, arn: string): Promise<TagMap> =>
123125
}
124126
})
125127

128+
const listNodegroups = async ({
129+
eks,
130+
clusterName,
131+
}: {
132+
eks: EKS
133+
clusterName: string
134+
}): Promise<string[]> =>
135+
new Promise<string[]>(resolve => {
136+
const nodeGroupsList: string[] = []
137+
let args: ListNodegroupsRequest = { clusterName }
138+
const listAllNodeGroups = (token?: string): void => {
139+
if (token) {
140+
args = { ...args, nextToken: token }
141+
}
142+
143+
try {
144+
eks.listNodegroups(
145+
args,
146+
(err: AWSError, data: ListNodegroupsResponse) => {
147+
if (err) {
148+
errorLog.generateAwsErrorLog({
149+
functionName: 'eks:listNodegroups',
150+
err,
151+
})
152+
}
153+
154+
/**
155+
* No node groups for this region
156+
*/
157+
if (isEmpty(data)) {
158+
return resolve(nodeGroupsList)
159+
}
160+
161+
const { nextToken, nodegroups } = data || {}
162+
163+
nodeGroupsList.push(...nodegroups)
164+
165+
if (nextToken) {
166+
listAllNodeGroups(nextToken)
167+
}
168+
169+
resolve(nodeGroupsList)
170+
}
171+
)
172+
} catch (error) {
173+
resolve([])
174+
}
175+
}
176+
listAllNodeGroups()
177+
})
178+
126179
export interface RawAwsEksCluster extends Omit<Cluster, 'Tags'> {
127180
region: string
128181
Tags?: TagMap
182+
NodeGroups?: string[]
129183
}
130184

131185
export default async ({
@@ -140,6 +194,7 @@ export default async ({
140194
const regionPromises = []
141195
const clusterPromises = []
142196
const tagsPromises = []
197+
const nodeGroupsPromises = []
143198

144199
// get all clusters for all regions
145200
regions.split(',').map(region => {
@@ -192,6 +247,22 @@ export default async ({
192247
})
193248

194249
await Promise.all(tagsPromises)
250+
251+
// get all node groups for each cluster
252+
eksData.map(({ name, region }, idx) => {
253+
const eks = new EKS({ ...config, region, endpoint })
254+
const nodeGroupsPromise = new Promise<void>(async resolveNodeGroups => {
255+
const nodeGroups: string[] = await listNodegroups({
256+
eks,
257+
clusterName: name,
258+
})
259+
eksData[idx].NodeGroups = nodeGroups
260+
resolveNodeGroups()
261+
})
262+
nodeGroupsPromises.push(nodeGroupsPromise)
263+
})
264+
265+
await Promise.all(nodeGroupsPromises)
195266
errorLog.reset()
196267

197268
resolve(groupBy(eksData, 'region'))

src/services/eksCluster/format.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ export default ({
2929
platformVersion,
3030
encryptionConfig,
3131
Tags = {},
32+
NodeGroups: nodeGroups = []
3233
} = service
3334

3435
const formattedKubernetesNetworkConfig = {
@@ -70,5 +71,6 @@ export default ({
7071
...config,
7172
})),
7273
tags: formatTagsFromMap(Tags),
74+
nodeGroups
7375
}
7476
}

src/services/eksCluster/schema.graphql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ type awsEksCluster implements awsBaseService @key(fields: "arn") {
1313
platformVersion: String @search(by: [hash, regexp])
1414
encryptionConfig: [awsEksEncryptionConfig]
1515
tags: [awsRawTag]
16+
nodeGroups: [String] @search(by: [hash])
1617
iamRoles: [awsIamRole] @hasInverse(field: eksClusters)
1718
kms: [awsKms] @hasInverse(field: eksCluster)
1819
securityGroups: [awsSecurityGroup] @hasInverse(field: eksCluster)

src/types/generated.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -849,6 +849,7 @@ export type AwsCloudfront = AwsBaseService & {
849849

850850
export type AwsCloudfrontCacheBehavior = {
851851
allowedMethods?: Maybe<Array<Maybe<Scalars['String']>>>;
852+
cachePolicyId?: Maybe<Scalars['String']>;
852853
cachedMethods?: Maybe<Array<Maybe<Scalars['String']>>>;
853854
compress?: Maybe<Scalars['String']>;
854855
defaultTtl?: Maybe<Scalars['String']>;
@@ -2376,6 +2377,7 @@ export type AwsEksCluster = AwsBaseService & {
23762377
kubernetesNetworkConfig?: Maybe<AwsEksKubernetesNetworkConfigResponse>;
23772378
logging?: Maybe<AwsEksLogging>;
23782379
name?: Maybe<Scalars['String']>;
2380+
nodeGroups?: Maybe<Array<Maybe<Scalars['String']>>>;
23792381
platformVersion?: Maybe<Scalars['String']>;
23802382
resourcesVpcConfig?: Maybe<AwsEksVpcConfigResponse>;
23812383
securityGroups?: Maybe<Array<Maybe<AwsSecurityGroup>>>;

0 commit comments

Comments
 (0)