Skip to content

Commit

Permalink
Merge pull request #2 from celestiaorg/jose/hackground-k8s-tf
Browse files Browse the repository at this point in the history
feat: K8S IaC - GitOps with ArgoCD
  • Loading branch information
Bidon15 committed May 24, 2023
2 parents a7ae96a + 41edeaa commit 8ffdef1
Show file tree
Hide file tree
Showing 566 changed files with 119,636 additions and 24,572 deletions.
12 changes: 12 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
root = true

[*]
charset = utf-8
end_of_line = lf
indent_size = 4
indent_style = space
insert_final_newline = true
trim_trailing_whitespace = true

[*.{yaml,yml,tf}]
indent_size = 2
5 changes: 5 additions & 0 deletions argocd-root/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization

resources:
- root.yaml
22 changes: 22 additions & 0 deletions argocd-root/root.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# We generate this ArgoCD application with Terraform, but we keep it here as a workaround
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
name: root
spec:
project: default
source:
repoURL: https://github.com/celestiaorg/testground-infra.git
path: 'argocd'
targetRevision: jose/hackground-k8s-tf
destination:
name: in-cluster
namespace: argocd
syncPolicy:
automated:
prune: true
allowEmpty: true
selfHeal: true
syncOptions:
- ApplyOutOfSyncOnly=true
- CreateNamespace=true
34 changes: 34 additions & 0 deletions argocd/aws-applicationset.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
apiVersion: argoproj.io/v1alpha1
kind: ApplicationSet
metadata:
name: aws
namespace: argocd
spec:
generators:
- git:
repoURL: https://github.com/celestiaorg/testground-infra.git
revision: jose/hackground-k8s-tf
directories:
- path: 'manifests/aws/*'
- path: manifests/aws/deactivated
exclude: true
template:
metadata:
name: 'aws-{{path[2]}}'
spec:
project: default
source:
repoURL: https://github.com/celestiaorg/testground-infra.git
path: 'manifests/aws/{{path[2]}}'
targetRevision: jose/hackground-k8s-tf
destination:
name: in-cluster
namespace: default
syncPolicy:
automated:
prune: true
allowEmpty: true
selfHeal: true
syncOptions:
- ApplyOutOfSyncOnly=true
- CreateNamespace=true
11 changes: 11 additions & 0 deletions argocd/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization

namespace: argocd

