diff --git a/pkg/azure/azure.go b/pkg/azure/azure.go index 284538d38..713f08abe 100644 --- a/pkg/azure/azure.go +++ b/pkg/azure/azure.go @@ -7,6 +7,7 @@ package azure import ( "fmt" + "regexp" "strings" "github.com/golang/glog" @@ -14,14 +15,20 @@ import ( "github.com/Azure/application-gateway-kubernetes-ingress/pkg/controllererrors" ) -// SubscriptionID is the subscription of the resource in the resourceID -type SubscriptionID string +type ( + // SubscriptionID is the subscription of the resource in the resourceID + SubscriptionID string -// ResourceGroup is the resource group in which resource is deployed in the resourceID -type ResourceGroup string + // ResourceGroup is the resource group in which resource is deployed in the resourceID + ResourceGroup string -// ResourceName is the resource name in the resourceID -type ResourceName string + // ResourceName is the resource name in the resourceID + ResourceName string +) + +var ( + operationIDRegex = regexp.MustCompile(`/operations/(.+)\?api-version`) +) // ParseResourceID gets subscriptionId, resource group, resource name from resourceID func ParseResourceID(ID string) (SubscriptionID, ResourceGroup, ResourceName) { @@ -83,3 +90,16 @@ func ConvertToClusterResourceGroup(subscriptionID SubscriptionID, resourceGroup return fmt.Sprintf("/subscriptions/%s/resourcegroups/%s/providers/Microsoft.ContainerService/managedClusters/%s", subscriptionID, split[1], split[2]), nil } + +// GetOperationIDFromPollingURL extracts operationID from pollingURL +func GetOperationIDFromPollingURL(pollingURL string) string { + operationID := "" + if pollingURL != "" { + matchGroup := operationIDRegex.FindStringSubmatch(pollingURL) + if len(matchGroup) == 2 { + operationID = matchGroup[1] + } + } + + return operationID +} diff --git a/pkg/azure/azure_test.go b/pkg/azure/azure_test.go index 0b44e7027..453667efd 100644 --- a/pkg/azure/azure_test.go +++ b/pkg/azure/azure_test.go @@ -157,5 +157,19 @@ var _ = Describe("Azure", func() { Expect(subResource).To(Equal(ResourceName(""))) }) }) + + Context("test GetOperationIDFromPollingURL func", func() { + It("should be able to parse operationID", func() { + pollingURL := "https://management.azure.com/subscriptions/87654321-abcd-1234-b193-d305572e416f/providers/Microsoft.Network/locations/eastus2/operations/c24da597-9666-4950-a9f7-10bdfa17883d?api-version=2020-05-01" + expectedOperationID := "c24da597-9666-4950-a9f7-10bdfa17883d" + Expect(GetOperationIDFromPollingURL(pollingURL)).To(Equal(expectedOperationID)) + }) + + It("should give empty string when unable to parse", func() { + pollingURL := "random" + expectedOperationID := "" + Expect(GetOperationIDFromPollingURL(pollingURL)).To(Equal(expectedOperationID)) + }) + }) }) }) diff --git a/pkg/azure/client.go b/pkg/azure/client.go index 0bf48c235..4939cfc80 100644 --- a/pkg/azure/client.go +++ b/pkg/azure/client.go @@ -197,6 +197,10 @@ func (az *azClient) UpdateGateway(appGwObj *n.ApplicationGateway) (err error) { return } + if appGwFuture.PollingURL() != "" { + glog.V(3).Infof("OperationID='%s'", GetOperationIDFromPollingURL(appGwFuture.PollingURL())) + } + // Wait until deployment finshes and save the error message err = appGwFuture.WaitForCompletionRef(az.ctx, az.appGatewaysClient.BaseClient.Client) return