Skip to content

Commit

Permalink
Fargate fix (#81)
Browse files Browse the repository at this point in the history
* fix

* fargate

* fargate

* increase sleep for connection test

* increase sleep for connection test

* increase sleep for connection test

* increase sleep for connection test

* fix

* fix set

* windows faraget profile

* windows prerequisites fix

* increase retries

* increase retries

* fix set yaml

* mac

* fix

* linux + mac

* linux eksctl

* change regex

* fix

* remove fargate profile creating output

* version

* fargate

* fargate metrics

* consts

* typo

* fix

* increase retries and sleep
  • Loading branch information
ShiranAvidov authored Apr 4, 2023
1 parent 221abce commit 1e204a3
Show file tree
Hide file tree
Showing 38 changed files with 514 additions and 211 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
# are_all_pods_running_or_completed - Tells if all pods are running or completed (true/false)
function are_all_pods_running_or_completed () {
retries=0
while [ $retries -lt 3 ]; do
while [ $retries -lt 18 ]; do
let "retries++"
local pod_statuses=$(kubectl -n monitoring get pods --no-headers -o custom-columns=":.status.phase")
local bad_statusses=$(echo -e "$pod_statuses" | grep -v -e Running -e Completed -e Succeeded)
Expand Down
8 changes: 4 additions & 4 deletions Kubernetes/EKS/Kubernetes/prerequisites/mac/functions.bash
Original file line number Diff line number Diff line change
Expand Up @@ -74,15 +74,15 @@ function can_k8s_cluster_connect_to_logzio_logs () {
fi

local is_pod_completed=false
local retries=3
local retries=18
while [[ $retries -ne 0 ]]; do
local pod_status=$(kubectl get pods | grep logzio-logs-connection-test | tr -s ' ' | cut -d ' ' -f3)
if [[ "$pod_status" == "Completed" ]]; then
is_pod_completed=true
break
fi

sleep 5
sleep 10
((retries--))
done

Expand Down Expand Up @@ -140,15 +140,15 @@ function can_k8s_cluster_connect_to_logzio_metrics () {
fi

local is_pod_completed=false
local retries=3
local retries=18
while [[ $retries -ne 0 ]]; do
local pod_status=$(kubectl get pods | grep logzio-metrics-connection-test | tr -s ' ' | cut -d ' ' -f3)
if [[ "$pod_status" == "Completed" ]]; then
is_pod_completed=true
break
fi

sleep 5
sleep 10
((retries--))
done

Expand Down
91 changes: 91 additions & 0 deletions Kubernetes/EKS/Kubernetes/telemetry/installer/mac/functions.bash
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,97 @@ function get_environment_id () {
write_run "env_id='$env_id_value'"
}

# Gets is Fargate was selected
# Output:
# is_fargate - Tells is Fargate option was selected (true/false)
# Error:
# Exit Code 11
function get_is_fargate_was_selected () {
write_log "INFO" "Getting is Fargate was selected ..."

local is_fargate_param=$(find_param "$general_params" "isFargate")
if [[ -z "$is_fargate_param" ]]; then
write_run "print_error \"installer.bash (11): isFargate param was not found\""
return 11
fi

local is_fargate_value=$(echo -e "$is_fargate_param" | $jq_bin -r '.value')
if [[ "$is_fargate_value" = null ]]; then
write_run "print_error \"installer.bash (11): '.configuration.subtypes[0].datasources[0].params[{name=isFargate}].value' was not found in application JSON\""
return 11
fi
if [[ -z "$is_fargate_value" ]]; then
write_run "print_error \"installer.bash (11): '.configuration.subtypes[0].datasources[0].params[{name=isFargate}].value' is empty in application JSON\""
return 11
fi

if ! $is_fargate_value; then
write_log "INFO isFargate value = false"
else
write_log "INFO isFargate value = true"
fi

write_run "is_farget=$is_fargate_value"
}

# Downloads eksctl
# Output:
# eksctl_bin - eksctl bin file in temp directory
# Error:
# Exit Code 12
function download_eksctl () {
write_log "INFO" "Downloading eksctl ..."

curl -fsSL https://github.com/weaveworks/eksctl/releases/download/v0.133.0/eksctl_Darwin_amd64.tar.gz > $logzio_temp_dir/eksctl.tar.gz 2>$task_error_file
if [[ $? -ne 0 ]]; then
local err=$(cat $task_error_file)
write_run "print_error \"instalelr.bash (12): failed to download eksctl.\n $err\""
return 12
fi

tar -zxf $logzio_temp_dir/eksctl.tar.gz --directory $logzio_temp_dir
write_run "eksctl_bin=\"$logzio_temp_dir/eksctl\""
}

# Creates Fargate profile with monitoring namespace on Kubernetes cluster
# Error:
# Exit Code 13
function create_fargate_profile () {
write_log "INFO" "Creating Fargate profile with monitoring namespace on Kubernetes cluster ..."

local kubectl_context
kubectl_context=$(kubectl config current-context 2>$task_error_file)
if [[ $? -ne 0 ]]; then
local err=$(cat $task_error_file)
write_run "print_error \"instalelr.bash (13): error getting kubectl current context.\n $err\""
return 13
fi

local cluster_name=$(echo -e "$kubectl_context" | cut -d'/' -f2)
local cluster_region=$(echo -e "$kubectl_context" | cut -d':' -f4)

local fargate_profiles
fargate_profiles=$($eksctl_bin get fargateprofile --region "$cluster_region" --cluster "$cluster_name" 2>$task_error_file)
if [[ $? -ne 0 ]]; then
local err=$(cat $task_error_file)
write_run "print_error \"instalelr.bash (13): error checking if Fargate profile 'fp-monitoring' in region '$cluster_region' on Kubernetes cluster '$cluster_name' exists.\n $err\""
return 13
fi

local monitoringFargateProfile=$(echo -e "$fargate_profiles" | grep -e '\smonitoring')
if [[ ! -z "$monitoringFargateProfile" ]]; then
write_log "INFO" "Fargate profile 'fp-monitoring' in region '$cluster_region' on Kubernetes cluster '$cluster_name' is already exists"
return
fi

$eksctl_bin create fargateprofile --region $cluster_region --namespace monitoring --cluster $cluster_name --name 'fp-monitoring' >/dev/null 2>$task_error_file
if [[ $? -ne 0 ]]; then
local err=$(cat $task_error_file)
write_run "print_error \"instalelr.bash (13): error creating Fargate profile 'fp-monitoring' in region '$cluster_region' with namespace 'monitoring' on Kubernetes cluster '$cluster_name'.\n $err\""
return 13
fi
}

# Builds enable metrics or traces Helm set
# Output:
# helm_sets - Contains all the Helm sets
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@ execute_task "build_tolerations_helm_sets" "building tolerations Helm sets"
# Get environment ID
execute_task "get_environment_id" "getting environment ID"

# Get is Fargate option was selected
execute_task "get_is_fargate_was_selected" "getting is Fargate was selected"
if $is_fargate; then
execute_task 'download_eksctl' 'downloading eksctl binary file'
execute_task 'create_fargate_profile' 'creating Fargate profile with monitoring namespace on Kubernetes cluster'
fi

# Build enable metrics or traces helm set
if $is_metrics_option_selected || $is_traces_option_selected; then
execute_task "build_enable_metrics_or_traces_helm_set" "building enable metrics or traces Helm set"
Expand Down
70 changes: 1 addition & 69 deletions Kubernetes/EKS/Kubernetes/telemetry/logs/mac/functions.bash
Original file line number Diff line number Diff line change
Expand Up @@ -81,81 +81,13 @@ function build_environment_id_helm_set () {
write_run "helm_sets+='$helm_set'"
}

# Builds enable Fargate Helm set
# Output:
# helm_sets - Contains all the Helm sets
# Error:
# Exit Code 3
function build_is_fargate_helm_set () {
write_log "INFO" "Building enable Fargate Helm set ..."

local is_fargate_param=$(find_param "$logs_params" "isFargate")
if [[ -z "$is_fargate_param" ]]; then
write_run "print_error \"installer.bash (3): isFargate param was not found\""
return 3
fi

local is_fargate_value=$(echo -e "$is_fargate_param" | $jq_bin -r '.value')
if [[ "$is_fargate_value" = null ]]; then
write_run "print_error \"installer.bash (3): '.configuration.subtypes[0].datasources[0].params[{name=isFargate}].value' was not found in application JSON\""
return 3
fi
if [[ -z "$is_fargate_value" ]]; then
write_run "print_error \"installer.bash (3): '.configuration.subtypes[0].datasources[0].params[{name=isFargate}].value' is empty in application JSON\""
return 3
fi

if ! $is_fargate_value; then
write_log "INFO isFargate value = false"
return
fi

local helm_set="--set fargateLogRouter.enabled=true"
write_log "INFO" "helm_set = $helm_set"
write_run "log_helm_sets+='$helm_set'"
write_run "helm_sets+='$helm_set'"
}

# Gets is Fargate was selected
# Output:
# helm_sets - Contains all the Helm sets
# Error:
# Exit Code 3
function get_is_fargate_was_selected () {
write_log "INFO" "Getting is Fargate was selected ..."

local is_fargate_param=$(find_param "$logs_params" "isFargate")
if [[ -z "$is_fargate_param" ]]; then
write_run "print_error \"installer.bash (3): isFargate param was not found\""
return 3
fi

local is_fargate_value=$(echo -e "$is_fargate_param" | $jq_bin -r '.value')
if [[ "$is_fargate_value" = null ]]; then
write_run "print_error \"installer.bash (3): '.configuration.subtypes[0].datasources[0].params[{name=isFargate}].value' was not found in application JSON\""
return 3
fi
if [[ -z "$is_fargate_value" ]]; then
write_run "print_error \"installer.bash (3): '.configuration.subtypes[0].datasources[0].params[{name=isFargate}].value' is empty in application JSON\""
return 3
fi

if ! $is_fargate_value; then
write_log "INFO isFargate value = false"
else
write_log "INFO isFargate value = true"
fi

write_run "is_farget=$is_fargate_value"
}

# Builds enable Fargate Helm set
# Output:
# helm_sets - Contains all the Helm sets
function build_enable_fargate_helm_set () {
write_log "INFO" "Building enable Fargate Helm set ..."

local helm_set=" --set fargateLogRouter.enabled=true"
local helm_set=" --set logzio-fluentd.fargateLogRouter.enabled=true"
write_log "INFO" "helm_set = $helm_set"
write_run "log_helm_sets+='$helm_set'"
write_run "helm_sets+='$helm_set'"
Expand Down
2 changes: 0 additions & 2 deletions Kubernetes/EKS/Kubernetes/telemetry/logs/mac/logs.bash
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ execute_task "build_logzio_logs_token_helm_set" "building Logz.io logs token Hel
# Build environment ID Helm set
execute_task "build_environment_id_helm_set" "building environment ID Helm set"

# Get is Fargate was selected
execute_task "get_is_fargate_was_selected" "getting is Farget was selceted"
if $is_farget; then
# Build enable Fargate Helm set
execute_task "build_enable_fargate_helm_set" "building enable Fargate Helm set"
Expand Down
12 changes: 12 additions & 0 deletions Kubernetes/EKS/Kubernetes/telemetry/metrics/mac/functions.bash
Original file line number Diff line number Diff line change
Expand Up @@ -104,3 +104,15 @@ function build_enable_metrics_filter_helm_set () {
write_run "log_helm_sets+='$helm_set'"
write_run "helm_sets+='$helm_set'"
}

# Builds Fargate collector mode standalone Helm set
# Output:
# helm_sets - Contains all the Helm sets
function build_fargate_collector_mode_standalone_helm_set () {
write_log "INFO" "Building Fargate collector standalone Helm set ..."

local helm_set=" --set logzio-k8s-telemetry.collector.mode=standalone"
write_log "INFO" "helm_set = $helm_set"
write_run "log_helm_sets+='$helm_set'"
write_run "helm_sets+='$helm_set'"
}
4 changes: 4 additions & 0 deletions Kubernetes/EKS/Kubernetes/telemetry/metrics/mac/metrics.bash
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,7 @@ if $is_filter; then
# Build enable metrics filter Helm set
execute_task "build_enable_metrics_filter_helm_set" "building enable metrics filter Helm set"
fi

if $is_fargate; then
execute_task "build_fargate_collector_mode_standalone_helm_set" "building Fargate collector mode standalone Helm set"
fi
16 changes: 8 additions & 8 deletions configs/2-2-k8s-eks.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,14 @@
"description": "Taints allow a node to repel a series of pods. Tolerations are applied to pods and allow them to schedule onto nodes with matching taints. Enable to force deployment on all pods.",
"hint": "By checking this option the Logz.io Telemetry Collector will be deployed on all nodes.",
"value": true
},
{
"type": "boolean",
"name": "isFargate",
"label": "AWS Fargate",
"description": "AWS Fargate is a serverless, pay-as-you-go compute engine that lets you focus on building applications without managing servers. Enable this if your EKS is based on Fargate.",
"hint": "By checking this option the Logz.io Telemetry Collector will be deployed on EKS based on Fargate.",
"value": false
}
],
"telemetries": [
Expand All @@ -44,14 +52,6 @@
"description": "",
"hint": "Switch the toggle on if you want Logz.io Telemetry Collector to collect logs from your Kubernetes cluster components and applications pods",
"params": [
{
"type": "boolean",
"name": "isFargate",
"label": "AWS Fargate",
"description": "AWS Fargate is a serverless, pay-as-you-go compute engine that lets you focus on building applications without managing servers. Enable this if your EKS is based on Fargate.",
"hint": "By checking this option the Logz.io Telemetry Collector will be deployed on EKS based on Fargate.",
"value": false
}
]
},
{
Expand Down
2 changes: 1 addition & 1 deletion datasources/linux/aws/ec2/system/installer/functions.bash
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ function load_installer_utils {
source "$ALL_RESOURCES_LINUX_DIR/datasource_installer_utils.bash" 2>"$TASK_ERROR_FILE"
if [[ $? -ne 0 ]]; then
message="installer.bash ($EXIT_CODE): error loading installer utils functions: $(get_task_error_message)"
send_log_to_logzio "$LOG_LEVEL_ERROR" "$message" "$LOG_STEP_PREREQUISITES" "$LOG_SCRIPT_PREREQUISITES" "$func_name" "$AGENT_ID" "$PLATFORM" "$SUB_TYPE" "$CURRENT_DATA_SOURCE"
send_log_to_logzio "$LOG_LEVEL_ERROR" "$message" "$LOG_STEP_INSTALLATION" "$LOG_SCRIPT_INSTALLER" "$func_name" "$AGENT_ID" "$PLATFORM" "$SUB_TYPE" "$CURRENT_DATA_SOURCE"
write_error "$message"

IS_AGENT_FAILED=true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ function load_installer_utils {
local func_name="${FUNCNAME[0]}"

local message='Laoding installer utils functions ...'
send_log_to_logzio "$LOG_LEVEL_DEBUG" "$message" "$LOG_STEP_PRE_INSTALLATION" "$LOG_SCRIPT_INSTALLER" "$func_name" "$AGENT_ID" "$PLATFORM" "$SUB_TYPE"
send_log_to_logzio "$LOG_LEVEL_DEBUG" "$message" "$LOG_STEP_INSTALLATION" "$LOG_SCRIPT_INSTALLER" "$func_name" "$AGENT_ID" "$PLATFORM" "$SUB_TYPE" "$CURRENT_DATA_SOURCE"
write_log "$LOG_LEVEL_DEBUG" "$message"

source "$ALL_RESOURCES_LINUX_DIR/datasource_installer_utils.bash" 2>"$TASK_ERROR_FILE"
if [[ $? -ne 0 ]]; then
message="installer.bash ($EXIT_CODE): error loading installer utils functions: $(get_task_error_message)"
send_log_to_logzio "$LOG_LEVEL_DEBUG" "$message" "$LOG_STEP_PRE_INSTALLATION" "$LOG_SCRIPT_INSTALLER" "$func_name" "$AGENT_ID" "$PLATFORM" "$SUB_TYPE"
send_log_to_logzio "$LOG_LEVEL_DEBUG" "$message" "$LOG_STEP_INSTALLATION" "$LOG_SCRIPT_INSTALLER" "$func_name" "$AGENT_ID" "$PLATFORM" "$SUB_TYPE" "$CURRENT_DATA_SOURCE"
write_error "$message"

IS_AGENT_FAILED=true
Expand All @@ -30,7 +30,7 @@ function load_installer_utils {
source "$KUBERNETES_RESOURCES_LINUX_DIR/datasource_installer_utils.bash" 2>"$TASK_ERROR_FILE"
if [[ $? -ne 0 ]]; then
message="installer.bash ($EXIT_CODE): error loading installer utils functions: $(get_task_error_message)"
send_log_to_logzio "$LOG_LEVEL_DEBUG" "$message" "$LOG_STEP_PRE_INSTALLATION" "$LOG_SCRIPT_INSTALLER" "$func_name" "$AGENT_ID" "$PLATFORM" "$SUB_TYPE"
send_log_to_logzio "$LOG_LEVEL_DEBUG" "$message" "$LOG_STEP_INSTALLATION" "$LOG_SCRIPT_INSTALLER" "$func_name" "$AGENT_ID" "$PLATFORM" "$SUB_TYPE" "$CURRENT_DATA_SOURCE"
write_error "$message"

IS_AGENT_FAILED=true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ function get_is_kubernetes_run_on_windows_os_was_selected {
write_log "$LOG_LEVEL_DEBUG" "$message"

PARAMS=("${METRICS_PARAMS[@]}")
get_param_value_list 'isWindows'
get_param_value 'isWindows'
if [[ $? -ne 0 ]]; then
message="metrics.bash ($EXIT_CODE): $(get_task_error_message)"
send_log_to_logzio "$LOG_LEVEL_ERROR" "$message" "$LOG_STEP_METRICS" "$LOG_SCRIPT_METRICS" "$func_name" "$AGENT_ID" "$PLATFORM" "$SUB_TYPE" "$CURRENT_DATA_SOURCE"
Expand All @@ -80,7 +80,7 @@ function get_is_kubernetes_run_on_windows_os_was_selected {
# Input:
# ---
# Output:
# LOG_HELM_SETS - Containt all the Helm sets for logging
# LOG_HELM_SETS - Contains all the Helm sets for logging
# HELM_SETS - Contains all the Helm sets
function build_windows_node_username_and_password_helm_sets {
local func_name="${FUNCNAME[0]}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ function load_installer_utils {
local func_name="${FUNCNAME[0]}"

local message='Laoding installer utils functions ...'
send_log_to_logzio "$LOG_LEVEL_DEBUG" "$message" "$LOG_STEP_PRE_INSTALLATION" "$LOG_SCRIPT_INSTALLER" "$func_name" "$AGENT_ID" "$PLATFORM" "$SUB_TYPE"
send_log_to_logzio "$LOG_LEVEL_DEBUG" "$message" "$LOG_STEP_INSTALLATION" "$LOG_SCRIPT_INSTALLER" "$func_name" "$AGENT_ID" "$PLATFORM" "$SUB_TYPE" "$CURRENT_DATA_SOURCE"
write_log "$LOG_LEVEL_DEBUG" "$message"

source "$ALL_RESOURCES_LINUX_DIR/datasource_installer_utils.bash" 2>"$TASK_ERROR_FILE"
if [[ $? -ne 0 ]]; then
message="installer.bash ($EXIT_CODE): error loading installer utils functions: $(get_task_error_message)"
send_log_to_logzio "$LOG_LEVEL_DEBUG" "$message" "$LOG_STEP_PRE_INSTALLATION" "$LOG_SCRIPT_INSTALLER" "$func_name" "$AGENT_ID" "$PLATFORM" "$SUB_TYPE"
send_log_to_logzio "$LOG_LEVEL_DEBUG" "$message" "$LOG_STEP_INSTALLATION" "$LOG_SCRIPT_INSTALLER" "$func_name" "$AGENT_ID" "$PLATFORM" "$SUB_TYPE" "$CURRENT_DATA_SOURCE"
write_error "$message"

IS_AGENT_FAILED=true
Expand All @@ -30,7 +30,7 @@ function load_installer_utils {
source "$KUBERNETES_RESOURCES_LINUX_DIR/datasource_installer_utils.bash" 2>"$TASK_ERROR_FILE"
if [[ $? -ne 0 ]]; then
message="installer.bash ($EXIT_CODE): error loading installer utils functions: $(get_task_error_message)"
send_log_to_logzio "$LOG_LEVEL_DEBUG" "$message" "$LOG_STEP_PRE_INSTALLATION" "$LOG_SCRIPT_INSTALLER" "$func_name" "$AGENT_ID" "$PLATFORM" "$SUB_TYPE"
send_log_to_logzio "$LOG_LEVEL_DEBUG" "$message" "$LOG_STEP_INSTALLATION" "$LOG_SCRIPT_INSTALLER" "$func_name" "$AGENT_ID" "$PLATFORM" "$SUB_TYPE" "$CURRENT_DATA_SOURCE"
write_error "$message"

IS_AGENT_FAILED=true
Expand Down
Loading

0 comments on commit 1e204a3

Please sign in to comment.