resources:
- aws-applicationset.yaml
- observability-applicationset.yaml
- testground-applicationset.yaml
- networking-applicationset.yaml
- testground-tools-applicationset.yaml
35 changes: 35 additions & 0 deletions argocd/networking-applicationset.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
apiVersion: argoproj.io/v1alpha1
kind: ApplicationSet
metadata:
name: networking
namespace: argocd
spec:
generators:
- git:
repoURL: https://github.com/celestiaorg/testground-infra.git
revision: jose/hackground-k8s-tf
directories:
- path: 'manifests/networking/*'
- path: manifests/networking/deactivated
exclude: true
template:
metadata:
name: 'networking-{{path[2]}}'
spec:
project: default
source:
repoURL: https://github.com/celestiaorg/testground-infra.git
path: 'manifests/networking/{{path[2]}}'
targetRevision: jose/hackground-k8s-tf
destination:
name: in-cluster
namespace: default
syncPolicy:
automated:
prune: true
allowEmpty: true
selfHeal: true
syncOptions:
- ApplyOutOfSyncOnly=true
- CreateNamespace=true
- ServerSideApply=true
35 changes: 35 additions & 0 deletions argocd/observability-applicationset.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
apiVersion: argoproj.io/v1alpha1
kind: ApplicationSet
metadata:
name: observability
namespace: argocd
spec:
generators:
- git:
repoURL: https://github.com/celestiaorg/testground-infra.git
revision: jose/hackground-k8s-tf
directories:
- path: 'manifests/observability/*'
- path: manifests/observability/deactivated
exclude: true
template:
metadata:
name: 'observability-{{path[2]}}'
spec:
project: default
source:
repoURL: https://github.com/celestiaorg/testground-infra.git
path: 'manifests/observability/{{path[2]}}'
targetRevision: jose/hackground-k8s-tf
destination:
name: in-cluster
namespace: default
syncPolicy:
automated:
prune: true
allowEmpty: true
selfHeal: true
syncOptions:
- ApplyOutOfSyncOnly=true
- CreateNamespace=true
- ServerSideApply=true
41 changes: 41 additions & 0 deletions argocd/telegraf-operator.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
name: testground-tools-telegraf-operator
namespace: argocd
spec:
project: default
source:
chart: telegraf-operator
repoURL: https://helm.influxdata.com/
targetRevision: 1.3.11
helm:
releaseName: telegraf-operator
values: |
replicaCount: 2
classes:
data:
default: |
[[outputs.influxdb]]
urls = ["http://influxdb.default.svc:8086"]
database = "testground"
resources:
limits:
cpu: 400m
memory: 256Mi
requests:
cpu: 50m
memory: 64Mi
hotReload: true
destination:
namespace: default
name: in-cluster
syncPolicy:
automated:
prune: true
selfHeal: true
allowEmpty: true
syncOptions:
- ApplyOutOfSyncOnly=true
- CreateNamespace=true
- ServerSideApply=true
35 changes: 35 additions & 0 deletions argocd/testground-applicationset.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
apiVersion: argoproj.io/v1alpha1
kind: ApplicationSet
metadata:
name: testground
namespace: argocd
spec:
generators:
- git:
repoURL: https://github.com/celestiaorg/testground-infra.git
revision: jose/hackground-k8s-tf
directories:
- path: 'manifests/testground/*'
- path: manifests/testground/deactivated
exclude: true
template:
metadata:
name: 'testground-{{path[2]}}'
spec:
project: default
source:
repoURL: https://github.com/celestiaorg/testground-infra.git
path: 'manifests/testground/{{path[2]}}'
targetRevision: jose/hackground-k8s-tf
destination:
name: in-cluster
namespace: default
syncPolicy:
automated:
prune: true
allowEmpty: true
selfHeal: true
syncOptions:
- ApplyOutOfSyncOnly=true
- CreateNamespace=true
- ServerSideApply=true
35 changes: 35 additions & 0 deletions argocd/testground-tools-applicationset.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
apiVersion: argoproj.io/v1alpha1
kind: ApplicationSet
metadata:
name: testground-tools
namespace: argocd
spec:
generators:
- git:
repoURL: https://github.com/celestiaorg/testground-infra.git
revision: jose/hackground-k8s-tf
directories:
- path: 'manifests/tooling/*'
- path: manifests/tooling/deactivated
exclude: true
template:
metadata:
name: 'testground-tools-{{path[2]}}'
spec:
project: default
source:
repoURL: https://github.com/celestiaorg/testground-infra.git
path: 'manifests/tooling/{{path[2]}}'
targetRevision: jose/hackground-k8s-tf
destination:
name: in-cluster
namespace: default
syncPolicy:
automated:
prune: true
allowEmpty: true
selfHeal: true
syncOptions:
- ApplyOutOfSyncOnly=true
- CreateNamespace=true
- ServerSideApply=true
Binary file added docs/argocd_dashboard.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/argocd_root_app.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
34 changes: 17 additions & 17 deletions k8s/eks/bash/functions.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/bash

