Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding eks-customer module #731

Merged
merged 61 commits into from
Sep 20, 2024
Merged

Adding eks-customer module #731

merged 61 commits into from
Sep 20, 2024

Conversation

andrleite
Copy link
Contributor

Summary

This PR will add a new module to create EKS clusters + deploy utilities using Argocd.

Ticket Link

https://mattermost.atlassian.net/browse/CLD-7696

Release Note

New eks-customer module

@andrleite andrleite requested a review from a team as a code owner September 17, 2024 20:56
@@ -0,0 +1,101 @@
module "eks" {
source = "terraform-aws-modules/eks/aws"
version = "20.14.0"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lets make version variable

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this isn't possible due to terraform limitations. hashicorp/terraform#28912

namespace_service_accounts = ["${each.value.name}:${each.value.service_account}"]
}
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work!

while_repo_exists
git clone "https://${GIT_REPO_USERNAME}:${GITLAB_OAUTH_TOKEN}@${GIT_HOST}/${GIT_REPO_PATH}" $gitops_sre_dir
git config --global user.name "${GIT_REPO_USERNAME}"
git config --global user.email "${GIT_REPO_USERNAME}@mattermost.com"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

make it $GIT_REPO_URL


module "irsa" {
source = "terraform-aws-modules/iam/aws//modules/iam-role-for-service-accounts-eks"
version = "5.44.0"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this version should be hardcoded?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, let's make it variable Thanks

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this isn't possible due to terraform limitations. hashicorp/terraform#28912

@@ -0,0 +1,132 @@
#/usr/bin/env bash
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#/usr/bin/env bash
#!/usr/bin/env bash


function create_cluster_folder() {
echo "Creating custom values file"
mkdir $gitops_apps_dir/${ENV}/helm-values/${CLUSTER_NAME} || true
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

|| true suppresses all errors, was there any reason for that?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is to avoid errors when the file already exists.

Comment on lines 86 to 94
sed -i "s/<CLUSTER_ID>/${CLUSTER_NAME}/g" $gitops_apps_dir/${ENV}/helm-values/${CLUSTER_NAME}/$utility_name-custom-values.yaml
sed -i "s/<ENV>/${ENV}/g" $gitops_apps_dir/${ENV}/helm-values/${CLUSTER_NAME}/$utility_name-custom-values.yaml
sed -i "s/<CLUSTER_ID>/${CLUSTER_NAME}/g" $gitops_apps_dir/${ENV}/helm-values/${CLUSTER_NAME}/$utility_name-custom-values.yaml
sed -i "s/<CERTFICATE_ARN>/$certificate_arn/g" $gitops_apps_dir/${ENV}/helm-values/${CLUSTER_NAME}/$utility_name-custom-values.yaml
sed -i "s/<PRIVATE_CERTIFICATE_ARN>/$private_certificate_arn/g" $gitops_apps_dir/${ENV}/helm-values/${CLUSTER_NAME}/$utility_name-custom-values.yaml
sed -i "s/<VPC_ID>/${VPC_ID}/g" $gitops_apps_dir/${ENV}/helm-values/${CLUSTER_NAME}/$utility_name-custom-values.yaml
sed -i "s/<PRIVATE_DOMAIN>/${PRIVATE_DOMAIN}/g" $gitops_apps_dir/${ENV}/helm-values/${CLUSTER_NAME}/$utility_name-custom-values.yaml
sed -i "s/<IP_RANGE>/$allow_list_cidr_range/g" $gitops_apps_dir/${ENV}/helm-values/${CLUSTER_NAME}/$utility_name-custom-values.yaml
sed -i "s/hostNetwork: false/hostNetwork: true/g" $gitops_apps_dir/${ENV}/helm-values/${CLUSTER_NAME}/$utility_name-custom-values.yaml
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe something

sed -i -e "s/<CLUSTER_ID>/${CLUSTER_NAME}/g" \
       -e "s/<ENV>/${ENV}/g" \
       -e "s/<CERTIFICATE_ARN>/$certificate_arn/g" \
       ... \
       "$target_file"

since the target file is the same

sed -i "s/<CLUSTER_ID>/${CLUSTER_NAME}/g" $gitops_apps_dir/${ENV}/helm-values/${CLUSTER_NAME}/$utility_name-custom-values.yaml
sed -i "s/<ENV>/${ENV}/g" $gitops_apps_dir/${ENV}/helm-values/${CLUSTER_NAME}/$utility_name-custom-values.yaml
sed -i "s/<CLUSTER_ID>/${CLUSTER_NAME}/g" $gitops_apps_dir/${ENV}/helm-values/${CLUSTER_NAME}/$utility_name-custom-values.yaml
sed -i "s/<CERTFICATE_ARN>/$certificate_arn/g" $gitops_apps_dir/${ENV}/helm-values/${CLUSTER_NAME}/$utility_name-custom-values.yaml
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there is a typo: CERTFICATE_ARN maybe CERTIFICATE_ARN

Comment on lines +39 to +44
clone_repo
remove_utilities
remove_helm_values
wait_for_argocd
remove_cluster
clean_up
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clone_repo and clean_up funcs exist in other script, will they be available in that main?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, because I'm "loading" them into the script

source $(dirname "$0")/utils.sh

Comment on lines +125 to +129
clone_repo
add_cluster
create_cluster_folder
deploy_utility
clean_up
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clone_repo and clean_up funcs exist in other script, will they be available in that main?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, because I'm "loading" them into the script

source $(dirname "$0")/utils.sh

@@ -0,0 +1,47 @@
#/usr/bin/env bash
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#/usr/bin/env bash
#!/usr/bin/env bash

@@ -0,0 +1,88 @@
#/usr/bin/env bash
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#/usr/bin/env bash
#!/usr/bin/env bash

echo "Commiting changes: Adding cluster ${CLUSTER_NAME}"
commit_changes "Remove utilities: ${CLUSTER_NAME}" $gitops_apps_dir/${ENV}/helm-values
fi
echo "No helm values found for cluster ${CLUSTER_NAME}"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This message is printed regardless of whether the directory exists or not.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
echo "No helm values found for cluster ${CLUSTER_NAME}"
else
echo "No helm values found for cluster ${CLUSTER_NAME}"
fi

not sure if that's better

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good catch

}

function remove_cluster() {
local cluster_id=$1
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is that used?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nope! good catch. old value.

@andrleite andrleite merged commit 77f3669 into master Sep 20, 2024
1 check passed
@andrleite andrleite deleted the cld-7696 branch September 20, 2024 19:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants