-
Notifications
You must be signed in to change notification settings - Fork 205
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1029 from aws-quickstart/feature/cxpAddonUpgrade
Upbound CrossPlane addon upgrade
- Loading branch information
Showing
4 changed files
with
114 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,97 @@ | ||
import { CoreAddOn } from "../core-addon"; | ||
import { supportsX86 } from "../../utils"; | ||
import 'source-map-support/register'; | ||
import { Construct } from 'constructs'; | ||
import {ClusterInfo, Values} from "../../spi"; | ||
import { merge } from "ts-deepmerge"; | ||
import {createNamespace, supportsALL} from '../../utils'; | ||
import {IRole, Policy, PolicyDocument} from 'aws-cdk-lib/aws-iam'; | ||
import * as cdk from 'aws-cdk-lib'; | ||
import {HelmAddOn, HelmAddOnUserProps} from "../helm-addon"; | ||
|
||
/** | ||
* Interface for Upbound Universal Crossplane EKS add-on options | ||
* User provided options for the Helm Chart. | ||
*/ | ||
interface UpboundUniversalCrossplaneAddOnProps { | ||
export interface UpboundCrossplaneAddOnProps extends HelmAddOnUserProps { | ||
/** | ||
* Version of the driver to deploy | ||
* To Create Namespace using CDK | ||
*/ | ||
version?: string; | ||
createNamespace?: boolean; | ||
/* | ||
* EKS Cluster Access Role. | ||
* This is a role with right permissions that will be used by CrossPlane AWS provider | ||
* to provision AWS resources. | ||
*/ | ||
clusterAccessRole: IRole; | ||
} | ||
|
||
/** | ||
* Default values for the add-on | ||
*/ | ||
const defaultProps = { | ||
addOnName: "upbound_universal-crossplane", | ||
version: "v1.9.1-eksbuild.0" | ||
name: 'uxp', | ||
release: 'blueprints-addon-uxp', | ||
namespace: 'upbound-system', | ||
chart: 'universal-crossplane', | ||
version: '1.14.5-up.1', | ||
repository: 'https://charts.upbound.io/stable', | ||
values: {} | ||
}; | ||
|
||
/** | ||
* Implementation of Upbound Crossplane EKS add-on | ||
*/ | ||
@supportsX86 | ||
export class UpboundUniversalCrossplaneAddOn extends CoreAddOn { | ||
|
||
constructor(readonly options?: UpboundUniversalCrossplaneAddOnProps) { | ||
super({ | ||
addOnName: defaultProps.addOnName, | ||
version: options?.version ?? defaultProps.version, | ||
saName: "" | ||
}); | ||
@supportsALL | ||
export class UpboundCrossplaneAddOn extends HelmAddOn { | ||
|
||
readonly options: UpboundCrossplaneAddOnProps; | ||
|
||
constructor( props?: UpboundCrossplaneAddOnProps) { | ||
super({...defaultProps, ...props}); | ||
|
||
this.options = this.props as UpboundCrossplaneAddOnProps; | ||
} | ||
} | ||
|
||
deploy(clusterInfo: ClusterInfo): void | Promise<Construct> { | ||
const cluster = clusterInfo.cluster; | ||
|
||
// Create the `upbound-system` namespace. | ||
const ns = createNamespace(this.options.namespace!, cluster, true); | ||
|
||
// Create the CrossPlane AWS Provider IRSA. | ||
const serviceAccountName = "provider-aws"; | ||
const sa = cluster.addServiceAccount(serviceAccountName, { | ||
name: serviceAccountName, | ||
namespace: this.options.namespace!, | ||
|
||
}); | ||
|
||
sa.node.addDependency(ns); | ||
sa.role.attachInlinePolicy(new Policy(cluster.stack, 'eks-connect-policy', { | ||
document: PolicyDocument.fromJson({ | ||
"Version": "2012-10-17", | ||
"Statement": [ | ||
{ | ||
"Effect": "Allow", | ||
"Action": ["sts:AssumeRole"], | ||
"Resource": `${this.options.clusterAccessRole.roleArn}` | ||
}, | ||
{ | ||
"Effect": "Allow", | ||
"Action": ["eks:*"], | ||
"Resource": `*` | ||
} | ||
] | ||
})})); | ||
|
||
clusterInfo.addAddOnContext(UpboundCrossplaneAddOn.name, { | ||
arn: sa.role.roleArn | ||
}); | ||
|
||
new cdk.CfnOutput(cluster.stack, 'providerawssaiamrole', | ||
{ | ||
value: sa.role.roleArn, | ||
description: 'provider AWS IAM role', | ||
exportName : 'providerawssaiamrole' | ||
}); | ||
|
||
let values: Values = this.options.values ?? {}; | ||
values = merge(values, values); | ||
|
||
const chart = this.addHelmChart(clusterInfo, values, false, true); | ||
chart.node.addDependency(sa); | ||
return Promise.resolve(chart); | ||
} | ||
} |