Skip to content

Commit

Permalink
Updates to make file and added tests
Browse files Browse the repository at this point in the history
updated the create-eks-cluster to use a configfile
add config file for clsuter creation
added integration test skeleton
  • Loading branch information
roberthocking committed Nov 15, 2023
1 parent ce7d039 commit b3d3cc4
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 5 deletions.
15 changes: 10 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -278,10 +278,10 @@ dockerized-build-vendor:

.PHONY: create-eks-cluster
create-eks-cluster:
@eksctl create cluster \
--name $(namespace) \
--region $(region) \
--zones $(region)a,$(region)b
sed -i '' 's/<namespace>/$(namespace)/g' NodeGroups.yaml
sed -i '' 's/<region>/$(region)/g' NodeGroups.yaml
eksctl create cluster --config-file=NodeGroups.yaml


.PHONY: destroy-eks-cluster
destroy-eks-cluster:
Expand All @@ -296,7 +296,6 @@ deploy-test:
--set image.repository=$(image_repo) \
--set image.tag=$(image_tag)


.PHONY: init
init:
@go_version=$$(go version | cut -d' ' -f3 | sed 's/go//'); \
Expand All @@ -309,3 +308,9 @@ init:
echo "Please download and install $(REQUIRED_GO_VERSION) using brew or other method of your choice"; \
exit 1; \
fi

smoke-test:
make create-eks-cluster
make deploy-test
go test Tools/cz_tests/cz_integration_test.go --logGroupName="/aws/containerinsights/$(namespace)/performance" --region="$(region)"
make destroy-eks-cluster
22 changes: 22 additions & 0 deletions NodeGroups.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# cluster.yaml
# A cluster with two managed nodegroups
---
apiVersion: eksctl.io/v1alpha5
kind: ClusterConfig

metadata:
name: <namespace>
region: <region>

managedNodeGroups:
- name: <namespace>-nodegroup-1
instanceType: t2.large
minSize: 2
maxSize: 3
iam:
attachPolicyARNs:
- arn:aws:iam::aws:policy/AmazonEKSWorkerNodePolicy
- arn:aws:iam::aws:policy/AmazonEKS_CNI_Policy
- arn:aws:iam::aws:policy/AmazonEC2ContainerRegistryReadOnly
- arn:aws:iam::aws:policy/ElasticLoadBalancingFullAccess
- arn:aws:iam::aws:policy/CloudWatchAgentServerPolicy
59 changes: 59 additions & 0 deletions Tools/cz_tests/cz_integration_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package cz_tests

import (
"flag"
"testing"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/cloudwatchlogs"
)

var (
logGroupName = flag.String("logGroupName", "", "Name of the CloudWatch log group")
region = flag.String("region", "", "Name of the AWS region")
)

func getCloudWatchLogGroupName(logGroupName, region string) (string, error) {
sess, err := session.NewSession(&aws.Config{Region: aws.String(region)})
if err != nil {
return "", err
}

client := cloudwatchlogs.New(sess)

input := &cloudwatchlogs.DescribeLogGroupsInput{
LogGroupNamePrefix: aws.String(logGroupName),
Limit: aws.Int64(1),
}

resp, err := client.DescribeLogGroups(input)
if err != nil {
return "", err
}

if len(resp.LogGroups) == 0 {
return "", nil
}

return *resp.LogGroups[0].LogGroupName, nil
}

func TestGetCloudWatchLogGroupName(t *testing.T) {
flag.Parse()

if *logGroupName == "" {
t.Fatal("Please provide the CloudWatch log group name using the -logGroupName flag")
}

if *region == "" {
t.Fatal("Please provide the CloudWatch log group name using the -logGroupName flag")
}
logGroupName, err := getCloudWatchLogGroupName(*logGroupName, *region)

if err != nil {
t.Fatalf("Error getting CloudWatch log group name: %v", err)
}

t.Logf("CloudWatch Log Group Name: %s", logGroupName)
}

0 comments on commit b3d3cc4

Please sign in to comment.