Skip to content
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

Unable to directly use ApiObject in python #2161

Open
iliapolo opened this issue Jun 2, 2024 · 1 comment
Open

Unable to directly use ApiObject in python #2161

iliapolo opened this issue Jun 2, 2024 · 1 comment
Labels
bug Something isn't working @component/cdk8s-core Issue related to cdk8s-core effort/medium 1 week tops priority/p1 Should be on near term plans

Comments

@iliapolo
Copy link
Member

iliapolo commented Jun 2, 2024

Description of the bug:

The ApiObject class in python doesn't allow arbitrary key values, which means it doesn't allow configuring spec, data, or whatever else belongs in the body of a resource.

Reproduction Steps:

#!/usr/bin/env python
from constructs import Construct
from cdk8s import App, Chart, ApiObject

class MyChart(Chart):
    def __init__(self, scope: Construct, id: str):
        super().__init__(scope, id)

        ApiObject(self, 'ApiObject', spec={ 'foo': 'bar' })

app = App()
MyChart(app, "pod")

app.synth()

Error Log:

TypeError: ApiObject.__init__() got an unexpected keyword argument 'spec'
Error: command "pipenv run python main.py " at /private/tmp/cdk8s-python returned a non-zero exit code 1
    at ChildProcess.<anonymous> (/opt/homebrew/lib/node_modules/cdk8s-cli/lib/util.js:54:27)
    at Object.onceWrapper (node:events:634:26)
    at ChildProcess.emit (node:events:519:28)
    at ChildProcess._handle.onexit (node:internal/child_process:294:12)

This is 🐛 Bug Report

@iliapolo iliapolo added bug Something isn't working needs-triage Priority and effort undetermined yet priority/p1 Should be on near term plans labels Jun 2, 2024
@iliapolo
Copy link
Member Author

iliapolo commented Jun 2, 2024

This is because of #2167.

https://github.com/cdk8s-team/cdk8s-core/blob/f0f5413a41915c5343a73efa49b63e6604e0be8f/src/api-object.ts#L30-L35

As a workaround, we can apply json patches:

obj = ApiObject(self, ...)
obj.add_json_patch(JsonPatch.add('/spec', {}))
obj.add_json_patch(JsonPatch.add('/spec/foo', 'bar'))

@iliapolo iliapolo added effort/medium 1 week tops and removed needs-triage Priority and effort undetermined yet labels Jun 2, 2024
@iliapolo iliapolo added the @component/cdk8s-core Issue related to cdk8s-core label Sep 20, 2024
@iliapolo iliapolo transferred this issue from cdk8s-team/cdk8s-core Sep 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working @component/cdk8s-core Issue related to cdk8s-core effort/medium 1 week tops priority/p1 Should be on near term plans
Projects
None yet
Development

No branches or pull requests

1 participant