Skip to content

Commit

Permalink
Remove unused return values (errors)
Browse files Browse the repository at this point in the history
In this functions the returned errors are always nil. They can be
removed and this makes the code a little bit simpler.

Signed-off-by: Atanas Alexandrov <[email protected]>
  • Loading branch information
cupakob committed Oct 29, 2024
1 parent e7d1d54 commit 3b5d943
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 23 deletions.
23 changes: 7 additions & 16 deletions pkg/cache/client/round_tripper.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,17 +72,8 @@ func (c *ShardRoundTripper) RoundTrip(req *http.Request) (*http.Response, error)
shard := ShardFromContext(req.Context())
if !shard.Empty() {
req = req.Clone(req.Context())
path, err := generatePath(req.URL.Path, shard)
if err != nil {
return nil, err
}
req.URL.Path = path

rawPath, err := generatePath(req.URL.RawPath, shard)
if err != nil {
return nil, err
}
req.URL.RawPath = rawPath
req.URL.Path = generatePath(req.URL.Path, shard)
req.URL.RawPath = generatePath(req.URL.RawPath, shard)
}
return c.delegate.RoundTrip(req)
}
Expand All @@ -92,24 +83,24 @@ func (c *ShardRoundTripper) WrappedRoundTripper() http.RoundTripper {
}

// generatePath formats the request path to target the specified shard.
func generatePath(originalPath string, shard clientshard.Name) (string, error) {
func generatePath(originalPath string, shard clientshard.Name) string {
// if the originalPath already has the shard then the path was already modified and no change needed
if strings.HasPrefix(originalPath, shard.Path()) {
return originalPath, nil
return originalPath
}
// if the originalPath already has a shard set just overwrite it to the given one
if strings.HasPrefix(originalPath, "/shards") {
matches := shardNameRegex.FindStringSubmatch(originalPath)
if len(matches) >= 2 {
// replace /shards/$oldName/reminder with /shards/$newName/reminder
return strings.Replace(originalPath, clientshard.New(matches[1]).Path(), shard.Path(), 1), nil
return strings.Replace(originalPath, clientshard.New(matches[1]).Path(), shard.Path(), 1)
} else {
// the path is either /shards/name/ or /shards/name
path := shard.Path()
if originalPath[len(originalPath)-1] == '/' {
path += "/"
}
return path, nil
return path
}
}

Expand All @@ -121,7 +112,7 @@ func generatePath(originalPath string, shard clientshard.Name) (string, error) {
}
// finally append the original path
path += originalPath
return path, nil
return path
}

// WithDefaultShardRoundTripper wraps an existing config's with DefaultShardRoundTripper
Expand Down
9 changes: 2 additions & 7 deletions pkg/server/openapiv3/servicecache.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,10 +175,7 @@ func (c *ServiceCache) ServeHTTP(w http.ResponseWriter, r *http.Request) {
}

// add static and dynamic APIs
if err := addSpecs(service, c.staticSpecs, orderedCRDs, specs, log); err != nil {
responsewriters.InternalError(w, r, err)
return
}
addSpecs(service, c.staticSpecs, orderedCRDs, specs, log)

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

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 {
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) {
// start with static specs
byGroupVersionSpecs := make(map[string][]cached.Value[*spec3.OpenAPI])
for gvPath, spec := range static {
Expand Down Expand Up @@ -238,8 +235,6 @@ func addSpecs(service *handler3.OpenAPIService, static map[string]cached.Value[*
specs)
service.UpdateGroupVersionLazy(gvPath, gvSpec)
}

return nil
}

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

0 comments on commit 3b5d943

Please sign in to comment.