Skip to content

AUTOSCALE-551: Add argument for default tag#9046

Draft
jkyros wants to merge 1 commit into
openshift:mainfrom
jkyros:test-upstream-tags
Draft

AUTOSCALE-551: Add argument for default tag#9046
jkyros wants to merge 1 commit into
openshift:mainfrom
jkyros:test-upstream-tags

Conversation

@jkyros

@jkyros jkyros commented Jul 21, 2026

Copy link
Copy Markdown
Member

What this PR does / why we need it:

Ignore this for now, upstream is potentially adding plumbing for allowing changing the default eks: tag in aws/karpenter-provider-aws#9252, this just attempts to consume it via hypershift for ergonomic feel/smoke test reasons. Seems like it works 😄

Which issue(s) this PR fixes:

Fixes AUTOSCALE-551

Special notes for your reviewer:

Checklist:

  • Subject and description added to both, commit and PR.
  • Relevant issues have been referenced.
  • This change includes docs.
  • This change includes unit tests.

Summary by CodeRabbit

  • New Features
    • Added support for configuring a custom AWS EC2 cluster-name tag key for Karpenter-managed resources.
    • The custom key is propagated from HostedCluster to HostedControlPlane and applied to the Karpenter provider deployment via CLUSTER_NAME_TAG_KEY.
    • Default tagging behavior remains unchanged when the custom key annotation is not set.
  • Tests
    • Added an AWS-only end-to-end test validating tag-key propagation through provisioning and confirming the expected EC2 instance tagging.
  • Chores
    • Updated linting configuration for expanded Kube API linter exclusions.

@openshift-merge-bot

Copy link
Copy Markdown
Contributor

Pipeline controller notification
This repo is configured to use the pipeline controller. Second-stage tests will be triggered either automatically or after lgtm label is added, depending on the repository configuration. The pipeline controller will automatically detect which contexts are required and will utilize /test Prow commands to trigger the second stage.

For optional jobs, comment /test ? to see a list of all defined jobs. To trigger manually all jobs from second stage use /pipeline required command.

This repository is configured in: LGTM mode

@openshift-ci

openshift-ci Bot commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

Skipping CI for Draft Pull Request.
If you want CI signal for your change, please convert it to an actual PR.
You can still manually trigger a test run with /test all

@openshift-ci openshift-ci Bot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Jul 21, 2026
@openshift-ci-robot openshift-ci-robot added the jira/valid-reference Indicates that this PR references a valid Jira ticket of any type. label Jul 21, 2026
@openshift-ci-robot

openshift-ci-robot commented Jul 21, 2026

Copy link
Copy Markdown

@jkyros: This pull request references AUTOSCALE-551 which is a valid jira issue.

Warning: The referenced jira issue has an invalid target version for the target branch this PR targets: expected the story to target the "5.0.0" version, but no target version was set.

Details

In response to this:

What this PR does / why we need it:

Ignore this for now, upstream is potentially adding plumbing for allowing changing the default eks: tag in aws/karpenter-provider-aws#9252, this just attempts to consume it via hypershift for ergonomic feel/smoke test reasons. Seems like it works 😄

Which issue(s) this PR fixes:

Fixes AUTOSCALE-551

Special notes for your reviewer:

Checklist:

  • Subject and description added to both, commit and PR.
  • Relevant issues have been referenced.
  • This change includes docs.
  • This change includes unit tests.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the openshift-eng/jira-lifecycle-plugin repository.

@openshift-ci openshift-ci Bot added do-not-merge/needs-area area/api Indicates the PR includes changes for the API area/control-plane-operator Indicates the PR includes changes for the control plane operator - in an OCP release area/hypershift-operator Indicates the PR includes changes for the hypershift operator and API - outside an OCP release area/testing Indicates the PR includes changes for e2e testing and removed do-not-merge/needs-area labels Jul 21, 2026
@openshift-ci

openshift-ci Bot commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: jkyros
Once this PR has been reviewed and has the lgtm label, please assign csrwng for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@coderabbitai

