diff --git a/examples/python/provider/Pulumi.yaml b/examples/python/provider/Pulumi.yaml new file mode 100644 index 0000000000..cf67a9181f --- /dev/null +++ b/examples/python/provider/Pulumi.yaml @@ -0,0 +1,3 @@ +name: provider +description: A program that smoke-tests Kubernetes first-class providers +runtime: python diff --git a/examples/python/provider/__main__.py b/examples/python/provider/__main__.py new file mode 100644 index 0000000000..149d7db0f8 --- /dev/null +++ b/examples/python/provider/__main__.py @@ -0,0 +1,32 @@ +# Copyright 2016-2018, Pulumi Corporation. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +from os import path +from pulumi import ResourceOptions +from pulumi_kubernetes import Provider +from pulumi_kubernetes.core.v1 import Pod + +kubeconfig_file = path.join(path.expanduser("~"), ".kube", "config") +with open(kubeconfig_file) as f: + kubeconfig = f.read() + +my_k8s = Provider("myk8s", kubeconfig=kubeconfig) +nginx = Pod("nginx", spec={ + "containers": [{ + "image": "nginx:1.7.9", + "name": "nginx", + "ports": [{ + "container_port": 80, + }], + }], +}, __opts__=ResourceOptions(provider=my_k8s)) diff --git a/examples/python/provider/requirements.txt b/examples/python/provider/requirements.txt new file mode 100644 index 0000000000..19f57885c9 --- /dev/null +++ b/examples/python/provider/requirements.txt @@ -0,0 +1 @@ +pulumi>=0.16.10,<0.17.0 diff --git a/examples/python/python_test.go b/examples/python/python_test.go index 0917d7de39..216fbcfeb0 100644 --- a/examples/python/python_test.go +++ b/examples/python/python_test.go @@ -141,3 +141,20 @@ func TestGuestbook(t *testing.T) { }) integration.ProgramTest(t, &options) } + +// Smoke test for first-class Kubernetes providers. +func TestProvider(t *testing.T) { + kubectx := os.Getenv("KUBERNETES_CONTEXT") + if kubectx == "" { + t.Skipf("Skipping test due to missing KUBERNETES_CONTEXT variable") + } + + cwd, err := os.Getwd() + if !assert.NoError(t, err) { + t.FailNow() + } + options := baseOptions.With(integration.ProgramTestOptions{ + Dir: filepath.Join(cwd, "provider"), + }) + integration.ProgramTest(t, &options) +} diff --git a/pkg/gen/python-templates/root__init__.py.mustache b/pkg/gen/python-templates/root__init__.py.mustache index 3321a6190c..6c603bcdfd 100644 --- a/pkg/gen/python-templates/root__init__.py.mustache +++ b/pkg/gen/python-templates/root__init__.py.mustache @@ -8,3 +8,6 @@ __all__ = [ "{{Group}}", {{/Groups}} ] + +# Expose the provider directly. +from .provider import Provider diff --git a/sdk/python/pulumi_kubernetes/__init__.py b/sdk/python/pulumi_kubernetes/__init__.py index cda6d278b6..1c6e164588 100755 --- a/sdk/python/pulumi_kubernetes/__init__.py +++ b/sdk/python/pulumi_kubernetes/__init__.py @@ -26,3 +26,6 @@ "settings", "storage", ] + +# Expose the provider directly. +from .provider import Provider diff --git a/sdk/python/pulumi_kubernetes/provider.py b/sdk/python/pulumi_kubernetes/provider.py new file mode 100644 index 0000000000..2e3d15929a --- /dev/null +++ b/sdk/python/pulumi_kubernetes/provider.py @@ -0,0 +1,32 @@ +import pulumi +from . import tables + +class Provider(pulumi.ProviderResource): + """ + The provider type for the kubernetes package. + """ + def __init__(self, + __name__, + __opts__=None, + cluster=None, + context=None, + kubeconfig=None, + namespace=None): + """ + Create a Provider resource with the given unique name, arguments, and options. + + :param str __name__: The unique name of the resource. + :param pulumi.ResourceOptions __opts__: An optional bag of options that controls this resource's behavior. + :param str cluster: If present, the name of the kubeconfig cluster to use. + :param str context: If present, the name of the kubeconfig context to use. + :param str kubeconfig: The contents of a kubeconfig file. If this is set, this config will be used instead + of $KUBECONFIG. + :param str namespace: If present, the namespace scope to use. + """ + __props__ = { + "cluster": cluster, + "context": context, + "kubeconfig": kubeconfig, + "namespace": namespace, + } + super(Provider, self).__init__("kubernetes", __name__, __props__, __opts__) diff --git a/sdk/python/setup.py b/sdk/python/setup.py index 5142d1bbd4..d5d64e8160 100644 --- a/sdk/python/setup.py +++ b/sdk/python/setup.py @@ -26,6 +26,6 @@ def readme(): license='Apache-2.0', packages=find_packages(), install_requires=[ - 'pulumi>=0.16.4,<0.17.0' + 'pulumi>=0.16.10,<0.17.0' ], zip_safe=False)