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

Commit c9d2292

Browse files
authored
pkg/*: un-export k8s client implementing interface (#4002)
Un-exports the struct types that are implementing an interface because consumers should not be directly interacting with the internal interface implementation. Signed-off-by: Shashank Ram <[email protected]>
1 parent fdef5c5 commit c9d2292

11 files changed

+108
-110
lines changed

pkg/configurator/client.go

+11-11
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,14 @@ func NewConfigurator(kubeClient versioned.Interface, stop <-chan struct{}, osmNa
2828
return newConfigurator(kubeClient, stop, osmNamespace, meshConfigName)
2929
}
3030

31-
func newConfigurator(meshConfigClientSet versioned.Interface, stop <-chan struct{}, osmNamespace string, meshConfigName string) *Client {
31+
func newConfigurator(meshConfigClientSet versioned.Interface, stop <-chan struct{}, osmNamespace string, meshConfigName string) *client {
3232
informerFactory := informers.NewSharedInformerFactoryWithOptions(
3333
meshConfigClientSet,
3434
k8s.DefaultKubeEventResyncInterval,
3535
informers.WithNamespace(osmNamespace),
3636
)
3737
informer := informerFactory.Config().V1alpha1().MeshConfigs().Informer()
38-
client := Client{
38+
c := &client{
3939
informer: informer,
4040
cache: informer.GetStore(),
4141
osmNamespace: osmNamespace,
@@ -51,16 +51,16 @@ func newConfigurator(meshConfigClientSet versioned.Interface, stop <-chan struct
5151
informer.AddEventHandler(k8s.GetKubernetesEventHandlers(meshConfigInformerName, meshConfigProviderName, nil, eventTypes))
5252

5353
// start listener
54-
go client.runMeshConfigListener(stop)
54+
go c.runMeshConfigListener(stop)
5555

56-
client.run(stop)
56+
c.run(stop)
5757

58-
return &client
58+
return c
5959
}
6060

6161
// Listens to MeshConfig events and notifies dispatcher to issue config updates to the envoys based
6262
// on config seen on the MeshConfig
63-
func (c *Client) runMeshConfigListener(stop <-chan struct{}) {
63+
func (c *client) runMeshConfigListener(stop <-chan struct{}) {
6464
// Create the subscription channel synchronously
6565
cfgSubChannel := events.Subscribe(
6666
announcements.MeshConfigAdded,
@@ -95,17 +95,17 @@ func (c *Client) runMeshConfigListener(stop <-chan struct{}) {
9595
}
9696
}
9797

98-
func (c *Client) run(stop <-chan struct{}) {
98+
func (c *client) run(stop <-chan struct{}) {
9999
go c.informer.Run(stop) // run the informer synchronization
100100
log.Debug().Msgf("Started OSM MeshConfig informer")
101-
log.Debug().Msg("[MeshConfig Client] Waiting for MeshConfig informer's cache to sync")
101+
log.Debug().Msg("[MeshConfig client] Waiting for MeshConfig informer's cache to sync")
102102
if !cache.WaitForCacheSync(stop, c.informer.HasSynced) {
103103
// TODO(#3962): metric might not be scraped before process restart resulting from this error
104104
log.Error().Str(errcode.Kind, errcode.GetErrCodeWithMetric(errcode.ErrMeshConfigInformerInitCache)).Msg("Failed initial cache sync for MeshConfig informer")
105105
return
106106
}
107107

108-
log.Debug().Msg("[MeshConfig Client] Cache sync for MeshConfig informer finished")
108+
log.Debug().Msg("[MeshConfig client] Cache sync for MeshConfig informer finished")
109109
}
110110

111111
func meshConfigAddedMessageHandler(psubMsg *events.PubSubMessage) {
@@ -183,12 +183,12 @@ func meshConfigUpdatedMessageHandler(psubMsg *events.PubSubMessage) {
183183
}
184184
}
185185

186-
func (c *Client) getMeshConfigCacheKey() string {
186+
func (c *client) getMeshConfigCacheKey() string {
187187
return fmt.Sprintf("%s/%s", c.osmNamespace, c.meshConfigName)
188188
}
189189

190190
// Returns the current MeshConfig
191-
func (c *Client) getMeshConfig() *v1alpha1.MeshConfig {
191+
func (c *client) getMeshConfig() *v1alpha1.MeshConfig {
192192
meshConfigCacheKey := c.getMeshConfigCacheKey()
193193
item, exists, err := c.cache.GetByKey(meshConfigCacheKey)
194194
if err != nil {

pkg/configurator/methods.go

+27-27
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,12 @@ const (
3131
// The functions in this file implement the configurator.Configurator interface
3232

3333
// GetMeshConfig returns the MeshConfig resource corresponding to the control plane
34-
func (c *Client) GetMeshConfig() *configv1alpha1.MeshConfig {
34+
func (c *client) GetMeshConfig() *configv1alpha1.MeshConfig {
3535
return c.getMeshConfig()
3636
}
3737

3838
// GetOSMNamespace returns the namespace in which the OSM controller pod resides.
39-
func (c *Client) GetOSMNamespace() string {
39+
func (c *client) GetOSMNamespace() string {
4040
return c.osmNamespace
4141
}
4242

@@ -49,7 +49,7 @@ func marshalConfigToJSON(config *configv1alpha1.MeshConfigSpec) (string, error)
4949
}
5050

5151
// GetMeshConfigJSON returns the MeshConfig in pretty JSON.
52-
func (c *Client) GetMeshConfigJSON() (string, error) {
52+
func (c *client) GetMeshConfigJSON() (string, error) {
5353
cm, err := marshalConfigToJSON(&c.getMeshConfig().Spec)
5454
if err != nil {
5555
log.Error().Err(err).Str(errcode.Kind, errcode.GetErrCodeWithMetric(errcode.ErrMeshConfigMarshaling)).Msgf("Error marshaling MeshConfig %s: %+v", c.getMeshConfigCacheKey(), c.getMeshConfig())
@@ -62,27 +62,27 @@ func (c *Client) GetMeshConfigJSON() (string, error) {
6262
// where all existing traffic is allowed to flow as it is,
6363
// or it is in SMI Spec mode, in which only traffic between source/destinations
6464
// referenced in SMI policies is allowed.
65-
func (c *Client) IsPermissiveTrafficPolicyMode() bool {
65+
func (c *client) IsPermissiveTrafficPolicyMode() bool {
6666
return c.getMeshConfig().Spec.Traffic.EnablePermissiveTrafficPolicyMode
6767
}
6868

6969
// IsEgressEnabled determines whether egress is globally enabled in the mesh or not.
70-
func (c *Client) IsEgressEnabled() bool {
70+
func (c *client) IsEgressEnabled() bool {
7171
return c.getMeshConfig().Spec.Traffic.EnableEgress
7272
}
7373

7474
// IsDebugServerEnabled determines whether osm debug HTTP server is enabled
75-
func (c *Client) IsDebugServerEnabled() bool {
75+
func (c *client) IsDebugServerEnabled() bool {
7676
return c.getMeshConfig().Spec.Observability.EnableDebugServer
7777
}
7878

7979
// IsTracingEnabled returns whether tracing is enabled
80-
func (c *Client) IsTracingEnabled() bool {
80+
func (c *client) IsTracingEnabled() bool {
8181
return c.getMeshConfig().Spec.Observability.Tracing.Enable
8282
}
8383

8484
// GetTracingHost is the host to which we send tracing spans
85-
func (c *Client) GetTracingHost() string {
85+
func (c *client) GetTracingHost() string {
8686
tracingAddress := c.getMeshConfig().Spec.Observability.Tracing.Address
8787
if tracingAddress != "" {
8888
return tracingAddress
@@ -91,7 +91,7 @@ func (c *Client) GetTracingHost() string {
9191
}
9292

9393
// GetTracingPort returns the tracing listener port
94-
func (c *Client) GetTracingPort() uint32 {
94+
func (c *client) GetTracingPort() uint32 {
9595
tracingPort := c.getMeshConfig().Spec.Observability.Tracing.Port
9696
if tracingPort != 0 {
9797
return uint32(tracingPort)
@@ -100,7 +100,7 @@ func (c *Client) GetTracingPort() uint32 {
100100
}
101101

102102
// GetTracingEndpoint returns the listener's collector endpoint
103-
func (c *Client) GetTracingEndpoint() string {
103+
func (c *client) GetTracingEndpoint() string {
104104
tracingEndpoint := c.getMeshConfig().Spec.Observability.Tracing.Endpoint
105105
if tracingEndpoint != "" {
106106
return tracingEndpoint
@@ -109,17 +109,17 @@ func (c *Client) GetTracingEndpoint() string {
109109
}
110110

111111
// UseHTTPSIngress determines whether traffic between ingress and backend pods should use HTTPS protocol
112-
func (c *Client) UseHTTPSIngress() bool {
112+
func (c *client) UseHTTPSIngress() bool {
113113
return c.getMeshConfig().Spec.Traffic.UseHTTPSIngress
114114
}
115115

116116
// GetMaxDataPlaneConnections returns the max data plane connections allowed, 0 if disabled
117-
func (c *Client) GetMaxDataPlaneConnections() int {
117+
func (c *client) GetMaxDataPlaneConnections() int {
118118
return c.getMeshConfig().Spec.Sidecar.MaxDataPlaneConnections
119119
}
120120

121121
// GetEnvoyLogLevel returns the envoy log level
122-
func (c *Client) GetEnvoyLogLevel() string {
122+
func (c *client) GetEnvoyLogLevel() string {
123123
logLevel := c.getMeshConfig().Spec.Sidecar.LogLevel
124124
if logLevel != "" {
125125
return logLevel
@@ -128,7 +128,7 @@ func (c *Client) GetEnvoyLogLevel() string {
128128
}
129129

130130
// GetEnvoyImage returns the envoy image
131-
func (c *Client) GetEnvoyImage() string {
131+
func (c *client) GetEnvoyImage() string {
132132
image := c.getMeshConfig().Spec.Sidecar.EnvoyImage
133133
if image != "" {
134134
return image
@@ -137,7 +137,7 @@ func (c *Client) GetEnvoyImage() string {
137137
}
138138

139139
// GetEnvoyWindowsImage returns the envoy windows image
140-
func (c *Client) GetEnvoyWindowsImage() string {
140+
func (c *client) GetEnvoyWindowsImage() string {
141141
image := c.getMeshConfig().Spec.Sidecar.EnvoyWindowsImage
142142
if image != "" {
143143
return image
@@ -146,7 +146,7 @@ func (c *Client) GetEnvoyWindowsImage() string {
146146
}
147147

148148
// GetInitContainerImage returns the init container image
149-
func (c *Client) GetInitContainerImage() string {
149+
func (c *client) GetInitContainerImage() string {
150150
initImage := c.getMeshConfig().Spec.Sidecar.InitContainerImage
151151
if initImage != "" {
152152
return initImage
@@ -155,7 +155,7 @@ func (c *Client) GetInitContainerImage() string {
155155
}
156156

157157
// GetServiceCertValidityPeriod returns the validity duration for service certificates, and a default in case of invalid duration
158-
func (c *Client) GetServiceCertValidityPeriod() time.Duration {
158+
func (c *client) GetServiceCertValidityPeriod() time.Duration {
159159
durationStr := c.getMeshConfig().Spec.Certificate.ServiceCertValidityDuration
160160
validityDuration, err := time.ParseDuration(durationStr)
161161
if err != nil {
@@ -167,7 +167,7 @@ func (c *Client) GetServiceCertValidityPeriod() time.Duration {
167167
}
168168

169169
// GetCertKeyBitSize returns the certificate key bit size to be used
170-
func (c *Client) GetCertKeyBitSize() int {
170+
func (c *client) GetCertKeyBitSize() int {
171171
bitSize := c.getMeshConfig().Spec.Certificate.CertKeyBitSize
172172
if bitSize < minCertKeyBitSize || bitSize > maxCertKeyBitSize {
173173
log.Error().Msgf("Invalid key bit size: %d", bitSize)
@@ -178,28 +178,28 @@ func (c *Client) GetCertKeyBitSize() int {
178178
}
179179

180180
// GetOutboundIPRangeExclusionList returns the list of IP ranges of the form x.x.x.x/y to exclude from outbound sidecar interception
181-
func (c *Client) GetOutboundIPRangeExclusionList() []string {
181+
func (c *client) GetOutboundIPRangeExclusionList() []string {
182182
return c.getMeshConfig().Spec.Traffic.OutboundIPRangeExclusionList
183183
}
184184

185185
// GetOutboundPortExclusionList returns the list of ports (positive integers) to exclude from outbound sidecar interception
186-
func (c *Client) GetOutboundPortExclusionList() []int {
186+
func (c *client) GetOutboundPortExclusionList() []int {
187187
return c.getMeshConfig().Spec.Traffic.OutboundPortExclusionList
188188
}
189189

190190
// GetInboundPortExclusionList returns the list of ports (positive integers) to exclude from inbound sidecar interception
191-
func (c *Client) GetInboundPortExclusionList() []int {
191+
func (c *client) GetInboundPortExclusionList() []int {
192192
return c.getMeshConfig().Spec.Traffic.InboundPortExclusionList
193193
}
194194

195195
// IsPrivilegedInitContainer returns whether init containers should be privileged
196-
func (c *Client) IsPrivilegedInitContainer() bool {
196+
func (c *client) IsPrivilegedInitContainer() bool {
197197
return c.getMeshConfig().Spec.Sidecar.EnablePrivilegedInitContainer
198198
}
199199

200200
// GetConfigResyncInterval returns the duration for resync interval.
201201
// If error or non-parsable value, returns 0 duration
202-
func (c *Client) GetConfigResyncInterval() time.Duration {
202+
func (c *client) GetConfigResyncInterval() time.Duration {
203203
resyncDuration := c.getMeshConfig().Spec.Sidecar.ConfigResyncInterval
204204
duration, err := time.ParseDuration(resyncDuration)
205205
if err != nil {
@@ -210,12 +210,12 @@ func (c *Client) GetConfigResyncInterval() time.Duration {
210210
}
211211

212212
// GetProxyResources returns the `Resources` configured for proxies, if any
213-
func (c *Client) GetProxyResources() corev1.ResourceRequirements {
213+
func (c *client) GetProxyResources() corev1.ResourceRequirements {
214214
return c.getMeshConfig().Spec.Sidecar.Resources
215215
}
216216

217217
// GetInboundExternalAuthConfig returns the External Authentication configuration for incoming traffic, if any
218-
func (c *Client) GetInboundExternalAuthConfig() auth.ExtAuthConfig {
218+
func (c *client) GetInboundExternalAuthConfig() auth.ExtAuthConfig {
219219
extAuthConfig := auth.ExtAuthConfig{}
220220
inboundExtAuthzMeshConfig := c.getMeshConfig().Spec.Traffic.InboundExternalAuthorization
221221

@@ -236,11 +236,11 @@ func (c *Client) GetInboundExternalAuthConfig() auth.ExtAuthConfig {
236236
}
237237

238238
// GetFeatureFlags returns OSM's feature flags
239-
func (c *Client) GetFeatureFlags() configv1alpha1.FeatureFlags {
239+
func (c *client) GetFeatureFlags() configv1alpha1.FeatureFlags {
240240
return c.getMeshConfig().Spec.FeatureFlags
241241
}
242242

243243
// GetOSMLogLevel returns the configured OSM log level
244-
func (c *Client) GetOSMLogLevel() string {
244+
func (c *client) GetOSMLogLevel() string {
245245
return c.getMeshConfig().Spec.Observability.OSMLogLevel
246246
}

pkg/configurator/methods_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import (
1919
)
2020

2121
func TestGetMeshConfigCacheKey(t *testing.T) {
22-
c := Client{
22+
c := client{
2323
meshConfigName: "configName",
2424
osmNamespace: "namespaceName",
2525
}

pkg/configurator/types.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,8 @@ var (
1717
log = logger.New("configurator")
1818
)
1919

20-
// Client is the k8s client struct for the MeshConfig CRD.
21-
type Client struct {
22-
// TODO: rename it to `client`
20+
// client is the type used to represent the Kubernetes client for the config.openservicemesh.io API group
21+
type client struct {
2322
osmNamespace string
2423
informer cache.SharedIndexInformer
2524
cache cache.Store

0 commit comments

Comments
 (0)