Skip to content

refactor: migrate /apply calls to REST endpoints for component and workload creation#253

Draft
binoyPeries wants to merge 1 commit intoopenchoreo:mainfrom
binoyPeries:role-ui-revamp
Draft

refactor: migrate /apply calls to REST endpoints for component and workload creation#253
binoyPeries wants to merge 1 commit intoopenchoreo:mainfrom
binoyPeries:role-ui-revamp

Conversation

@binoyPeries
Copy link
Contributor

@binoyPeries binoyPeries commented Feb 16, 2026

Purpose

Replace the generic POST /apply (K8s-style resource apply) calls in the openchoreo:component:create scaffolder action with the dedicated REST endpoints: createComponent and createWorkload.

  • Update OpenAPI spec to add componentType, autoDeploy, parameters, traits, and workflow fields to CreateComponentRequest, along with new ComponentTraitInput and ComponentWorkflowInput schemas
  • Refactor buildComponentResource to return a flat CreateComponentRequest body instead of a K8s-style ComponentResource wrapper
  • Refactor buildWorkloadResource to return a WorkloadBody (containers + endpoints) instead of a full WorkloadResource with apiVersion/kind/metadata
  • Replace POST /apply for component creation with POST /namespaces/{ns}/projects/{proj}/components
  • Replace POST /apply for workload creation with POST /namespaces/{ns}/projects/{proj}/components/{comp}/workloads
  • Delete componentResourceInterface.ts (K8s-style interfaces no longer needed)
  • Update tests to match new return types

Goals

Describe the solutions that this feature/fix will introduce to resolve the problems described above

Approach

Describe how you are implementing the solutions. Include an animated GIF or screenshot if the change affects the UI (email documentation@wso2.com to review all UI text). Include a link to a Markdown file or Google doc if the feature write-up is too long to paste here.

User stories

Summary of user stories addressed by this change>

Release note

Brief description of the new feature or bug fix as it will appear in the release notes

Documentation

Link(s) to product documentation that addresses the changes of this PR. If no doc impact, enter “N/A” plus brief explanation of why there’s no doc impact

Training

Link to the PR for changes to the training content in https://github.com/wso2/WSO2-Training, if applicable

Certification

Type “Sent” when you have provided new/updated certification questions, plus four answers for each question (correct answer highlighted in bold), based on this change. Certification questions/answers should be sent to certification@wso2.com and NOT pasted in this PR. If there is no impact on certification exams, type “N/A” and explain why.

Marketing

Link to drafts of marketing content that will describe and promote this feature, including product page changes, technical articles, blog posts, videos, etc., if applicable

Automation tests

  • Unit tests

    Code coverage information

  • Integration tests

    Details about the test cases and coverage

Security checks

Samples

Provide high-level details about the samples related to this feature

Related PRs

List any other related PRs

Migrations (if applicable)

Describe migration steps and platforms on which migration has been tested

Test environment

List all JDK versions, operating systems, databases, and browser/versions on which this feature/fix was tested

Learning

Describe the research phase and any blog posts, patterns, libraries, or add-ons you used to solve the problem.

Summary by CodeRabbit

  • New Features

    • Enhanced component creation with new customization options: traits support, auto-deploy flag, and improved workflow configuration capabilities.
    • Expanded workflow configuration options including system parameters for repository management.
  • Refactor

    • Streamlined API endpoints for component and workload creation with simplified request structures.
    • Updated component creation to use direct path parameters instead of embedded payload fields.

@coderabbitai
Copy link

coderabbitai bot commented Feb 16, 2026

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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

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

🤖 Fix all issues with AI agents
In `@plugins/scaffolder-backend-module-openchoreo/src/actions/component.ts`:
- Line 448: The use of a blanket type assertion "body: workloadBody as any"
masks a schema mismatch between the OpenAPI createWorkload contract and the
WorkloadBody interface; fix by making the contract and runtime shape consistent:
either update the OpenAPI schema for createWorkload to explicitly declare the
containers (required) and endpoints (optional) properties to match the
WorkloadBody interface, or validate workloadBody at runtime before sending
(e.g., check that the variable workloadBody contains the required containers
array and optional endpoints) and only then pass it as body without as any;
locate references to workloadBody, the createWorkload call, and the WorkloadBody
interface to implement the schema change or add validation.
🧹 Nitpick comments (5)
plugins/scaffolder-backend-module-openchoreo/src/actions/component.ts (2)

370-378: Consider including error response body in failure messages.

The error message only includes status code and status text, but the API likely returns useful error details in the response body. This could make debugging failures more difficult.

Suggested improvement
       if (createError || !createResponse.ok) {
+        const errorBody = createError ? JSON.stringify(createError) : 'No error details';
         throw new Error(
-          `Failed to create component: ${createResponse.status} ${createResponse.statusText}`,
+          `Failed to create component: ${createResponse.status} ${createResponse.statusText}. Details: ${errorBody}`,
         );
       }

452-457: Workload creation errors don't fail the action but log errors.

The workload creation failure is logged but doesn't throw, allowing the scaffolder action to complete successfully even when the workload setup fails. This is intentional (component was created), but the error message could be more actionable.

The current message mentions "manual configuration" but doesn't specify how. Consider adding a link or specific instructions.

