|
|
@@ -5,12 +5,15 @@ import {
|
|
|
AWSClusterNetwork,
|
|
|
Cluster,
|
|
|
EKS,
|
|
|
+ EKSLogging,
|
|
|
EKSNodeGroup,
|
|
|
EnumCloudProvider,
|
|
|
GKE,
|
|
|
GKENetwork,
|
|
|
GKENodePool,
|
|
|
GKENodePoolType,
|
|
|
+ LoadBalancer,
|
|
|
+ LoadBalancerType,
|
|
|
NodeGroupType,
|
|
|
NodePoolType,
|
|
|
type Contract,
|
|
|
@@ -19,8 +22,11 @@ import { match } from "ts-pattern";
|
|
|
|
|
|
import {
|
|
|
type AKSClientClusterConfig,
|
|
|
+ type AWSRegion,
|
|
|
+ type AzureRegion,
|
|
|
type ClientClusterContract,
|
|
|
type EKSClientClusterConfig,
|
|
|
+ type GCPRegion,
|
|
|
type GKEClientClusterConfig,
|
|
|
} from "./types";
|
|
|
|
|
|
@@ -41,7 +47,7 @@ export function updateExistingClusterContract(
|
|
|
if (cluster.kindValues.case !== "eksKind") {
|
|
|
throw new Error("Invalid kind value for EKS");
|
|
|
}
|
|
|
- cluster.kindValues.value = updateEKSKindValues(
|
|
|
+ cluster.kindValues.value = clientEKSConfigToProto(
|
|
|
config,
|
|
|
cluster.kindValues.value
|
|
|
);
|
|
|
@@ -50,7 +56,7 @@ export function updateExistingClusterContract(
|
|
|
if (cluster.kindValues.case !== "gkeKind") {
|
|
|
throw new Error("Invalid kind value for GKE");
|
|
|
}
|
|
|
- cluster.kindValues.value = updateGKEKindValues(
|
|
|
+ cluster.kindValues.value = clientGKEConfigToProto(
|
|
|
config,
|
|
|
cluster.kindValues.value
|
|
|
);
|
|
|
@@ -59,7 +65,7 @@ export function updateExistingClusterContract(
|
|
|
if (cluster.kindValues.case !== "aksKind") {
|
|
|
throw new Error("Invalid kind value for AKS");
|
|
|
}
|
|
|
- cluster.kindValues.value = updateAKSKindValues(
|
|
|
+ cluster.kindValues.value = clientAKSConfigToProto(
|
|
|
config,
|
|
|
cluster.kindValues.value
|
|
|
);
|
|
|
@@ -68,7 +74,7 @@ export function updateExistingClusterContract(
|
|
|
return cluster;
|
|
|
}
|
|
|
|
|
|
-function updateEKSKindValues(
|
|
|
+function clientEKSConfigToProto(
|
|
|
clientConfig: EKSClientClusterConfig,
|
|
|
existingConfig: EKS
|
|
|
): EKS {
|
|
|
@@ -90,15 +96,44 @@ function updateEKSKindValues(
|
|
|
.otherwise(() => NodeGroupType.UNSPECIFIED),
|
|
|
});
|
|
|
}),
|
|
|
- cidrRange: clientConfig.cidrRange, // this should be removed once we no longer use the deprecated value
|
|
|
network: new AWSClusterNetwork({
|
|
|
...(existingConfig?.network ?? {}),
|
|
|
vpcCidr: clientConfig.cidrRange,
|
|
|
}),
|
|
|
+ loadBalancer: new LoadBalancer({
|
|
|
+ loadBalancerType: match(clientConfig.loadBalancer.type)
|
|
|
+ .with("NLB", () => LoadBalancerType.NLB)
|
|
|
+ .with("ALB", () => LoadBalancerType.ALB)
|
|
|
+ .otherwise(() => LoadBalancerType.UNSPECIFIED),
|
|
|
+ wildcardDomain: clientConfig.loadBalancer.wildcardDomain,
|
|
|
+ allowlistIpRanges: clientConfig.loadBalancer.allowlistIpRanges,
|
|
|
+ enableWafv2: clientConfig.loadBalancer.isWafV2Enabled,
|
|
|
+ wafv2Arn: clientConfig.loadBalancer.wafV2Arn,
|
|
|
+ additionalCertificateArns: clientConfig.loadBalancer.certificateArns.map(
|
|
|
+ (certArn) => certArn.arn
|
|
|
+ ),
|
|
|
+ tags: Object.fromEntries(
|
|
|
+ clientConfig.loadBalancer.awsTags
|
|
|
+ .filter((tag) => tag.key.length > 0 && tag.value.length > 0)
|
|
|
+ .map((tag) => [tag.key, tag.value])
|
|
|
+ ),
|
|
|
+ }),
|
|
|
+ logging: new EKSLogging({
|
|
|
+ ...(existingConfig?.logging ?? {}),
|
|
|
+ enableApiServerLogs: clientConfig.logging.isApiServerLogsEnabled,
|
|
|
+ enableAuditLogs: clientConfig.logging.isAuditLogsEnabled,
|
|
|
+ enableAuthenticatorLogs: clientConfig.logging.isAuthenticatorLogsEnabled,
|
|
|
+ enableControllerManagerLogs:
|
|
|
+ clientConfig.logging.isControllerManagerLogsEnabled,
|
|
|
+ enableSchedulerLogs: clientConfig.logging.isSchedulerLogsEnabled,
|
|
|
+ }),
|
|
|
+ enableEcrScanning: clientConfig.isEcrScanningEnabled,
|
|
|
+ enableGuardDuty: clientConfig.isGuardDutyEnabled,
|
|
|
+ enableKmsEncryption: clientConfig.isKmsEncryptionEnabled,
|
|
|
});
|
|
|
}
|
|
|
|
|
|
-function updateGKEKindValues(
|
|
|
+function clientGKEConfigToProto(
|
|
|
clientConfig: GKEClientClusterConfig,
|
|
|
existingConfig: GKE
|
|
|
): GKE {
|
|
|
@@ -133,7 +168,7 @@ function updateGKEKindValues(
|
|
|
});
|
|
|
}
|
|
|
|
|
|
-function updateAKSKindValues(
|
|
|
+function clientAKSConfigToProto(
|
|
|
clientConfig: AKSClientClusterConfig,
|
|
|
existingConfig: AKS
|
|
|
): AKS {
|
|
|
@@ -181,89 +216,138 @@ export function clientClusterContractFromProto(
|
|
|
.otherwise(() => "Local" as const),
|
|
|
cloudProviderCredentialsId: contractCluster.cloudProviderCredentialsId,
|
|
|
config: match(contractCluster.kindValues)
|
|
|
- .with({ case: "eksKind" }, ({ value }) => ({
|
|
|
- kind: "EKS" as const,
|
|
|
- clusterName: value.clusterName,
|
|
|
- clusterVersion: value.clusterVersion,
|
|
|
- region: value.region,
|
|
|
- nodeGroups: value.nodeGroups.map((ng) => {
|
|
|
- return {
|
|
|
- instanceType: ng.instanceType,
|
|
|
- minInstances: ng.minInstances,
|
|
|
- maxInstances: ng.maxInstances,
|
|
|
- nodeGroupType: match(ng.nodeGroupType)
|
|
|
- .with(NodeGroupType.UNSPECIFIED, () => "UNKNOWN" as const)
|
|
|
- .with(NodeGroupType.SYSTEM, () => "SYSTEM" as const)
|
|
|
- .with(NodeGroupType.MONITORING, () => "MONITORING" as const)
|
|
|
- .with(NodeGroupType.APPLICATION, () => "APPLICATION" as const)
|
|
|
- .with(NodeGroupType.CUSTOM, () => "CUSTOM" as const)
|
|
|
- .otherwise(() => "UNKNOWN" as const),
|
|
|
- };
|
|
|
- }),
|
|
|
- cidrRange: value.network?.vpcCidr ?? value.cidrRange ?? "", // network will always be provided in one of those fields
|
|
|
- }))
|
|
|
- .with({ case: "gkeKind" }, ({ value }) => ({
|
|
|
- kind: "GKE" as const,
|
|
|
- clusterName: value.clusterName,
|
|
|
- clusterVersion: value.clusterVersion,
|
|
|
- region: value.region,
|
|
|
- nodeGroups: value.nodePools.map((ng) => {
|
|
|
- return {
|
|
|
- instanceType: ng.instanceType,
|
|
|
- minInstances: ng.minInstances,
|
|
|
- maxInstances: ng.maxInstances,
|
|
|
- nodeGroupType: match(ng.nodePoolType)
|
|
|
- .with(
|
|
|
- GKENodePoolType.GKE_NODE_POOL_TYPE_UNSPECIFIED,
|
|
|
- () => "UNKNOWN" as const
|
|
|
- )
|
|
|
- .with(
|
|
|
- GKENodePoolType.GKE_NODE_POOL_TYPE_SYSTEM,
|
|
|
- () => "SYSTEM" as const
|
|
|
- )
|
|
|
- .with(
|
|
|
- GKENodePoolType.GKE_NODE_POOL_TYPE_MONITORING,
|
|
|
- () => "MONITORING" as const
|
|
|
- )
|
|
|
- .with(
|
|
|
- GKENodePoolType.GKE_NODE_POOL_TYPE_APPLICATION,
|
|
|
- () => "APPLICATION" as const
|
|
|
- )
|
|
|
- .with(
|
|
|
- GKENodePoolType.GKE_NODE_POOL_TYPE_CUSTOM,
|
|
|
- () => "CUSTOM" as const
|
|
|
- )
|
|
|
- .otherwise(() => "UNKNOWN" as const),
|
|
|
- };
|
|
|
- }),
|
|
|
- cidrRange: value.network?.cidrRange ?? "", // network will always be provided
|
|
|
- }))
|
|
|
- .with({ case: "aksKind" }, ({ value }) => ({
|
|
|
- kind: "AKS" as const,
|
|
|
- clusterName: value.clusterName,
|
|
|
- clusterVersion: value.clusterVersion,
|
|
|
- region: value.location,
|
|
|
- nodeGroups: value.nodePools.map((ng) => {
|
|
|
- return {
|
|
|
- instanceType: ng.instanceType,
|
|
|
- minInstances: ng.minInstances,
|
|
|
- maxInstances: ng.maxInstances,
|
|
|
- nodeGroupType: match(ng.nodePoolType)
|
|
|
- .with(NodePoolType.UNSPECIFIED, () => "UNKNOWN" as const)
|
|
|
- .with(NodePoolType.SYSTEM, () => "SYSTEM" as const)
|
|
|
- .with(NodePoolType.MONITORING, () => "MONITORING" as const)
|
|
|
- .with(NodePoolType.APPLICATION, () => "APPLICATION" as const)
|
|
|
- .with(NodePoolType.CUSTOM, () => "CUSTOM" as const)
|
|
|
- .otherwise(() => "UNKNOWN" as const),
|
|
|
- };
|
|
|
- }),
|
|
|
- skuTier: match(value.skuTier)
|
|
|
- .with(AksSkuTier.FREE, () => "FREE" as const)
|
|
|
- .with(AksSkuTier.STANDARD, () => "STANDARD" as const)
|
|
|
- .otherwise(() => "UNKNOWN" as const),
|
|
|
- cidrRange: value.cidrRange,
|
|
|
- }))
|
|
|
+ .with({ case: "eksKind" }, ({ value }) =>
|
|
|
+ clientEKSConfigFromProto(value)
|
|
|
+ )
|
|
|
+ .with({ case: "gkeKind" }, ({ value }) =>
|
|
|
+ clientGKEConfigFromProto(value)
|
|
|
+ )
|
|
|
+ .with({ case: "aksKind" }, ({ value }) =>
|
|
|
+ clientAKSConfigFromProto(value)
|
|
|
+ )
|
|
|
.exhaustive(),
|
|
|
},
|
|
|
};
|
|
|
}
|
|
|
+
|
|
|
+const clientEKSConfigFromProto = (value: EKS): EKSClientClusterConfig => {
|
|
|
+ return {
|
|
|
+ kind: "EKS",
|
|
|
+ clusterName: value.clusterName,
|
|
|
+ region: value.region as AWSRegion, // remove type assertion here somehow
|
|
|
+ clusterVersion: value.clusterVersion,
|
|
|
+ nodeGroups: value.nodeGroups.map((ng) => {
|
|
|
+ return {
|
|
|
+ instanceType: ng.instanceType,
|
|
|
+ minInstances: ng.minInstances,
|
|
|
+ maxInstances: ng.maxInstances,
|
|
|
+ nodeGroupType: match(ng.nodeGroupType)
|
|
|
+ .with(NodeGroupType.UNSPECIFIED, () => "UNKNOWN" as const)
|
|
|
+ .with(NodeGroupType.SYSTEM, () => "SYSTEM" as const)
|
|
|
+ .with(NodeGroupType.MONITORING, () => "MONITORING" as const)
|
|
|
+ .with(NodeGroupType.APPLICATION, () => "APPLICATION" as const)
|
|
|
+ .with(NodeGroupType.CUSTOM, () => "CUSTOM" as const)
|
|
|
+ .otherwise(() => "UNKNOWN" as const),
|
|
|
+ };
|
|
|
+ }),
|
|
|
+ cidrRange: value.network?.vpcCidr ?? value.cidrRange ?? "", // network will always be provided in one of those fields
|
|
|
+ logging: {
|
|
|
+ isApiServerLogsEnabled: value.logging?.enableApiServerLogs ?? false,
|
|
|
+ isAuditLogsEnabled: value.logging?.enableAuditLogs ?? false,
|
|
|
+ isAuthenticatorLogsEnabled:
|
|
|
+ value.logging?.enableAuthenticatorLogs ?? false,
|
|
|
+ isControllerManagerLogsEnabled:
|
|
|
+ value.logging?.enableControllerManagerLogs ?? false,
|
|
|
+ isSchedulerLogsEnabled: value.logging?.enableSchedulerLogs ?? false,
|
|
|
+ },
|
|
|
+ loadBalancer: {
|
|
|
+ type: match(value.loadBalancer?.loadBalancerType)
|
|
|
+ .with(LoadBalancerType.NLB, () => "NLB" as const)
|
|
|
+ .with(LoadBalancerType.ALB, () => "ALB" as const)
|
|
|
+ .otherwise(() => "UNKNOWN" as const),
|
|
|
+ wildcardDomain: value.loadBalancer?.wildcardDomain ?? "",
|
|
|
+ allowlistIpRanges: value.loadBalancer?.allowlistIpRanges ?? "",
|
|
|
+ certificateArns: (
|
|
|
+ value.loadBalancer?.additionalCertificateArns ?? []
|
|
|
+ ).map((arn) => ({ arn })),
|
|
|
+ awsTags: Object.entries(value.loadBalancer?.tags ?? {}).map((tag) => {
|
|
|
+ return {
|
|
|
+ key: tag[0],
|
|
|
+ value: tag[1],
|
|
|
+ };
|
|
|
+ }),
|
|
|
+ isWafV2Enabled: value.loadBalancer?.enableWafv2 ?? false,
|
|
|
+ wafV2Arn: value.loadBalancer?.wafv2Arn ?? "",
|
|
|
+ },
|
|
|
+ isEcrScanningEnabled: value.enableEcrScanning,
|
|
|
+ isGuardDutyEnabled: value.enableGuardDuty,
|
|
|
+ isKmsEncryptionEnabled: value.enableKmsEncryption,
|
|
|
+ };
|
|
|
+};
|
|
|
+
|
|
|
+const clientGKEConfigFromProto = (value: GKE): GKEClientClusterConfig => {
|
|
|
+ return {
|
|
|
+ kind: "GKE",
|
|
|
+ clusterName: value.clusterName,
|
|
|
+ region: value.region as GCPRegion, // remove type assertion here somehow
|
|
|
+ clusterVersion: value.clusterVersion,
|
|
|
+ nodeGroups: value.nodePools.map((ng) => {
|
|
|
+ return {
|
|
|
+ instanceType: ng.instanceType,
|
|
|
+ minInstances: ng.minInstances,
|
|
|
+ maxInstances: ng.maxInstances,
|
|
|
+ nodeGroupType: match(ng.nodePoolType)
|
|
|
+ .with(
|
|
|
+ GKENodePoolType.GKE_NODE_POOL_TYPE_UNSPECIFIED,
|
|
|
+ () => "UNKNOWN" as const
|
|
|
+ )
|
|
|
+ .with(
|
|
|
+ GKENodePoolType.GKE_NODE_POOL_TYPE_SYSTEM,
|
|
|
+ () => "SYSTEM" as const
|
|
|
+ )
|
|
|
+ .with(
|
|
|
+ GKENodePoolType.GKE_NODE_POOL_TYPE_MONITORING,
|
|
|
+ () => "MONITORING" as const
|
|
|
+ )
|
|
|
+ .with(
|
|
|
+ GKENodePoolType.GKE_NODE_POOL_TYPE_APPLICATION,
|
|
|
+ () => "APPLICATION" as const
|
|
|
+ )
|
|
|
+ .with(
|
|
|
+ GKENodePoolType.GKE_NODE_POOL_TYPE_CUSTOM,
|
|
|
+ () => "CUSTOM" as const
|
|
|
+ )
|
|
|
+ .otherwise(() => "UNKNOWN" as const),
|
|
|
+ };
|
|
|
+ }),
|
|
|
+ cidrRange: value.network?.cidrRange ?? "", // network will always be provided
|
|
|
+ };
|
|
|
+};
|
|
|
+
|
|
|
+const clientAKSConfigFromProto = (value: AKS): AKSClientClusterConfig => {
|
|
|
+ return {
|
|
|
+ kind: "AKS",
|
|
|
+ clusterName: value.clusterName,
|
|
|
+ region: value.location as AzureRegion, // remove type assertion here somehow
|
|
|
+ clusterVersion: value.clusterVersion,
|
|
|
+ nodeGroups: value.nodePools.map((ng) => {
|
|
|
+ return {
|
|
|
+ instanceType: ng.instanceType,
|
|
|
+ minInstances: ng.minInstances,
|
|
|
+ maxInstances: ng.maxInstances,
|
|
|
+ nodeGroupType: match(ng.nodePoolType)
|
|
|
+ .with(NodePoolType.UNSPECIFIED, () => "UNKNOWN" as const)
|
|
|
+ .with(NodePoolType.SYSTEM, () => "SYSTEM" as const)
|
|
|
+ .with(NodePoolType.MONITORING, () => "MONITORING" as const)
|
|
|
+ .with(NodePoolType.APPLICATION, () => "APPLICATION" as const)
|
|
|
+ .with(NodePoolType.CUSTOM, () => "CUSTOM" as const)
|
|
|
+ .otherwise(() => "UNKNOWN" as const),
|
|
|
+ };
|
|
|
+ }),
|
|
|
+ skuTier: match(value.skuTier)
|
|
|
+ .with(AksSkuTier.FREE, () => "FREE" as const)
|
|
|
+ .with(AksSkuTier.STANDARD, () => "STANDARD" as const)
|
|
|
+ .otherwise(() => "UNKNOWN" as const),
|
|
|
+ cidrRange: value.cidrRange,
|
|
|
+ };
|
|
|
+};
|