Skip to content

Commit d6d9b82

Browse files
authored
Update test-infra for EKS (#1219)
Update the helm test, provider aliases, and kubeconfig_path output. Remove kubernetes provider from AKS and GKE.
1 parent 49d4008 commit d6d9b82

File tree

5 files changed

+30
-76
lines changed

5 files changed

+30
-76
lines changed

kubernetes/test-infra/aks/main.tf

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,3 @@
1-
terraform {
2-
required_providers {
3-
kubernetes = {
4-
source = "localhost/test/kubernetes"
5-
version = "9.9.9"
6-
}
7-
}
8-
}
9-
101
locals {
112
random_prefix = "${var.prefix}-${random_id.tf-k8s-acc.hex}"
123
}
Lines changed: 17 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
terraform {
22
required_providers {
3-
kubernetes = {
3+
kubernetes-local = {
44
source = "localhost/test/kubernetes"
55
version = "9.9.9"
66
}
@@ -12,54 +12,30 @@ terraform {
1212
}
1313

1414
resource "kubernetes_namespace" "test" {
15+
provider = kubernetes-local
1516
metadata {
1617
name = "test"
1718
}
1819
}
1920

20-
resource "kubernetes_deployment" "test" {
21-
metadata {
22-
name = "test"
23-
namespace= kubernetes_namespace.test.metadata.0.name
24-
}
25-
spec {
26-
replicas = 2
27-
selector {
28-
match_labels = {
29-
app = "test"
30-
}
31-
}
32-
template {
33-
metadata {
34-
labels = {
35-
app = "test"
36-
}
37-
}
38-
spec {
39-
container {
40-
image = "nginx:1.19.4"
41-
name = "nginx"
42-
43-
resources {
44-
limits = {
45-
memory = "512M"
46-
cpu = "1"
47-
}
48-
requests = {
49-
memory = "256M"
50-
cpu = "50m"
51-
}
52-
}
53-
}
54-
}
55-
}
56-
}
57-
}
58-
59-
resource "helm_release" "nginx_ingress" {
21+
resource helm_release nginx_ingress {
6022
wait = false
6123
name = "ingress-nginx"
24+
6225
repository = "https://kubernetes.github.io/ingress-nginx"
6326
chart = "ingress-nginx"
6427
version = "v3.24.0"
28+
29+
set {
30+
name = "controller.updateStrategy.rollingUpdate.maxUnavailable"
31+
value = "1"
32+
}
33+
set {
34+
name = "controller.replicaCount"
35+
value = "2"
36+
}
37+
set_sensitive {
38+
name = "controller.maxmindLicenseKey"
39+
value = "testSensitiveValue"
40+
}
6541
}

kubernetes/test-infra/eks/main.tf

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ terraform {
1010
# A "required_providers" block needs to be added to all sub-modules in order to use a custom "source" and "version".
1111
# Otherwise, the sub-module will use defaults, which in our case means an empty provider config.
1212
# https://github.com/hashicorp/terraform/issues/27361
13-
kubernetes-released = {
13+
kubernetes = {
1414
source = "hashicorp/kubernetes"
1515
version = ">= 2.0.2"
1616
}
@@ -29,13 +29,12 @@ data "aws_eks_cluster" "default" {
2929
name = module.cluster.cluster_id
3030
}
3131

32-
# This configuration relies on a plugin binary to fetch the token to the EKS cluster.
33-
# The main advantage is that the token will always be up-to-date, even when the `terraform apply` runs for
34-
# a longer time than the token TTL. The downside of this approach is that the binary must be present
35-
# on the system running terraform, either in $PATH as shown below, or in another location, which can be
36-
# specified in the `command`.
37-
# See the commented provider blocks below for alternative configuration options.
38-
provider "kubernetes-released" {
32+
data "aws_eks_cluster_auth" "default" {
33+
name = module.cluster.cluster_id
34+
}
35+
36+
# Test exec plugin based auth.
37+
provider "kubernetes" {
3938
host = data.aws_eks_cluster.default.endpoint
4039
cluster_ca_certificate = base64decode(data.aws_eks_cluster.default.certificate_authority[0].data)
4140
exec {
@@ -52,15 +51,15 @@ provider "kubernetes-local" {
5251
config_path = module.cluster.kubeconfig_filename
5352
}
5453

54+
# Test token data source based auth.
5555
provider "helm" {
56+
experiments {
57+
manifest = true
58+
}
5659
kubernetes {
5760
host = data.aws_eks_cluster.default.endpoint
5861
cluster_ca_certificate = base64decode(data.aws_eks_cluster.default.certificate_authority[0].data)
59-
exec {
60-
api_version = "client.authentication.k8s.io/v1alpha1"
61-
args = ["eks", "get-token", "--cluster-name", module.vpc.cluster_name]
62-
command = "aws"
63-
}
62+
token = data.aws_eks_cluster_auth.default.token
6463
}
6564
}
6665

@@ -72,7 +71,6 @@ module "vpc" {
7271
}
7372

7473
module "cluster" {
75-
providers = {kubernetes = kubernetes-released}
7674
source = "terraform-aws-modules/eks/aws"
7775
version = "14.0.0"
7876

@@ -83,7 +81,6 @@ module "cluster" {
8381
cluster_version = var.kubernetes_version
8482
manage_aws_auth = true
8583
write_kubeconfig = true
86-
kubeconfig_name = "kubeconfig"
8784

8885
# See this file for more options
8986
# https://github.com/terraform-aws-modules/terraform-aws-eks/blob/master/local.tf#L28
@@ -107,7 +104,6 @@ module "cluster" {
107104
}
108105

109106
module "kubernetes-config" {
110-
providers = {kubernetes = kubernetes-local}
111107
cluster_name = module.cluster.cluster_id # creates dependency on cluster creation
112108
source = "./kubernetes-config"
113109
k8s_node_role_arn = module.cluster.worker_iam_role_arn

kubernetes/test-infra/eks/output.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
output "kubeconfig_path" {
2-
value = abspath("${path.root}/kubeconfig")
2+
value = abspath(module.cluster.kubeconfig_filename)
33
}
44

55
output "cluster_name" {

kubernetes/test-infra/gke/main.tf

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,3 @@
1-
terraform {
2-
required_providers {
3-
kubernetes = {
4-
source = "localhost/test/kubernetes"
5-
version = "9.9.9"
6-
}
7-
}
8-
}
9-
101
provider "google" {
112
// Provider settings to be provided via ENV variables
123
}

0 commit comments

Comments
 (0)