plugins/scaffolder-backend-module-openchoreo/src/actions/componentResourceBuilder.test.ts (1)

228-255: Consider adding test coverage for workload edge cases.

The workload tests cover basic scenarios but could benefit from additional cases:

  1. Workload without image (should have empty containers)
  2. Workload with envVars and fileMounts
  3. Workload with endpoints map (not just legacy port)
Suggested additional tests
it('should build workload body with empty containers when no image provided', () => {
  const result = buildWorkloadResource({
    endpoints: { api: { type: 'HTTP', port: 3000 } },
  });

  expect(result.containers).toEqual({});
  expect(result.endpoints).toEqual({ api: { type: 'HTTP', port: 3000 } });
});

it('should add env vars and file mounts to container', () => {
  const result = buildWorkloadResource({
    containerImage: 'nginx:latest',
    envVars: [{ key: 'NODE_ENV', value: 'production' }],
    fileMounts: [{ key: 'config', mountPath: '/etc/config', value: 'data' }],
  });

  expect(result.containers.main.env).toEqual([{ key: 'NODE_ENV', value: 'production' }]);
  expect(result.containers.main.files).toEqual([{ key: 'config', mountPath: '/etc/config', value: 'data' }]);
});

it('should prefer endpoints map over legacy port', () => {
  const result = buildWorkloadResource({
    containerImage: 'nginx:latest',
    port: 8080,
    endpoints: { api: { type: 'REST', port: 3000 } },
  });

  expect(result.endpoints).toEqual({ api: { type: 'REST', port: 3000 } });
});
plugins/scaffolder-backend-module-openchoreo/src/actions/componentResourceBuilder.ts (2)

91-91: Type assertion as any on systemParameters.

The systemParameters: { repository } as any cast bypasses type checking. This is likely due to the secretRef field not being in the official OpenAPI schema (as mentioned in component.ts line 543-544).

Consider documenting why this assertion is needed, or update the OpenAPI schema to include secretRef if it's a supported feature.


144-147: WorkloadBody interface could be derived from OpenAPI schema.

Similar to CreateComponentRequest, the WorkloadBody interface could potentially be derived from the OpenAPI-generated types to ensure consistency. However, since the workload endpoint accepts additionalProperties: true, a local interface may be acceptable.

componentName: ctx.input.componentName,
},
},
body: workloadBody as any,
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# First, check the OpenAPI spec for workload-related schemas
rg -n -A 10 'createWorkload|WorkloadRequest|workloads:' packages/openchoreo-client-node/openapi/openchoreo-api.yaml

Repository: openchoreo/backstage-plugins

Length of output: 531


🏁 Script executed:

#!/bin/bash
# Get context around line 448 in component.ts
cat -n plugins/scaffolder-backend-module-openchoreo/src/actions/component.ts | sed -n '430,465p'

Repository: openchoreo/backstage-plugins

Length of output: 1618


🏁 Script executed:

#!/bin/bash
# Search for WorkloadBody interface definition
rg -n 'interface WorkloadBody|type WorkloadBody' plugins/scaffolder-backend-module-openchoreo/

Repository: openchoreo/backstage-plugins

Length of output: 192


🏁 Script executed:

#!/bin/bash
# Get the WorkloadBody interface definition
cat -n plugins/scaffolder-backend-module-openchoreo/src/actions/componentResourceBuilder.ts | sed -n '144,180p'

Repository: openchoreo/backstage-plugins

Length of output: 1550


🏁 Script executed:

#!/bin/bash
# Get the request body schema from OpenAPI spec for createWorkload
rg -n -A 30 'operationId: createWorkload' packages/openchoreo-client-node/openapi/openchoreo-api.yaml | grep -A 25 'requestBody'

Repository: openchoreo/backstage-plugins

Length of output: 460


Type assertion as any indicates schema mismatch that warrants review.

The body: workloadBody as any cast is necessary because the OpenAPI schema for createWorkload (defined as a generic object with additionalProperties: true) does not align with the specific WorkloadBody interface structure (containers property required, endpoints optional). The permissive OpenAPI schema forces the cast to bypass type checking, which can mask type errors if either the interface or API contract changes.

Consider either:

  • Updating the OpenAPI schema to define explicit containers and endpoints properties matching the WorkloadBody interface, or
  • Adding a runtime validation that the constructed workloadBody matches the expected shape before casting.
🤖 Prompt for AI Agents
In `@plugins/scaffolder-backend-module-openchoreo/src/actions/component.ts` at
line 448, The use of a blanket type assertion "body: workloadBody as any" masks
a schema mismatch between the OpenAPI createWorkload contract and the
WorkloadBody interface; fix by making the contract and runtime shape consistent:
either update the OpenAPI schema for createWorkload to explicitly declare the
containers (required) and endpoints (optional) properties to match the
WorkloadBody interface, or validate workloadBody at runtime before sending
(e.g., check that the variable workloadBody contains the required containers
array and optional endpoints) and only then pass it as body without as any;
locate references to workloadBody, the createWorkload call, and the WorkloadBody
interface to implement the schema change or add validation.

…rkload creation

Signed-off-by: binoyPeries <binoyperies98@gmail.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.

1 participant