Skip to content

Commit e400603

Browse files
committed
make EndpointResolver logs verbose and remove endpoints parameter from sessionForRegionV2
Signed-off-by: Pankaj Walke <[email protected]>
1 parent 4e180d1 commit e400603

File tree

5 files changed

+18
-8
lines changed

5 files changed

+18
-8
lines changed

pkg/cloud/endpointsv2/endpoints.go

+8-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright 2020 The Kubernetes Authors.
2+
Copyright 2025 The Kubernetes Authors.
33
44
Licensed under the Apache License, Version 2.0 (the "License");
55
you may not use this file except in compliance with the License.
@@ -25,6 +25,7 @@ import (
2525

2626
"github.com/aws/aws-sdk-go-v2/service/s3"
2727
smithyendpoints "github.com/aws/smithy-go/endpoints"
28+
"sigs.k8s.io/cluster-api-provider-aws/v2/pkg/logger"
2829
)
2930

3031
var (
@@ -104,11 +105,15 @@ type S3EndpointResolver struct {
104105
// ResolveEndpoint for S3.
105106
func (s *S3EndpointResolver) ResolveEndpoint(ctx context.Context, params s3.EndpointParameters) (smithyendpoints.Endpoint, error) {
106107
// If custom endpoint not found, return default endpoint for the service
107-
if _, ok := s.endpoints[s3.ServiceID]; !ok {
108+
log := logger.FromContext(ctx)
109+
endpoint, ok := s.endpoints[s3.ServiceID]
110+
111+
if !ok {
112+
log.Debug("Custom endpoint not found, using default endpoint")
108113
return s3.NewDefaultEndpointResolverV2().ResolveEndpoint(ctx, params)
109114
}
110115

111-
endpoint := ServiceEndpointsMap[s3.ServiceID]
116+
log.Debug("Custom endpoint found, using custom endpoint", "endpoint", endpoint.URL)
112117
params.Endpoint = &endpoint.URL
113118
params.Region = &endpoint.SigningRegion
114119
return s3.NewDefaultEndpointResolverV2().ResolveEndpoint(ctx, params)

pkg/cloud/identityv2/identity.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright 2021 The Kubernetes Authors.
2+
Copyright 2025 The Kubernetes Authors.
33
44
Licensed under the Apache License, Version 2.0 (the "License");
55
you may not use this file except in compliance with the License.

pkg/cloud/metricsv2/metrics.go

+7-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright 2020 The Kubernetes Authors.
2+
Copyright 2025 The Kubernetes Authors.
33
44
Licensed under the Apache License, Version 2.0 (the "License");
55
you may not use this file except in compliance with the License.
@@ -219,7 +219,7 @@ func getContext(ctx context.Context) *RequestData {
219219

220220
// CaptureRequestMetrics will monitor and capture request metrics.
221221
func (r *RequestData) CaptureRequestMetrics() {
222-
if r.Service == "" || r.Region == "" || r.OperationName == "" || r.Controller == "" {
222+
if !r.IsIncomplete() {
223223
return
224224
}
225225

@@ -255,3 +255,8 @@ func (r *RequestData) CaptureRequestMetrics() {
255255
r.OperationName,
256256
).Observe(float64(retryCount))
257257
}
258+
259+
// IsIncomplete will return true if the RequestData was incomplete.
260+
func (r *RequestData) IsIncomplete() bool {
261+
return r.Service == "" || r.Region == "" || r.OperationName == "" || r.Controller == ""
262+
}

pkg/cloud/scope/global.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ func NewGlobalScope(params GlobalScopeParams) (*GlobalScope, error) {
3838
return nil, errors.Wrap(err, "failed to create aws session")
3939
}
4040

41-
ns2, _, err := sessionForRegionV2(params.Region, params.Endpoints)
41+
ns2, _, err := sessionForRegionV2(params.Region)
4242
if err != nil {
4343
return nil, errors.Wrap(err, "failed to create aws V2 session")
4444
}

pkg/cloud/scope/session.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ func sessionForRegion(region string, endpoint []ServiceEndpoint) (*session.Sessi
117117
return ns, sl, nil
118118
}
119119

120-
func sessionForRegionV2(region string, _ []ServiceEndpoint) (*awsv2.Config, throttle.ServiceLimiters, error) {
120+
func sessionForRegionV2(region string) (*awsv2.Config, throttle.ServiceLimiters, error) {
121121
if s, ok := sessionCacheV2.Load(region); ok {
122122
entry := s.(*sessionCacheEntry)
123123
return entry.sessionV2, entry.serviceLimiters, nil

0 commit comments

Comments
 (0)