# error log prep check
prep_log_dir(){
prep_log_dir(){
mkdir -p $real_path/log/$start-log/
mkdir -p $real_path/.cluster/
}
Expand Down Expand Up @@ -319,7 +319,7 @@ aws_get_vpc_id(){
vpc_id=$(aws ec2 describe-vpcs --region $REGION --filters Name=tag:Name,Values=eksctl-$CLUSTER_NAME-cluster/VPC |jq -r ".Vpcs[] | .VpcId")
}

aws_get_subnet_id(){
aws_get_subnet_id(){
aws_get_vpc_id
concat_availability_zone
upper_az=$(echo $AVAILABILITY_ZONE | tr '[:lower:]' '[:upper:]' | tr -d \-)
Expand All @@ -334,7 +334,7 @@ aws_get_sg_id(){
aws_create_efs_mount_point(){
aws efs create-mount-target --file-system-id $efs_fs_id --subnet-id $subnet_id --security-group $efs_sg_id --region $REGION
efs_dns=$efs_fs_id.efs.$REGION.amazonaws.com

}

create_cm_efs(){
Expand Down Expand Up @@ -365,10 +365,10 @@ aws_create_ebs(){
echo -e "EBS created with this volume ID: $ebs_volume\n"
else
echo "EBS already exists, skipping to the next step."
fi
fi
}

make_persistent_volume(){
make_persistent_volume(){
export TG_EBS_DATADIR_VOLUME_ID=$ebs_volume

EBS_PV=$(mktemp)
Expand All @@ -378,11 +378,11 @@ make_persistent_volume(){

helm_redis_add_repo(){
helm repo add bitnami https://charts.bitnami.com/bitnami
}
}

helm_infra_install_redis(){
helm install testground-infra-redis --set auth.enabled=false --set master.nodeSelector='testground.node.role.infra: "true"' bitnami/redis
}
}

helm_infra_install_influx_db(){
# We are using v2.6.1 of the helm chart, which has been evicted from the regular index.yaml.
Expand All @@ -402,7 +402,7 @@ metadata:
data:
.env.toml: |
["aws"]
region = "$REGION"
region = "$REGION"
[runners."cluster:k8s"]
run_timeout_min = 15
Expand Down Expand Up @@ -506,26 +506,26 @@ log(){
echo "========================"
echo "Log file generated with name $start-$CLUSTER_NAME.tar.gz"
echo -e "\n"
rm -rf $real_path/log/$start-log/
rm -rf $real_path/log/$start-log/
}

##### Functions below are used by the 'testground_uninstall.sh' script #######

remove_efs_mp_timer(){
remove_efs_mp_timer(){
efs_mp_state=available # setting the start value for the loop to consider
sleep 15
while [[ $efs_mp_state == available ]];do
while [[ $efs_mp_state == available ]];do
efs_mp_state=$(aws efs describe-mount-targets --file-system-id $efs --region $region | jq -r ".MountTargets[] | .LifeCycleState")
sleep 1
done
done
}

remove_efs_fs_timer(){
remove_efs_fs_timer(){
efs_fs_state=available # setting the start value for the loop to consider
while [[ $efs_fs_state == available ]];do
while [[ $efs_fs_state == available ]];do
efs_fs_state=$(aws efs describe-file-systems --region $region --file-system-id $efs | jq -r ".FileSystems[] | .LifeCycleState")
sleep 1
done
done
}

obtain_efs_id(){
Expand Down Expand Up @@ -621,12 +621,12 @@ cleanup(){
else
echo -e "Looks like the EBS you have specified ($ebs) does not exist in the selected region ($region).\nIt is possible that it has already been deleted.\n"
fi

if [ "$efs_deleted" == "true" ] && [ "$ebs_deleted" == "true" ] && [ "$cluster_deleted" == "true" ]
then
rm -f $real_path/.cluster/$cluster_name-$region.cs
echo -e "Uninstall script completed and removed the '.cluster/$cluster_name-$region.cs' file.\n"
else
echo -e "Uninstall script completed, but did not remove the '.cluster/$cluster_name-$region.cs' file due to other resources not being deleted.\nPlease check the '.cluster/$cluster_name-$region.cs' file and try again.\n"
fi
}
}
Loading

0 comments on commit 8ffdef1

Please sign in to comment.