Skip to content

feat: Add ScaledObject resources #2497

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 16 commits into from
Aug 14, 2025
Merged

feat: Add ScaledObject resources #2497

merged 16 commits into from
Aug 14, 2025

Conversation

dbasunag
Copy link
Contributor

@dbasunag dbasunag commented Aug 13, 2025

Short description:
More details:
What this PR does / why we need it:
Which issue(s) this PR fixes:
Special notes for reviewer:
Bug:

Summary by CodeRabbit

  • New Features

    • Added support for managing KEDA ScaledObject resources with scale targets, triggers, and optional tuning (polling, cooldowns, min/max/idle replicas, fallback, advanced settings) and validation for required fields.
  • Documentation

    • Updated generated Deployment docstrings to replace references to stopSignal with livenessProbe and reorganize related fields.
  • Chores

    • Removed the Pod manifest "resources" field from generated outputs/tests.
  • Tests

    • Reordered and adjusted resource kinds used in a generator test.

Copy link

coderabbitai bot commented Aug 13, 2025

Walkthrough

Adds ApiGroup.KEDA_SH constant and a new NamespacedResource ScaledObject with spec fields and required-field validation; removes Pod resources support in generated manifest, updates Deployment generated docstrings, and reorders/changes resource kinds in a class generator test file.

Changes

Cohort / File(s) Summary
API group constant
ocp_resources/resource.py
Adds ApiGroup.KEDA_SH = "keda.sh".
KEDA ScaledObject resource
ocp_resources/scaled_object.py
Adds ScaledObject (inherits NamespacedResource) with api_group = NamespacedResource.ApiGroup.KEDA_SH, constructor for spec fields, and to_dict() that validates required scale_target_ref and triggers and assembles spec fields (advanced, cooldownPeriod, fallback, idleReplicaCount, initialCooldownPeriod, maxReplicaCount, minReplicaCount, pollingInterval, scaleTargetRef, triggers).
Generated manifest changes
class_generator/tests/manifests/Deployment/deployment.py, class_generator/tests/manifests/Pod/pod.py
Deployment generated docstrings updated (replace stopSignal with livenessProbe, reorder container/resource doc sections); Pod generated manifest: removed resources constructor parameter, assignment, and emission from to_dict(); docstring adjusted.
Test resource-kind list changes
class_generator/tests/test_class_generator.py
Reordered and modified resource_kinds list used by test_parse_explain (kinds and order changed; test logic unchanged).

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Suggested labels

size/L, can-be-merged

Suggested reviewers

  • rnetser
  • myakove

Tip

🔌 Remote MCP (Model Context Protocol) integration is now available!

Pro plan users can now connect to remote MCP servers from the "Integrations" page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

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

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@redhat-qe-bot1
Copy link

Report bugs in Issues

Welcome! 🎉

This pull request will be automatically processed with the following features:

🔄 Automatic Actions

  • Reviewer Assignment: Reviewers are automatically assigned based on the OWNERS file in the repository root
  • Size Labeling: PR size labels (XS, S, M, L, XL, XXL) are automatically applied based on changes
  • Issue Creation: A tracking issue is created for this PR and will be closed when the PR is merged or closed
  • Pre-commit Checks: pre-commit runs automatically if .pre-commit-config.yaml exists
  • Branch Labeling: Branch-specific labels are applied to track the target branch
  • Auto-verification: Auto-verified users have their PRs automatically marked as verified

📋 Available Commands

PR Status Management

  • /wip - Mark PR as work in progress (adds WIP: prefix to title)
  • /wip cancel - Remove work in progress status
  • /hold - Block PR merging (approvers only)
  • /hold cancel - Unblock PR merging
  • /verified - Mark PR as verified
  • /verified cancel - Remove verification status

Review & Approval

  • /lgtm - Approve changes (looks good to me)
  • /approve - Approve PR (approvers only)
  • /automerge - Enable automatic merging when all requirements are met (maintainers and approvers only)
  • /assign-reviewers - Assign reviewers based on OWNERS file
  • /assign-reviewer @username - Assign specific reviewer
  • /check-can-merge - Check if PR meets merge requirements

