Skip to content

Tag the gate resource group with CreatedOn when it is created - #1865

Open
Ewerton Scaboro da Silva (ewertons) wants to merge 2 commits into
mainfrom
fix/tag-gate-resource-groups-on-creation
Open

Tag the gate resource group with CreatedOn when it is created#1865
Ewerton Scaboro da Silva (ewertons) wants to merge 2 commits into
mainfrom
fix/tag-gate-resource-groups-on-creation

Conversation

@ewertons

Copy link
Copy Markdown
Contributor

What

One line: tag the gate resource group with CreatedOn as part of az group create.

-    az group create --name $ResourceGroup --location $Region --output none
+    az group create --name $ResourceGroup --location $Region --tags "CreatedOn=$([datetime]::UtcNow.ToString('o'))" --output none

Why

The scheduled cleanup that deletes leftover javasdkgate* groups lives in the C# repo (Azure/azure-iot-sdk-csharp, vsts/resource-group-cleanup.yaml) — it handles javasdkgate* and dotnetsdkgate* together. Today it deletes every matching group unconditionally, with no age check, including groups belonging to a Java gate run that is still executing. When it fires mid-run it removes that run's IoT hub, DPS instance and storage account, and the run fails on unrelated errors.

Azure/azure-iot-sdk-csharp#3538 fixes that by only deleting a group once it is at least 3 h old, judged by a CreatedOn tag.

Groups created here carry no tags at all, so without this change every Java gate group lands on the slower fallback path that PR keeps for untagged groups (stamp on first sight, delete after 24 h). They would still be cleaned up and still be safe from mid-run deletion — just reclaimed roughly a day later than necessary. This restores the fast 3 h path.

Two details

  • Tagged during creation, not after. A separate follow-up call would leave a window where a run that dies mid-setup leaves an untagged group behind — the same class of bug being fixed elsewhere in this family.
  • A single tag, on purpose. Under the AzureCLI@2 task, --tags with several key=value arguments collapses them into one tag value. Azure/iot-sdks-e2e-fx already hit this (d87ebbb). One pair has nothing to collapse.

Ordering

Independent of Azure/azure-iot-sdk-csharp#3538 and safe to merge in either order. Before it, this tag is simply unused; after it, it moves Java groups onto the fast path.

Testing

I have no ARM credential in this environment, so this is not verified against live Azure — please confirm on a gate run.

Verified locally with PowerShell 7.4.6: the script parses clean, the tag reaches az as a single argument token (CreatedOn=2026-08-24T20:17:00.0327400Z, confirmed by argument-count check, so the collapsing bug cannot apply), and the value round-trips through the exact [datetimeoffset]::Parse(..., AssumeUniversal) call the cleanup uses to judge age.

The existing behaviour is otherwise untouched: the group is still only created when az group exists reports False, so a pre-existing group is not retagged.

The scheduled cleanup that deletes leftover 'javasdkgate*' resource groups
lives in Azure/azure-iot-sdk-csharp (vsts/resource-group-cleanup.yaml). It used
to delete every matching group unconditionally, including groups belonging to a
Java gate run that was still executing, which tore that run's IoT hub, DPS
instance and storage account away mid-run.

That cleanup is being changed to only delete a group once it is at least three
hours old, judged by a 'CreatedOn' tag. Groups created here carry no tags at
all, so without this change every Java gate group falls onto the slower
fallback path the cleanup keeps for untagged groups, and lingers about a day
before it is reclaimed.

Set the tag as part of `az group create` rather than in a following call, so a
run that dies mid-setup cannot leave a group with no tag. A single tag is
passed deliberately: under the AzureCLI@2 task, '--tags' with several key=value
arguments collapses them into one tag value.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Tags Java gate resource groups at creation so scheduled cleanup can apply age-based deletion safely.

Changes:

  • Adds an ISO 8601 UTC CreatedOn tag to az group create.
  • Documents why tagging must be atomic and limited to one tag.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

The comment claimed a failed second tagging call leaves the group untagged
forever. The scheduled cleanup stamps an untagged group and deletes it once the
stamp ages, so the real consequence is the slower 24-hour fallback rather than
the 3-hour path.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants