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

Add CustomResource to Python SDK #543

Merged
merged 3 commits into from
Apr 24, 2019
Merged

Add CustomResource to Python SDK #543

merged 3 commits into from
Apr 24, 2019

Conversation

lblackstone
Copy link
Member

@lblackstone lblackstone commented Apr 22, 2019

Fixes #326

Based on #327

This adds CR support to the Python SDK. Here's what it currently looks like:

from pulumi_kubernetes.apiextensions import CustomResource
from pulumi_kubernetes.apiextensions.v1beta1 import CustomResourceDefinition

crd = CustomResourceDefinition(
    "foobar",
    metadata={
        "name": "foobars.stable.example.com"
    },
    spec={
        "group": "stable.example.com",
        "version": "v1",
        "scope": "Namespaced",
        "names": {
            "plural": "foobars",
            "singular": "foobar",
            "kind": "FooBar",
            "shortNames": ["fb"]
        }
    }
)

cr = CustomResource(
    "my-new-foobar-object",
    api_version="stable.example.com/v1",
    kind="FooBar",
    metadata={
        "namespace": namespace
    },
    spec={ "foo": "such amaze", "bar": "wow" }
)

Compare to the NodeJS SDK:

import * as k8s from "@pulumi/kubernetes";

new k8s.apiextensions.v1beta1.CustomResourceDefinition("foobar", {
    metadata: { name: "foobars.stable.example.com" },
    spec: {
        group: "stable.example.com",
        version: "v1",
        scope: "Namespaced",
        names: {
            plural: "foobars",
            singular: "foobar",
            kind: "FooBar",
            shortNames: ["fb"]
        }
    }
});

new k8s.apiextensions.CustomResource(
    "my-new-foobar-object",
    {
        apiVersion: "stable.example.com/v1",
        kind: "FooBar",
        metadata: {
          namespace: namespace.metadata.name,
        },
        spec: { foo: "such amaze", bar: "wow" }
    },
);

@lblackstone lblackstone marked this pull request as ready for review April 23, 2019 19:29
@lblackstone lblackstone requested a review from metral April 23, 2019 19:48
@lblackstone
Copy link
Member Author

lblackstone commented Apr 23, 2019

@hausdorff @metral Ok, I think this is ready to go. Semantics are equivalent to the NodeJS SDK, and I tested both with manual creation of CRD/CR and from a YAML manifest.

apiVersion: apiextensions.k8s.io/v1beta1
kind: CustomResourceDefinition
metadata:
  name: foos.bar.example.com
spec:
  group: bar.example.com
  versions:
    - name: v1
      served: true
      storage: true
  scope: Namespaced
  names:
    plural: foos
    singular: foo
    kind: Foo
---
apiVersion: bar.example.com/v1
kind: Foo
metadata:
  name: foobar
spec:
  foo: "such amaze"
  bar: "wow"

results in the following:

     Type                                                            Name                   Status
 +   pulumi:pulumi:Stack                                             yaml-test-python-yaml  created
 +   ├─ kubernetes:yaml:ConfigFile                                   yaml-test              created
 +   │  ├─ kubernetes:apiextensions.k8s.io:CustomResourceDefinition  foos.bar.example.com   created
 +   │  └─ kubernetes:bar.example.com:Foo                            foobar                 created
 +   └─ kubernetes:core:Namespace                                    ns                     created

Resources:
    + 5 created

__props__,
__opts__)

def translate_output_property(self, prop: str) -> str:
Copy link
Contributor

Choose a reason for hiding this comment

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

I suspect that this is going to burn us in the future, though I'm not sure what we can do about it now.

We use the _CASING tables to convert to and from kubernetesCase to python_case, but these tables are derived from the OpenAPI spec. If a custom resource defines a property that isn't in the upstream Kubernetes openAPI spec, it's going to stay in kubernetesCase, which is going to be annoying.

I don't think there's anything to do here but it's worth noting this possibility.

@lblackstone lblackstone merged commit 57dc227 into master Apr 24, 2019
@pulumi-bot pulumi-bot deleted the lblackstone/python-cr branch April 24, 2019 18:33
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.

CustomResource in Python is missing
3 participants