Skip to content

Commit 3246f5e

Browse files
committed
Use EnsureCert from lib-common
This is test. If it will work fine, should be merged with previous commits Signed-off-by: Slawek Kaplonski <skaplons@redhat.com>
1 parent 6c1aaf3 commit 3246f5e

7 files changed

Lines changed: 36 additions & 119 deletions

File tree

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ require (
1010
github.com/onsi/ginkgo/v2 v2.28.2
1111
github.com/onsi/gomega v1.39.1
1212
github.com/openstack-k8s-operators/infra-operator/apis v0.6.1-0.20260416122644-5476763a36b6
13+
github.com/openstack-k8s-operators/lib-common/modules/certmanager v0.6.1-0.20260417092244-81c71b39e981
1314
github.com/openstack-k8s-operators/lib-common/modules/common v0.6.1-0.20260417092244-81c71b39e981
1415
github.com/openstack-k8s-operators/lib-common/modules/test v0.6.1-0.20260417092244-81c71b39e981
1516
github.com/openstack-k8s-operators/ovn-operator/api v0.0.0-20230418071801-b5843d9e05fb

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,8 @@ github.com/openshift/api v0.0.0-20250711200046-c86d80652a9e h1:E1OdwSpqWuDPCedyU
120120
github.com/openshift/api v0.0.0-20250711200046-c86d80652a9e/go.mod h1:Shkl4HanLwDiiBzakv+con/aMGnVE2MAGvoKp5oyYUo=
121121
github.com/openstack-k8s-operators/infra-operator/apis v0.6.1-0.20260416122644-5476763a36b6 h1:117Gu9HCSu2tAp579WnCJ9QtnslH2qnPB8UFvn8ZpqE=
122122
github.com/openstack-k8s-operators/infra-operator/apis v0.6.1-0.20260416122644-5476763a36b6/go.mod h1:i7l8cihvFktd/LSuyvL2z6OcwauarQGoVhDMePL4VyI=
123+
github.com/openstack-k8s-operators/lib-common/modules/certmanager v0.6.1-0.20260417092244-81c71b39e981 h1:G0YU5B6AhXDy/46urlNjz6tMXmHGDdoslgucTIN3F30=
124+
github.com/openstack-k8s-operators/lib-common/modules/certmanager v0.6.1-0.20260417092244-81c71b39e981/go.mod h1:GzD7Jc5o98ptJ97DSjhC0CQ6OiTP0PB/2qJqxYGcOH8=
123125
github.com/openstack-k8s-operators/lib-common/modules/common v0.6.1-0.20260417092244-81c71b39e981 h1:v1viH0gmNb+AXMg/0GxDcj8VUTdjVLotfOIGrNyMxHk=
124126
github.com/openstack-k8s-operators/lib-common/modules/common v0.6.1-0.20260417092244-81c71b39e981/go.mod h1:I/VBXZLdjk8DUGsEbB+Ha72JBFYYntP7Pm2FpEto9K8=
125127
github.com/openstack-k8s-operators/lib-common/modules/test v0.6.1-0.20260417092244-81c71b39e981 h1:KAQ8T+Ri3JWgsyK1D6QybScMh6fpkYUUA+0ntnOiAl4=

internal/controller/ovncontroller_controller.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ import (
3939

4040
certmgrv1 "github.com/cert-manager/cert-manager/pkg/apis/certmanager/v1"
4141
topologyv1 "github.com/openstack-k8s-operators/infra-operator/apis/topology/v1beta1"
42+
certmanager "github.com/openstack-k8s-operators/lib-common/modules/certmanager"
4243
"github.com/openstack-k8s-operators/lib-common/modules/common"
4344
"github.com/openstack-k8s-operators/lib-common/modules/common/condition"
4445
"github.com/openstack-k8s-operators/lib-common/modules/common/configmap"
@@ -892,7 +893,13 @@ func (r *OVNControllerReconciler) reconcileNormal(ctx context.Context, instance
892893
certName := ovncontroller.RbacCertName(nodeName)
893894
nodeSystemIDs[nodeName] = systemID
894895

895-
certResult, certErr := ovncontroller.EnsureRbacCert(ctx, r.Client, r.Scheme, instance, certName, systemID, instance.Spec.OvnIssuerName, ovnServiceLabels)
896+
_, certResult, certErr := certmanager.EnsureCert(ctx, helper, certmanager.CertificateRequest{
897+
IssuerName: instance.Spec.OvnIssuerName,
898+
CertName: certName,
899+
CommonName: &systemID,
900+
Labels: ovnServiceLabels,
901+
Usages: []certmgrv1.KeyUsage{certmgrv1.UsageClientAuth, certmgrv1.UsageDigitalSignature},
902+
}, instance)
896903
if certErr != nil {
897904
return certResult, certErr
898905
}

internal/ovncontroller/cert.go

Lines changed: 0 additions & 115 deletions
This file was deleted.

internal/ovncontroller/configjob.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ func ConfigJob(
9292
if systemID, ok := nodeSystemIDs[nodeName]; ok {
9393
jobEnvVars["SYSTEM_ID"] = env.SetValue(systemID)
9494

95-
certSecretName := RbacCertName(nodeName)
95+
certSecretName := RbacCertSecretName(nodeName)
9696
volumes = append(volumes, corev1.Volume{
9797
Name: "ovn-rbac-cert",
9898
VolumeSource: corev1.VolumeSource{

internal/ovncontroller/utils.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@ func RbacCertName(nodeName string) string {
3636
return fmt.Sprintf("ovn-controller-cert-%s", nodeName)
3737
}
3838

39+
// RbacCertSecretName returns the Secret name created by cert-manager for a given node's RBAC certificate
40+
func RbacCertSecretName(nodeName string) string {
41+
return "cert-" + RbacCertName(nodeName)
42+
}
43+
3944
func getPhysicalNetworks(
4045
instance *ovnv1.OVNController,
4146
) string {

test/functional/ovncontroller_controller_test.go

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ import (
3737
batchv1 "k8s.io/api/batch/v1"
3838
corev1 "k8s.io/api/core/v1"
3939
k8s_errors "k8s.io/apimachinery/pkg/api/errors"
40+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
4041
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
4142
"k8s.io/apimachinery/pkg/types"
4243
"sigs.k8s.io/controller-runtime/pkg/client"
@@ -1185,6 +1186,21 @@ var _ = Describe("OVNController controller", func() {
11851186
Name: OvnDbCertSecretName,
11861187
Namespace: namespace,
11871188
}))
1189+
1190+
issuer := &certmgrv1.Issuer{
1191+
ObjectMeta: metav1.ObjectMeta{
1192+
Name: OvnIssuerName,
1193+
Namespace: namespace,
1194+
},
1195+
Spec: certmgrv1.IssuerSpec{
1196+
IssuerConfig: certmgrv1.IssuerConfig{
1197+
SelfSigned: &certmgrv1.SelfSignedIssuer{},
1198+
},
1199+
},
1200+
}
1201+
Expect(k8sClient.Create(ctx, issuer)).To(Succeed())
1202+
DeferCleanup(k8sClient.Delete, ctx, issuer)
1203+
11881204
dbs = CreateTLSOVNDBClusters(namespace, map[string][]string{}, 1)
11891205
DeferCleanup(DeleteOVNDBClusters, dbs)
11901206
northdName := CreateReadyOVNNorthd(namespace, GetDefaultOVNNorthdSpec())
@@ -1248,6 +1264,7 @@ var _ = Describe("OVNController controller", func() {
12481264

12491265
nodeName := daemonSetName.Name
12501266
certName := ovncontroller.RbacCertName(nodeName)
1267+
certSecretName := ovncontroller.RbacCertSecretName(nodeName)
12511268

12521269
// Wait for the Certificate CR to be created, then simulate
12531270
// cert-manager by creating the cert Secret
@@ -1256,7 +1273,7 @@ var _ = Describe("OVNController controller", func() {
12561273
Namespace: namespace,
12571274
})
12581275
DeferCleanup(k8sClient.Delete, ctx, th.CreateCertSecret(types.NamespacedName{
1259-
Name: certName,
1276+
Name: certSecretName,
12601277
Namespace: namespace,
12611278
}))
12621279

@@ -1296,7 +1313,7 @@ var _ = Describe("OVNController controller", func() {
12961313
// Check RBAC cert volume references the cert secret
12971314
hasRbacVolume := false
12981315
for _, v := range job.Spec.Template.Spec.Volumes {
1299-
if v.Name == "ovn-rbac-cert" && v.Secret != nil && v.Secret.SecretName == certName {
1316+
if v.Name == "ovn-rbac-cert" && v.Secret != nil && v.Secret.SecretName == certSecretName {
13001317
hasRbacVolume = true
13011318
}
13021319
}

0 commit comments

Comments
 (0)