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 demo for namespace recommendations #86

Merged
merged 13 commits into from
Oct 1, 2024
47 changes: 47 additions & 0 deletions common/common_helper.sh
Original file line number Diff line number Diff line change
Expand Up @@ -422,3 +422,50 @@ function delete_namespace() {
echo "#########################################"
echo
}

###########################################
# Apply namespace resource quota
###########################################
function apply_namespace_resource_quota() {
# Define the namespace and resource quota file path
CAPP_NAMESPACE="${1:-default}"
RESOURCE_QUOTA_FILE="${2:-namespace_resource_quota.yaml}"

echo
echo "Updating namespace resource quota YAML"
sed -i 's/namespace: default/namespace: "'"${CAPP_NAMESPACE}"'"/' "${RESOURCE_QUOTA_FILE}"
echo
echo "Applying namespace resource quota in namespace: ${CAPP_NAMESPACE}"

# Apply the resource quota YAML to the namespace
if kubectl apply -f "${RESOURCE_QUOTA_FILE}" -n "${CAPP_NAMESPACE}" &> /dev/null; then
echo "Resource quota applied successfully."
else
echo "Failed to apply resource quota."
fi

echo "#########################################"
echo
}

###########################################
# Delete namespace resource quota
###########################################
function delete_namespace_resource_quota() {
# Define the namespace and resource quota name
CAPP_NAMESPACE="${1:-default}"
RESOURCE_QUOTA_NAME="${2:-default-ns-quota}"

echo
echo "Deleting namespace resource quota: ${RESOURCE_QUOTA_NAME} in namespace: ${CAPP_NAMESPACE}"

# Delete the resource quota in the namespace
if kubectl delete resourcequota "${RESOURCE_QUOTA_NAME}" -n "${CAPP_NAMESPACE}" &> /dev/null; then
echo "Namespace resource quota ${RESOURCE_QUOTA_NAME} deleted successfully."
else
echo "Failed to delete namespace resource quota. It may not exist or there was an error."
fi

echo "#########################################"
echo
}
24 changes: 24 additions & 0 deletions monitoring/local_monitoring/create_namespace_exp.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
[{
"version": "v2.0",
"experiment_name": "monitor_app_namespace",
"cluster_name": "default",
"performance_profile": "resource-optimization-local-monitoring",
"mode": "monitor",
"target_cluster": "local",
"datasource": "prometheus-1",
"experiment_type": "namespace",
"kubernetes_objects": [
{
"namespaces": {
"namespace_name": "default"
}
}
],
"trial_settings": {
"measurement_duration": "15min"
},
"recommendation_settings": {
"threshold": "0.1"
}
}]

12 changes: 12 additions & 0 deletions monitoring/local_monitoring/local_monitoring_demo.sh
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ function kruize_local() {
curl -X DELETE http://${KRUIZE_URL}/createExperiment -d @./create_tfb_exp.json
echo "curl -X DELETE http://${KRUIZE_URL}/createExperiment -d @./create_tfb-db_exp.json"
curl -X DELETE http://${KRUIZE_URL}/createExperiment -d @./create_tfb-db_exp.json
echo "curl -X DELETE http://${KRUIZE_URL}/createExperiment -d @./create_namespace_exp.json"
curl -X DELETE http://${KRUIZE_URL}/createExperiment -d @./create_namespace_exp.json
echo

echo
Expand All @@ -128,6 +130,7 @@ function kruize_local() {
echo
sed -i 's/"namespace": "default"/"namespace": "'"${APP_NAMESPACE}"'"/' ./create_tfb_exp.json
sed -i 's/"namespace": "default"/"namespace": "'"${APP_NAMESPACE}"'"/' ./create_tfb-db_exp.json
sed -i 's/"namespace_name": "default"/"namespace_name": "'"${APP_NAMESPACE}"'"/' ./create_namespace_exp.json
echo

echo
Expand All @@ -139,6 +142,8 @@ function kruize_local() {
curl -X POST http://${KRUIZE_URL}/createExperiment -d @./create_tfb_exp.json
echo "curl -X POST http://${KRUIZE_URL}/createExperiment -d @./create_tfb-db_exp.json"
curl -X POST http://${KRUIZE_URL}/createExperiment -d @./create_tfb-db_exp.json
echo "curl -X POST http://${KRUIZE_URL}/createExperiment -d @./create_namespace_exp.json"
curl -X POST http://${KRUIZE_URL}/createExperiment -d @./create_namespace_exp.json
echo

apply_benchmark_load ${APP_NAMESPACE}
Expand All @@ -152,6 +157,8 @@ function kruize_local() {
curl -X POST "http://${KRUIZE_URL}/generateRecommendations?experiment_name=monitor_tfb_benchmark"
echo "curl -X POST http://${KRUIZE_URL}/generateRecommendations?experiment_name=monitor_tfb-db_benchmark"
curl -X POST "http://${KRUIZE_URL}/generateRecommendations?experiment_name=monitor_tfb-db_benchmark"
echo "curl -X POST http://${KRUIZE_URL}/generateRecommendations?experiment_name=monitor_app_namespace"
curl -X POST "http://${KRUIZE_URL}/generateRecommendations?experiment_name=monitor_app_namespace"

echo ""
echo "######################################################"
Expand All @@ -164,10 +171,12 @@ function kruize_local() {
echo "Generate fresh recommendations using"
echo "curl -X POST http://${KRUIZE_URL}/generateRecommendations?experiment_name=monitor_tfb_benchmark"
echo "curl -X POST http://${KRUIZE_URL}/generateRecommendations?experiment_name=monitor_tfb-db_benchmark"
echo "curl -X POST http://${KRUIZE_URL}/generateRecommendations?experiment_name=monitor_app_namespace"
echo
echo "List Recommendations using "
echo "curl http://${KRUIZE_URL}/listRecommendations?experiment_name=monitor_tfb_benchmark"
echo "curl http://${KRUIZE_URL}/listRecommendations?experiment_name=monitor_tfb-db_benchmark"
echo "curl http://${KRUIZE_URL}/listRecommendations?experiment_name=monitor_app_namespace"
echo
echo "######################################################"
echo
Expand Down Expand Up @@ -287,6 +296,7 @@ function kruize_local_patch() {
function kruize_local_demo_setup() {
# Start all the installs
start_time=$(get_date)
namespace_quota_yaml="${current_dir}/namespace_resource_quota.yaml"
echo
echo "#######################################"
echo "# Kruize Local Demo Setup #"
Expand All @@ -311,6 +321,7 @@ function kruize_local_demo_setup() {
prometheus_install
fi
create_namespace ${APP_NAMESPACE}
apply_namespace_resource_quota ${APP_NAMESPACE} ${namespace_quota_yaml}
benchmarks_install ${APP_NAMESPACE} ${BENCHMARK_MANIFESTS}
fi
kruize_local_patch
Expand Down Expand Up @@ -420,6 +431,7 @@ function kruize_local_demo_terminate() {
kruize_uninstall
fi
benchmarks_uninstall ${APP_NAMESPACE} ${BENCHMARK_MANIFESTS}
delete_namespace_resource_quota ${APP_NAMESPACE}
delete_repos autotune
end_time=$(get_date)
elapsed_time=$(time_diff "${start_time}" "${end_time}")
Expand Down
12 changes: 12 additions & 0 deletions monitoring/local_monitoring/namespace_resource_quota.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
apiVersion: v1
kind: ResourceQuota
metadata:
name: default-ns-quota
namespace: "default"
spec:
hard:
pods: "20"
requests.cpu: "16"
requests.memory: "32Gi"
limits.cpu: "32"
limits.memory: "64Gi"