Skip to content

Commit

Permalink
Merge pull request #6717 from r4f4/azure-servp-fix
Browse files Browse the repository at this point in the history
OCPBUGS-4549: destroy: azure: handle `nil` responses from msgraph sdk
  • Loading branch information
openshift-merge-robot committed Jan 27, 2023
2 parents fca4137 + 420b556 commit 5ad7ab9
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions pkg/destroy/azure/azure.go
Expand Up @@ -578,14 +578,18 @@ func extractODataError(err error) error {
}

func deleteApplicationRegistrations(ctx context.Context, graphClient *msgraphsdk.GraphServiceClient, logger logrus.FieldLogger, infraID string) error {
var errorList []error

tag := fmt.Sprintf("kubernetes.io_cluster.%s=owned", infraID)
servicePrincipals, err := getServicePrincipalsByTag(ctx, graphClient, tag, infraID)
if err != nil {
return errors.Wrap(err, "failed to gather list of Service Principals by tag")
}
// msgraphsdk can return a `nil` response even if no errors occurred
if servicePrincipals == nil {
logger.Debug("Empty response from API when listing Service Principals by tag")
return nil
}

var errorList []error
for _, sp := range servicePrincipals {
appID := *sp.GetAppId()
logger := logger.WithField("appID", appID)
Expand All @@ -602,6 +606,11 @@ func deleteApplicationRegistrations(ctx context.Context, graphClient *msgraphsdk
errorList = append(errorList, err)
continue
}
// msgraphsdk can return a `nil` response even if no errors occurred
if resp == nil {
logger.Debugf("Empty response getting Application from Service Principal %s", *sp.GetDisplayName())
continue
}
apps := resp.GetValue()
if len(apps) != 1 {
err = fmt.Errorf("should have received only a single matching AppID, received %d instead", len(apps))
Expand All @@ -626,7 +635,7 @@ func getServicePrincipalsByTag(ctx context.Context, graphClient *msgraphsdk.Grap
},
}
resp, err := graphClient.ServicePrincipals().Get(ctx, &listQuery)
if err != nil {
if err != nil || resp == nil {
return nil, err
}
return resp.GetValue(), nil
Expand Down

0 comments on commit 5ad7ab9

Please sign in to comment.