From 9ee01dae76f0d0ced9e66e6c172f197d2a1b761e Mon Sep 17 00:00:00 2001 From: Zhihong Lin Date: Thu, 16 Jan 2025 11:18:40 -0500 Subject: [PATCH 1/3] Add pod identity credential integration test --- .../eksdeploymenttype/eks_deployment_type.go | 18 +- generator/test_case_generator.go | 4 + .../daemon/credentials/pod_identity/main.tf | 324 ++++++++++++++++++ .../credentials/pod_identity/providers.tf | 29 ++ .../credentials/pod_identity/variables.tf | 42 +++ test/metric/container_insights_util.go | 19 + .../eks_daemonset_test.go | 5 +- .../metrics_value_benchmark_test.go | 10 + 8 files changed, 442 insertions(+), 9 deletions(-) create mode 100644 terraform/eks/daemon/credentials/pod_identity/main.tf create mode 100644 terraform/eks/daemon/credentials/pod_identity/providers.tf create mode 100644 terraform/eks/daemon/credentials/pod_identity/variables.tf diff --git a/environment/eksdeploymenttype/eks_deployment_type.go b/environment/eksdeploymenttype/eks_deployment_type.go index 856a2db00..5fb0edb9d 100644 --- a/environment/eksdeploymenttype/eks_deployment_type.go +++ b/environment/eksdeploymenttype/eks_deployment_type.go @@ -8,18 +8,20 @@ import "strings" type EKSDeploymentType string const ( - DAEMON EKSDeploymentType = "DAEMON" - REPLICA EKSDeploymentType = "REPLICA" - SIDECAR EKSDeploymentType = "SIDECAR" - STATEFUL EKSDeploymentType = "STATEFUL" + DAEMON EKSDeploymentType = "DAEMON" + REPLICA EKSDeploymentType = "REPLICA" + SIDECAR EKSDeploymentType = "SIDECAR" + STATEFUL EKSDeploymentType = "STATEFUL" + PODIDENTITY EKSDeploymentType = "PODIDENTITY" ) var ( eksDeploymentTypes = map[string]EKSDeploymentType{ - "DAEMON": DAEMON, - "REPLICA": REPLICA, - "SIDECAR": SIDECAR, - "STATEFUL": STATEFUL, + "DAEMON": DAEMON, + "REPLICA": REPLICA, + "SIDECAR": SIDECAR, + "STATEFUL": STATEFUL, + "PODIDENTITY": PODIDENTITY, } ) diff --git a/generator/test_case_generator.go b/generator/test_case_generator.go index 26c245623..7258f362d 100644 --- a/generator/test_case_generator.go +++ b/generator/test_case_generator.go @@ -242,6 +242,10 @@ var testTypeToTestConfig = map[string][]testConfig{ testDir: "./test/efa", terraformDir: "terraform/eks/daemon/efa", targets: map[string]map[string]struct{}{"arc": {"amd64": {}}}, }, + { + testDir: "./test/metric_value_benchmark", terraformDir: "terraform/eks/daemon/credentials/pod_identity", + targets: map[string]map[string]struct{}{"arc": {"amd64": {}}}, + }, }, "eks_deployment": { {testDir: "./test/metric_value_benchmark"}, diff --git a/terraform/eks/daemon/credentials/pod_identity/main.tf b/terraform/eks/daemon/credentials/pod_identity/main.tf new file mode 100644 index 000000000..044093bce --- /dev/null +++ b/terraform/eks/daemon/credentials/pod_identity/main.tf @@ -0,0 +1,324 @@ +// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. +// SPDX-License-Identifier: MIT + +module "common" { + source = "../../../../common" +} + +module "basic_components" { + source = "../../../../basic_components" + + region = var.region +} + +locals { + aws_eks = "aws eks --region ${var.region}" +} + +data "aws_eks_cluster_auth" "this" { + name = aws_eks_cluster.this.name +} + +resource "aws_eks_cluster" "this" { + name = "cwagent-eks-integ-${module.common.testing_id}" + role_arn = module.basic_components.role_arn + version = var.k8s_version + vpc_config { + subnet_ids = module.basic_components.public_subnet_ids + security_group_ids = [module.basic_components.security_group] + } +} + +# EKS Node Groups +resource "aws_eks_node_group" "this" { + cluster_name = aws_eks_cluster.this.name + node_group_name = "cwagent-eks-integ-node-${module.common.testing_id}" + node_role_arn = aws_iam_role.node_role.arn + subnet_ids = module.basic_components.public_subnet_ids + + scaling_config { + desired_size = 1 + max_size = 1 + min_size = 1 + } + + ami_type = var.ami_type + capacity_type = "ON_DEMAND" + disk_size = 20 + instance_types = [var.instance_type] + + depends_on = [ + aws_iam_role_policy_attachment.node_AmazonEC2ContainerRegistryReadOnly, + aws_iam_role_policy_attachment.node_AmazonEKS_CNI_Policy, + aws_iam_role_policy_attachment.node_AmazonEKSWorkerNodePolicy, + aws_iam_role_policy_attachment.pod_CloudWatchAgentServerPolicy + ] +} + +resource "aws_eks_addon" "pod_identity_addon" { + cluster_name = aws_eks_cluster.this.name + addon_name = "eks-pod-identity-agent" + depends_on = [aws_eks_node_group.this] +} + +# EKS Node IAM Role +resource "aws_iam_role" "node_role" { + name = "cwagent-eks-Worker-Role-${module.common.testing_id}" + + assume_role_policy = < Date: Thu, 16 Jan 2025 11:31:24 -0500 Subject: [PATCH 2/3] Fix linter error --- terraform/eks/daemon/credentials/pod_identity/main.tf | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/terraform/eks/daemon/credentials/pod_identity/main.tf b/terraform/eks/daemon/credentials/pod_identity/main.tf index 044093bce..266ceaf41 100644 --- a/terraform/eks/daemon/credentials/pod_identity/main.tf +++ b/terraform/eks/daemon/credentials/pod_identity/main.tf @@ -58,7 +58,7 @@ resource "aws_eks_node_group" "this" { resource "aws_eks_addon" "pod_identity_addon" { cluster_name = aws_eks_cluster.this.name addon_name = "eks-pod-identity-agent" - depends_on = [aws_eks_node_group.this] + depends_on = [aws_eks_node_group.this] } # EKS Node IAM Role @@ -124,11 +124,11 @@ resource "aws_iam_role_policy_attachment" "pod_CloudWatchAgentServerPolicy" { } resource "aws_eks_pod_identity_association" "association" { - cluster_name = aws_eks_cluster.this.name - namespace = "amazon-cloudwatch" + cluster_name = aws_eks_cluster.this.name + namespace = "amazon-cloudwatch" service_account = "cloudwatch-agent" - role_arn = aws_iam_role.pod-identity-role.arn - depends_on = [aws_eks_cluster.this] + role_arn = aws_iam_role.pod-identity-role.arn + depends_on = [aws_eks_cluster.this] } # TODO: these security groups be created once and then reused From 03b5fe8335155d6cb09de38fd0b10aa0314709c2 Mon Sep 17 00:00:00 2001 From: Zhihong Lin Date: Thu, 23 Jan 2025 21:32:11 -0500 Subject: [PATCH 3/3] Remove fluentbit changes --- terraform/eks/daemon/credentials/pod_identity/main.tf | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/terraform/eks/daemon/credentials/pod_identity/main.tf b/terraform/eks/daemon/credentials/pod_identity/main.tf index 266ceaf41..59b1ca5d0 100644 --- a/terraform/eks/daemon/credentials/pod_identity/main.tf +++ b/terraform/eks/daemon/credentials/pod_identity/main.tf @@ -254,7 +254,6 @@ resource "null_resource" "update_image" { command = <<-EOT kubectl -n amazon-cloudwatch patch AmazonCloudWatchAgent cloudwatch-agent --type='json' -p='[{"op": "replace", "path": "/spec/image", "value": "${var.cwagent_image_repo}:${var.cwagent_image_tag}"}]' kubectl set image deployment/amazon-cloudwatch-observability-controller-manager -n amazon-cloudwatch manager=public.ecr.aws/cloudwatch-agent/cloudwatch-agent-operator:latest - kubectl set image daemonset/fluent-bit -n amazon-cloudwatch fluent-bit=506463145083.dkr.ecr.us-west-2.amazonaws.com/fluent-bit-test:latest sleep 10 EOT } @@ -314,7 +313,7 @@ resource "null_resource" "validator" { provisioner "local-exec" { command = <<-EOT - echo "Validating CloudWatch Agent and FluentBit with pod identity credential" + echo "Validating CloudWatch Agent with pod identity credential" cd ../../../../.. go test ./test/metric_value_benchmark -timeout 1h -eksClusterName=${aws_eks_cluster.this.name} -computeType=EKS -v -eksDeploymentStrategy=PODIDENTITY -instanceId=${data.aws_instance.eks_node_detail.instance_id} && go test ./test/fluent -eksClusterName=${aws_eks_cluster.this.name} -computeType=EKS -v -eksDeploymentStrategy=DAEMON