Testing & Validation

  • /retest tox - Run Python test suite with tox
  • /retest python-module-install - Test Python package installation
  • /retest conventional-title - Validate commit message format
  • /retest all - Run all available tests

Container Operations

  • /build-and-push-container - Build and push container image (tagged with PR number)
    • Supports additional build arguments: /build-and-push-container --build-arg KEY=value

Cherry-pick Operations

  • /cherry-pick <branch> - Schedule cherry-pick to target branch when PR is merged
    • Multiple branches: /cherry-pick branch1 branch2 branch3

Label Management

  • /<label-name> - Add a label to the PR
  • /<label-name> cancel - Remove a label from the PR

✅ Merge Requirements

This PR will be automatically approved when the following conditions are met:

  1. Approval: /approve from at least one approver
  2. LGTM Count: Minimum 0 /lgtm from reviewers
  3. Status Checks: All required status checks must pass
  4. No Blockers: No WIP, hold, or conflict labels
  5. Verified: PR must be marked as verified (if verification is enabled)

📊 Review Process

Approvers and Reviewers

Approvers:

  • myakove
  • rnetser

Reviewers:

  • dbasunag
  • myakove
  • rnetser
Available Labels
  • hold
  • verified
  • wip
  • lgtm
  • approve
  • automerge

💡 Tips

  • WIP Status: Use /wip when your PR is not ready for review
  • Verification: The verified label is automatically removed on each new commit
  • Cherry-picking: Cherry-pick labels are processed when the PR is merged
  • Container Builds: Container images are automatically tagged with the PR number
  • Permission Levels: Some commands require approver permissions
  • Auto-verified Users: Certain users have automatic verification and merge privileges

For more information, please refer to the project documentation or contact the maintainers.

@dbasunag
Copy link
Contributor Author

/verified

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Nitpick comments (2)
ocp_resources/scaled_object.py (2)

16-29: Tighten the type of triggers for clarity and correctness.

triggers are objects with well-defined fields (e.g., type/metadata/authRef). Using list[dict[str, Any]] improves readability and static analysis without being overly strict.

Apply this diff to refine the annotation:

-        triggers: list[Any] | None = None,
+        triggers: list[dict[str, Any]] | None = None,

30-52: Docstring nit: minor grammar polish.

"AdvancedConfig specifies advance scaling options" → "AdvancedConfig specifies advanced scaling options".

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 0bc2e5c and eac94e1.

