AKS icon indicating copy to clipboard operation
AKS copied to clipboard

Cluster creation reports failure but goes on to succeed - confuses automation tooling

Open dimbleby opened this issue 6 years ago • 77 comments

What happened:

We create AKS clusters using terraform. Reasonably often we see that failing with an error like this:

waiting for creation of Managed Kubernetes Cluster "simpl-cluster-integration-2-aks-k8s" (Resource Group "simpl-cluster-integration-2-aks"): Code="InternalOperationError" Message="AKS encountered an internal error while attempting the requested Creating operation. AKS will continuously retry the requested operation until successful or a retry timeout is hit. Check back to see if the operation requires resubmission. Correlation ID: d0f19ff8-d361-8447-7250-139174c4389d, Operation ID: 0c29feeb-a9d0-418f-b429-8b1e520e120a, Timestamp: 2020-11-16T14:23:54Z, Error: addonIdentityReconciler retry failed: autorest/azure: Service returned an error. Status=403 Code=\"AuthorizationFailed\" Message=\"The client '329189cb-bb7e-47b0-852d-9535eee6569f' with object id '329189cb-bb7e-47b0-852d-9535eee6569f' does not have authorization to perform action 'Microsoft.ManagedIdentity/userAssignedIdentities/write' over scope '/subscriptions/<redacted>/resourceGroups/MC_simpl-cluster-integration-2-aks_simpl-cluster-integration-2-aks-k8s_uksouth/providers/Microsoft.ManagedIdentity/userAssignedIdentities/omsagent-simpl-cluster-integration-2-aks-k8s' or the scope is invalid. If access was recently granted, please refresh your credentials.\"."

where that client ID is AzureContainerService:

Get-AzureADObjectByObjectId -ObjectIDs 329189cb-bb7e-47b0-852d-9535eee6569f

ObjectId                             AppId                                DisplayName
--------                             -----                                -----------
329189cb-bb7e-47b0-852d-9535eee6569f 7319c514-987d-4e9b-ac3d-d38c4f427f4c AzureContainerService

Failing is OK: the issue is that after reporting failure, retries happen - and the cluster goes on to be created successfully.

This is particularly confusing for terraform, which becomes awkward to use when its state file does not match reality. When this happens it believes that the cluster does not exist, but it does, and so further attempts to manage it fail.

I'd think that other automation tools might similarly be confused: the API seems to have reported an error but then the operation succeeds anyway.

What you expected to happen:

Don't report an error if retries are still happening and the operation might yet succeed.

I guess a flag "dont-retry-after-reporting-errors" or somesuch that could be used by automation tooling would work.

How to reproduce it (as minimally and precisely as possible):

We see this only intermittently. Repro is simply to use the terraform azurerm_kubernetes_cluster resource to create a cluster.

If it becomes important to the investigation please say so and I can try to extract a suitable fragment from our larger configuration.

Anything else we need to know?:

I've also raised https://github.com/terraform-providers/terraform-provider-azurerm/issues/9342 asking whether the terraform provider can do better with this. But on reflection a report here seemed worthwhile too.

Environment:

The cluster isn't yet created at the time we hit the issue, I don't think this section is relevant.

dimbleby avatar Nov 18 '20 12:11 dimbleby

Hi dimbleby, AKS bot here :wave: Thank you for posting on the AKS Repo, I'll do my best to get a kind human from the AKS team to assist you.

I might be just a bot, but I'm told my suggestions are normally quite good, as such:

  1. If this case is urgent, please open a Support Request so that our 24/7 support team may help you faster.
  2. Please abide by the AKS repo Guidelines and Code of Conduct.
  3. If you're having an issue, could it be described on the AKS Troubleshooting guides or AKS Diagnostics?
  4. Make sure your subscribed to the AKS Release Notes to keep up to date with all that's new on AKS.
  5. Make sure there isn't a duplicate of this issue already reported. If there is, feel free to close this one and '+1' the existing issue.
  6. If you have a question, do take a look at our AKS FAQ. We place the most common ones there!

ghost avatar Nov 18 '20 12:11 ghost

Hi @dimbleby ,

thanks for reporting. That's actually a bug in our code. It did not wait long enough for the granted permission to take effect and failed. You saw the cluster later became Succeeded is because we have built auto-repair for all Failed clusters. That kicked in soon and since the granted permission took effect already, everything succeeded.

We realized the bug from internal monitoring and has fixed the issue already. It's pending a hotfix release to rollout.

yangl900 avatar Nov 20 '20 06:11 yangl900

Hi,

Great to hear that there's a bug here that's being fixed, thank you!

However I am still interested in the wider question. Bugs and errors will always happen; and an API that says "no" but means "maybe" is hard to handle - certainly for terraform because of its state file, but I'd think also for other tooling.

Could you comment on this too?

Thanks again.

dimbleby avatar Nov 20 '20 08:11 dimbleby

The API actually said "internal error" on the creation failure, if you check the Activity Log of the resource group, you will see the error. And if you do a GET right after the failure, you will see the cluster exits and in "Failed" state.

At client side, if you retry the original PUT operation again, you should see Succeeded result. If client did not retry, the back end will try to heal the cluster as well, and bring it to "Succeeded" state.

I'm not very familiar with the terraform provider, are you saying it did not retry on the internal error? or it attempted but expect the resource doesn't exist?

yangl900 avatar Nov 23 '20 07:11 yangl900

