mirror of
https://github.com/cozystack/cozystack.git
synced 2026-12-02 13:18:38 +09:00
The opensearch suite wrote the history jsonpath out as a literal, so the contract test that runs HELMRELEASE_HISTORY_JSONPATH against the upstream Flux type never saw the expression this suite hands kubectl. A field rename upstream would have reached it only as an empty read. The suite now takes the shared expression, and the contract test reads every Chainsaw suite that calls the guard, so a suite copying the literal, or assigning the shared name after sourcing the library, fails in the unit lane instead of going unchecked. The read is matched inside the script step that calls the guard, because every step runs in a shell of its own and a read in another step never reaches the call. Assisted-by: LLM Signed-off-by: Aleksei Sviridkin <f@lex.la>
596 lines
27 KiB
YAML
596 lines
27 KiB
YAML
# The move onto the cert-manager HTTP issuer, run on a cluster.
|
|
#
|
|
# packages/apps/opensearch/tests/tls_upgrade_test.yaml pins that one set of
|
|
# values renders the CR, the cert-manager chain and the tenant sentinel
|
|
# together. Three things it cannot observe decide whether the move survives
|
|
# contact with a running cluster: whether the CR converges when `generate` is
|
|
# dropped from it, whether the operator re-mints the admin certificate once the
|
|
# CA subject changes, and whether the nodePool StatefulSet finishes rolling as
|
|
# the mount plan moves from one whole-secret volume to three subPath mounts
|
|
# (opensearch-k8s-operator v2.8.0, pkg/reconcilers/tls.go handleHttp: one
|
|
# whole-folder volume while the operator generates, three mount() calls carrying
|
|
# SubPath once caSecret is set).
|
|
#
|
|
# The starting state is `tls.issuer: operator` rather than the previous chart
|
|
# version, so the suite runs the move and not the chart bump. Removing the key
|
|
# leaves exactly the values an upgraded release arrives with, and the resolution
|
|
# of an absent key is settled by the render tests. The step that a chart bump
|
|
# would add and this cannot is the one where the OLD chart wrote the CR; a suite
|
|
# in this tree has no second chart version to install from.
|
|
apiVersion: chainsaw.kyverno.io/v1alpha1
|
|
kind: Test
|
|
metadata:
|
|
name: opensearch
|
|
spec:
|
|
catch:
|
|
- events: {}
|
|
- describe:
|
|
apiVersion: helm.toolkit.fluxcd.io/v2
|
|
kind: HelmRelease
|
|
name: opensearch-test
|
|
- describe:
|
|
apiVersion: opensearch.opster.io/v1
|
|
kind: OpenSearchCluster
|
|
name: opensearch-test
|
|
# The roll's own fields — updateRevision, currentRevision, generation,
|
|
# updatedReplicas — are what separate a template that was never rewritten from
|
|
# one the operator has not restarted the pod onto (#4259). The nodePool
|
|
# StatefulSet is OnDelete (opensearch-k8s-operator v2.8.0, builders/cluster.go
|
|
# sets UpdateStrategy.Type OnDelete), so the roll is the operator's
|
|
# rolling-restart reconciler's to drive — it deletes the pod itself — not the
|
|
# StatefulSet controller's. describe omits those fields, so the StatefulSet is
|
|
# captured both ways: get -o yaml carries the revisions and the rendered volume
|
|
# list, describe carries the pod template and the controller's events.
|
|
- get:
|
|
apiVersion: apps/v1
|
|
kind: StatefulSet
|
|
format: yaml
|
|
- describe:
|
|
apiVersion: apps/v1
|
|
kind: StatefulSet
|
|
name: opensearch-test-nodes
|
|
# cert-manager records a refusal to issue in the Certificate's conditions.
|
|
# Without this an unissued chain shows up only as an absent Secret, and the
|
|
# CR then names a Secret that is never going to appear.
|
|
- describe:
|
|
apiVersion: cert-manager.io/v1
|
|
kind: Certificate
|
|
# The controller writes its verdict into the sentinel's status conditions
|
|
# (SourceNotFound, SourceRejected, ProjectionCollision).
|
|
- describe:
|
|
apiVersion: internal.cozystack.io/v1alpha1
|
|
kind: TenantProjection
|
|
- podLogs:
|
|
selector: opster.io/opensearch-cluster=opensearch-test
|
|
tail: 100
|
|
# The restart is the operator's rolling-restart reconciler's to start (see the
|
|
# StatefulSet catch note above). It logs "Starting rolling restart of the
|
|
# StatefulSet" at rollingRestart.go:155 (opensearch-k8s-operator v2.8.0) once
|
|
# the early gates pass — cluster Initialized (:123), every replica ready (:94),
|
|
# an update actually pending (:150-154). Just before that line, at :138, it
|
|
# builds its OpenSearch client, which pings the cluster
|
|
# (NewOsClusterClientFromConfig, os_client.go:104-112) and returns the error
|
|
# from the reconcile at :139-141 when the cluster is unreachable. So the line's
|
|
# absence reads two ways, not one: an early gate held silently, or that client
|
|
# ping failed — loudly, as a reconcile error — before the line was reached. The
|
|
# line present and followed by "Couldn't proceed with rolling restart ...
|
|
# because <reason>" (:182) means the roll reached the health/pod-delete stage,
|
|
# where CheckClusterStatusForRestart (:177) holds it until cluster health is
|
|
# green: a yellow cluster no longer holds under an exception — it enables shard
|
|
# allocation, waits for every data node to join, waits for shard activity to
|
|
# settle, then proceeds — so only red reaches the health hold, and <reason>
|
|
# names it "waiting for health to be green" for the mount-plan incident.
|
|
# That "Couldn't proceed ... because" line is the health hold's signal, one per
|
|
# ~10s requeue and what the tail below is sized for, and
|
|
# CheckClusterStatusForRestart is not the last gate: PreparePodForDelete (:195)
|
|
# follows it. The verdict is in the operator, not the cluster pods above, and it
|
|
# runs in its own namespace.
|
|
- podLogs:
|
|
namespace: cozy-opensearch-operator
|
|
selector: control-plane=controller-manager
|
|
# tail spans the whole assert window. The manager logs ~4-5 lines per ~10s
|
|
# requeue, not one, so 100 lines reach back only about a third of a 12m roll
|
|
# and can lose a one-shot cause. 2000 is effectively everything the container
|
|
# has logged, not a sized window — on run 105251129282 it returned all 457
|
|
# lines since start.
|
|
tail: 2000
|
|
# The external Service is a LoadBalancer, so an address pool with nothing left
|
|
# in it holds the HelmRelease short of Ready with nothing in the HelmRelease
|
|
# itself naming the cause.
|
|
- get:
|
|
apiVersion: v1
|
|
kind: Service
|
|
format: yaml
|
|
# The operator logs that cluster health held a restart back, never what the
|
|
# health was or which shards kept it there, and neither is a Kubernetes object.
|
|
- script:
|
|
# Three reads of at most 30s each. The op timeout sits above their sum so
|
|
# that an inner budget is what fires and the later reads still run.
|
|
timeout: 2m
|
|
content: |
|
|
for path in '_cluster/health?level=indices&pretty' '_cat/shards?v' '_cluster/allocation/explain?pretty'; do
|
|
echo "== $path"
|
|
timeout 30 kubectl -n "$NAMESPACE" exec opensearch-test-nodes-0 -c opensearch -- /bin/bash -c '
|
|
curl -k --silent --show-error --max-time 20 \
|
|
-u "$(cat /mnt/admin-credentials/username):$(cat /mnt/admin-credentials/password)" \
|
|
"https://localhost:9200/$1"' os_api "$path" || true
|
|
echo
|
|
done
|
|
steps:
|
|
- name: create-opensearch
|
|
try:
|
|
- apply:
|
|
file: opensearch.yaml
|
|
|
|
- name: wait-helmrelease-ready
|
|
try:
|
|
# 11m: above the 600s install timeout cozystack-api gives this release;
|
|
# see "Sizing an HR-Ready budget" in docs/agents/e2e-testing.md.
|
|
- assert:
|
|
timeout: 11m
|
|
resource:
|
|
apiVersion: helm.toolkit.fluxcd.io/v2
|
|
kind: HelmRelease
|
|
metadata:
|
|
name: opensearch-test
|
|
status:
|
|
(conditions[?type == 'Ready']):
|
|
- status: "True"
|
|
|
|
- name: verify-operator-managed-listener
|
|
try:
|
|
- assert:
|
|
timeout: 2m
|
|
resource:
|
|
apiVersion: opensearch.opster.io/v1
|
|
kind: OpenSearchCluster
|
|
metadata:
|
|
name: opensearch-test
|
|
spec:
|
|
security:
|
|
tls:
|
|
http:
|
|
generate: true
|
|
# The starting state has to be the one being moved off, or the whole suite
|
|
# asserts a chain that was there from the start. A Certificate that does not
|
|
# exist will not start existing while chainsaw waits, so these are short.
|
|
- error:
|
|
timeout: 30s
|
|
resource:
|
|
apiVersion: cert-manager.io/v1
|
|
kind: Certificate
|
|
metadata:
|
|
name: opensearch-test-http-ca
|
|
- error:
|
|
timeout: 30s
|
|
resource:
|
|
apiVersion: v1
|
|
kind: Secret
|
|
metadata:
|
|
name: opensearch-test.tenant-ca
|
|
# Longer than the waits around it, so justified in-line (e2e-testing.md
|
|
# reviewer checklist, item 6): this is a first boot, so it
|
|
# covers the OpenSearch image pull, the operator's bootstrap pod and the
|
|
# securityadmin job before the nodePool pod reports ready.
|
|
#
|
|
# The mount plan is the half that has to move, so it is pinned on both sides.
|
|
# Here the operator generated its own certificates and mounts the whole
|
|
# Secret it wrote them into (mountFolder, one volume). Projections rather
|
|
# than a volume list: the list is the operator's to order.
|
|
- assert:
|
|
timeout: 12m
|
|
resource:
|
|
apiVersion: apps/v1
|
|
kind: StatefulSet
|
|
metadata:
|
|
name: opensearch-test-nodes
|
|
(spec.template.spec.volumes[?name == 'http-cert'].secret.secretName):
|
|
- opensearch-test-http-cert
|
|
(length(spec.template.spec.volumes[?name == 'http-ca'])): 0
|
|
status:
|
|
readyReplicas: 1
|
|
|
|
# On one data node an index that asks for a replica leaves the cluster yellow
|
|
# for good, because the copy has no second node to land on, and the operator
|
|
# restarts a pod only once its health gate opens. A release gets there without
|
|
# anyone asking for it: the security audit log and any index a tenant creates
|
|
# with the default replica count both do it. Whether one exists by the time the
|
|
# listener moves is a matter of timing, so the suite creates one itself and the
|
|
# roll below always has to get through a yellow cluster.
|
|
- name: make-the-cluster-permanently-yellow
|
|
try:
|
|
# The bootstrap pod stays cluster-manager after the data node is Ready, and
|
|
# answers 503 until its own security config loads; once it is gone, the
|
|
# Ready data node is the manager. The handoff takes seconds; 3m leaves room
|
|
# for several 10s retire retries, a 30s requeue and the 30s grace period.
|
|
- error:
|
|
timeout: 3m
|
|
resource:
|
|
apiVersion: v1
|
|
kind: Pod
|
|
metadata:
|
|
name: opensearch-test-bootstrap-0
|
|
# The same Initialized flag also releases any restart that became pending
|
|
# during first boot, and on one replica it takes the only node down. 6m:
|
|
# the health steps requeue every 10s, then the pod restarts on an image the
|
|
# node already has.
|
|
- assert:
|
|
timeout: 6m
|
|
resource:
|
|
apiVersion: apps/v1
|
|
kind: StatefulSet
|
|
metadata:
|
|
name: opensearch-test-nodes
|
|
(status.observedGeneration == metadata.generation): true
|
|
status:
|
|
readyReplicas: 1
|
|
updatedReplicas: 1
|
|
(currentRevision == updateRevision): true
|
|
- script:
|
|
# Above the two in-pod budgets below, so one of them is what fires.
|
|
timeout: 3m
|
|
content: |
|
|
set -eu
|
|
|
|
# The credentials and the form of the operator's own readiness probe,
|
|
# so a pod that reports Ready answers this as well.
|
|
os_api() {
|
|
kubectl -n "$NAMESPACE" exec opensearch-test-nodes-0 -c opensearch -- /bin/bash -c '
|
|
curl -k --silent --show-error --max-time 75 \
|
|
-u "$(cat /mnt/admin-credentials/username):$(cat /mnt/admin-credentials/password)" \
|
|
-H "Content-Type: application/json" "$@"' os_api "$@"
|
|
}
|
|
|
|
os_api --fail -X PUT "https://localhost:9200/unassignable-replica" \
|
|
--data '{"settings":{"index":{"number_of_shards":1,"number_of_replicas":1}}}'
|
|
|
|
# wait_for_status is satisfied by green as well, so the answer is read
|
|
# rather than trusted: a fixture that stopped holding the cluster
|
|
# yellow would leave the roll below proving nothing about the gate.
|
|
# No --fail here: a wait that times out answers 408 with the health in
|
|
# its body, and that body is what the message below has to print.
|
|
health=$(os_api "https://localhost:9200/_cluster/health/unassignable-replica?wait_for_status=yellow&timeout=60s")
|
|
case "$health" in
|
|
*'"status":"yellow"'*) ;;
|
|
*)
|
|
echo "an index with an unassignable replica did not leave the cluster yellow" >&2
|
|
echo "$health" >&2
|
|
exit 1
|
|
;;
|
|
esac
|
|
|
|
- name: move-onto-cert-manager-issuer
|
|
try:
|
|
# A JSON-patch remove rather than an apply of a second fixture: what an
|
|
# upgrade delivers is the absence of the key, and an apply that merely
|
|
# omitted it would leave the old value in place.
|
|
- script:
|
|
timeout: 1m
|
|
content: |
|
|
set -eu
|
|
kubectl -n "$NAMESPACE" patch opensearches.apps.cozystack.io test \
|
|
--type=json --patch '[{"op": "remove", "path": "/spec/tls/issuer"}]'
|
|
|
|
- name: verify-certmanager-chain-issued
|
|
try:
|
|
- assert:
|
|
timeout: 3m
|
|
resource:
|
|
apiVersion: cert-manager.io/v1
|
|
kind: Certificate
|
|
metadata:
|
|
name: opensearch-test-http-ca
|
|
status:
|
|
(conditions[?type == 'Ready']):
|
|
- status: "True"
|
|
- assert:
|
|
timeout: 3m
|
|
resource:
|
|
apiVersion: cert-manager.io/v1
|
|
kind: Certificate
|
|
metadata:
|
|
name: opensearch-test-http-server
|
|
status:
|
|
(conditions[?type == 'Ready']):
|
|
- status: "True"
|
|
|
|
# The first of the three things a render cannot reach: `generate` was written
|
|
# into a live CR by the previous reconcile and has to be gone from it, not
|
|
# merely absent from the new manifest.
|
|
- name: verify-cr-dropped-generate
|
|
try:
|
|
- assert:
|
|
timeout: 3m
|
|
resource:
|
|
apiVersion: opensearch.opster.io/v1
|
|
kind: OpenSearchCluster
|
|
metadata:
|
|
name: opensearch-test
|
|
(spec.security.tls.http.generate == null): true
|
|
spec:
|
|
security:
|
|
tls:
|
|
http:
|
|
secret:
|
|
name: opensearch-test-http-server
|
|
caSecret:
|
|
name: opensearch-test.http-ca
|
|
|
|
# The second: the operator decides whether to re-mint the admin certificate by
|
|
# comparing the DN bytes of its issuer against the CA subject
|
|
# (shouldCreateAdminCert -> IsSignedByCA). Once the CR names the chart's CA
|
|
# that comparison has to fail and the certificate has to be reissued under it,
|
|
# or securityadmin presents one signed by a CA the listener no longer trusts
|
|
# and the security configuration stops applying with a job timeout as the only
|
|
# sign. Nothing models this as a Kubernetes condition, so it is read out of the
|
|
# certificate itself.
|
|
- name: verify-admin-certificate-moved-to-the-chart-ca
|
|
try:
|
|
- script:
|
|
timeout: 5m
|
|
content: |
|
|
set -eu
|
|
|
|
# Both sides are printed with the same -nameopt, so they are
|
|
# comparable whatever the local openssl's default format is.
|
|
ca_subject=$(kubectl -n "$NAMESPACE" get secret opensearch-test.http-ca \
|
|
-o jsonpath='{.data.tls\.crt}' | base64 -d \
|
|
| openssl x509 -noout -subject -nameopt RFC2253)
|
|
ca_subject=${ca_subject#subject=}
|
|
|
|
# Polls rather than reads once: the re-mint and the StatefulSet update
|
|
# come out of the same reconcile and nothing orders them against each
|
|
# other, so a single read can land between the two.
|
|
deadline=$(( $(date +%s) + 240 ))
|
|
while :; do
|
|
issuer=$(kubectl -n "$NAMESPACE" get secret opensearch-test-admin-cert \
|
|
-o jsonpath='{.data.tls\.crt}' | base64 -d \
|
|
| openssl x509 -noout -issuer -nameopt RFC2253) || issuer=""
|
|
issuer=${issuer#issuer=}
|
|
if [ "$issuer" = "$ca_subject" ]; then
|
|
break
|
|
fi
|
|
if [ "$(date +%s)" -ge "$deadline" ]; then
|
|
echo "the admin certificate is still signed by the operator's own CA" >&2
|
|
echo "issuer: $issuer" >&2
|
|
echo "chart CA: $ca_subject" >&2
|
|
exit 1
|
|
fi
|
|
# TODO(e2e-replace-fixed-timeouts): the operator re-mints the admin
|
|
# certificate on its next reconcile and records no condition for it.
|
|
sleep 5
|
|
done
|
|
|
|
# The third: the mount plan moves from one whole-secret volume to three
|
|
# subPath mounts, and the StatefulSet has to finish rolling onto it. Equal
|
|
# revisions plus a ready updated replica is the roll completing; the volume
|
|
# projections are what it rolled onto. Same 12m as the first boot, for the
|
|
# same reason — the replacement pod pulls and starts OpenSearch from scratch.
|
|
- name: verify-statefulset-rolled-onto-the-new-mount-plan
|
|
try:
|
|
# Two asserts, not one, so a timeout names which half did not happen: the
|
|
# template rewrite and the roll onto it are separate outcomes with separate
|
|
# owners (#4259).
|
|
#
|
|
# First half: the operator rewrote the template onto the subPath mount plan.
|
|
# That is the operator's to do the moment the CR names the cert-manager
|
|
# Secrets, which verify-cr-dropped-generate and the certificate steps already
|
|
# waited for, so it lands within a reconcile or two rather than a pod
|
|
# lifetime. A shorter budget than the roll below, and a failure here is the
|
|
# operator not writing the volumes — not a pod that will not start.
|
|
- assert:
|
|
timeout: 6m
|
|
resource:
|
|
apiVersion: apps/v1
|
|
kind: StatefulSet
|
|
metadata:
|
|
name: opensearch-test-nodes
|
|
(spec.template.spec.volumes[?name == 'http-cert'].secret.secretName):
|
|
- opensearch-test-http-server
|
|
(spec.template.spec.volumes[?name == 'http-key'].secret.secretName):
|
|
- opensearch-test-http-server
|
|
(spec.template.spec.volumes[?name == 'http-ca'].secret.secretName):
|
|
- opensearch-test.http-ca
|
|
# Second half: the operator restarted the pod onto that template and the
|
|
# StatefulSet finished rolling. currentRevision only advances here once the
|
|
# operator's rolling-restart reconciler patches it (see the StatefulSet catch
|
|
# note above), so equal revisions plus a ready updated replica is that
|
|
# reconciler having run to the end. This half also asserts readyReplicas, so a
|
|
# failure with the assert above green is the roll not completing — either the
|
|
# operator never restarted the pod (the reconciler holds on the health gate,
|
|
# per the podLogs note) or a replacement was deleted but never came Ready — not
|
|
# a template that was never written.
|
|
#
|
|
# The three volume projections are carried in here too, so the roll is pinned
|
|
# to the template the first half checked and not to whatever revision happens
|
|
# to be current when the status converges. The CR moves only
|
|
# once in this suite, but the split otherwise lets a rewrite landing after the
|
|
# first assert satisfy this half on its own. observedGeneration == generation
|
|
# is compared at the resource root because a status-scoped expression cannot
|
|
# reach metadata from its own node.
|
|
- assert:
|
|
timeout: 12m
|
|
resource:
|
|
apiVersion: apps/v1
|
|
kind: StatefulSet
|
|
metadata:
|
|
name: opensearch-test-nodes
|
|
(status.observedGeneration == metadata.generation): true
|
|
(spec.template.spec.volumes[?name == 'http-cert'].secret.secretName):
|
|
- opensearch-test-http-server
|
|
(spec.template.spec.volumes[?name == 'http-key'].secret.secretName):
|
|
- opensearch-test-http-server
|
|
(spec.template.spec.volumes[?name == 'http-ca'].secret.secretName):
|
|
- opensearch-test.http-ca
|
|
status:
|
|
readyReplicas: 1
|
|
updatedReplicas: 1
|
|
(currentRevision == updateRevision): true
|
|
|
|
# The sentinel and the projection are Helm-owned and controller-written
|
|
# respectively, so this is the half of the move that has to appear rather than
|
|
# converge. tenantresource is the lineage webhook's verdict, computed from the
|
|
# ApplicationDefinition selector, and nothing short of a cluster proves it.
|
|
- name: verify-tenant-anchor-published
|
|
try:
|
|
- assert:
|
|
timeout: 3m
|
|
resource:
|
|
apiVersion: v1
|
|
kind: Secret
|
|
metadata:
|
|
name: opensearch-test.tenant-ca
|
|
labels:
|
|
internal.cozystack.io/tenant-ca: "true"
|
|
internal.cozystack.io/tenantresource: "true"
|
|
type: Opaque
|
|
# Deterministic once the assert above passes, so no retry.
|
|
- script:
|
|
timeout: 2m
|
|
content: |
|
|
set -eu
|
|
|
|
# Exactly one key, and it is ca.crt. The source Secret holds the CA
|
|
# private key under tls.key, so a second key here is that key leaving
|
|
# the namespace.
|
|
keys=$(kubectl -n "$NAMESPACE" get secret opensearch-test.tenant-ca \
|
|
-o go-template='{{range $k, $v := .data}}{{$k}}{{"\n"}}{{end}}' | sort | tr '\n' ' ')
|
|
if [ "$keys" != "ca.crt " ]; then
|
|
echo "projection must hold exactly ca.crt, holds: $keys" >&2
|
|
exit 1
|
|
fi
|
|
|
|
# Asserting the source really does carry tls.key keeps the check above
|
|
# honest: if cert-manager ever stopped storing it there, the check
|
|
# would keep passing while proving nothing.
|
|
if ! kubectl -n "$NAMESPACE" get secret opensearch-test.http-ca \
|
|
-o go-template='{{if .data}}{{range $k, $v := .data}}{{$k}}{{"\n"}}{{end}}{{end}}' | grep -qx 'tls.key'; then
|
|
echo "opensearch-test.http-ca no longer carries tls.key — this check has stopped proving anything" >&2
|
|
exit 1
|
|
fi
|
|
|
|
# The delivery path the README tells a tenant to use. Everything above
|
|
# reads the raw Secret, which only an admin can do.
|
|
anchor=$(kubectl -n "$NAMESPACE" get tenantsecret opensearch-test.tenant-ca \
|
|
-o jsonpath='{.data.ca\.crt}' | base64 -d)
|
|
if ! echo "$anchor" | grep -q 'BEGIN CERTIFICATE'; then
|
|
echo "the trust anchor is not served through core.cozystack.io/tenantsecrets" >&2
|
|
exit 1
|
|
fi
|
|
|
|
# And the negative that gives it meaning: the key-bearing Secrets must
|
|
# not be reachable the same way.
|
|
for s in opensearch-test.http-ca opensearch-test-http-server; do
|
|
if kubectl -n "$NAMESPACE" get tenantsecret "$s" >/dev/null 2>&1; then
|
|
echo "key-bearing $s is being served as a tenant secret" >&2
|
|
exit 1
|
|
fi
|
|
done
|
|
|
|
# The outcome the whole move is for, and the only check that reads what the
|
|
# pods are actually serving rather than what they were asked to serve. A roll
|
|
# that completed onto a stale mount passes every assert above and fails here.
|
|
- name: verify-endpoint-serves-the-chart-chain
|
|
try:
|
|
- script:
|
|
timeout: 4m
|
|
content: |
|
|
set -eu
|
|
workdir=$(mktemp -d)
|
|
trap '[ -n "${pf_pid:-}" ] && kill "$pf_pid" 2>/dev/null || true; rm -rf "$workdir"' EXIT
|
|
|
|
kubectl -n "$NAMESPACE" get secret opensearch-test.tenant-ca \
|
|
-o jsonpath='{.data.ca\.crt}' | base64 -d > "$workdir/ca.crt"
|
|
kubectl -n "$NAMESPACE" get secret opensearch-test-http-server \
|
|
-o jsonpath='{.data.tls\.crt}' | base64 -d > "$workdir/chart-leaf.crt"
|
|
|
|
# Through the chart's own external Service rather than the operator's,
|
|
# because that is the path a tenant takes. Its selector is untouched
|
|
# here: the selector this branch repairs belongs to the Dashboards
|
|
# Service, which the fixture leaves off, so no cluster step covers it.
|
|
kubectl -n "$NAMESPACE" port-forward service/opensearch-test-external 9200:9200 >/dev/null 2>&1 &
|
|
pf_pid=$!
|
|
# TODO(e2e-replace-fixed-timeouts): nothing models a port-forward
|
|
# becoming ready; the socket opening is the only signal.
|
|
timeout 30 sh -ec 'until nc -z localhost 9200; do sleep 1; done'
|
|
|
|
# -verify_return_error turns a chain that does not build into a
|
|
# non-zero exit. The anchor is the one the tenant is handed, so this
|
|
# is the tenant's own verification, not an admin's.
|
|
if ! openssl s_client -connect 127.0.0.1:9200 -servername opensearch-test \
|
|
-CAfile "$workdir/ca.crt" -verify_return_error </dev/null \
|
|
>"$workdir/handshake.log" 2>&1; then
|
|
echo "the HTTP listener does not verify against the anchor published to the tenant" >&2
|
|
cat "$workdir/handshake.log" >&2
|
|
exit 1
|
|
fi
|
|
|
|
# Verifying against the CA says the chain is the chart's. This says
|
|
# the pods picked up the leaf cert-manager minted, which is the half
|
|
# the subPath mount plan puts at risk.
|
|
sed -n '/BEGIN CERTIFICATE/,/END CERTIFICATE/p' "$workdir/handshake.log" > "$workdir/served.crt"
|
|
served_fp=$(openssl x509 -noout -fingerprint -sha256 -in "$workdir/served.crt")
|
|
chart_fp=$(openssl x509 -noout -fingerprint -sha256 -in "$workdir/chart-leaf.crt")
|
|
if [ "$served_fp" != "$chart_fp" ]; then
|
|
echo "the listener is not serving the certificate the chart minted" >&2
|
|
echo "served: $served_fp" >&2
|
|
echo "chart: $chart_fp" >&2
|
|
exit 1
|
|
fi
|
|
|
|
# e2e-testing.md §6: the move is an upgrade of the parent HelmRelease, and the
|
|
# failure it is most likely to produce is Flux uninstalling the release and
|
|
# reinstalling it — which leaves the cluster Ready and every assert above
|
|
# green, having taken the tenant's search cluster down on the way.
|
|
- name: verify-helmrelease-did-not-remediate
|
|
try:
|
|
- script:
|
|
timeout: 2m
|
|
content: |
|
|
set -eu
|
|
cd ../../..
|
|
. hack/e2e-chainsaw/_lib/remediation-guard.sh
|
|
statuses=$(kubectl -n "$NAMESPACE" get helmrelease opensearch-test \
|
|
-o "jsonpath=${HELMRELEASE_HISTORY_JSONPATH}")
|
|
# Always emit the raw value so a silent future-Flux field rename shows
|
|
# up as "empty history on a Ready HR" in CI logs rather than vanishing.
|
|
# The helper reads empty input as "no cycle observed", so without this
|
|
# the guard passes on a rename, an empty answer or a broken jsonpath.
|
|
echo "HelmRelease history statuses:"
|
|
printf '%s\n' "${statuses:-<empty>}"
|
|
if [ -z "$statuses" ]; then
|
|
echo "Unexpected empty .status.history on a Ready HelmRelease - Flux API shape may have changed." >&2
|
|
kubectl -n "$NAMESPACE" describe helmrelease opensearch-test >&2
|
|
exit 1
|
|
fi
|
|
if helmrelease_has_remediation_cycle "$statuses"; then
|
|
echo "the HelmRelease remediated across the move; history:" >&2
|
|
echo "$statuses" >&2
|
|
exit 1
|
|
fi
|
|
|
|
# The nodePool claim is templated by the StatefulSet, so deleting the app is
|
|
# not enough to reclaim it: Kubernetes never garbage-collects a
|
|
# StatefulSet-templated PVC (#3059), this chart ships no cleanup hook the way
|
|
# qdrant, mariadb and clickhouse do, and the operator's own DeleteResources is
|
|
# empty at v2.8.0. e2e-testing.md §4 puts that on the test, so it is pruned here
|
|
# rather than left holding its storage for whatever suite runs next.
|
|
# Chainsaw's cleanup still deletes the app it applied; a second delete of an
|
|
# object that is already gone is a no-op.
|
|
- name: delete-and-prune-the-templated-claim
|
|
try:
|
|
- delete:
|
|
ref:
|
|
apiVersion: apps.cozystack.io/v1alpha1
|
|
kind: OpenSearch
|
|
name: test
|
|
- script:
|
|
timeout: 5m
|
|
content: |
|
|
set -eu
|
|
# --ignore-not-found covers a run where the claim was never bound; a
|
|
# delete that hangs still fails the step on the timeout below, which
|
|
# is the stuck teardown convention 4 exists to surface.
|
|
kubectl -n "$NAMESPACE" delete pvc data-opensearch-test-nodes-0 \
|
|
--ignore-not-found --wait=true --timeout=4m
|