Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions src/provider-helm.tf
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,8 @@ locals {
"--profile", var.kube_exec_auth_aws_profile
] : []

kube_exec_auth_role_arn = coalesce(var.kube_exec_auth_role_arn, module.iam_roles.terraform_role_arn)
exec_role = local.kube_exec_auth_enabled && var.kube_exec_auth_role_arn_enabled ? [
"--role-arn", local.kube_exec_auth_role_arn
"--role-arn", coalesce(var.kube_exec_auth_role_arn, module.iam_roles.terraform_role_arn)
] : []

# Provide dummy configuration for the case where the EKS cluster is not available.
Expand Down
2 changes: 1 addition & 1 deletion src/remote-state.tf
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module "eks" {
source = "cloudposse/stack-config/yaml//modules/remote-state"
version = "1.5.0"
version = "1.8.0"

component = var.eks_component_name

Expand Down
5 changes: 5 additions & 0 deletions test/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
state/
.cache
test/test-suite.json
.atmos
test_suite.yaml
98 changes: 98 additions & 0 deletions test/component_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
package test

import (
"context"
"fmt"
"testing"
"strings"
helper "github.com/cloudposse/test-helpers/pkg/atmos/component-helper"
awsHelper "github.com/cloudposse/test-helpers/pkg/aws"
"github.com/cloudposse/test-helpers/pkg/atmos"
"github.com/cloudposse/test-helpers/pkg/helm"
"github.com/stretchr/testify/assert"
"github.com/gruntwork-io/terratest/modules/random"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
aggregatorclientset "k8s.io/kube-aggregator/pkg/client/clientset_generated/clientset"
)

type ComponentSuite struct {
helper.TestSuite
}

func (s *ComponentSuite) TestBasic() {
const component = "eks/metrics-server/basic"
const stack = "default-test"
const awsRegion = "us-east-2"

randomID := strings.ToLower(random.UniqueId())

namespace := fmt.Sprintf("metrics-server-%s", randomID)

inputs := map[string]interface{}{
"kubernetes_namespace": namespace,
}

defer s.DestroyAtmosComponent(s.T(), component, stack, &inputs)
options, _ := s.DeployAtmosComponent(s.T(), component, stack, &inputs)
assert.NotNil(s.T(), options)

metadataArray := []helm.Metadata{}

atmos.OutputStruct(s.T(), options, "metadata", &metadataArray)

assert.Equal(s.T(), len(metadataArray), 1)
metadata := metadataArray[0]

assert.Equal(s.T(), metadata.AppVersion, "0.6.2")
assert.Equal(s.T(), metadata.Chart, "metrics-server")
assert.NotNil(s.T(), metadata.FirstDeployed)
assert.NotNil(s.T(), metadata.LastDeployed)
assert.Equal(s.T(), metadata.Name, "metrics-server")
assert.Equal(s.T(), metadata.Namespace, namespace)
assert.NotNil(s.T(), metadata.Values)
assert.Equal(s.T(), metadata.Version, "6.2.6")

clusterOptions := s.GetAtmosOptions("eks/cluster", stack, nil)
clusrerId := atmos.Output(s.T(), clusterOptions, "eks_cluster_id")

cluster := awsHelper.GetEksCluster(s.T(), context.Background(), awsRegion, clusrerId)


config, err := awsHelper.NewK8SClientConfig(cluster)
assert.NoError(s.T(), err)
assert.NotNil(s.T(), config)

clientset, err := aggregatorclientset.NewForConfig(config)
assert.NoError(s.T(), err)
assert.NotNil(s.T(), clientset)

// Retrieve the APIService for v1beta1.metrics.k8s.io
apiService, err := clientset.ApiregistrationV1().APIServices().Get(context.Background(), "v1beta1.metrics.k8s.io", metav1.GetOptions{})
assert.NoError(s.T(), err)
assert.NotNil(s.T(), apiService.Spec.Service)

assert.Equal(s.T(), apiService.Spec.Service.Name, "metrics-server")
assert.Equal(s.T(), apiService.Spec.Service.Namespace, namespace)

s.DriftTest(component, stack, &inputs)
}

func (s *ComponentSuite) TestEnabledFlag() {
const component = "eks/metrics-server/disabled"
const stack = "default-test"
s.VerifyEnabledFlag(component, stack, nil)
}

func (s *ComponentSuite) SetupSuite() {
s.TestSuite.InitConfig()
s.TestSuite.Config.ComponentDestDir = "components/terraform/eks/metrics-server"
s.TestSuite.SetupSuite()
}

func TestRunSuite(t *testing.T) {
suite := new(ComponentSuite)
suite.AddDependency(t, "vpc", "default-test", nil)
suite.AddDependency(t, "eks/cluster", "default-test", nil)
helper.Run(t, suite)
}
77 changes: 77 additions & 0 deletions test/fixtures/atmos.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
# CLI config is loaded from the following locations (from lowest to highest priority):
# system dir (`/usr/local/etc/atmos` on Linux, `%LOCALAPPDATA%/atmos` on Windows)
# home dir (~/.atmos)
# current directory
# ENV vars
# Command-line arguments
#
# It supports POSIX-style Globs for file names/paths (double-star `**` is supported)
# https://en.wikipedia.org/wiki/Glob_(programming)

# Base path for components, stacks and workflows configurations.
# Can also be set using `ATMOS_BASE_PATH` ENV var, or `--base-path` command-line argument.
# Supports both absolute and relative paths.
# If not provided or is an empty string, `components.terraform.base_path`, `components.helmfile.base_path`, `stacks.base_path` and `workflows.base_path`
# are independent settings (supporting both absolute and relative paths).
# If `base_path` is provided, `components.terraform.base_path`, `components.helmfile.base_path`, `stacks.base_path` and `workflows.base_path`
# are considered paths relative to `base_path`.
base_path: ""

components:
terraform:
# Can also be set using `ATMOS_COMPONENTS_TERRAFORM_BASE_PATH` ENV var, or `--terraform-dir` command-line argument
# Supports both absolute and relative paths
base_path: "components/terraform"
# Can also be set using `ATMOS_COMPONENTS_TERRAFORM_APPLY_AUTO_APPROVE` ENV var
apply_auto_approve: true
# Can also be set using `ATMOS_COMPONENTS_TERRAFORM_DEPLOY_RUN_INIT` ENV var, or `--deploy-run-init` command-line argument
deploy_run_init: true
# Can also be set using `ATMOS_COMPONENTS_TERRAFORM_INIT_RUN_RECONFIGURE` ENV var, or `--init-run-reconfigure` command-line argument
init_run_reconfigure: true
# Can also be set using `ATMOS_COMPONENTS_TERRAFORM_AUTO_GENERATE_BACKEND_FILE` ENV var, or `--auto-generate-backend-file` command-line argument
auto_generate_backend_file: true

stacks:
# Can also be set using `ATMOS_STACKS_BASE_PATH` ENV var, or `--config-dir` and `--stacks-dir` command-line arguments
# Supports both absolute and relative paths
base_path: "stacks"
# Can also be set using `ATMOS_STACKS_INCLUDED_PATHS` ENV var (comma-separated values string)
# Since we are distinguishing stacks based on namespace, and namespace is not part
# of the stack name, we have to set `included_paths` via the ENV var in the Dockerfile
included_paths:
- "orgs/**/*"

# Can also be set using `ATMOS_STACKS_EXCLUDED_PATHS` ENV var (comma-separated values string)
excluded_paths:
- "**/_defaults.yaml"

# Can also be set using `ATMOS_STACKS_NAME_PATTERN` ENV var
name_pattern: "{tenant}-{stage}"

workflows:
# Can also be set using `ATMOS_WORKFLOWS_BASE_PATH` ENV var, or `--workflows-dir` command-line arguments
# Supports both absolute and relative paths
base_path: "stacks/workflows"

# https://github.com/cloudposse/atmos/releases/tag/v1.33.0
logs:
file: "/dev/stdout"
# Supported log levels: Trace, Debug, Info, Warning, Off
level: Info

settings:
# Can also be set using 'ATMOS_SETTINGS_LIST_MERGE_STRATEGY' environment variable, or '--settings-list-merge-strategy' command-line argument
list_merge_strategy: replace

# `Go` templates in Atmos manifests
# https://atmos.tools/core-concepts/stacks/templating
# https://pkg.go.dev/text/template
templates:
settings:
enabled: true
# https://masterminds.github.io/sprig
sprig:
enabled: true
# https://docs.gomplate.ca
gomplate:
enabled: true
46 changes: 46 additions & 0 deletions test/fixtures/stacks/catalog/account-map.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
components:
terraform:
account-map:
metadata:
terraform_workspace: core-gbl-root
vars:
tenant: core
environment: gbl
stage: root

# This remote state is only for Cloud Posse internal use.
# It references the Cloud Posse test organizations actual infrastructure.
# remote_state_backend:
# s3:
# bucket: cptest-core-ue2-root-tfstate-core
# dynamodb_table: cptest-core-ue2-root-tfstate-core-lock
# role_arn: arn:aws:iam::822777368227:role/cptest-core-gbl-root-tfstate-core-ro
# encrypt: true
# key: terraform.tfstate
# acl: bucket-owner-full-control
# region: us-east-2

remote_state_backend_type: static
remote_state_backend:
# This static backend is used for tests that only need to use the account map iam-roles module
# to find the role to assume for Terraform operations. It is configured to use whatever
# the current user's role is, but the environment variable `TEST_ACCOUNT_ID` must be set to
# the account ID of the account that the user is currently assuming a role in.
#
# For some components, this backend is missing important data, and those components
# will need that data added to the backend configuration in order to work properly.
static:
account_info_map: {}
all_accounts: []
aws_partition: aws
full_account_map: {}
iam_role_arn_templates: {}
non_eks_accounts: []
profiles_enabled: false
root_account_aws_name: root
terraform_access_map: {}
terraform_dynamic_role_enabled: false
terraform_role_name_map:
apply: terraform
plan: planner
terraform_roles: {}
94 changes: 94 additions & 0 deletions test/fixtures/stacks/catalog/eks-cluster.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
components:
terraform:
eks/cluster:
metadata:
component: eks/cluster
vars:
enabled: true

# Cluster node configuration
aws_ssm_agent_enabled: true
managed_node_groups_enabled: true
node_groups: # will create node group for each item in map
main: # Karpenter is responsible for scaling nodes, but this default node group is required for deploying EKS Addons
# EKS AMI version to use, e.g. "1.16.13-20200821" (no "v").
ami_release_version: null
# Type of Amazon Machine Image (AMI) associated with the EKS Node Group
ami_type: AL2_x86_64
# Additional name attributes (e.g. `1`) for the node group
attributes: []
# will create 1 auto scaling group in each specified availability zone
# or all AZs with subnets if none are specified anywhere
availability_zones: null
# Whether to enable Node Group to scale its AutoScaling Group
cluster_autoscaler_enabled: false
# True (recommended) to create new node_groups before deleting old ones, avoiding a temporary outage
create_before_destroy: true
# Desired number of worker nodes when initially provisioned
desired_group_size: 2
# Enable disk encryption for the created launch template (if we aren't provided with an existing launch template)
disk_encryption_enabled: true
# Disk size in GiB for worker nodes. Terraform will only perform drift detection if a configuration value is provided.
disk_size: 20
# Set of instance types associated with the EKS Node Group. Terraform will only perform drift detection if a configuration value is provided.
instance_types:
- t3.small
kubernetes_labels: {}
kubernetes_taints: []
node_role_policy_arns: null
kubernetes_version: null
max_group_size: 3
min_group_size: 2
resources_to_tag:
- instance
- volume
tags: null

access_config:
authentication_mode: "API"
bootstrap_cluster_creator_admin_permissions: true

# Fargate profiles, required for Karpenter
# fargate_profiles:
# karpenter:
# kubernetes_namespace: karpenter
# kubernetes_labels: null
# fargate_profile_iam_role_kubernetes_namespace_delimiter: "@"
# karpenter_iam_role_enabled: true

# Legacy settings
# The upstream component sets these to true by default to avoid breaking existing deployments,
# but new deployments should have these settings all disabled.
legacy_fargate_1_role_per_profile_enabled: false

addons_depends_on: true
deploy_addons_to_fargate: false

allow_ingress_from_vpc_accounts: []
public_access_cidrs: ["0.0.0.0/0"]
allowed_cidr_blocks: []
allowed_security_groups: []

enabled_cluster_log_types: []
apply_config_map_aws_auth: true
availability_zone_abbreviation_type: fixed
cluster_private_subnets_only: true
cluster_encryption_config_enabled: true
cluster_endpoint_private_access: true
cluster_endpoint_public_access: true
cluster_log_retention_period: 90
oidc_provider_enabled: true
cluster_kubernetes_version: "1.31"
addons:
vpc-cni:
addon_version: "v1.18.3-eksbuild.3"
kube-proxy:
addon_version: "v1.30.3-eksbuild.5"
coredns:
addon_version: "v1.11.3-eksbuild.1"
configuration_values: '{"autoScaling":{"enabled":true,"minReplicas":3}}'
aws-ebs-csi-driver:
addon_version: "v1.34.0-eksbuild.1"
configuration_values: '{"sidecars":{"snapshotter":{"forceEnable":false}}}'
aws-efs-csi-driver:
addon_version: "v2.0.8-eksbuild.1"
10 changes: 10 additions & 0 deletions test/fixtures/stacks/catalog/usecase/basic.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
components:
terraform:
eks/metrics-server/basic:
metadata:
component: eks/metrics-server
vars:
enabled: true
kube_exec_auth_role_arn_enabled: false
name: "metrics-server"
kubernetes_namespace: "metrics-server"
10 changes: 10 additions & 0 deletions test/fixtures/stacks/catalog/usecase/disabled.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
components:
terraform:
eks/metrics-server/disabled:
metadata:
component: eks/metrics-server
vars:
enabled: false
kube_exec_auth_role_arn_enabled: false
name: "metrics-server"
kubernetes_namespace: "metrics-server"
19 changes: 19 additions & 0 deletions test/fixtures/stacks/catalog/vpc.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
components:
terraform:
vpc:
metadata:
component: vpc
vars:
name: "vpc"
availability_zones:
- "b"
- "c"
public_subnets_enabled: true
max_nats: 1
# Private subnets do not need internet access
nat_gateway_enabled: true
nat_instance_enabled: false
subnet_type_tag_key: "eg.cptest.co/subnet/type"
max_subnet_count: 3
vpc_flow_logs_enabled: false
ipv4_primary_cidr_block: "172.16.0.0/16"
Loading