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

Commit fa17242

Browse files
authored
small cert related changes. (#4870)
1. align imports on casing for tresorFake 2. use GetTrustedCAs where appropriate 3. use a logger component in certificate package Signed-off-by: Sean Teeling <[email protected]>
1 parent 3bf989a commit fa17242

File tree

11 files changed

+20
-19
lines changed

11 files changed

+20
-19
lines changed

pkg/certificate/certificate.go

-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ package certificate
33
import (
44
time "time"
55

6-
"github.com/rs/zerolog/log"
7-
86
"github.com/openservicemesh/osm/pkg/certificate/pem"
97
"github.com/openservicemesh/osm/pkg/errcode"
108
)

pkg/certificate/manager.go

+5-2
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,18 @@ import (
77
"sync"
88
"time"
99

10-
"github.com/rs/zerolog/log"
11-
1210
"github.com/openservicemesh/osm/pkg/announcements"
1311
"github.com/openservicemesh/osm/pkg/constants"
1412
"github.com/openservicemesh/osm/pkg/errcode"
1513
"github.com/openservicemesh/osm/pkg/k8s/events"
14+
"github.com/openservicemesh/osm/pkg/logger"
1615
"github.com/openservicemesh/osm/pkg/messaging"
1716
)
1817

18+
var (
19+
log = logger.New("certificate")
20+
)
21+
1922
// NewManager creates a new CertificateManager with the passed MRCClient and options
2023
func NewManager(ctx context.Context, mrcClient MRCClient, getServiceCertValidityPeriod func() time.Duration, getIngressCertValidityDuration func() time.Duration, msgBroker *messaging.Broker, checkInterval time.Duration) (*Manager, error) {
2124
m := &Manager{

pkg/crdconversion/crdconversion.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ func updateCrdConfiguration(cert *certificate.Certificate, crdClient apiclient.A
8686
Port: pointer.Int32(constants.CRDConversionWebhookPort),
8787
Path: &crdConversionPath,
8888
},
89-
CABundle: cert.GetIssuingCA(),
89+
CABundle: cert.GetTrustedCAs(),
9090
},
9191
ConversionReviewVersions: conversionReviewVersions,
9292
},

pkg/envoy/lds/response_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import (
1616
"k8s.io/client-go/kubernetes"
1717
testclient "k8s.io/client-go/kubernetes/fake"
1818

19-
tresorfake "github.com/openservicemesh/osm/pkg/certificate/providers/tresor/fake"
19+
tresorFake "github.com/openservicemesh/osm/pkg/certificate/providers/tresor/fake"
2020

2121
configv1alpha2 "github.com/openservicemesh/osm/pkg/apis/config/v1alpha2"
2222
configFake "github.com/openservicemesh/osm/pkg/gen/client/config/clientset/versioned/fake"
@@ -101,7 +101,7 @@ func TestNewResponse(t *testing.T) {
101101
return nil, fmt.Errorf("dummy error")
102102
}), nil)
103103

104-
cm := tresorfake.NewFake(nil, 1*time.Hour)
104+
cm := tresorFake.NewFake(nil, 1*time.Hour)
105105
resources, err := NewResponse(meshCatalog, proxy, nil, mockConfigurator, cm, proxyRegistry)
106106
assert.NotNil(err)
107107
assert.Nil(resources)

pkg/envoy/rds/response_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import (
1919
"k8s.io/client-go/kubernetes"
2020
testclient "k8s.io/client-go/kubernetes/fake"
2121

22-
tresorfake "github.com/openservicemesh/osm/pkg/certificate/providers/tresor/fake"
22+
tresorFake "github.com/openservicemesh/osm/pkg/certificate/providers/tresor/fake"
2323

2424
configv1alpha2 "github.com/openservicemesh/osm/pkg/apis/config/v1alpha2"
2525

@@ -297,7 +297,7 @@ func TestNewResponse(t *testing.T) {
297297
ResourceNames: []string{},
298298
}
299299

300-
mc := tresorfake.NewFake(nil, 1*time.Hour)
300+
mc := tresorFake.NewFake(nil, 1*time.Hour)
301301

302302
resources, err := NewResponse(mockCatalog, proxy, &discoveryRequest, mockConfigurator, mc, proxyRegistry)
303303
assert.Nil(err)
@@ -444,7 +444,7 @@ func TestResponseRequestCompletion(t *testing.T) {
444444
return []service.MeshService{tests.BookstoreV1Service}, nil
445445
}), nil)
446446

447-
mc := tresorfake.NewFake(nil, 1*time.Hour)
447+
mc := tresorFake.NewFake(nil, 1*time.Hour)
448448

449449
mockCatalog.EXPECT().GetInboundMeshTrafficPolicy(gomock.Any(), gomock.Any()).Return(nil).AnyTimes()
450450
mockCatalog.EXPECT().GetOutboundMeshTrafficPolicy(gomock.Any()).Return(nil).AnyTimes()

