Skip to content

Commit

Permalink
Merge pull request #673 from micw523/yaml-list
Browse files Browse the repository at this point in the history
Extend YAML load functionality to *LIST and multi-resources
  • Loading branch information
k8s-ci-robot authored Mar 19, 2019
2 parents 374233d + c0f71c3 commit 84c057b
Show file tree
Hide file tree
Showing 14 changed files with 657 additions and 106 deletions.
3 changes: 2 additions & 1 deletion examples/create_deployment_from_yaml.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ def main():
# default location.
config.load_kube_config()
k8s_client = client.ApiClient()
k8s_api = utils.create_from_yaml(k8s_client, "nginx-deployment.yaml")
utils.create_from_yaml(k8s_client, "nginx-deployment.yaml")
k8s_api = client.ExtensionsV1beta1Api(k8s_client)
deps = k8s_api.read_namespaced_deployment("nginx-deployment", "default")
print("Deployment {0} created".format(deps.metadata.name))

Expand Down
333 changes: 268 additions & 65 deletions kubernetes/e2e_test/test_utils.py

Large diffs are not rendered by default.

60 changes: 60 additions & 0 deletions kubernetes/e2e_test/test_yaml/implicit-svclist.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
{
"kind":"ServiceList",
"apiVersion":"v1",
"items":[
{
"metadata":{
"name":"mock-3",
"labels":{
"app":"mock-3"
}
},
"spec":{
"ports": [{
"protocol": "TCP",
"port": 99,
"targetPort": 9949
}],
"selector":{
"app":"mock-3"
}
}
},
{
"metadata":{
"name":"mock-3",
"labels":{
"app":"mock-3"
}
},
"spec":{
"ports": [{
"protocol": "TCP",
"port": 99,
"targetPort": 9949
}],
"selector":{
"app":"mock-3"
}
}
},
{
"metadata":{
"name":"mock-4",
"labels":{
"app":"mock-4"
}
},
"spec":{
"ports": [{
"protocol": "TCP",
"port": 99,
"targetPort": 9949
}],
"selector":{
"app":"mock-4"
}
}
}
]
}
29 changes: 29 additions & 0 deletions kubernetes/e2e_test/test_yaml/list.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
apiVersion: v1
kind: List
items:
- apiVersion: v1
kind: Service
metadata:
name: list-service-test
spec:
ports:
- protocol: TCP
port: 80
selector:
app: list-deployment-test
- apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: list-deployment-test
labels:
app: list-deployment-test
spec:
replicas: 1
template:
metadata:
labels:
app: list-deployment-test
spec:
containers:
- name: nginx
image: nginx
47 changes: 47 additions & 0 deletions kubernetes/e2e_test/test_yaml/multi-resource-with-list.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
apiVersion: v1
kind: PodList
items:
- apiVersion: v1
kind: Pod
metadata:
name: mock-pod-0
labels:
app: mock-pod-0
spec:
containers:
- name: mock-pod-0
image: busybox
command: ['sh', '-c', 'echo Hello Kubernetes! && sleep 3600']
- apiVersion: v1
kind: Pod
metadata:
name: mock-pod-1
labels:
app: mock-pod-1
spec:
containers:
- name: mock-pod-1
image: busybox
command: ['sh', '-c', 'echo Hello Kubernetes! && sleep 3600']
---
apiVersion: apps/v1beta1
kind: Deployment
metadata:
name: mock
labels:
app: mock
spec:
replicas: 3
selector:
matchLabels:
app: mock
template:
metadata:
labels:
app: mock
spec:
containers:
- name: mock
image: nginx:1.15.4
ports:
- containerPort: 80
33 changes: 33 additions & 0 deletions kubernetes/e2e_test/test_yaml/multi-resource.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
apiVersion: v1
kind: Service
metadata:
name: mock
labels:
app: mock
spec:
ports:
- port: 99
protocol: TCP
targetPort: 9949
selector:
app: mock
---
apiVersion: v1
kind: ReplicationController
metadata:
name: mock
spec:
replicas: 1
selector:
app: mock
template:
metadata:
labels:
app: mock
spec:
containers:
- name: mock-container
image: k8s.gcr.io/pause:2.0
ports:
- containerPort: 9949
protocol: TCP
15 changes: 15 additions & 0 deletions kubernetes/e2e_test/test_yaml/namespace-list.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
apiVersion: v1
kind: NamespaceList
items:
- apiVersion: v1
kind: Namespace
metadata:
name: mock-1
labels:
name: mock-1
- apiVersion: v1
kind: Namespace
metadata:
name: mock-2
labels:
name: mock-2
50 changes: 50 additions & 0 deletions kubernetes/e2e_test/test_yaml/triple-nginx.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: triple-nginx
spec:
replicas: 3
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:1.7.9
ports:
- containerPort: 80
---
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: triple-nginx
spec:
replicas: 3
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:1.7.9
ports:
- containerPort: 80
---
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: triple-nginx
spec:
replicas: 3
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:1.7.9
ports:
- containerPort: 80
13 changes: 13 additions & 0 deletions kubernetes/e2e_test/test_yaml/yaml-conflict-first.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
apiVersion: v1
kind: Service
metadata:
name: mock-2
labels:
app: mock-2
spec:
ports:
- port: 99
protocol: TCP
targetPort: 9949
selector:
app: mock-2
33 changes: 33 additions & 0 deletions kubernetes/e2e_test/test_yaml/yaml-conflict-multi.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
apiVersion: v1
kind: Service
metadata:
name: mock-2
labels:
app: mock-2
spec:
ports:
- port: 99
protocol: TCP
targetPort: 9949
selector:
app: mock-2
---
apiVersion: v1
kind: ReplicationController
metadata:
name: mock-2
spec:
replicas: 1
selector:
app: mock-2
template:
metadata:
labels:
app: mock-2
spec:
containers:
- name: mock-container
image: k8s.gcr.io/pause:2.0
ports:
- containerPort: 9949
protocol: TCP
4 changes: 3 additions & 1 deletion kubernetes/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from .create_from_yaml import create_from_yaml
from __future__ import absolute_import

from .create_from_yaml import FailToCreateError, create_from_yaml
Loading

0 comments on commit 84c057b

Please sign in to comment.