coderabbitai Bot commented Jul 21, 2026

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

Adds an exported annotation constant for overriding the AWS cluster-name tag key. The HostedCluster controller mirrors this annotation to the HostedControlPlane, where the Karpenter deployment receives it as CLUSTER_NAME_TAG_KEY. A new AWS-only end-to-end test validates propagation, Karpenter readiness, node provisioning, and EC2 instance tags.

Sequence Diagram(s)

sequenceDiagram
  participant HostedCluster
  participant HostedControlPlane
  participant Karpenter
  participant AWS_EC2
  HostedCluster->>HostedControlPlane: mirror custom tag key annotation
  HostedControlPlane->>Karpenter: set CLUSTER_NAME_TAG_KEY
  Karpenter->>AWS_EC2: provision node with custom cluster tag
  AWS_EC2-->>Karpenter: return provisioned instance
  AWS_EC2-->>HostedCluster: expose custom tag with InfraID value
Loading

Suggested reviewers: muraee

🚥 Pre-merge checks | ✅ 10 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Ipv6 And Disconnected Network Test Compatibility ⚠️ Warning The new e2e test pulls public quay.io images and calls AWS EC2 APIs, so it won’t be disconnected-safe. Use mirrored/internal images and add [Skipped:Disconnected] if AWS/public connectivity cannot be removed.
✅ Passed checks (10 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title matches the main change: adding a new Karpenter tag-related argument/option for the default AWS tag key.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Stable And Deterministic Test Names ✅ Passed All added/updated test titles are static strings; no timestamps, IDs, node/namespace names, or generated values appear in titles.
Test Structure And Quality ✅ Passed Focused on one Karpenter tag-key feature, uses bounded waits/helpers, and cleans up created NodePool/workload in line with repo patterns.
Topology-Aware Scheduling Compatibility ✅ Passed No new affinity, nodeSelector, topologySpread, or replica logic was added; the changes only mirror annotations and set Karpenter env vars.
No-Weak-Crypto ✅ Passed The new code only propagates annotation strings and checks EC2 tag strings; no weak crypto or secret comparisons were added.
Container-Privileges ✅ Passed Patch only adds Karpenter annotation/env-var plumbing and a test; no privileged, host* , SYS_ADMIN, root, or allowPrivilegeEscalation settings appear in the diff.
No-Sensitive-Data-In-Logs ✅ Passed No new logs expose secrets or PII; added test logs only print annotation keys, node/instance IDs, and infraID, and implementation code adds no logging.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
control-plane-operator/controllers/hostedcontrolplane/v2/karpenter/deployment.go (1)

44-49: 🔒 Security & Privacy | 🔵 Trivial | ⚡ Quick win

No validation on the custom tag key value.

clusterNameTagKey is taken straight from the HCP annotation and injected verbatim as the AWS tag key Karpenter will use on managed EC2 instances, with no check against empty values or the reserved hypershift.openshift.io/* tag namespace. Based on learnings, AWS resource tag keys under hypershift.openshift.io/* should be treated as reserved/internal, and user-supplied tag conflicts should be rejected early rather than silently applied.

🛡️ Suggested guard
 		if clusterNameTagKey, exists := hcp.Annotations[hyperkarpenterv1.KarpenterProviderAWSClusterNameTagKey]; exists {
+			if clusterNameTagKey != "" && !strings.HasPrefix(clusterNameTagKey, "hypershift.openshift.io/") {
 			c.Env = append(c.Env, corev1.EnvVar{
 				Name:  "CLUSTER_NAME_TAG_KEY",
 				Value: clusterNameTagKey,
 			})
+			}
 		}
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@control-plane-operator/controllers/hostedcontrolplane/v2/karpenter/deployment.go`
around lines 44 - 49, Validate clusterNameTagKey before appending the
CLUSTER_NAME_TAG_KEY environment variable: reject empty values and any key
beginning with the reserved hypershift.openshift.io/ namespace. Propagate an
early error through the surrounding deployment/reconciliation path instead of
injecting the invalid annotation value.

Source: Learnings

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@test/e2e/karpenter_cluster_name_tag_test.go`:
- Around line 45-51: Remove the KarpenterProviderAWSImage annotation override
and its associated temporary TODO from the cluster setup in the test, leaving
only the intended cluster-name tag configuration. Do not reference the personal
quay.io image in CI.

---

Nitpick comments:
In
`@control-plane-operator/controllers/hostedcontrolplane/v2/karpenter/deployment.go`:
- Around line 44-49: Validate clusterNameTagKey before appending the
CLUSTER_NAME_TAG_KEY environment variable: reject empty values and any key
beginning with the reserved hypershift.openshift.io/ namespace. Propagate an
early error through the surrounding deployment/reconciliation path instead of
injecting the invalid annotation value.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository YAML (base), Central YAML (inherited)

Review profile: CHILL

Plan: Enterprise

Run ID: 8ad7f995-b540-463c-af4c-98e4e3c17ecb

📥 Commits

Reviewing files that changed from the base of the PR and between d255fd6 and 6881351.

⛔ Files ignored due to path filters (1)
  • vendor/github.com/openshift/hypershift/api/karpenter/v1/karpenter_types.go is excluded by !vendor/**, !**/vendor/**
📒 Files selected for processing (4)
  • api/karpenter/v1/karpenter_types.go
  • control-plane-operator/controllers/hostedcontrolplane/v2/karpenter/deployment.go
  • hypershift-operator/controllers/hostedcluster/hostedcluster_controller.go
  • test/e2e/karpenter_cluster_name_tag_test.go

Comment on lines +45 to +51
customTagKey := "openshift:cluster-name"
clusterOpts.Annotations = append(clusterOpts.Annotations,
fmt.Sprintf("%s=%s", hyperkarpenterv1.KarpenterProviderAWSClusterNameTagKey, customTagKey),
// TODO(jkyros): Tag stuff hasn't merged upstream yet, take this out once it has, we're just testing plumbing for now,
// this absolutely needs to come out before we merge
fmt.Sprintf("%s=%s", hyperkarpenterv1.KarpenterProviderAWSImage, "quay.io/jkyros/aws-karpenter-provider-aws:tags"),
)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🩺 Stability & Availability | 🟠 Major | ⚡ Quick win

Hardcoded personal quay.io image must be removed before merge.

The KarpenterProviderAWSImage override points at a personal fork (quay.io/jkyros/aws-karpenter-provider-aws:tags) to test unreleased upstream tag-key support. The TODO already flags this as unmergeable as-is — an unmaintained, single-user registry image is a supply-chain/availability risk if this lands in CI (image could be deleted, retagged, or become stale).

Do you want me to open a follow-up issue to track removing this once the upstream Karpenter tag-key support merges?

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@test/e2e/karpenter_cluster_name_tag_test.go` around lines 45 - 51, Remove the
KarpenterProviderAWSImage annotation override and its associated temporary TODO
from the cluster setup in the test, leaving only the intended cluster-name tag
configuration. Do not reference the personal quay.io image in CI.

@codecov

codecov Bot commented Jul 21, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 44.38%. Comparing base (8b5103a) to head (7d3fed2).
⚠️ Report is 164 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #9046      +/-   ##
==========================================
+ Coverage   43.50%   44.38%   +0.87%     
==========================================
  Files         771      781      +10     
  Lines       95722    98709    +2987     
==========================================
+ Hits        41648    43816    +2168     
- Misses      51174    51827     +653     
- Partials     2900     3066     +166     
Files with missing lines Coverage Δ
...lers/hostedcontrolplane/v2/karpenter/deployment.go 100.00% <100.00%> (ø)
...trollers/hostedcluster/hostedcluster_controller.go 54.69% <100.00%> (-0.03%) ⬇️

... and 95 files with indirect coverage changes

Flag Coverage Δ
cmd-support 38.39% <ø> (+1.26%) ⬆️
cpo-hostedcontrolplane 47.21% <100.00%> (+1.70%) ⬆️
cpo-other 45.25% <ø> (+0.14%) ⬆️
hypershift-operator 54.22% <100.00%> (+0.56%) ⬆️
other 33.84% <ø> (+1.75%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@jkyros
jkyros force-pushed the test-upstream-tags branch from 6881351 to a44501e Compare July 21, 2026 17:36
Upstream is potentially adding plumbing for allowing changing the
default eks: tag, so this just attempts to consume it via hypershift for
ergonomic feel/smoke test reasons. It seems like it works.

Signed-off-by: John Kyros <jkyros@redhat.com>
@jkyros
jkyros force-pushed the test-upstream-tags branch from a44501e to 7d3fed2 Compare July 21, 2026 20:26

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In
`@control-plane-operator/controllers/hostedcontrolplane/v2/karpenter/component_test.go`:
- Around line 118-119: Update the table-driven test case name in the Karpenter
component tests to follow the required “When ... it should ...” format,
capitalizing the opening word and polishing the wording while preserving the
described annotation and CLUSTER_NAME_TAG_KEY behavior.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository YAML (base), Central YAML (inherited)

Review profile: CHILL

Plan: Enterprise

Run ID: 3c0b3a1d-83dc-4c67-8da4-16e3513401d3

📥 Commits

Reviewing files that changed from the base of the PR and between a44501e and 7d3fed2.

⛔ Files ignored due to path filters (1)
  • vendor/github.com/openshift/hypershift/api/karpenter/v1/karpenter_types.go is excluded by !vendor/**, !**/vendor/**
📒 Files selected for processing (6)
  • api/.golangci.yml
  • api/karpenter/v1/karpenter_types.go
  • control-plane-operator/controllers/hostedcontrolplane/v2/karpenter/component_test.go
  • control-plane-operator/controllers/hostedcontrolplane/v2/karpenter/deployment.go
  • hypershift-operator/controllers/hostedcluster/hostedcluster_controller.go
  • test/e2e/karpenter_cluster_name_tag_test.go
🚧 Files skipped from review as they are similar to previous changes (4)
  • hypershift-operator/controllers/hostedcluster/hostedcluster_controller.go
  • control-plane-operator/controllers/hostedcontrolplane/v2/karpenter/deployment.go
  • api/karpenter/v1/karpenter_types.go
  • test/e2e/karpenter_cluster_name_tag_test.go

Comment on lines +118 to +119
{
name: "when HCP has KarpenterProviderAWSClusterNameTagKey annotation, it should set CLUSTER_NAME_TAG_KEY env var",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

Use the required When ... it should ... test-case format.

Capitalize and slightly polish the new table-driven test description to match the repository convention.

Proposed fix
-			name: "when HCP has KarpenterProviderAWSClusterNameTagKey annotation, it should set CLUSTER_NAME_TAG_KEY env var",
+			name: "When the HCP has the KarpenterProviderAWSClusterNameTagKey annotation, it should set the CLUSTER_NAME_TAG_KEY env var",
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
{
name: "when HCP has KarpenterProviderAWSClusterNameTagKey annotation, it should set CLUSTER_NAME_TAG_KEY env var",
name: "When the HCP has the KarpenterProviderAWSClusterNameTagKey annotation, it should set the CLUSTER_NAME_TAG_KEY env var",
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@control-plane-operator/controllers/hostedcontrolplane/v2/karpenter/component_test.go`
around lines 118 - 119, Update the table-driven test case name in the Karpenter
component tests to follow the required “When ... it should ...” format,
capitalizing the opening word and polishing the wording while preserving the
described annotation and CLUSTER_NAME_TAG_KEY behavior.

Source: Coding guidelines

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/api Indicates the PR includes changes for the API area/control-plane-operator Indicates the PR includes changes for the control plane operator - in an OCP release area/hypershift-operator Indicates the PR includes changes for the hypershift operator and API - outside an OCP release area/testing Indicates the PR includes changes for e2e testing do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. jira/valid-reference Indicates that this PR references a valid Jira ticket of any type.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants