|
| 1 | +setup() { |
| 2 | + bats_load_library bats-support |
| 3 | + bats_load_library bats-assert |
| 4 | +} |
| 5 | + |
| 6 | +@test "can create clients with admin cli" { |
| 7 | + jmp admin create client test-client-oidc --unsafe --out /dev/null \ |
| 8 | + --oidc-username dex:test-client-oidc |
| 9 | + jmp admin create client test-client-sa --unsafe --out /dev/null \ |
| 10 | + --oidc-username dex:system:serviceaccount:default:test-client-sa |
| 11 | + jmp admin create client test-client-legacy --unsafe --save |
| 12 | +} |
| 13 | + |
| 14 | +@test "can create exporters with admin cli" { |
| 15 | + jmp admin create exporter test-exporter-oidc --out /dev/null \ |
| 16 | + --oidc-username dex:test-exporter-oidc \ |
| 17 | + --label example.com/board=oidc |
| 18 | + jmp admin create exporter test-exporter-sa --out /dev/null \ |
| 19 | + --oidc-username dex:system:serviceaccount:default:test-exporter-sa \ |
| 20 | + --label example.com/board=sa |
| 21 | + jmp admin create exporter test-exporter-legacy --save \ |
| 22 | + --label example.com/board=legacy |
| 23 | +} |
| 24 | + |
| 25 | +@test "can login with oidc" { |
| 26 | + jmp config client list |
| 27 | + jmp config exporter list |
| 28 | + |
| 29 | + jmp login --client test-client-oidc \ |
| 30 | + --endpoint "$ENDPOINT" --namespace default --name test-client-oidc \ |
| 31 | + --issuer https://dex.dex.svc.cluster.local:5556 \ |
| 32 | + --username test-client-oidc@example.com --password password --unsafe |
| 33 | + |
| 34 | + jmp login --client test-client-sa \ |
| 35 | + --endpoint "$ENDPOINT" --namespace default --name test-client-sa \ |
| 36 | + --issuer https://dex.dex.svc.cluster.local:5556 \ |
| 37 | + --connector-id kubernetes \ |
| 38 | + --token $(kubectl create -n default token test-client-sa) --unsafe |
| 39 | + |
| 40 | + jmp login --exporter test-exporter-oidc \ |
| 41 | + --endpoint "$ENDPOINT" --namespace default --name test-exporter-oidc \ |
| 42 | + --issuer https://dex.dex.svc.cluster.local:5556 \ |
| 43 | + --username test-exporter-oidc@example.com --password password |
| 44 | + |
| 45 | + jmp login --exporter test-exporter-sa \ |
| 46 | + --endpoint "$ENDPOINT" --namespace default --name test-exporter-sa \ |
| 47 | + --issuer https://dex.dex.svc.cluster.local:5556 \ |
| 48 | + --connector-id kubernetes \ |
| 49 | + --token $(kubectl create -n default token test-exporter-sa) |
| 50 | + |
| 51 | + go run github.com/mikefarah/yq/v4@latest -i ". * load(\"$GITHUB_ACTION_PATH/exporter.yaml\")" \ |
| 52 | + /etc/jumpstarter/exporters/test-exporter-oidc.yaml |
| 53 | + go run github.com/mikefarah/yq/v4@latest -i ". * load(\"$GITHUB_ACTION_PATH/exporter.yaml\")" \ |
| 54 | + /etc/jumpstarter/exporters/test-exporter-sa.yaml |
| 55 | + go run github.com/mikefarah/yq/v4@latest -i ". * load(\"$GITHUB_ACTION_PATH/exporter.yaml\")" \ |
| 56 | + /etc/jumpstarter/exporters/test-exporter-legacy.yaml |
| 57 | + |
| 58 | + jmp config client list |
| 59 | + jmp config exporter list |
| 60 | +} |
| 61 | + |
| 62 | +@test "can run exporters" { |
| 63 | + cat <<EOF | bash 3>&- & |
| 64 | +while true; do |
| 65 | + jmp run --exporter test-exporter-oidc |
| 66 | +done |
| 67 | +EOF |
| 68 | + |
| 69 | + cat <<EOF | bash 3>&- & |
| 70 | +while true; do |
| 71 | + jmp run --exporter test-exporter-sa |
| 72 | +done |
| 73 | +EOF |
| 74 | + |
| 75 | + cat <<EOF | bash 3>&- & |
| 76 | +while true; do |
| 77 | + jmp run --exporter test-exporter-legacy |
| 78 | +done |
| 79 | +EOF |
| 80 | + |
| 81 | + kubectl -n default wait --for=condition=Online --for=condition=Registered \ |
| 82 | + exporters.jumpstarter.dev/test-exporter-oidc |
| 83 | + kubectl -n default wait --for=condition=Online --for=condition=Registered \ |
| 84 | + exporters.jumpstarter.dev/test-exporter-sa |
| 85 | + kubectl -n default wait --for=condition=Online --for=condition=Registered \ |
| 86 | + exporters.jumpstarter.dev/test-exporter-legacy |
| 87 | +} |
| 88 | + |
| 89 | +@test "can specify client config only using environment variables" { |
| 90 | + kubectl -n default wait --for=condition=Online --for=condition=Registered \ |
| 91 | + exporters.jumpstarter.dev/test-exporter-oidc |
| 92 | + |
| 93 | + JMP_NAMEPSACE=default \ |
| 94 | + JMP_NAME=test-exporter-legacy \ |
| 95 | + JMP_ENDPOINT=$(kubectl get clients.jumpstarter.dev -n default test-client-legacy -o 'jsonpath={.status.endpoint}') \ |
| 96 | + JMP_TOKEN=$(kubectl get secrets -n default test-client-legacy-client -o 'jsonpath={.data.token}' | base64 -d) \ |
| 97 | + jmp shell --selector example.com/board=oidc j power on |
| 98 | +} |
| 99 | + |
| 100 | +@test "can operate on leases" { |
| 101 | + kubectl -n default wait --for=condition=Online --for=condition=Registered \ |
| 102 | + exporters.jumpstarter.dev/test-exporter-oidc |
| 103 | + |
| 104 | + jmp config client use test-client-oidc |
| 105 | + |
| 106 | + jmp create lease --selector example.com/board=oidc --duration 1d |
| 107 | + jmp get leases |
| 108 | + jmp get exporters |
| 109 | + jmp delete leases --all |
| 110 | +} |
| 111 | + |
| 112 | +@test "can lease and connect to exporters" { |
| 113 | + kubectl -n default wait --for=condition=Online --for=condition=Registered \ |
| 114 | + exporters.jumpstarter.dev/test-exporter-oidc |
| 115 | + kubectl -n default wait --for=condition=Online --for=condition=Registered \ |
| 116 | + exporters.jumpstarter.dev/test-exporter-sa |
| 117 | + kubectl -n default wait --for=condition=Online --for=condition=Registered \ |
| 118 | + exporters.jumpstarter.dev/test-exporter-legacy |
| 119 | + |
| 120 | + jmp shell --client test-client-oidc --selector example.com/board=oidc j power on |
| 121 | + jmp shell --client test-client-sa --selector example.com/board=sa j power on |
| 122 | + jmp shell --client test-client-legacy --selector example.com/board=legacy j power on |
| 123 | +} |
| 124 | + |
| 125 | +@test "can get crds with admin cli" { |
| 126 | + jmp admin get client |
| 127 | + jmp admin get exporter |
| 128 | + jmp admin get lease |
| 129 | +} |
| 130 | + |
| 131 | +@test "can delete clients with admin cli" { |
| 132 | + kubectl -n default get secret test-client-oidc-client |
| 133 | + kubectl -n default get clients.jumpstarter.dev/test-client-oidc |
| 134 | + kubectl -n default get clients.jumpstarter.dev/test-client-sa |
| 135 | + kubectl -n default get clients.jumpstarter.dev/test-client-legacy |
| 136 | + |
| 137 | + jmp admin delete client test-client-oidc --delete |
| 138 | + jmp admin delete client test-client-sa --delete |
| 139 | + jmp admin delete client test-client-legacy --delete |
| 140 | + |
| 141 | + run ! kubectl -n default get secret test-client-oidc-client |
| 142 | + run ! kubectl -n default get clients.jumpstarter.dev/test-client-oidc |
| 143 | + run ! kubectl -n default get clients.jumpstarter.dev/test-client-sa |
| 144 | + run ! kubectl -n default get clients.jumpstarter.dev/test-client-legacy |
| 145 | +} |
| 146 | + |
| 147 | +@test "can delete exporters with admin cli" { |
| 148 | + kubectl -n default get secret test-exporter-oidc-exporter |
| 149 | + kubectl -n default get exporters.jumpstarter.dev/test-exporter-oidc |
| 150 | + kubectl -n default get exporters.jumpstarter.dev/test-exporter-sa |
| 151 | + kubectl -n default get exporters.jumpstarter.dev/test-exporter-legacy |
| 152 | + |
| 153 | + jmp admin delete exporter test-exporter-oidc --delete |
| 154 | + jmp admin delete exporter test-exporter-sa --delete |
| 155 | + jmp admin delete exporter test-exporter-legacy --delete |
| 156 | + |
| 157 | + run ! kubectl -n default get secret test-exporter-oidc-exporter |
| 158 | + run ! kubectl -n default get exporters.jumpstarter.dev/test-exporter-oidc |
| 159 | + run ! kubectl -n default get exporters.jumpstarter.dev/test-exporter-sa |
| 160 | + run ! kubectl -n default get exporters.jumpstarter.dev/test-exporter-legacy |
| 161 | +} |
0 commit comments