Skip to content

Commit f8fe716

Browse files
authored
Merge pull request #3193 from cupakob/small-code-improvements
🌱 Remove unused return value (error)
2 parents 720cca1 + dda62e4 commit f8fe716

File tree

3 files changed

+10
-27
lines changed

3 files changed

+10
-27
lines changed

pkg/cache/client/round_tripper.go

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -72,17 +72,8 @@ func (c *ShardRoundTripper) RoundTrip(req *http.Request) (*http.Response, error)
7272
shard := ShardFromContext(req.Context())
7373
if !shard.Empty() {
7474
req = req.Clone(req.Context())
75-
path, err := generatePath(req.URL.Path, shard)
76-
if err != nil {
77-
return nil, err
78-
}
79-
req.URL.Path = path
80-
81-
rawPath, err := generatePath(req.URL.RawPath, shard)
82-
if err != nil {
83-
return nil, err
84-
}
85-
req.URL.RawPath = rawPath
75+
req.URL.Path = generatePath(req.URL.Path, shard)
76+
req.URL.RawPath = generatePath(req.URL.RawPath, shard)
8677
}
8778
return c.delegate.RoundTrip(req)
8879
}
@@ -92,24 +83,24 @@ func (c *ShardRoundTripper) WrappedRoundTripper() http.RoundTripper {
9283
}
9384

9485
// generatePath formats the request path to target the specified shard.
95-
func generatePath(originalPath string, shard clientshard.Name) (string, error) {
86+
func generatePath(originalPath string, shard clientshard.Name) string {
9687
// if the originalPath already has the shard then the path was already modified and no change needed
9788
if strings.HasPrefix(originalPath, shard.Path()) {
98-
return originalPath, nil
89+
return originalPath
9990
}
10091
// if the originalPath already has a shard set just overwrite it to the given one
10192
if strings.HasPrefix(originalPath, "/shards") {
10293
matches := shardNameRegex.FindStringSubmatch(originalPath)
10394
if len(matches) >= 2 {
10495
// replace /shards/$oldName/reminder with /shards/$newName/reminder
105-
return strings.Replace(originalPath, clientshard.New(matches[1]).Path(), shard.Path(), 1), nil
96+
return strings.Replace(originalPath, clientshard.New(matches[1]).Path(), shard.Path(), 1)
10697
} else {
10798
// the path is either /shards/name/ or /shards/name
10899
path := shard.Path()
109100
if originalPath[len(originalPath)-1] == '/' {
110101
path += "/"
111102
}
112-
return path, nil
103+
return path
113104
}
114105
}
115106

@@ -121,7 +112,7 @@ func generatePath(originalPath string, shard clientshard.Name) (string, error) {
121112
}
122113
// finally append the original path
123114
path += originalPath
124-
return path, nil
115+
return path
125116
}
126117

127118
// WithDefaultShardRoundTripper wraps an existing config's with DefaultShardRoundTripper

pkg/cache/client/round_tripper_test.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,7 @@ func TestShardRoundTripper(t *testing.T) {
6969
}
7070
for testName, tt := range tests {
7171
t.Run(testName, func(t *testing.T) {
72-
result, err := generatePath(tt.originalPath, shard.New("amber"))
73-
if err != nil {
74-
t.Error(err)
75-
}
72+
result := generatePath(tt.originalPath, shard.New("amber"))
7673
if result != tt.desired {
7774
t.Errorf("got %v, want %v", result, tt.desired)
7875
}

pkg/server/openapiv3/servicecache.go

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -175,10 +175,7 @@ func (c *ServiceCache) ServeHTTP(w http.ResponseWriter, r *http.Request) {
175175
}
176176

177177
// add static and dynamic APIs
178-
if err := addSpecs(service, c.staticSpecs, orderedCRDs, specs, log); err != nil {
179-
responsewriters.InternalError(w, r, err)
180-
return
181-
}
178+
addSpecs(service, c.staticSpecs, orderedCRDs, specs, log)
182179

183180
// remember for next time
184181
c.services.Add(key, m)
@@ -191,7 +188,7 @@ func (c *ServiceCache) ServeHTTP(w http.ResponseWriter, r *http.Request) {
191188
service.ServeHTTP(w, r)
192189
}
193190

194-
func addSpecs(service *handler3.OpenAPIService, static map[string]cached.Value[*spec3.OpenAPI], crds []*apiextensionsv1.CustomResourceDefinition, specs []map[string]cached.Value[*spec3.OpenAPI], log logr.Logger) error {
191+
func addSpecs(service *handler3.OpenAPIService, static map[string]cached.Value[*spec3.OpenAPI], crds []*apiextensionsv1.CustomResourceDefinition, specs []map[string]cached.Value[*spec3.OpenAPI], log logr.Logger) {
195192
// start with static specs
196193
byGroupVersionSpecs := make(map[string][]cached.Value[*spec3.OpenAPI])
197194
for gvPath, spec := range static {
@@ -238,8 +235,6 @@ func addSpecs(service *handler3.OpenAPIService, static map[string]cached.Value[*
238235
specs)
239236
service.UpdateGroupVersionLazy(gvPath, gvSpec)
240237
}
241-
242-
return nil
243238
}
244239

245240
func apiConfigurationKey(orderedCRDs []*apiextensionsv1.CustomResourceDefinition, specs []map[string]cached.Value[*spec3.OpenAPI]) (string, error) {

0 commit comments

Comments
 (0)