Skip to content

Commit

Permalink
Fix L3Network task endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
nandakishorepeddi committed May 31, 2024
1 parent 0d76564 commit c4abaea
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 10 deletions.
4 changes: 0 additions & 4 deletions azure-pipelines.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,6 @@ stages:
displayName: Check Go format and Suspicious constructs
inputs:
script: 'make verify'
- task: CmdLine@2
displayName: Check documentation
inputs:
script: 'make docs'
- stage: ContainerImage
dependsOn: PreCheck
jobs:
Expand Down
30 changes: 28 additions & 2 deletions pkg/networkmanager/networkmanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,28 @@ func getDefaultL3Network(tm *tokenmanager.TokenManager) string {
return DefaultL3Network
}

func getTaskApi(tm *tokenmanager.TokenManager) string {
if tm.CMVersion != "" {
verLst := strings.Split(tm.CMVersion, ".")
if len(verLst) == 3 {
v1, err1 := strconv.ParseFloat(verLst[0]+"."+verLst[1], 64)
v2, err2 := strconv.Atoi(verLst[2])
if err1 != nil {
log.Errorf("error parsing float CM version: %v, error: %v", tm.CMVersion, err1)
}
if err2 != nil {
log.Errorf("error parsing int CM version: %v, error: %v", tm.CMVersion, err2)
}
if err1 == nil && err2 == nil {
if v1 < 20.2 || (v1 == 20.2 && v2 < 1) {
return TaskBaseURI
}
}
}
}
return ""
}

// SetInstanceIds performs an HTTP GET request to the API, extracts address and ID mappings, and stores them
func (nm *NetworkManager) SetInstanceIds(bigIpConfigs []cisapiv1.BigIpConfig, controllerID string) error {

Expand Down Expand Up @@ -359,11 +381,11 @@ func (nm *NetworkManager) DeleteL3Forward(instanceId, l3ForwardID string) error
func (nm *NetworkManager) GetTaskStatus(taskRef string) (string, string, error) {

// Create request
req, err := http.NewRequest("GET", nm.CMTokenManager.ServerURL+TaskBaseURI+taskRef, nil)
taskApi := getTaskApi(nm.CMTokenManager)
req, err := http.NewRequest("GET", nm.CMTokenManager.ServerURL+taskApi+taskRef, nil)
if err != nil {
return "", "", err
}

// Set authorization header
req.Header.Set("Authorization", "Bearer "+nm.CMTokenManager.GetToken())

Expand Down Expand Up @@ -662,6 +684,10 @@ func (fs *L3ForwardStore) addL3ForwardEntry(instanceId string, l3Forward L3Forwa
}

func getRetryTimeout(retryTimeout int) int {
// // Reset to 0 after 64 seconds
if retryTimeout >= 64 {
retryTimeout = 0
}
if retryTimeout == 0 {
retryTimeout = 1
} else {
Expand Down
8 changes: 4 additions & 4 deletions pkg/networkmanager/networkmanager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ var _ = Describe("Network Manager Tests", func() {
}`, Completed)
server.AppendHandlers(
ghttp.CombineHandlers(
ghttp.VerifyRequest("GET", TaskBaseURI+TaskRef),
ghttp.VerifyRequest("GET", TaskRef),
ghttp.RespondWithJSONEncoded(statusCodeOk, stringToJson(routeTaskSuccessResponse)),
))

Expand Down Expand Up @@ -181,7 +181,7 @@ var _ = Describe("Network Manager Tests", func() {
}`, Completed)
server.AppendHandlers(
ghttp.CombineHandlers(
ghttp.VerifyRequest("GET", TaskBaseURI+TaskRef),
ghttp.VerifyRequest("GET", TaskRef),
ghttp.RespondWithJSONEncoded(statusCodeOk, stringToJson(routeTaskSuccessResponse)),
))
routeStore[BigIP{
Expand Down Expand Up @@ -259,7 +259,7 @@ var _ = Describe("Network Manager Tests", func() {
}`, Failed)
server.AppendHandlers(
ghttp.CombineHandlers(
ghttp.VerifyRequest("GET", TaskBaseURI+TaskRef),
ghttp.VerifyRequest("GET", TaskRef),
ghttp.RespondWithJSONEncoded(statusCodeOk, stringToJson(routeTaskFailureResponse)),
))

Expand Down Expand Up @@ -302,7 +302,7 @@ var _ = Describe("Network Manager Tests", func() {
}`, Failed)
server.AppendHandlers(
ghttp.CombineHandlers(
ghttp.VerifyRequest("GET", TaskBaseURI+TaskRef),
ghttp.VerifyRequest("GET", TaskRef),
ghttp.RespondWithJSONEncoded(statusCodeOk, stringToJson(routeTaskFailureResponse)),
))

Expand Down

0 comments on commit c4abaea

Please sign in to comment.