Skip to content

Commit

Permalink
Make Certifacte factory more generic
Browse files Browse the repository at this point in the history
Signed-off-by: Matthias Wessendorf <[email protected]>
  • Loading branch information
matzew committed Feb 20, 2025
1 parent 51637df commit 7c2ac01
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
2 changes: 1 addition & 1 deletion pkg/reconciler/integration/sink/integrationsink.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ func (r *Reconciler) reconcileService(ctx context.Context, sink *sinks.Integrati

func (r *Reconciler) reconcileCMCertificate(ctx context.Context, sink *sinks.IntegrationSink) (*cmv1.Certificate, error) {

expected := resources.MakeCertificate(sink)
expected := resources.MakeCertificate(sink, sink.Name)

cert, err := r.cmCertificateLister.Certificates(sink.Namespace).Get(expected.Name)
if apierrors.IsNotFound(err) {
Expand Down
15 changes: 7 additions & 8 deletions pkg/reconciler/integration/sink/resources/certificate.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,28 +25,27 @@ import (
"knative.dev/pkg/kmeta"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"knative.dev/eventing/pkg/apis/sinks/v1alpha1"
)

func CertificateName(sinkName string) string {
return kmeta.ChildName(sinkName, "-server-tls")
}

func MakeCertificate(sink *v1alpha1.IntegrationSink) *cmv1.Certificate {
func MakeCertificate(sink kmeta.OwnerRefableAccessor, name string) *cmv1.Certificate {
return &cmv1.Certificate{
ObjectMeta: metav1.ObjectMeta{
Name: CertificateName(sink.Name),
Namespace: sink.Namespace,
Name: CertificateName(name),
Namespace: sink.GetNamespace(),
OwnerReferences: []metav1.OwnerReference{
*kmeta.NewControllerRef(sink),
},
},
Spec: cmv1.CertificateSpec{
SecretName: CertificateName(sink.Name),
SecretName: CertificateName(name),
SecretTemplate: &cmv1.CertificateSecretTemplate{
Labels: map[string]string{
"app.kubernetes.io/component": "knative-eventing",
"app.kubernetes.io/name": sink.Name,
"app.kubernetes.io/name": name,
},
},
Duration: &metav1.Duration{
Expand All @@ -66,8 +65,8 @@ func MakeCertificate(sink *v1alpha1.IntegrationSink) *cmv1.Certificate {
RotationPolicy: cmv1.RotationPolicyAlways,
},
DNSNames: []string{
fmt.Sprintf("%s.%s.svc.cluster.local", DeploymentName(sink.Name), sink.Namespace),
fmt.Sprintf("%s.%s.svc", DeploymentName(sink.Name), sink.Namespace),
fmt.Sprintf("%s.%s.svc.cluster.local", DeploymentName(name), sink.GetNamespace()),
fmt.Sprintf("%s.%s.svc", DeploymentName(name), sink.GetNamespace()),
},
IssuerRef: cmmeta.ObjectReference{
Name: "knative-eventing-ca-issuer",
Expand Down

0 comments on commit 7c2ac01

Please sign in to comment.