pkg/ingress/gateway.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ func (c *client) createAndStoreGatewayCert(spec configv1alpha2.IngressGatewayCer
7676
// storeCertInSecret stores the certificate in the specified k8s TLS secret
7777
func (c *client) storeCertInSecret(cert *certificate.Certificate, secret corev1.SecretReference) error {
7878
secretData := map[string][]byte{
79-
"ca.crt": cert.GetIssuingCA(),
79+
"ca.crt": cert.GetTrustedCAs(),
8080
"tls.crt": cert.GetCertificateChain(),
8181
"tls.key": cert.GetPrivateKey(),
8282
}

pkg/utils/grpc_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ func TestNewGrpc(t *testing.T) {
1919

2020
certPem := adsCert.GetCertificateChain()
2121
keyPem := adsCert.GetPrivateKey()
22-
rootPem := adsCert.GetIssuingCA()
22+
rootPem := adsCert.GetTrustedCAs()
2323
var emptyByteArray []byte
2424

2525
type newGrpcTest struct {
@@ -59,7 +59,7 @@ func TestGrpcServe(t *testing.T) {
5959

6060
serverType := "ADS"
6161
port := 9999
62-
grpcServer, lis, err := NewGrpc(serverType, port, adsCert.GetCertificateChain(), adsCert.GetPrivateKey(), adsCert.GetIssuingCA())
62+
grpcServer, lis, err := NewGrpc(serverType, port, adsCert.GetCertificateChain(), adsCert.GetPrivateKey(), adsCert.GetTrustedCAs())
6363
assert.Nil(err)
6464

6565
ctx, cancel := context.WithCancel(context.Background())

pkg/utils/mtls_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ func TestSetupMutualTLS(t *testing.T) {
3737
serverType := "ADS"
3838
goodCertPem := adsCert.GetCertificateChain()
3939
goodKeyPem := adsCert.GetPrivateKey()
40-
goodCA := adsCert.GetIssuingCA()
40+
goodCA := adsCert.GetTrustedCAs()
4141
var emptyByteArray []byte
4242

4343
setupMutualTLStests := []setupMutualTLStest{

pkg/validator/patch.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ func createOrUpdateValidatingWebhook(clientSet kubernetes.Interface, cert *certi
7676
Path: &webhookPath,
7777
Port: &webhookPort,
7878
},
79-
CABundle: cert.GetIssuingCA()},
79+
CABundle: cert.GetTrustedCAs()},
8080
FailurePolicy: &failurePolicy,
8181
MatchPolicy: &matchPolicy,
8282
NamespaceSelector: &metav1.LabelSelector{

tests/scenarios/traffic_split_with_apex_service_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import (
1616
"github.com/openservicemesh/osm/pkg/identity"
1717

1818
catalogFake "github.com/openservicemesh/osm/pkg/catalog/fake"
19-
tresorfake "github.com/openservicemesh/osm/pkg/certificate/providers/tresor/fake"
19+
tresorFake "github.com/openservicemesh/osm/pkg/certificate/providers/tresor/fake"
2020
"github.com/openservicemesh/osm/pkg/configurator"
2121
"github.com/openservicemesh/osm/pkg/envoy"
2222
"github.com/openservicemesh/osm/pkg/envoy/rds"
@@ -51,7 +51,7 @@ func TestRDSNewResponseWithTrafficSplit(t *testing.T) {
5151
EnableEgressPolicy: false,
5252
}).AnyTimes()
5353

54-
mc := tresorfake.NewFake(nil, 1*time.Hour)
54+
mc := tresorFake.NewFake(nil, 1*time.Hour)
5555
a.NotNil(a)
5656

5757
resources, err := rds.NewResponse(meshCatalog, proxy, nil, mockConfigurator, mc, proxyRegistry)

tests/scenarios/traffic_split_with_zero_weight_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import (
2020
configv1alpha2 "github.com/openservicemesh/osm/pkg/apis/config/v1alpha2"
2121

2222
"github.com/openservicemesh/osm/pkg/catalog"
23-
tresorfake "github.com/openservicemesh/osm/pkg/certificate/providers/tresor/fake"
23+
tresorFake "github.com/openservicemesh/osm/pkg/certificate/providers/tresor/fake"
2424
"github.com/openservicemesh/osm/pkg/configurator"
2525
"github.com/openservicemesh/osm/pkg/constants"
2626
"github.com/openservicemesh/osm/pkg/endpoint"
@@ -253,7 +253,7 @@ func TestRDSRespose(t *testing.T) {
253253
mockCatalog.EXPECT().GetIngressTrafficPolicy(gomock.Any()).Return(nil, nil).AnyTimes()
254254
mockCatalog.EXPECT().GetEgressTrafficPolicy(gomock.Any()).Return(nil, nil).AnyTimes()
255255

256-
cm := tresorfake.NewFake(nil, 1*time.Hour)
256+
cm := tresorFake.NewFake(nil, 1*time.Hour)
257257

258258
resources, err := rds.NewResponse(mockCatalog, proxy, nil, mockConfigurator, cm, proxyRegistry)
259259
assert.Nil(err)

0 commit comments

Comments
 (0)