@@ -21,6 +21,7 @@ import (
21
21
"github.com/openservicemesh/osm/pkg/certificate/providers/vault"
22
22
"github.com/openservicemesh/osm/pkg/configurator"
23
23
"github.com/openservicemesh/osm/pkg/constants"
24
+ "github.com/openservicemesh/osm/pkg/k8s/informers"
24
25
"github.com/openservicemesh/osm/pkg/messaging"
25
26
)
26
27
@@ -43,42 +44,60 @@ var getCA func(certificate.Issuer) (pem.RootCertificate, error) = func(i certifi
43
44
// NewCertificateManager returns a new certificate manager, with an MRC compat client.
44
45
// TODO(4713): Use an informer behind a feature flag.
45
46
func NewCertificateManager (ctx context.Context , kubeClient kubernetes.Interface , kubeConfig * rest.Config , cfg configurator.Configurator ,
46
- providerNamespace string , options Options , msgBroker * messaging.Broker ) (* certificate.Manager , error ) {
47
+ providerNamespace string , options Options , msgBroker * messaging.Broker , informers * informers. InformerCollection ) (* certificate.Manager , error ) {
47
48
if err := options .Validate (); err != nil {
48
49
return nil , err
49
50
}
50
51
51
- // TODO(4713): Switch the compat client to an informer. Might need another struct to compose the informer and
52
- // provider generator.
53
- mrcClient := & MRCCompatClient {
54
- MRCProviderGenerator : MRCProviderGenerator {
55
- kubeClient : kubeClient ,
56
- kubeConfig : kubeConfig ,
57
- KeyBitSize : cfg .GetCertKeyBitSize (),
58
- caExtractorFunc : getCA ,
59
- },
60
- mrc : & v1alpha2.MeshRootCertificate {
61
- ObjectMeta : metav1.ObjectMeta {
62
- Name : "legacy-compat" ,
63
- Namespace : providerNamespace ,
64
- Annotations : map [string ]string {
65
- constants .MRCVersionAnnotation : "legacy-compat" ,
66
- },
52
+ var mrcClient certificate.MRCClient
53
+ // TODO(4713): Switch out with feature flag or some other mechanism
54
+ if true {
55
+ c := & MRCCompatClient {
56
+ MRCProviderGenerator : MRCProviderGenerator {
57
+ kubeClient : kubeClient ,
58
+ kubeConfig : kubeConfig ,
59
+ KeyBitSize : cfg .GetCertKeyBitSize (),
60
+ caExtractorFunc : getCA ,
67
61
},
68
- Spec : v1alpha2.MeshRootCertificateSpec {
69
- Provider : options .AsProviderSpec (),
62
+ mrc : & v1alpha2.MeshRootCertificate {
63
+ ObjectMeta : metav1.ObjectMeta {
64
+ Name : "legacy-compat" ,
65
+ Namespace : providerNamespace ,
66
+ Annotations : map [string ]string {
67
+ constants .MRCVersionAnnotation : "legacy-compat" ,
68
+ },
69
+ },
70
+ Spec : v1alpha2.MeshRootCertificateSpec {
71
+ Provider : options .AsProviderSpec (),
72
+ },
73
+ // TODO(#4713): Detect if an actual MRC exists, and set the status accordingly.
74
+ Status : v1alpha2.MeshRootCertificateStatus {
75
+ State : constants .MRCStateComplete ,
76
+ RotationStage : constants .MRCStageIssuing ,
77
+ },
70
78
},
71
- // TODO(#4713): Detect if an actual MRC exists, and set the status accordingly.
72
- Status : v1alpha2.MeshRootCertificateStatus {
73
- State : constants .MRCStateComplete ,
74
- RotationStage : constants .MRCStageIssuing ,
79
+ }
80
+ // TODO(#4745): Remove after deprecating the osm.vault.token option.
81
+ if vaultOption , ok := options .(VaultOptions ); ok {
82
+ c .MRCProviderGenerator .DefaultVaultToken = vaultOption .VaultToken
83
+ }
84
+ mrcClient = c
85
+ } else {
86
+ c := & MRCClientImpl {
87
+ MRCProviderGenerator : MRCProviderGenerator {
88
+ kubeClient : kubeClient ,
89
+ kubeConfig : kubeConfig ,
90
+ KeyBitSize : cfg .GetCertKeyBitSize (),
91
+ caExtractorFunc : getCA ,
75
92
},
76
- },
77
- }
93
+ informerCollection : informers ,
94
+ }
95
+
96
+ if vaultOption , ok := options .(VaultOptions ); ok {
97
+ c .MRCProviderGenerator .DefaultVaultToken = vaultOption .VaultToken
98
+ }
78
99
79
- // TODO(#4745): Remove after deprecating the osm.vault.token option.
80
- if vaultOption , ok := options .(VaultOptions ); ok {
81
- mrcClient .MRCProviderGenerator .DefaultVaultToken = vaultOption .VaultToken
100
+ mrcClient = c
82
101
}
83
102
84
103
return certificate .NewManager (ctx , mrcClient , cfg .GetServiceCertValidityPeriod (), msgBroker )
0 commit comments