Skip to content
This repository was archived by the owner on Jul 11, 2023. It is now read-only.

Commit 5db50ff

Browse files
committed
Fix failing tests, add tests for NewCertificateManagerFromMRC, and
use MRC name for the issuer ID. Signed-off-by: jaellio <[email protected]>
1 parent d9fd7c0 commit 5db50ff

File tree

8 files changed

+295
-65
lines changed

8 files changed

+295
-65
lines changed

cmd/osm-bootstrap/osm-bootstrap.go

+1-4
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ func main() {
230230
"Error initializing certificate manager of kind %s from MRC", certProviderKind)
231231
}
232232
} else {
233-
certManager, err = providers.NewCertificateManager(ctx, kubeClient, kubeConfig, cfg, osmNamespace, certOpts, msgBroker, informerCollection, 5*time.Second)
233+
certManager, err = providers.NewCertificateManager(ctx, kubeClient, kubeConfig, cfg, osmNamespace, certOpts, msgBroker, 5*time.Second)
234234
if err != nil {
235235
events.GenericEventRecorder().FatalEvent(err, events.InvalidCertificateManager,
236236
"Error initializing certificate manager of kind %s", certProviderKind)
@@ -457,9 +457,6 @@ func buildMeshRootCertificate(presetMeshRootCertificateConfigMap *corev1.ConfigM
457457
},
458458
ObjectMeta: metav1.ObjectMeta{
459459
Name: meshRootCertificateName,
460-
Annotations: map[string]string{
461-
constants.MRCVersionAnnotation: "0",
462-
},
463460
},
464461
Spec: presetMeshRootCertificateSpec,
465462
}

cmd/osm-controller/osm-controller.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ func main() {
222222
}
223223
} else {
224224
certManager, err = providers.NewCertificateManager(ctx, kubeClient, kubeConfig, cfg, osmNamespace,
225-
certOpts, msgBroker, informerCollection, 5*time.Second)
225+
certOpts, msgBroker, 5*time.Second)
226226
if err != nil {
227227
events.GenericEventRecorder().FatalEvent(err, events.InvalidCertificateManager,
228228
"Error fetching certificate manager of kind %s", certProviderKind)

cmd/osm-injector/osm-injector.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ func main() {
216216
}
217217
} else {
218218
certManager, err = providers.NewCertificateManager(ctx, kubeClient, kubeConfig, cfg, osmNamespace,
219-
certOpts, msgBroker, informerCollection, 5*time.Second)
219+
certOpts, msgBroker, 5*time.Second)
220220
if err != nil {
221221
events.GenericEventRecorder().FatalEvent(err, events.InvalidCertificateManager,
222222
"Error initializing certificate manager of kind %s", certProviderKind)

pkg/certificate/fake_manager.go

-3
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,6 @@ func (c *fakeMRCClient) Watch(ctx context.Context) (<-chan MRCEvent, error) {
4343
ObjectMeta: metav1.ObjectMeta{
4444
Name: "osm-mesh-root-certificate",
4545
Namespace: "osm-system",
46-
Annotations: map[string]string{
47-
constants.MRCVersionAnnotation: "0",
48-
},
4946
},
5047
Spec: v1alpha2.MeshRootCertificateSpec{
5148
Provider: v1alpha2.ProviderSpec{

pkg/certificate/providers/config.go

+6-26
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ var getCA func(certificate.Issuer) (pem.RootCertificate, error) = func(i certifi
4444
// NewCertificateManager returns a new certificate manager with a MRC compat client.
4545
// TODO(4713): Remove and use NewCertificateManagerFromMRC
4646
func NewCertificateManager(ctx context.Context, kubeClient kubernetes.Interface, kubeConfig *rest.Config, cfg configurator.Configurator,
47-
providerNamespace string, option Options, msgBroker *messaging.Broker, ic *informers.InformerCollection, checkInterval time.Duration) (*certificate.Manager, error) {
47+
providerNamespace string, option Options, msgBroker *messaging.Broker, checkInterval time.Duration) (*certificate.Manager, error) {
4848
if err := option.Validate(); err != nil {
4949
return nil, err
5050
}
@@ -60,9 +60,6 @@ func NewCertificateManager(ctx context.Context, kubeClient kubernetes.Interface,
6060
ObjectMeta: metav1.ObjectMeta{
6161
Name: "legacy-compat",
6262
Namespace: providerNamespace,
63-
Annotations: map[string]string{
64-
constants.MRCVersionAnnotation: "legacy-compat",
65-
},
6663
},
6764
Spec: v1alpha2.MeshRootCertificateSpec{
6865
Provider: option.AsProviderSpec(),
@@ -134,13 +131,6 @@ func (c *MRCProviderGenerator) GetCertIssuerForMRC(mrc *v1alpha2.MeshRootCertifi
134131
return issuer, ca, id, nil
135132
}
136133

137-
func getMRCID(mrc *v1alpha2.MeshRootCertificate) (string, error) {
138-
if mrc.Annotations == nil || mrc.Annotations[constants.MRCVersionAnnotation] == "" {
139-
return "", fmt.Errorf("no annotation found for MRC %s/%s, expected annotation %s", mrc.Namespace, mrc.Name, constants.MRCVersionAnnotation)
140-
}
141-
return mrc.Annotations[constants.MRCVersionAnnotation], nil
142-
}
143-
144134
// getTresorOSMCertificateManager returns a certificate manager instance with Tresor as the certificate provider
145135
func (c *MRCProviderGenerator) getTresorOSMCertificateManager(mrc *v1alpha2.MeshRootCertificate) (certificate.Issuer, string, error) {
146136
var err error
@@ -177,11 +167,7 @@ func (c *MRCProviderGenerator) getTresorOSMCertificateManager(mrc *v1alpha2.Mesh
177167
return nil, "", fmt.Errorf("failed to instantiate Tresor as a Certificate Manager: %w", err)
178168
}
179169

180-
id, err := getMRCID(mrc)
181-
if err != nil {
182-
return nil, "", err
183-
}
184-
return tresorClient, id, nil
170+
return tresorClient, mrc.Name, nil
185171
}
186172

187173
// getHashiVaultOSMCertificateManager returns a certificate manager instance with Hashi Vault as the certificate provider
@@ -210,11 +196,8 @@ func (c *MRCProviderGenerator) getHashiVaultOSMCertificateManager(mrc *v1alpha2.
210196
if err != nil {
211197
return nil, "", fmt.Errorf("error instantiating Hashicorp Vault as a Certificate Manager: %w", err)
212198
}
213-
id, err := getMRCID(mrc)
214-
if err != nil {
215-
return nil, "", err
216-
}
217-
return vaultClient, id, nil
199+
200+
return vaultClient, mrc.Name, nil
218201
}
219202

220203
// getHashiVaultOSMToken returns the Hashi Vault token from the secret specified in the provided secret key reference
@@ -253,9 +236,6 @@ func (c *MRCProviderGenerator) getCertManagerOSMCertificateManager(mrc *v1alpha2
253236
if err != nil {
254237
return nil, "", fmt.Errorf("error instantiating Jetstack cert-manager client: %w", err)
255238
}
256-
id, err := getMRCID(mrc)
257-
if err != nil {
258-
return nil, "", err
259-
}
260-
return cmClient, id, nil
239+
240+
return cmClient, mrc.Name, nil
261241
}

0 commit comments

Comments
 (0)