From c6531de4b98fc14682ada85c5d75b7ad52f2af8b Mon Sep 17 00:00:00 2001 From: Ishwar Kanse Date: Mon, 9 Oct 2023 14:22:40 +0530 Subject: [PATCH] Add e2e test case for multi-cluster by exposing OTEL collector. (#1956) --- .../multi-cluster/00-assert.yaml | 13 ++ .../multi-cluster/00-create-namespaces.yaml | 10 ++ .../multi-cluster/01-assert.yaml | 126 +++++++++++++++ .../multi-cluster/01-create-jaeger.yaml | 9 ++ .../multi-cluster/02-assert.yaml | 147 ++++++++++++++++++ .../multi-cluster/02-otlp-receiver.yaml | 49 ++++++ .../multi-cluster/03-assert.yaml | 107 +++++++++++++ .../multi-cluster/03-otlp-sender.yaml | 46 ++++++ .../multi-cluster/04-assert.yaml | 20 +++ .../multi-cluster/04-generate-traces.yaml | 41 +++++ .../multi-cluster/05-assert.yaml | 6 + .../multi-cluster/check_traces.sh | 26 ++++ .../multi-cluster/create_otlp_sender.sh | 62 ++++++++ .../multi-cluster/generate_certs.sh | 59 +++++++ 14 files changed, 721 insertions(+) create mode 100644 tests/e2e-openshift/multi-cluster/00-assert.yaml create mode 100644 tests/e2e-openshift/multi-cluster/00-create-namespaces.yaml create mode 100644 tests/e2e-openshift/multi-cluster/01-assert.yaml create mode 100644 tests/e2e-openshift/multi-cluster/01-create-jaeger.yaml create mode 100644 tests/e2e-openshift/multi-cluster/02-assert.yaml create mode 100644 tests/e2e-openshift/multi-cluster/02-otlp-receiver.yaml create mode 100644 tests/e2e-openshift/multi-cluster/03-assert.yaml create mode 100644 tests/e2e-openshift/multi-cluster/03-otlp-sender.yaml create mode 100644 tests/e2e-openshift/multi-cluster/04-assert.yaml create mode 100644 tests/e2e-openshift/multi-cluster/04-generate-traces.yaml create mode 100644 tests/e2e-openshift/multi-cluster/05-assert.yaml create mode 100755 tests/e2e-openshift/multi-cluster/check_traces.sh create mode 100755 tests/e2e-openshift/multi-cluster/create_otlp_sender.sh create mode 100755 tests/e2e-openshift/multi-cluster/generate_certs.sh diff --git a/tests/e2e-openshift/multi-cluster/00-assert.yaml b/tests/e2e-openshift/multi-cluster/00-assert.yaml new file mode 100644 index 0000000000..cf530e1d45 --- /dev/null +++ b/tests/e2e-openshift/multi-cluster/00-assert.yaml @@ -0,0 +1,13 @@ +apiVersion: project.openshift.io/v1 +kind: Project +metadata: + name: kuttl-multi-cluster-send +status: + phase: Active + +apiVersion: project.openshift.io/v1 +kind: Project +metadata: + name: kuttl-multi-cluster-receive +status: + phase: Active diff --git a/tests/e2e-openshift/multi-cluster/00-create-namespaces.yaml b/tests/e2e-openshift/multi-cluster/00-create-namespaces.yaml new file mode 100644 index 0000000000..15931a4001 --- /dev/null +++ b/tests/e2e-openshift/multi-cluster/00-create-namespaces.yaml @@ -0,0 +1,10 @@ +apiVersion: v1 +kind: Namespace +metadata: + name: kuttl-multi-cluster-send + +--- +apiVersion: v1 +kind: Namespace +metadata: + name: kuttl-multi-cluster-receive diff --git a/tests/e2e-openshift/multi-cluster/01-assert.yaml b/tests/e2e-openshift/multi-cluster/01-assert.yaml new file mode 100644 index 0000000000..f2c8714806 --- /dev/null +++ b/tests/e2e-openshift/multi-cluster/01-assert.yaml @@ -0,0 +1,126 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + labels: + app: jaeger + app.kubernetes.io/component: all-in-one + app.kubernetes.io/instance: jaeger-allinone + app.kubernetes.io/managed-by: jaeger-operator + app.kubernetes.io/name: jaeger-allinone + app.kubernetes.io/part-of: jaeger + name: jaeger-allinone + namespace: kuttl-multi-cluster-receive +status: + availableReplicas: 1 + readyReplicas: 1 + replicas: 1 + +--- +apiVersion: v1 +kind: Service +metadata: + labels: + app: jaeger + app.kubernetes.io/component: service-collector + app.kubernetes.io/instance: jaeger-allinone + app.kubernetes.io/managed-by: jaeger-operator + app.kubernetes.io/name: jaeger-allinone-collector + app.kubernetes.io/part-of: jaeger + name: jaeger-allinone-collector + namespace: kuttl-multi-cluster-receive +spec: + ports: + - name: http-zipkin + port: 9411 + protocol: TCP + targetPort: 9411 + - name: tls-grpc-jaeger + port: 14250 + protocol: TCP + targetPort: 14250 + - name: http-c-tchan-trft + port: 14267 + protocol: TCP + targetPort: 14267 + - name: http-c-binary-trft + port: 14268 + protocol: TCP + targetPort: 14268 + - name: admin-http + port: 14269 + protocol: TCP + targetPort: 14269 + - name: grpc-otlp + port: 4317 + protocol: TCP + targetPort: 4317 + - name: http-otlp + port: 4318 + protocol: TCP + targetPort: 4318 + selector: + app: jaeger + app.kubernetes.io/component: all-in-one + app.kubernetes.io/instance: jaeger-allinone + app.kubernetes.io/managed-by: jaeger-operator + app.kubernetes.io/name: jaeger-allinone + app.kubernetes.io/part-of: jaeger + type: ClusterIP + +--- +apiVersion: v1 +kind: Service +metadata: + labels: + app: jaeger + app.kubernetes.io/component: service-query + app.kubernetes.io/instance: jaeger-allinone + app.kubernetes.io/managed-by: jaeger-operator + app.kubernetes.io/name: jaeger-allinone-query + app.kubernetes.io/part-of: jaeger + name: jaeger-allinone-query + namespace: kuttl-multi-cluster-receive +spec: + ports: + - name: http-query + port: 16686 + protocol: TCP + targetPort: 16686 + - name: grpc-query + port: 16685 + protocol: TCP + targetPort: 16685 + - name: admin-http + port: 16687 + protocol: TCP + targetPort: 16687 + selector: + app: jaeger + app.kubernetes.io/component: all-in-one + app.kubernetes.io/instance: jaeger-allinone + app.kubernetes.io/managed-by: jaeger-operator + app.kubernetes.io/name: jaeger-allinone + app.kubernetes.io/part-of: jaeger + type: ClusterIP + +--- +apiVersion: route.openshift.io/v1 +kind: Route +metadata: + labels: + app: jaeger + app.kubernetes.io/component: query-route + app.kubernetes.io/instance: jaeger-allinone + app.kubernetes.io/managed-by: jaeger-operator + app.kubernetes.io/name: jaeger-allinone + app.kubernetes.io/part-of: jaeger + name: jaeger-allinone + namespace: kuttl-multi-cluster-receive +spec: + port: + targetPort: http-query + tls: + termination: edge + to: + kind: Service + name: jaeger-allinone-query diff --git a/tests/e2e-openshift/multi-cluster/01-create-jaeger.yaml b/tests/e2e-openshift/multi-cluster/01-create-jaeger.yaml new file mode 100644 index 0000000000..bac7266626 --- /dev/null +++ b/tests/e2e-openshift/multi-cluster/01-create-jaeger.yaml @@ -0,0 +1,9 @@ +apiVersion: jaegertracing.io/v1 +kind: Jaeger +metadata: + name: jaeger-allinone + namespace: kuttl-multi-cluster-receive +spec: + strategy: allinone + ingress: + security: none diff --git a/tests/e2e-openshift/multi-cluster/02-assert.yaml b/tests/e2e-openshift/multi-cluster/02-assert.yaml new file mode 100644 index 0000000000..9650dd59f3 --- /dev/null +++ b/tests/e2e-openshift/multi-cluster/02-assert.yaml @@ -0,0 +1,147 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + labels: + app.kubernetes.io/component: opentelemetry-collector + app.kubernetes.io/instance: kuttl-multi-cluster-receive.otlp-receiver + app.kubernetes.io/managed-by: opentelemetry-operator + app.kubernetes.io/name: otlp-receiver-collector + app.kubernetes.io/part-of: opentelemetry + app.kubernetes.io/version: latest + name: otlp-receiver-collector + namespace: kuttl-multi-cluster-receive +status: + availableReplicas: 1 + readyReplicas: 1 + replicas: 1 + +--- +apiVersion: v1 +kind: Service +metadata: + labels: + app.kubernetes.io/component: opentelemetry-collector + app.kubernetes.io/instance: kuttl-multi-cluster-receive.otlp-receiver + app.kubernetes.io/managed-by: opentelemetry-operator + app.kubernetes.io/name: otlp-receiver-collector + app.kubernetes.io/part-of: opentelemetry + app.kubernetes.io/version: latest + name: otlp-receiver-collector + namespace: kuttl-multi-cluster-receive +spec: + ports: + - appProtocol: h2c + name: otlp-grpc + port: 4317 + protocol: TCP + targetPort: 4317 + - appProtocol: http + name: otlp-http + port: 4318 + protocol: TCP + targetPort: 4318 + selector: + app.kubernetes.io/component: opentelemetry-collector + app.kubernetes.io/instance: kuttl-multi-cluster-receive.otlp-receiver + app.kubernetes.io/managed-by: opentelemetry-operator + app.kubernetes.io/part-of: opentelemetry + type: ClusterIP + +--- +apiVersion: v1 +kind: Service +metadata: + labels: + app.kubernetes.io/component: opentelemetry-collector + app.kubernetes.io/instance: kuttl-multi-cluster-receive.otlp-receiver + app.kubernetes.io/managed-by: opentelemetry-operator + app.kubernetes.io/name: otlp-receiver-collector + app.kubernetes.io/part-of: opentelemetry + app.kubernetes.io/version: latest + operator.opentelemetry.io/collector-headless-service: Exists + name: otlp-receiver-collector-headless + namespace: kuttl-multi-cluster-receive +spec: + ports: + - appProtocol: h2c + name: otlp-grpc + port: 4317 + protocol: TCP + targetPort: 4317 + - appProtocol: http + name: otlp-http + port: 4318 + protocol: TCP + targetPort: 4318 + selector: + app.kubernetes.io/component: opentelemetry-collector + app.kubernetes.io/instance: kuttl-multi-cluster-receive.otlp-receiver + app.kubernetes.io/managed-by: opentelemetry-operator + app.kubernetes.io/part-of: opentelemetry + type: ClusterIP + +--- +apiVersion: v1 +kind: Service +metadata: + labels: + app.kubernetes.io/component: opentelemetry-collector + app.kubernetes.io/instance: kuttl-multi-cluster-receive.otlp-receiver + app.kubernetes.io/managed-by: opentelemetry-operator + app.kubernetes.io/name: otlp-receiver-collector-monitoring + app.kubernetes.io/part-of: opentelemetry + app.kubernetes.io/version: latest + name: otlp-receiver-collector-monitoring + namespace: kuttl-multi-cluster-receive +spec: + ports: + - name: monitoring + port: 8888 + protocol: TCP + targetPort: 8888 + selector: + app.kubernetes.io/component: opentelemetry-collector + app.kubernetes.io/instance: kuttl-multi-cluster-receive.otlp-receiver + app.kubernetes.io/managed-by: opentelemetry-operator + app.kubernetes.io/part-of: opentelemetry + type: ClusterIP + +--- +apiVersion: route.openshift.io/v1 +kind: Route +metadata: + labels: + app.kubernetes.io/instance: kuttl-multi-cluster-receive.otlp-receiver + app.kubernetes.io/managed-by: opentelemetry-operator + app.kubernetes.io/name: otlp-grpc-otlp-receiver-route + name: otlp-grpc-otlp-receiver-route + namespace: kuttl-multi-cluster-receive +spec: + port: + targetPort: otlp-grpc + tls: + termination: passthrough + to: + kind: Service + name: otlp-receiver-collector + weight: 100 + +--- +apiVersion: route.openshift.io/v1 +kind: Route +metadata: + labels: + app.kubernetes.io/instance: kuttl-multi-cluster-receive.otlp-receiver + app.kubernetes.io/managed-by: opentelemetry-operator + app.kubernetes.io/name: otlp-http-otlp-receiver-route + name: otlp-http-otlp-receiver-route + namespace: kuttl-multi-cluster-receive +spec: + port: + targetPort: otlp-http + tls: + termination: passthrough + to: + kind: Service + name: otlp-receiver-collector + weight: 100 diff --git a/tests/e2e-openshift/multi-cluster/02-otlp-receiver.yaml b/tests/e2e-openshift/multi-cluster/02-otlp-receiver.yaml new file mode 100644 index 0000000000..d300458082 --- /dev/null +++ b/tests/e2e-openshift/multi-cluster/02-otlp-receiver.yaml @@ -0,0 +1,49 @@ +apiVersion: kuttl.dev/v1beta1 +kind: TestStep +commands: +- script: ./generate_certs.sh + +--- +apiVersion: opentelemetry.io/v1alpha1 +kind: OpenTelemetryCollector +metadata: + name: otlp-receiver + namespace: kuttl-multi-cluster-receive +spec: + mode: "deployment" + ingress: + type: route + route: + termination: "passthrough" + volumes: + - name: kuttl-certs + configMap: + name: kuttl-certs + volumeMounts: + - name: kuttl-certs + mountPath: /certs + config: | + receivers: + otlp: + protocols: + http: + tls: + cert_file: /certs/server.crt + key_file: /certs/server.key + client_ca_file: /certs/ca.crt + grpc: + tls: + cert_file: /certs/server.crt + key_file: /certs/server.key + client_ca_file: /certs/ca.crt + exporters: + otlp: + endpoint: "jaeger-allinone-collector.kuttl-multi-cluster-receive.svc:4317" + tls: + insecure: true + service: + pipelines: + traces: + receivers: [otlp] + processors: [] + exporters: [otlp] diff --git a/tests/e2e-openshift/multi-cluster/03-assert.yaml b/tests/e2e-openshift/multi-cluster/03-assert.yaml new file mode 100644 index 0000000000..8edce42aa8 --- /dev/null +++ b/tests/e2e-openshift/multi-cluster/03-assert.yaml @@ -0,0 +1,107 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + labels: + app.kubernetes.io/component: opentelemetry-collector + app.kubernetes.io/instance: kuttl-multi-cluster-send.otel-sender + app.kubernetes.io/managed-by: opentelemetry-operator + app.kubernetes.io/name: otel-sender-collector + app.kubernetes.io/part-of: opentelemetry + app.kubernetes.io/version: latest + name: otel-sender-collector + namespace: kuttl-multi-cluster-send +status: + availableReplicas: 1 + readyReplicas: 1 + replicas: 1 + +--- +apiVersion: v1 +kind: Service +metadata: + labels: + app.kubernetes.io/component: opentelemetry-collector + app.kubernetes.io/instance: kuttl-multi-cluster-send.otel-sender + app.kubernetes.io/managed-by: opentelemetry-operator + app.kubernetes.io/name: otel-sender-collector + app.kubernetes.io/part-of: opentelemetry + app.kubernetes.io/version: latest + name: otel-sender-collector + namespace: kuttl-multi-cluster-send +spec: + ports: + - appProtocol: grpc + name: otlp-grpc + port: 4317 + protocol: TCP + targetPort: 4317 + - appProtocol: http + name: otlp-http + port: 4318 + protocol: TCP + targetPort: 4318 + selector: + app.kubernetes.io/component: opentelemetry-collector + app.kubernetes.io/instance: kuttl-multi-cluster-send.otel-sender + app.kubernetes.io/managed-by: opentelemetry-operator + app.kubernetes.io/part-of: opentelemetry + type: ClusterIP + +--- +apiVersion: v1 +kind: Service +metadata: + labels: + app.kubernetes.io/component: opentelemetry-collector + app.kubernetes.io/instance: kuttl-multi-cluster-send.otel-sender + app.kubernetes.io/managed-by: opentelemetry-operator + app.kubernetes.io/name: otel-sender-collector + app.kubernetes.io/part-of: opentelemetry + app.kubernetes.io/version: latest + operator.opentelemetry.io/collector-headless-service: Exists + name: otel-sender-collector-headless + namespace: kuttl-multi-cluster-send +spec: + ports: + - appProtocol: grpc + name: otlp-grpc + port: 4317 + protocol: TCP + targetPort: 4317 + - appProtocol: http + name: otlp-http + port: 4318 + protocol: TCP + targetPort: 4318 + selector: + app.kubernetes.io/component: opentelemetry-collector + app.kubernetes.io/instance: kuttl-multi-cluster-send.otel-sender + app.kubernetes.io/managed-by: opentelemetry-operator + app.kubernetes.io/part-of: opentelemetry + type: ClusterIP + +--- +apiVersion: v1 +kind: Service +metadata: + labels: + app.kubernetes.io/component: opentelemetry-collector + app.kubernetes.io/instance: kuttl-multi-cluster-send.otel-sender + app.kubernetes.io/managed-by: opentelemetry-operator + app.kubernetes.io/name: otel-sender-collector-monitoring + app.kubernetes.io/part-of: opentelemetry + app.kubernetes.io/version: latest + name: otel-sender-collector-monitoring + namespace: kuttl-multi-cluster-send +spec: + ports: + - name: monitoring + port: 8888 + protocol: TCP + targetPort: 8888 + selector: + app.kubernetes.io/component: opentelemetry-collector + app.kubernetes.io/instance: kuttl-multi-cluster-send.otel-sender + app.kubernetes.io/managed-by: opentelemetry-operator + app.kubernetes.io/part-of: opentelemetry + type: ClusterIP diff --git a/tests/e2e-openshift/multi-cluster/03-otlp-sender.yaml b/tests/e2e-openshift/multi-cluster/03-otlp-sender.yaml new file mode 100644 index 0000000000..2c1d45273f --- /dev/null +++ b/tests/e2e-openshift/multi-cluster/03-otlp-sender.yaml @@ -0,0 +1,46 @@ +--- +apiVersion: v1 +kind: ServiceAccount +metadata: + name: kuttl-multi-cluster + namespace: kuttl-multi-cluster-send + +--- +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRole +metadata: + name: kuttl-multi-cluster +rules: +- apiGroups: ["config.openshift.io"] + resources: ["infrastructures", "infrastructures/status"] + verbs: ["get", "watch", "list"] +- apiGroups: ["apps"] + resources: ["replicasets"] + verbs: ["get", "watch", "list"] +- apiGroups: [""] + resources: ["pods"] + verbs: ["get", "watch", "list"] +- apiGroups: [""] + resources: ["namespaces"] + verbs: ["get", "watch", "list"] + +--- +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRoleBinding +metadata: + name: kuttl-multi-cluster +subjects: +- kind: ServiceAccount + name: kuttl-multi-cluster + namespace: kuttl-multi-cluster-send +roleRef: + kind: ClusterRole + name: kuttl-multi-cluster + apiGroup: rbac.authorization.k8s.io + +--- +--- +apiVersion: kuttl.dev/v1beta1 +kind: TestStep +commands: +- script: ./create_otlp_sender.sh diff --git a/tests/e2e-openshift/multi-cluster/04-assert.yaml b/tests/e2e-openshift/multi-cluster/04-assert.yaml new file mode 100644 index 0000000000..2a2a3b6221 --- /dev/null +++ b/tests/e2e-openshift/multi-cluster/04-assert.yaml @@ -0,0 +1,20 @@ +apiVersion: batch/v1 +kind: Job +metadata: + name: generate-traces-http + namespace: kuttl-multi-cluster-send +status: + conditions: + - status: "True" + type: Complete + +--- +apiVersion: batch/v1 +kind: Job +metadata: + name: generate-traces-grpc + namespace: kuttl-multi-cluster-send +status: + conditions: + - status: "True" + type: Complete diff --git a/tests/e2e-openshift/multi-cluster/04-generate-traces.yaml b/tests/e2e-openshift/multi-cluster/04-generate-traces.yaml new file mode 100644 index 0000000000..4c2d6b10fc --- /dev/null +++ b/tests/e2e-openshift/multi-cluster/04-generate-traces.yaml @@ -0,0 +1,41 @@ +apiVersion: batch/v1 +kind: Job +metadata: + name: generate-traces-http + namespace: kuttl-multi-cluster-send +spec: + template: + spec: + containers: + - name: telemetrygen + image: ghcr.io/open-telemetry/opentelemetry-collector-contrib/telemetrygen:v0.75.0 + args: + - traces + - --otlp-endpoint=otel-sender-collector:4318 + - --traces=100 + - --otlp-http + - --otlp-insecure=true + - --service=telemetrygen-http + - --otlp-attributes=protocol="http" + restartPolicy: Never + +--- +apiVersion: batch/v1 +kind: Job +metadata: + name: generate-traces-grpc + namespace: kuttl-multi-cluster-send +spec: + template: + spec: + containers: + - name: telemetrygen + image: ghcr.io/open-telemetry/opentelemetry-collector-contrib/telemetrygen:v0.75.0 + args: + - traces + - --otlp-endpoint=otel-sender-collector:4317 + - --traces=100 + - --otlp-insecure=true + - --service=telemetrygen-grpc + - --otlp-attributes=protocol="grpc" + restartPolicy: Never diff --git a/tests/e2e-openshift/multi-cluster/05-assert.yaml b/tests/e2e-openshift/multi-cluster/05-assert.yaml new file mode 100644 index 0000000000..73befbcd29 --- /dev/null +++ b/tests/e2e-openshift/multi-cluster/05-assert.yaml @@ -0,0 +1,6 @@ +--- +apiVersion: kuttl.dev/v1beta1 +kind: TestAssert +timeout: 30 +commands: +- script: ./tests/e2e-openshift/multi-cluster/check_traces.sh diff --git a/tests/e2e-openshift/multi-cluster/check_traces.sh b/tests/e2e-openshift/multi-cluster/check_traces.sh new file mode 100755 index 0000000000..7fe6eea518 --- /dev/null +++ b/tests/e2e-openshift/multi-cluster/check_traces.sh @@ -0,0 +1,26 @@ +#!/bin/bash + +# Define an array of service names +SERVICE_NAMES=("telemetrygen-http" "telemetrygen-grpc") + +# Get the Jaeger URL +JAEGER_URL=$(oc -n kuttl-multi-cluster-receive get route jaeger-allinone -o json | jq '.spec.host' -r) + +# Initialize a flag to check if any trace exists +trace_exists=false + +# Loop through each service name +for SERVICE_NAME in "${SERVICE_NAMES[@]}"; do + trace_count=$(curl -ksSL "https://$JAEGER_URL/api/traces?service=$SERVICE_NAME&limit=1" | jq -r '.data | length') + if [[ $trace_count -gt 0 ]]; then + echo "Traces for $SERVICE_NAME exist in Jaeger." + trace_exists=true + else + echo "Trace for $SERVICE_NAME does not exist in Jaeger." + fi +done + +# Fail the test step if no traces exist for any service name +if ! $trace_exists; then + exit 1 +fi diff --git a/tests/e2e-openshift/multi-cluster/create_otlp_sender.sh b/tests/e2e-openshift/multi-cluster/create_otlp_sender.sh new file mode 100755 index 0000000000..fadb2fc8a6 --- /dev/null +++ b/tests/e2e-openshift/multi-cluster/create_otlp_sender.sh @@ -0,0 +1,62 @@ +#!/bin/bash + +# Get the HTTP and GRPC routes from OpenTelemetry receiver collector. +otlp_route_http=$(oc -n kuttl-multi-cluster-receive get route otlp-http-otlp-receiver-route -o json | jq '.spec.host' -r) +otlp_route_grpc=$(oc -n kuttl-multi-cluster-receive get route otlp-grpc-otlp-receiver-route -o json | jq '.spec.host' -r) + +# Define the collector content +collector_content=$(cat < "$openssl_config" +[req] +req_extensions = v3_req + +[v3_req] +basicConstraints = CA:FALSE +keyUsage = nonRepudiation, digitalSignature, keyEncipherment +subjectAltName = @alt_names + +[alt_names] +DNS.1 = $hostname_domain +EOF + +# Generate private key for the server +openssl genpkey -algorithm RSA -out "$CERT_DIR/server.key" + +# Create CSR for the server with SANs +openssl req -new -key "$CERT_DIR/server.key" -out "$CERT_DIR/server.csr" -subj "$CERT_SUBJECT" -config "$openssl_config" + +# Generate self-signed certificate for the server with SANs +openssl x509 -req -days 365 -in "$CERT_DIR/server.csr" -signkey "$CERT_DIR/server.key" -out "$CERT_DIR/server.crt" -extensions v3_req -extfile "$openssl_config" + +# Generate a CA certificate (self-signed) +openssl req -new -x509 -days 365 -key "$CERT_DIR/server.key" -out "$CERT_DIR/ca.crt" -subj "$CERT_SUBJECT" + +echo "Certificates generated successfully in $CERT_DIR directory." + +# Delete any existing ConfigMaps +kubectl delete configmap -n kuttl-multi-cluster-send kuttl-certs +kubectl delete configmap -n kuttl-multi-cluster-receive kuttl-certs + +# Create a Kubernetes ConfigMap for the server certificate, private key, and CA certificate in kuttl-multi-cluster-send namespace +kubectl create configmap kuttl-certs -n kuttl-multi-cluster-send \ + --from-file=server.crt="$CERT_DIR/server.crt" \ + --from-file=server.key="$CERT_DIR/server.key" \ + --from-file=ca.crt="$CERT_DIR/ca.crt" + +# Create a Kubernetes ConfigMap for the server certificate, private key, and CA certificate in kuttl-multi-cluster-receive namespace +kubectl create configmap kuttl-certs -n kuttl-multi-cluster-receive \ + --from-file=server.crt="$CERT_DIR/server.crt" \ + --from-file=server.key="$CERT_DIR/server.key" \ + --from-file=ca.crt="$CERT_DIR/ca.crt" + +echo "ConfigMaps created successfully."