@@ -11,6 +11,7 @@ import (
11
11
corev1 "k8s.io/api/core/v1"
12
12
extv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
13
13
"k8s.io/apimachinery/pkg/api/errors"
14
+ metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
14
15
"sigs.k8s.io/controller-runtime/pkg/client"
15
16
)
16
17
@@ -82,7 +83,7 @@ func ensureCACertificate(ctx context.Context, c client.Client, l logr.Logger, ca
82
83
}
83
84
if errors .IsNotFound (err ) {
84
85
l .Info ("Service CA certificate doesn't exist, creating..." )
85
- initCACertificate ( & caCert , caNamespace )
86
+ caCert = newCACertificate ( caNamespace )
86
87
if err := c .Create (ctx , & caCert ); err != nil {
87
88
return err
88
89
}
@@ -113,22 +114,28 @@ func ensureServiceCAIssuer(ctx context.Context, c client.Client, l logr.Logger,
113
114
return nil
114
115
}
115
116
116
- // initCACertificate initializes the Service CA certificate resource
117
- func initCACertificate (caCert * cmapi.Certificate , caNamespace string ) {
118
- caCert .Name = CACertName
119
- caCert .Namespace = caNamespace
120
- caCert .Spec .IsCA = true
121
- caCert .Spec .CommonName = CAName
122
- caCert .Spec .SecretName = CASecretName
123
- // TODO: make the private key config configurable?
124
- caCert .Spec .PrivateKey = & cmapi.CertificatePrivateKey {
125
- Algorithm : cmapi .ECDSAKeyAlgorithm ,
126
- Size : 521 ,
127
- }
128
- caCert .Spec .IssuerRef = cmmeta.ObjectReference {
129
- Name : SelfSignedIssuerName ,
130
- Kind : "Issuer" ,
131
- Group : "cert-manager.io" ,
117
+ // newCACertificate returns a new Service CA certificate resource
118
+ func newCACertificate (caNamespace string ) cmapi.Certificate {
119
+ return cmapi.Certificate {
120
+ ObjectMeta : metav1.ObjectMeta {
121
+ Name : CACertName ,
122
+ Namespace : caNamespace ,
123
+ },
124
+ Spec : cmapi.CertificateSpec {
125
+ IsCA : true ,
126
+ CommonName : CAName ,
127
+ SecretName : CASecretName ,
128
+ // TODO: make the private key config configurable?
129
+ PrivateKey : & cmapi.CertificatePrivateKey {
130
+ Algorithm : cmapi .ECDSAKeyAlgorithm ,
131
+ Size : 521 ,
132
+ },
133
+ IssuerRef : cmmeta.ObjectReference {
134
+ Name : SelfSignedIssuerName ,
135
+ Kind : "Issuer" ,
136
+ Group : "cert-manager.io" ,
137
+ },
138
+ },
132
139
}
133
140
}
134
141
0 commit comments