⛔ Files ignored due to path filters (2)
  • class_generator/schema/__resources-mappings.json.gz is excluded by !**/*.gz, !class_generator/schema/**
  • class_generator/schema/_definitions.json is excluded by !class_generator/schema/**
📒 Files selected for processing (2)
  • ocp_resources/resource.py (1 hunks)
  • ocp_resources/scaled_object.py (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
ocp_resources/scaled_object.py (2)
ocp_resources/resource.py (4)
  • NamespacedResource (1533-1643)
  • ApiGroup (466-573)
  • to_dict (734-738)
  • to_dict (1641-1643)
ocp_resources/exceptions.py (1)
  • MissingRequiredArgumentError (5-10)
🔇 Additional comments (2)
ocp_resources/resource.py (1)

508-508: ApiGroup.KEDA_SH constant looks correct and unblocker for KEDA resources.

The value "keda.sh" matches KEDA's API group and will allow resolving apiVersion dynamically for ScaledObject.

ocp_resources/scaled_object.py (1)

9-15: LGTM: Correct API group for KEDA ScaledObject.

Setting api_group to NamespacedResource.ApiGroup.KEDA_SH is accurate and aligns with dynamic apiVersion resolution in the base class.

@myakove
Copy link
Collaborator

myakove commented Aug 13, 2025

@dbasunag on which cluster version did you update the schema? (k8s version - from oc version)

@dbasunag
Copy link
Contributor Author

dbasunag commented Aug 13, 2025

@myakove this is the cluster information

dbasunag@dbasunag-mac opendatahub-tests % oc get clusterversion
NAME      VERSION   AVAILABLE   PROGRESSING   SINCE   STATUS
version   4.18.20   True        False         9d      Cluster version is 4.18.20
dbasunag@dbasunag-mac opendatahub-tests % 

But this cluster is borrowed from the team the requires this resource.
k8s version is v1.31.10

@dbasunag
Copy link
Contributor Author

/verified

Copy link

@coderabbitai coderabbitai bot left a comment

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 (3)
class_generator/tests/test_class_generator.py (3)

94-109: Consider adding ScaledObject to generator coverage (optional)

Given this PR introduces the ScaledObject resource, consider adding "ScaledObject" here after you commit its golden(s), to keep generator coverage aligned with newly supported resources.

Apply this update when the golden exists:

 resource_kinds = [
     "Pod",
     "Pipeline",
     "OAuth",
     "ClusterOperator",
     "ImageContentSourcePolicy",
     "ServiceMeshMember",
     "NMState",
     "Deployment",
     "Machine",
     "APIServer",
     "Secret",
     "ConfigMap",
     "DNS",
+    "ScaledObject",
     "ServingRuntime",
     "RouteAdvertisements",
 ]

44-45: Use content-based comparison to avoid shallow stat-equality edge cases

filecmp.cmp defaults to shallow=True; using shallow=False makes the check robust against rare stat-based false positives.

Apply:

-            if not filecmp.cmp(output_file, expected_file):
+            if not filecmp.cmp(output_file, expected_file, shallow=False):

114-115: Right-size the thread pool to the workload (optional)

Scaling max_workers to the actual list size avoids spinning up surplus threads when resource_kinds is small.

-    with ThreadPoolExecutor(max_workers=8) as executor:
+    workers = min(8, len(resource_kinds))
+    with ThreadPoolExecutor(max_workers=workers) as executor:
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between eac94e1 and 94d86c4.

⛔ Files ignored due to path filters (2)
  • class_generator/schema/__resources-mappings.json.gz is excluded by !**/*.gz, !class_generator/schema/**
  • class_generator/schema/_definitions.json is excluded by !class_generator/schema/**
📒 Files selected for processing (5)
  • class_generator/tests/manifests/Deployment/deployment.py (4 hunks)
  • class_generator/tests/manifests/Pod/pod.py (5 hunks)
  • class_generator/tests/test_class_generator.py (1 hunks)
  • ocp_resources/resource.py (1 hunks)
  • ocp_resources/scaled_object.py (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • ocp_resources/scaled_object.py
  • ocp_resources/resource.py
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (9)
  • GitHub Check: can-be-merged
  • GitHub Check: can-be-merged
  • GitHub Check: can-be-merged
  • GitHub Check: can-be-merged
  • GitHub Check: can-be-merged
  • GitHub Check: can-be-merged
  • GitHub Check: python-module-install
  • GitHub Check: conventional-title
  • GitHub Check: tox
🔇 Additional comments (2)
class_generator/tests/test_class_generator.py (1)

94-109: Golden manifests for Pipeline and OAuth found — no test break expected

Verified that matching manifest directories and files exist:

  • class_generator/tests/manifests/Pipeline/pipeline.py
  • class_generator/tests/manifests/OAuth/oauth.py

No further action required.

class_generator/tests/manifests/Deployment/deployment.py (1)

96-99: Docstring refresh aligns with current oc explain (v1.31) — LGTM

Updates livenessProbe placement and scheduling/security fields organization in line with modern schema. No functional/API changes. Looks good.

Also applies to: 134-137, 172-172, 202-209

@myakove myakove merged commit 265c96a into RedHatQE:main Aug 14, 2025
6 of 7 checks passed
myakove pushed a commit that referenced this pull request Aug 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants