Skip to content

Commit

Permalink
feat: add switch case for middlewaretype
Browse files Browse the repository at this point in the history
  • Loading branch information
kmurudi committed Mar 6, 2024
1 parent bb41ff3 commit 33ab955
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
3 changes: 1 addition & 2 deletions cns/middlewares/SFSwiftV2.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@ package middlewares
import (
"context"

"github.com/Azure/azure-container-networking/cns/configuration"

"github.com/Azure/azure-container-networking/cns"

Check failure on line 6 in cns/middlewares/SFSwiftV2.go

View workflow job for this annotation

GitHub Actions / Lint (1.21.x, ubuntu-latest)

could not import github.com/Azure/azure-container-networking/cns (-: import cycle not allowed: import stack: [github.com/Azure/azure-container-networking/cni/network github.com/Azure/azure-container-networking/cns github.com/Azure/azure-container-networking/cns/configuration github.com/Azure/azure-container-networking/cns]) (typecheck)
"github.com/Azure/azure-container-networking/cns/configuration"
"github.com/Azure/azure-container-networking/cns/types"
"github.com/pkg/errors"
)
Expand Down
2 changes: 1 addition & 1 deletion cns/middlewares/k8sSwiftV2.go
Original file line number Diff line number Diff line change
Expand Up @@ -284,5 +284,5 @@ func (m *K8sSWIFTv2Middleware) setRoutes(podIPInfo *cns.PodIpInfo) error {
}

func (m *K8sSWIFTv2Middleware) GetMiddlewareType() configuration.SWIFTV2Mode {
return configuration.SFSWIFTV2
return configuration.K8sSWIFTV2
}
8 changes: 5 additions & 3 deletions cns/restserver/ipam.go
Original file line number Diff line number Diff line change
Expand Up @@ -280,11 +280,13 @@ func (service *HTTPRestService) requestIPConfigsHandler(w http.ResponseWriter, r
if service.IPConfigsHandlerMiddleware != nil {
// Wrap the default datapath handlers with the middleware depending on middleware type
var wrappedHandler cns.IPConfigsHandlerFunc
if service.IPConfigsHandlerMiddleware.GetMiddlewareType() == configuration.K8sSWIFTV2 {
switch service.IPConfigsHandlerMiddleware.GetMiddlewareType() {
case configuration.K8sSWIFTV2:
wrappedHandler = service.IPConfigsHandlerMiddleware.IPConfigsRequestHandlerWrapper(service.requestIPConfigHandlerHelper, service.releaseIPConfigHandlerHelper)
} else if service.IPConfigsHandlerMiddleware.GetMiddlewareType() == configuration.SFSWIFTV2 {
wrappedHandler = service.IPConfigsHandlerMiddleware.IPConfigsRequestHandlerWrapper(service.requestIPConfigHandlerHelperSF, service.releaseIPConfigHandlerHelper)
case configuration.SFSWIFTV2:
wrappedHandler = service.IPConfigsHandlerMiddleware.IPConfigsRequestHandlerWrapper(service.requestIPConfigHandlerHelperSF, nil)
}

ipConfigsResp, err = wrappedHandler(r.Context(), ipconfigsRequest)
} else {
ipConfigsResp, err = service.requestIPConfigHandlerHelper(r.Context(), ipconfigsRequest) // nolint:contextcheck // appease linter
Expand Down

0 comments on commit 33ab955

Please sign in to comment.