Skip to content

Commit 0998bb4

Browse files
authored
fix(iam): make karpenter and cluster-autoscaler mutual exclusion (#175)
<!-- ~ Copyright 2023 StreamNative, Inc. ~ ~ Licensed under the Apache License, Version 2.0 (the "License"); ~ you may not use this file except in compliance with the License. ~ You may obtain a copy of the License at ~ ~ http://www.apache.org/licenses/LICENSE-2.0 ~ ~ Unless required by applicable law or agreed to in writing, software ~ distributed under the License is distributed on an "AS IS" BASIS, ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ~ See the License for the specific language governing permissions and ~ limitations under the License. --> <!-- ### Contribution Checklist - Fill out the template below to describe the changes contributed by the pull request. That will give reviewers the context they need to do the review. - Each pull request should address only one issue, not mix up code from multiple issues. - Each commit in the pull request has a meaningful commit message - Once all items of the checklist are addressed, remove the above text and this checklist, leaving only the filled out template below. **(The sections below can be removed for hotfixes of typos)** --> ### Motivation We should make karpenter and cluster-autoscaler mutual exclusion ### Modifications - make karpenter and cluster-autoscaler mutual exclusion, and protect the output ### Verifying this change - [x] Make sure that the change passes the CI checks. ### Documentation - [x] `no-need-doc` Signed-off-by: Max Xu <[email protected]>
1 parent 3dcf193 commit 0998bb4

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

modules/iam/cluster_autoscaler.tf

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
data "aws_iam_policy_document" "cluster_autoscaler_sts" {
2-
count = var.enable_karpenter ? 1 : 0
2+
count = var.enable_karpenter ? 0 : 1
33

44
statement {
55
actions = [
@@ -24,7 +24,7 @@ data "aws_iam_policy_document" "cluster_autoscaler_sts" {
2424
}
2525

2626
resource "aws_iam_role" "cluster_autoscaler" {
27-
count = var.enable_karpenter ? 1 : 0
27+
count = var.enable_karpenter ? 0 : 1
2828

2929
name = format("%s-ca-role", var.cluster_name)
3030
description = format("Role used by IRSA and the KSA cluster-autoscaler on StreamNative Cloud EKS cluster %s", var.cluster_name)
@@ -35,7 +35,7 @@ resource "aws_iam_role" "cluster_autoscaler" {
3535
}
3636

3737
resource "aws_iam_role_policy_attachment" "cluster_autoscaler" {
38-
count = var.enable_karpenter ? 1 : 0
38+
count = var.enable_karpenter ? 0 : 1
3939

4040
policy_arn = local.default_service_policy_arn
4141
role = aws_iam_role.cluster_autoscaler.0.name

modules/iam/outputs.tf

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ output "cert_manager_arn" {
77
}
88

99
output "cluster_autoscaler_arn" {
10-
value = aws_iam_role.cluster_autoscaler.0.arn
10+
value = try(aws_iam_role.cluster_autoscaler[0].arn, null)
1111
}
1212

1313
output "csi_arn" {
@@ -19,9 +19,9 @@ output "external_dns_arn" {
1919
}
2020

2121
output "karpenter_arn" {
22-
value = aws_iam_role.karpenter.0.arn
22+
value = try(aws_iam_role.karpenter[0].arn, null)
2323
}
2424

2525
output "velero_arn" {
26-
value = aws_iam_role.velero.0.arn
26+
value = try(aws_iam_role.velero[0].arn, null)
2727
}

0 commit comments

Comments
 (0)