Skip to content

Preserve probe handler configuration for mTLS#951

Open
ossarga wants to merge 1 commit into
k8ssandra:masterfrom
ossarga:allow-probes-port-to-be-configurable
Open

Preserve probe handler configuration for mTLS#951
ossarga wants to merge 1 commit into
k8ssandra:masterfrom
ossarga:allow-probes-port-to-be-configurable

Conversation

@ossarga

@ossarga ossarga commented Jul 14, 2026

Copy link
Copy Markdown

Change Summary

  • Preserves probe configuration when mTLS is enabled
  • Extracts management API port from container port specification
  • Default probes are initialised using host and port values set for management API
  • Checks the probe handlers to ensure only one of the four probe mechanisms is set
  • Updated built pod host function to use new port resolution logic

Fixes #950

Testing

Unit tests were updated and executed on the latest changes. Details are as follows.

  • Probe Validation Tests (pkg/httphelper) - 14 tests
  • mTLS Probe Configuration Tests (pkg/httphelper) - 7 tests
  • Pod Spec Probe Initialization Tests (pkg/reconciliation) - 6 tests

Total Tests Run: 27
Status: 27 PASSED

Change Details

This change helps simplify probe configuration particularly when enabling mTLS.

The following explains how to configure the Management API port and its relationship to Kubernetes probe configurations.

Steps to Configure a Custom Management API Port

By default, the Management API listens on port 8080 and uses the port name mgmt-api-http.

The following steps can be used to specify a custom port for the Management API

Step 1: Define the Port in PodTemplateSpec

To use a custom Management API port, the value must be defined in the cassandra container's port specifications within the CassandraDatacenter manifest:

⚠️ Important: The port name must be mgmt-api-http for the operator to correctly identify and use it.

apiVersion: cassandra.datastax.com/v1beta1
kind: CassandraDatacenter
metadata:
  name: dc1
spec:
  clusterName: cluster1
  serverType: cassandra
  serverVersion: "4.0.1"
  size: 3
  podTemplateSpec:
    spec:
      containers:
      - name: cassandra
        ports:
        - containerPort: 9042
          name: native
        - containerPort: 8080      # Custom Management API port
          name: mgmt-api-http      # REQUIRED: Must use this exact name
        - containerPort: 9103
          name: metrics

Step 2: Update Probe Configurations

If custom liveness or readiness probes are in use, the port can be specified using the Kubernetes name reference. To use a named port reference, the custom probes must be defined in the podTemplateSpec.spec.containers[].livenessProbe or readinessProbe configuration.

In the following Custom Resource Definition (CRD) for a CassandraDatacenter, the port values for the livenessProbe and readinessProbe are set to the mgmt-api-http named value.

apiVersion: cassandra.datastax.com/v1beta1
kind: CassandraDatacenter
metadata:
  name: dc1
spec:
  clusterName: cluster1
  serverType: cassandra
  serverVersion: "4.0.1"
  size: 3
  podTemplateSpec:
    spec:
      containers:
      - name: cassandra
        ports:
        - containerPort: 9042
          name: native
        - containerPort: 8080
          name: mgmt-api-http
        livenessProbe:
          httpGet:
            path: /api/v0/probes/liveness
            port: mgmt-api-http    # Reference by name
            scheme: HTTP
          initialDelaySeconds: 15
          periodSeconds: 15
        readinessProbe:
          httpGet:
            path: /api/v0/probes/readiness
            port: mgmt-api-http    # Reference by name
            scheme: HTTP
          initialDelaySeconds: 20
          periodSeconds: 10

In the above case the port value for the probes will reference the cassandra container's containerPort value.

The cass-operator resolves the Management API port using the following logic:

  • Container Port Specification: Searches for a port named mgmt-api-http in the container's port list
  • Default Fallback: Uses port 8080 if mgmt-api-http is undefined

Example

The following CassandraDatacenter CRD defines a Custom Port with mTLS

apiVersion: cassandra.datastax.com/v1beta1
kind: CassandraDatacenter
metadata:
  name: dc1
spec:
  clusterName: cluster1
  size: 3
  managementApiAuth:
    insecure: {}
    manual:
      clientSecretName: mgmt-api-client-secret
      serverSecretName: mgmt-api-server-secret
  podTemplateSpec:
    spec:
      containers:
      - name: cassandra
        ports:
        - containerPort: 9000
          name: mgmt-api-http
        livenessProbe:
          httpGet:
            port: mgmt-api-http
        readinessProbe:
          httpGet:
            port: mgmt-api-http

* Preserves probe configuration when mTLS is enabled
* Extracts management API port from container port specification
* Default probes are initialised using host and port values set for management API
* Checks the probe handlers to ensure only one of the four probe mechanisms is set
* Updated built pod host function to use new port resolution logic
@ossarga
ossarga requested a review from a team as a code owner July 14, 2026 05:46
Comment thread pkg/httphelper/client.go
Comment on lines +222 to +229
func GetMgmtApiPortFromContainer(container *corev1.Container) int {
for _, port := range container.Ports {
if port.Name == "mgmt-api-http" {
return int(port.ContainerPort)
}
}
return MgmtApiTargetPort
}

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

@adejanovski this is needed for another fix I am going to raise for the k8ssandra-operator

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Readiness/Liveness probes configuration ignored when mTLS enabled

1 participant