|
| 1 | +#!/usr/bin/env bash |
| 2 | +set -euo pipefail |
| 3 | + |
| 4 | +embedded_cluster_config=" |
| 5 | +apiVersion: embeddedcluster.replicated.com/v1beta1 |
| 6 | +kind: Config |
| 7 | +spec: |
| 8 | + unsupportedOverrides: |
| 9 | + k0s: | |
| 10 | + config: |
| 11 | + metadata: |
| 12 | + name: testing-overrides-k0s-name |
| 13 | + spec: |
| 14 | + telemetry: |
| 15 | + enabled: true |
| 16 | +" |
| 17 | + |
| 18 | +embed_cluster_config() { |
| 19 | + content="$1" |
| 20 | + echo "$content" > /root/release.yaml |
| 21 | + tar -czvf /root/release.tar.gz /root/release.yaml |
| 22 | + objcopy --input-target binary --output-target binary --rename-section .data=sec_bundle /root/release.tar.gz /root/release.o |
| 23 | + objcopy --update-section sec_bundle=/root/release.o /usr/local/bin/embedded-cluster |
| 24 | +} |
| 25 | + |
| 26 | +wait_for_healthy_node() { |
| 27 | + ready=$(kubectl get nodes | grep -v NotReady | grep -c Ready || true) |
| 28 | + counter=0 |
| 29 | + while [ "$ready" -lt "1" ]; do |
| 30 | + if [ "$counter" -gt 36 ]; then |
| 31 | + return 1 |
| 32 | + fi |
| 33 | + sleep 5 |
| 34 | + counter=$((counter+1)) |
| 35 | + echo "Waiting for node to be ready" |
| 36 | + ready=$(kubectl get nodes | grep -v NotReady | grep -c Ready || true) |
| 37 | + kubectl get nodes || true |
| 38 | + done |
| 39 | + return 0 |
| 40 | +} |
| 41 | + |
| 42 | +override_applied() { |
| 43 | + grep -A1 telemetry "$K0SCTLCONFIG" > /tmp/telemetry-section |
| 44 | + if ! grep -q "enabled: true" /tmp/telemetry-section; then |
| 45 | + echo "override not applied, expected telemetry true, actual config:" |
| 46 | + cat "$K0SCTLCONFIG" |
| 47 | + return 1 |
| 48 | + fi |
| 49 | + if ! grep "testing-overrides-k0s-name" "$K0SCTLCONFIG"; then |
| 50 | + echo "override not applied, expected name testing-overrides-k0s-name, actual config:" |
| 51 | + cat "$K0SCTLCONFIG" |
| 52 | + return 1 |
| 53 | + fi |
| 54 | +} |
| 55 | + |
| 56 | +main() { |
| 57 | + cp -Rfp /usr/local/bin/embedded-cluster /usr/local/bin/embedded-cluster-copy |
| 58 | + embed_cluster_config "$embedded_cluster_config" |
| 59 | + if ! embedded-cluster install --no-prompt 2>&1 | tee /tmp/log ; then |
| 60 | + echo "Failed to install embedded-cluster" |
| 61 | + cat /tmp/log |
| 62 | + exit 1 |
| 63 | + fi |
| 64 | + if ! grep -q "Admin Console is ready!" /tmp/log; then |
| 65 | + echo "Failed to install embedded-cluster" |
| 66 | + exit 1 |
| 67 | + fi |
| 68 | + if ! override_applied; then |
| 69 | + echo "Expected override to be applied" |
| 70 | + exit 1 |
| 71 | + fi |
| 72 | +} |
| 73 | + |
| 74 | +export EMBEDDED_CLUSTER_METRICS_BASEURL="https://staging.replicated.app" |
| 75 | +export KUBECONFIG=/root/.config/.embedded-cluster/etc/kubeconfig |
| 76 | +export K0SCTLCONFIG=/root/.config/.embedded-cluster/etc/k0sctl.yaml |
| 77 | +export PATH=$PATH:/root/.config/.embedded-cluster/bin |
| 78 | +main |
0 commit comments