Skip to content

Commit 92fc786

Browse files
lmicciniclaude
andcommitted
Add TLS certificate for InstanceHA metrics endpoint
Create a cert-manager Certificate for the InstanceHA metrics service when pod-level TLS is enabled. The certificate uses the internal issuer with wildcard hostnames for the namespace, following the same pattern as EnsureOVNMetricsCert. The resulting secret (cert-instanceha-metrics) is consumed by the infra-operator InstanceHA controller. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent cdd350d commit 92fc786

1 file changed

Lines changed: 65 additions & 0 deletions

File tree

internal/openstack/instanceha.go

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@ package openstack
22

33
import (
44
"context"
5+
"fmt"
56

7+
certmgrv1 "github.com/cert-manager/cert-manager/pkg/apis/certmanager/v1"
8+
"github.com/openstack-k8s-operators/lib-common/modules/certmanager"
9+
"github.com/openstack-k8s-operators/lib-common/modules/common/clusterdns"
610
"github.com/openstack-k8s-operators/lib-common/modules/common/condition"
711
"github.com/openstack-k8s-operators/lib-common/modules/common/configmap"
812
"github.com/openstack-k8s-operators/lib-common/modules/common/helper"
@@ -21,6 +25,22 @@ const (
2125

2226
// ReconcileInstanceHa reconciles the instance HA configuration for the OpenStack control plane
2327
func ReconcileInstanceHa(ctx context.Context, instance *corev1beta1.OpenStackControlPlane, version *corev1beta1.OpenStackVersion, helper *helper.Helper) (ctrl.Result, error) {
28+
Log := GetLogger(ctx)
29+
30+
if instance.Spec.TLS.PodLevel.Enabled {
31+
_, err := EnsureInstanceHAMetricsCert(ctx, instance, helper)
32+
if err != nil {
33+
Log.Error(err, "Failed to ensure InstanceHA metrics certificate")
34+
instance.Status.Conditions.Set(condition.FalseCondition(
35+
corev1beta1.OpenStackControlPlaneInstanceHaCMReadyCondition,
36+
condition.ErrorReason,
37+
condition.SeverityWarning,
38+
corev1beta1.OpenStackControlPlaneInstanceHaCMReadyErrorMessage,
39+
err.Error()))
40+
return ctrl.Result{}, err
41+
}
42+
}
43+
2444
customData := map[string]string{
2545
InstanceHaImageKey: *getImg(version.Status.ContainerImages.OpenstackClientImage, &missingImageDefault),
2646
}
@@ -54,3 +74,48 @@ func ReconcileInstanceHa(ctx context.Context, instance *corev1beta1.OpenStackCon
5474

5575
return ctrl.Result{}, nil
5676
}
77+
78+
// EnsureInstanceHAMetricsCert creates a TLS certificate for InstanceHA metrics services
79+
func EnsureInstanceHAMetricsCert(ctx context.Context, instance *corev1beta1.OpenStackControlPlane, helper *helper.Helper) (string, error) {
80+
Log := GetLogger(ctx)
81+
82+
dnsSuffix := clusterdns.GetDNSClusterDomain()
83+
84+
certRequest := certmanager.CertificateRequest{
85+
IssuerName: instance.GetInternalIssuer(),
86+
CertName: "instanceha-metrics",
87+
Hostnames: []string{
88+
fmt.Sprintf("*.%s.svc", instance.Namespace),
89+
fmt.Sprintf("*.%s.svc.%s", instance.Namespace, dnsSuffix),
90+
},
91+
Ips: nil,
92+
Usages: []certmgrv1.KeyUsage{
93+
certmgrv1.UsageKeyEncipherment,
94+
certmgrv1.UsageDigitalSignature,
95+
certmgrv1.UsageServerAuth,
96+
},
97+
Labels: map[string]string{ServiceCertSelector: ""},
98+
}
99+
100+
if instance.Spec.TLS.PodLevel.Internal.Cert.Duration != nil {
101+
certRequest.Duration = &instance.Spec.TLS.PodLevel.Internal.Cert.Duration.Duration
102+
}
103+
if instance.Spec.TLS.PodLevel.Internal.Cert.RenewBefore != nil {
104+
certRequest.RenewBefore = &instance.Spec.TLS.PodLevel.Internal.Cert.RenewBefore.Duration
105+
}
106+
107+
certSecret, ctrlResult, err := certmanager.EnsureCert(
108+
ctx,
109+
helper,
110+
certRequest,
111+
nil)
112+
if err != nil {
113+
return "", err
114+
} else if (ctrlResult != ctrl.Result{}) {
115+
Log.Info("InstanceHA metrics certificate creation in progress", "certificate", certRequest.CertName)
116+
return "", fmt.Errorf("InstanceHA metrics certificate creation in progress")
117+
}
118+
119+
Log.Info("InstanceHA metrics certificate ensured", "secret", certSecret.Name, "certificate", certRequest.CertName)
120+
return certSecret.Name, nil
121+
}

0 commit comments

Comments
 (0)