Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 11 additions & 9 deletions build/ci/scripts/azure.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ set -e
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
source $SCRIPT_DIR/env.sh

HELM_RELEASE_NAMESPACE=peerd-ns
PEERD_HELM_CHART="$SCRIPT_DIR/../../package/peerd-helm"
SCANNER_APP_DEPLOY_TEMPLATE="$SCRIPT_DIR/../k8s/scanner.yml"
PEERD_LLM_CI_DEPLOY_TEMPLATE=$SCRIPT_DIR/../k8s/llm.yml
Expand Down Expand Up @@ -104,6 +105,7 @@ peerd_helm_deploy() {
if [ "$DRY_RUN" == "false" ]; then
HELM_RELEASE_NAME=peerd && \
helm install --wait $HELM_RELEASE_NAME $PEERD_HELM_CHART \
--namespace $HELM_RELEASE_NAMESPACE --create-namespace \
--set "peerd.image.ref=ghcr.io/azure/acr/dev/peerd:$peerd_image_tag" \
--set "peerd.configureMirrors=$configureMirrors" \
--set "peerd.hosts[0]=https://acrp2pci.azurecr.io" \
Expand All @@ -130,7 +132,7 @@ wait_for_pod_events() {
local found=0

# Get the list of pods.
pods=$(kubectl -n peerd-ns get pods -l $selector -o jsonpath='{.items[*].metadata.name}')
pods=$(kubectl -n $HELM_RELEASE_NAMESPACE get pods -l $selector -o jsonpath='{.items[*].metadata.name}')
echo "pods: $pods"
total=`echo "$pods" | tr -s " " "\012" | wc -l`

Expand All @@ -147,10 +149,10 @@ wait_for_pod_events() {
for pod in $( echo "$pods" | tr -s " " "\012" ); do
echo "checking pod '$pod' for event '$event'"

foundEvent=$(kubectl -n peerd-ns get events --field-selector involvedObject.kind=Pod,involvedObject.name=$pod -o json | jq -r ".items[] | select(.reason == \"$event\")")
foundEvent=$(kubectl -n $HELM_RELEASE_NAMESPACE get events --field-selector involvedObject.kind=Pod,involvedObject.name=$pod -o json | jq -r ".items[] | select(.reason == \"$event\")")
[[ "$foundEvent" == "" ]] && echo "Event '$event' not found for pod '$pod'" || found=$((found+1))

errorEvent=$(kubectl -n peerd-ns get events --field-selector involvedObject.kind=Pod,involvedObject.name=$pod -o json | jq -r '.items[] | select(.reason == "P2PDisconnected" or .resosn == "P2PFailed")')
errorEvent=$(kubectl -n $HELM_RELEASE_NAMESPACE get events --field-selector involvedObject.kind=Pod,involvedObject.name=$pod -o json | jq -r '.items[] | select(.reason == "P2PDisconnected" or .reason == "P2PFailed")')
[[ "$errorEvent" == "" ]] || (echo "Error event found for pod '$pod': $errorEvent" && exit 1)
done

Expand All @@ -171,13 +173,13 @@ wait_for_pod_events() {
}

print_peerd_metrics() {
p=$(kubectl -n peerd-ns get pods -l app=peerd -o jsonpath='{.items[*].metadata.name}')
p=$(kubectl -n $HELM_RELEASE_NAMESPACE get pods -l app=peerd -o jsonpath='{.items[*].metadata.name}')
echo "pods: $p"

for pod in $( echo "$p" | tr -s " " "\012" ); do
echo "checking pod '$pod' for metrics"
kubectl -n peerd-ns exec -i $pod -- bash -c "cat /var/log/peerdmetrics"
kubectl --context=$KIND_CLUSTER_CONTEXT -n peerd-ns exec -i $pod -- bash -c "curl http://localhost:5004/metrics/prometheus" | head -n 20 | echo " ..."
kubectl -n $HELM_RELEASE_NAMESPACE exec -i $pod -- bash -c "cat /var/log/peerdmetrics"
kubectl --context=$KIND_CLUSTER_CONTEXT -n $HELM_RELEASE_NAMESPACE exec -i $pod -- bash -c "curl http://localhost:5004/metrics/prometheus" | head -n 20 | echo " ..."
done
}

Expand All @@ -200,7 +202,7 @@ peerd_pod_watcher() {

for ((i = 1; i <= 300; i++)); do
# Get the list of pods with the label `app=peerd`
pods=$(kubectl -n peerd-ns get pods -l app=peerd -o jsonpath='{.items[*].metadata.name}')
pods=$(kubectl -n $HELM_RELEASE_NAMESPACE get pods -l app=peerd -o jsonpath='{.items[*].metadata.name}')
if [ -z "$pods" ]; then
echo "[Pod Watcher] No pods found with label 'app=peerd'. Retrying..."
sleep 15
Expand All @@ -213,11 +215,11 @@ peerd_pod_watcher() {
for pod in $pods; do
# echo "[Pod Watcher] Checking pod '$pod' for event '$event'"

if kubectl -n peerd-ns get events --field-selector involvedObject.kind=Pod,involvedObject.name="$pod" -o json | \
if kubectl -n $HELM_RELEASE_NAMESPACE get events --field-selector involvedObject.kind=Pod,involvedObject.name="$pod" -o json | \
jq -e ".items[] | select(.reason == \"$event\")" > /dev/null; then
# echo "[Pod Watcher] Event '$event' found for pod '$pod'"

NODE_NAME=$(kubectl -n peerd-ns get pod "$pod" -o jsonpath='{.spec.nodeName}')
NODE_NAME=$(kubectl -n $HELM_RELEASE_NAMESPACE get pod "$pod" -o jsonpath='{.spec.nodeName}')
if [ -n "$NODE_NAME" ]; then
currentLabel=$(kubectl get node $NODE_NAME -o jsonpath='{.metadata.labels.peerd-status}')
if [ "$currentLabel" == "connected" ]; then
Expand Down
17 changes: 9 additions & 8 deletions build/ci/scripts/kind.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ KIND_CLUSTER_CONTEXT="kind-$KIND_CLUSTER_NAME"
CLUSTER_CONFIG_FILE="$SCRIPT_DIR/../k8s/kind-cluster.yml"
HELM_CHART_DIR="$SCRIPT_DIR/../../package/peerd-helm"
HELM_RELEASE_NAME="peerd"
HELM_RELEASE_NAMESPACE="peerd-ns"
export GIT_ROOT="$(git rev-parse --show-toplevel)"

# Console colors and helpers
Expand Down Expand Up @@ -118,13 +119,13 @@ validate_params() {
}

print_p2p_metrics() {
p=$(kubectl --context=$KIND_CLUSTER_CONTEXT -n peerd-ns get pods -l app=peerd -o jsonpath='{.items[*].metadata.name}')
p=$(kubectl --context=$KIND_CLUSTER_CONTEXT -n $HELM_RELEASE_NAMESPACE get pods -l app=peerd -o jsonpath='{.items[*].metadata.name}')
echo "pods: $p"

for pod in $( echo "$p" | tr -s " " "\012" ); do
echo "checking pod '$pod' for metrics"
kubectl --context=$KIND_CLUSTER_CONTEXT -n peerd-ns exec -i $pod -- bash -c "cat /var/log/peerdmetrics"
kubectl --context=$KIND_CLUSTER_CONTEXT -n peerd-ns exec -i $pod -- bash -c "curl http://localhost:5004/metrics/prometheus" | head -n 10
kubectl --context=$KIND_CLUSTER_CONTEXT -n $HELM_RELEASE_NAMESPACE exec -i $pod -- bash -c "cat /var/log/peerdmetrics"
kubectl --context=$KIND_CLUSTER_CONTEXT -n $HELM_RELEASE_NAMESPACE exec -i $pod -- bash -c "curl http://localhost:5004/metrics/prometheus" | head -n 10
done
}

Expand Down Expand Up @@ -163,7 +164,7 @@ wait_for_events() {
local event=$2
local minimumRequired=$3

local ns="peerd-ns"
local ns="$HELM_RELEASE_NAMESPACE"
local found=0

# # Get app pods
Expand Down Expand Up @@ -290,9 +291,9 @@ cmd__test__random() {

echo "waiting for logs" && \
sleep 10 && \
kubectl --context=$KIND_CLUSTER_CONTEXT -n peerd-ns logs -l app=random -f
kubectl --context=$KIND_CLUSTER_CONTEXT -n peerd-ns delete ds/random
kubectl --context=$KIND_CLUSTER_CONTEXT -n $HELM_RELEASE_NAMESPACE logs -l app=random -f

kubectl --context=$KIND_CLUSTER_CONTEXT -n $HELM_RELEASE_NAMESPACE delete ds/random

echo "checking p2p active pods" && sleep 2
wait_for_events $KIND_CLUSTER_CONTEXT "P2PActive" 1
Expand Down Expand Up @@ -333,7 +334,7 @@ cmd__app__deploy() {
helm --kube-context=$KIND_CLUSTER_CONTEXT uninstall $HELM_RELEASE_NAME

echo "Helm installing release:" $HELM_RELEASE_NAME
helm --kube-context=$KIND_CLUSTER_CONTEXT install --wait $HELM_RELEASE_NAME $HELM_CHART_DIR \
helm --kube-context=$KIND_CLUSTER_CONTEXT install --namespace $HELM_RELEASE_NAMESPACE --create-namespace --wait $HELM_RELEASE_NAME $HELM_CHART_DIR \
--set peerd.image.ref=$PEERD_CONTAINER_IMAGE_REF

echo "waiting for pods to connect"
Expand Down
6 changes: 3 additions & 3 deletions build/package/peerd-helm/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ Expand the name of the chart.
{{- end }}

{{- define "peerd.namespace" -}}
{{- if .Values.peerd.namespace.k8s }}
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we set this to {{ .Release.Namespace }} instead?

Copy link
Contributor

Choose a reason for hiding this comment

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

I tried a CI run on Azure and peerd-ns is not cleaned up anymore after the run.

Copy link
Author

Choose a reason for hiding this comment

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

This is now fixed.

{{- .Values.peerd.namespace.k8s }}
{{- if .Release.Namespace }}
{{- .Release.Namespace }}
{{- else }}
{{ include "peerd.name" . }}-ns
{{- end }}
Expand Down Expand Up @@ -61,4 +61,4 @@ Common selector labels
app: {{ include "peerd.name" . }}
app.kubernetes.io/name: {{ include "peerd.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end }}
{{- end }}
2 changes: 1 addition & 1 deletion build/package/peerd-helm/templates/peerd-ns.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ kind: Namespace
metadata:
name: {{ include "peerd.namespace" . }}
Copy link
Contributor

Choose a reason for hiding this comment

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

This template can then be retained.

Copy link
Author

Choose a reason for hiding this comment

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

It is now re-instated.

labels:
{{- include "peerd.labels" . | nindent 4 }}
{{- include "peerd.labels" . | nindent 4 }}
4 changes: 0 additions & 4 deletions build/package/peerd-helm/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,6 @@ peerd:
# See: https://learn.microsoft.com/azure/azure-monitor/containers/prometheus-metrics-scrape-configuration?tabs=CRDConfig%2CCRDScrapeConfig#configmaps
aksAutoDiscovery: true

namespace:
# The kubernetes namespace for pod deployment and leader election.
k8s: peerd-ns

resources:
limits:
cpu: "1000m"
Expand Down
4 changes: 2 additions & 2 deletions docs/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ To run the tool:

```bash
CLUSTER_CONTEXT=<your-cluster-context> && \
helm --kube-context=$CLUSTER_CONTEXT install --wait overlaybd ./tools/configure-overlaybd-p2p-helm
helm --kube-context=$CLUSTER_CONTEXT install --namespace <your-namespace> --create-namespace --wait overlaybd ./tools/configure-overlaybd-p2p-helm
```

## Deployment
Expand All @@ -53,7 +53,7 @@ CLUSTER_CONTEXT=<your-cluster-context> && \

```bash
CLUSTER_CONTEXT=<your-cluster-context> && \
helm --kube-context=$CLUSTER_CONTEXT install --wait peerd ./build/package/peerd-helm \
helm --kube-context=$CLUSTER_CONTEXT install --namespace <your-namespace> --create-namespace --wait peerd ./build/package/peerd-helm \
--set peerd.image.ref=ghcr.io/azure/acr/dev/peerd:stable
```

Expand Down
Loading