-
Notifications
You must be signed in to change notification settings - Fork 116
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for Python first-class providers (#350)
* Add support for Python first-class providers Adds support for referring to the Kubernetes provider in a first-class manner in Python. This is accomplished using a similar method to Node - the provider is explicitly projected as a resource and users are free to instantiate it at-will and use it to create other Kubernetes resources. This commit also adds a smoke test for the feature. * Fix a few package issues 1. Fix the minimum version of the pulumi package to 0.16.10, the minimum for first-class providers 2. Hook up the smoke test to the integration test framework 3. Update the referenced version of pulumi in the provider test's requirements.txt * CR feedback: remove dead code
- Loading branch information
1 parent
2d39bf3
commit 1bd96ed
Showing
8 changed files
with
92 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
|
||
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)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
pulumi>=0.16.10,<0.17.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,3 +8,6 @@ __all__ = [ | |
"{{Group}}", | ||
{{/Groups}} | ||
] | ||
|
||
# Expose the provider directly. | ||
from .provider import Provider |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,3 +26,6 @@ | |
"settings", | ||
"storage", | ||
] | ||
|
||
# Expose the provider directly. | ||
from .provider import Provider |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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__) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters