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 support for Python first-class providers #350

Merged
merged 3 commits into from
Jan 17, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions examples/python/provider/Pulumi.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
name: provider
description: A program that smoke-tests Kubernetes first-class providers
runtime: python
32 changes: 32 additions & 0 deletions examples/python/provider/__main__.py
Original file line number Diff line number Diff line change
@@ -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()
hausdorff marked this conversation as resolved.
Show resolved Hide resolved

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))
1 change: 1 addition & 0 deletions examples/python/provider/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pulumi>=0.16.10,<0.17.0
17 changes: 17 additions & 0 deletions examples/python/python_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
3 changes: 3 additions & 0 deletions pkg/gen/python-templates/root__init__.py.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,6 @@ __all__ = [
"{{Group}}",
{{/Groups}}
]

# Expose the provider directly.
from .provider import Provider
3 changes: 3 additions & 0 deletions sdk/python/pulumi_kubernetes/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,6 @@
"settings",
"storage",
]

# Expose the provider directly.
from .provider import Provider
32 changes: 32 additions & 0 deletions sdk/python/pulumi_kubernetes/provider.py
Original file line number Diff line number Diff line change
@@ -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__)
2 changes: 1 addition & 1 deletion sdk/python/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)