I am not that familiar with the internals of the terraform provider either. As I understand it, it did not retry: and then subsequent manual retries failed (because the cluster does exist, but terraform's state file says otherwise). But I might have the wrong end of the stick.

I think you are saying that clients should consider "internal error" as being retriable.

I will update the terraform issue to point at this discussion, hopefully someone on that project will take a look.

dimbleby avatar Nov 23 '20 11:11 dimbleby

@yangl900 Can you please share the status of this hotfix? We don't use Terraform. And we are also running into this issue in our automation. This also need to be addressed in the Kubernetes version upgrade path.

ashtewari avatar Dec 15 '20 20:12 ashtewari

I'm making some enquiries about this with my colleagues in the AKS team.

JohnRusk avatar Jan 25 '21 22:01 JohnRusk

Here are some points of background info. @dimbleby I pretty sure you already know this background info, but I'm listing it here for completeness and for reference for anyone else who reads this thread.

There are two time periods of interest:

  1. The first is during the initial operation that created (or updated) a cluster. For long running operations such as that, you can poll for status until Azure considers the operation to be completed. Details on the polling process are here https://docs.microsoft.com/en-us/azure/azure-resource-manager/management/async-operations but normally you don't need to think about it because handling of these async long running operations is automatically built into most Azure SDKs.
  2. The second timeperiod is after Azure considers the initial long-running operation to be completed. There are various issues that can affect cluster health, and AKS runs a Remediator process to attempt to automatically fix them.

The message you report AKS will continuously retry the requested operation until successful or a retry timeout is hit indicates that the issues is being addressed by the remediator. So it falls into the time period I've labelled 2, above.

I'll continue to seek additional info, and post my findings here.

JohnRusk avatar Jan 26 '21 22:01 JohnRusk

@ashtewari After looking into the details, I beileve your version of this issue, which you've logged directly with Microsoft, is probably different from what is discussed in this GitHub issue. Firstly, yours is does not contain the permissions error which yangl900 said has been hotfixed, so that hotfix is not relevant to you. Secondly, indications so far are that the remediation/retry sequence of events in your case a substantially different from those outlined by dimbleby above. So let's handle yours through Microsoft support rather than this GitHub issue.

JohnRusk avatar Jan 27 '21 19:01 JohnRusk

@dimbleby You and yangl900 have covered things fully in your comments above. I don't have anything else to add. Can you please update us here if/when you hear back from the Terraform folks?

JohnRusk avatar Jan 27 '21 19:01 JohnRusk

@JohnRusk I would like to add that a very similar issue has come up with another customer using Terraform as well, particularly with the addition of node pools. On the high level, TF takes a return status code of "failed" as the final word and failed resources do not (by design) end up in the TF state file. Instead a future run of the same code will expect to deploy the missing resource and then update the state.

With some aspects of AKS configuration being subject to remediation and Azure effectively retrying the creation of that resource "out of band" - TF was already informed of failure, marked that portion of the deployment as failed and has moved on. When the same TF code is run again with the goal of building the failed item again, TF attempts to create a resource that already exists and THAT fails, which leaves the TF state file out of sync with reality and required manual intervention to correct. I assume that the aks-remediator uses the failed provision state to help determine what to retry, however that means that a "failed" state is not the final word regarding deployment state and causes pain with 3rd party tooling.

It would be great if there was a "soft failure" or "remediation" provisioning state that would potentially allow 3rd party tools to wait for a true end state of "succeeded" or "failed".

techbunny avatar Mar 03 '21 04:03 techbunny

Thanks for the great description @techbunny . cc'ing @miwithro since I'm not actually working on this aspect of AKS myself.

What do you think @miwithro?

JohnRusk avatar Mar 03 '21 20:03 JohnRusk

Thanks @JohnRusk and @miwithro. I realize that the "internal error" is basically a soft failure, at least from Azure's point of view and this behavior probably appears anywhere a similar error is thrown, as the TF interpretation and behavior is what it is.

techbunny avatar Mar 09 '21 20:03 techbunny

We'll look into it, but in essence those are standard states from ARM that AKS adheres to, other Azure resources like VMSS can also report provisioning failures or timeouts and keep retrying to ensure the instance correctly starts (and only then bring the VMSS to succeeded).

It's likely better to discuss this with the specific client in this case, I see the thread is still open, and align with TF folks how this can have a smooth UX.

We will to bring this up on our next meeting with them.

palma21 avatar Mar 23 '21 18:03 palma21

Thanks for reaching out. I'm closing this issue as it was marked with "Answer Provided" and it hasn't had activity for 2 days.

ghost avatar Mar 26 '21 00:03 ghost

Am surprised to see this being closed. @palma21 was that your intention when you added those labels?

From my point of view: we continue to hit the problem that this issue describes and - per your update - conversation is active and ongoing.

dimbleby avatar Mar 26 '21 08:03 dimbleby

Yup you're right, closed by mistake. Re-opening

palma21 avatar Mar 30 '21 02:03 palma21

Thanks for reaching out. I'm closing this issue as it was marked with "Answer Provided" and it hasn't had activity for 2 days.

ghost avatar Apr 01 '21 06:04 ghost

The bot insists! @palma21 can you remove the labels?

dimbleby avatar Apr 01 '21 08:04 dimbleby

He's in the right, it's the human's fault

palma21 avatar Apr 14 '21 06:04 palma21