Skip to content

Commit

Permalink
Set commonName for each certificate
Browse files Browse the repository at this point in the history
  • Loading branch information
wpjunior committed Sep 5, 2024
1 parent e3fdfe2 commit bd6c3ee
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
6 changes: 6 additions & 0 deletions internal/controllers/certificates/cert_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,11 @@ func newCertificate(instance *v1alpha1.RpaasInstance, issuer *cmmeta.ObjectRefer
labels["rpaas.extensions.tsuru.io/certificate-name"] = req.RequiredName()
labels["rpaas.extensions.tsuru.io/instance-name"] = instance.Name

var commonName string
if len(req.DNSNames) > 0 {
commonName = req.DNSNames[0]
}

return &cmv1.Certificate{
ObjectMeta: metav1.ObjectMeta{
Name: CertManagerCertificateNameForInstance(instance.Name, req),
Expand All @@ -215,6 +220,7 @@ func newCertificate(instance *v1alpha1.RpaasInstance, issuer *cmmeta.ObjectRefer
IssuerRef: *issuer,
DNSNames: req.DNSNames,
IPAddresses: req.IPAddresses,
CommonName: commonName,
SecretName: CertManagerCertificateNameForInstance(instance.Name, req),
SecretTemplate: &cmv1.CertificateSecretTemplate{
Labels: map[string]string{
Expand Down
7 changes: 7 additions & 0 deletions internal/controllers/certificates/cert_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ wg4cGbIbBPs=
Kind: "Issuer",
},
SecretName: cert.Name,
CommonName: "my-instance.example.com",
DNSNames: []string{"my-instance.example.com"},
IPAddresses: []string{"169.196.1.100"},
SecretTemplate: &cmv1.CertificateSecretTemplate{
Expand Down Expand Up @@ -319,6 +320,7 @@ wg4cGbIbBPs=
Kind: "Issuer",
},
SecretName: "my-instance-cert-01",
CommonName: "my-instance.example.com",
DNSNames: []string{"my-instance.example.com"},
SecretTemplate: &cmv1.CertificateSecretTemplate{
Labels: map[string]string{
Expand All @@ -335,6 +337,7 @@ wg4cGbIbBPs=
Kind: "Issuer",
},
SecretName: "my-instance-cert-02",
CommonName: "my-instance2.example.com",
DNSNames: []string{"my-instance2.example.com"},
SecretTemplate: &cmv1.CertificateSecretTemplate{
Labels: map[string]string{
Expand All @@ -351,6 +354,7 @@ wg4cGbIbBPs=
Kind: "Issuer",
},
SecretName: "my-instance-cert-03",
CommonName: "my-instance3.example.org",
DNSNames: []string{"my-instance3.example.org"},
SecretTemplate: &cmv1.CertificateSecretTemplate{
Labels: map[string]string{
Expand Down Expand Up @@ -425,6 +429,7 @@ wg4cGbIbBPs=
Kind: "Issuer",
},
SecretName: "my-instance-take-over-test-my-instance-take-over",
CommonName: "my-instance.example.com",
DNSNames: []string{"my-instance.example.com"},
SecretTemplate: &cmv1.CertificateSecretTemplate{
Labels: map[string]string{
Expand Down Expand Up @@ -497,6 +502,7 @@ wg4cGbIbBPs=
Kind: "Issuer",
},
SecretName: cert.Name,
CommonName: "my-instance.rpaasv2.example.org",
DNSNames: []string{"my-instance.rpaasv2.example.org"},
SecretTemplate: &cmv1.CertificateSecretTemplate{
Labels: map[string]string{
Expand Down Expand Up @@ -556,6 +562,7 @@ wg4cGbIbBPs=
Kind: "ClusterIssuer",
},
SecretName: cert.Name,
CommonName: "my-instance-2.example.com",
DNSNames: []string{"my-instance-2.example.com", "app1.example.com"},
IPAddresses: []string{"2001:db8:dead:beef::"},
SecretTemplate: &cmv1.CertificateSecretTemplate{
Expand Down

0 comments on commit bd6c3ee

Please sign in to comment.