Skip to content

Minor k8s fixes #11

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

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,11 @@ def run(self, image, mount_path, persistent_volume,
"""
name = self.generate_random_name()

storage_class = self.client.create_local_storageclass()

self.client.create_local_pv(
name,
storage_class=self.context["kubernetes"]["storageclass"],
storage_class=storage_class,
size=persistent_volume["size"],
volume_mode=persistent_volume["volume_mode"],
local_path=persistent_volume["local_path"],
Expand All @@ -67,7 +69,7 @@ def run(self, image, mount_path, persistent_volume,
self.client.create_local_pvc(
name,
namespace=self.namespace,
storage_class=self.context["kubernetes"]["storageclass"],
storage_class=storage_class,
access_modes=persistent_volume_claim["access_modes"],
size=persistent_volume_claim["size"]
)
Expand Down Expand Up @@ -120,3 +122,5 @@ def run(self, image, mount_path, persistent_volume,
name,
status_wait=status_wait
)

self.client.delete_local_storageclass(storage_class)
43 changes: 27 additions & 16 deletions rally_plugins/services/kube/kube.py
Original file line number Diff line number Diff line change
Expand Up @@ -686,7 +686,7 @@ def delete_rc(self, name, namespace, status_wait=True):

@atomic.action_timer("kubernetes.get_replicaset")
def get_replicaset(self, name, namespace, **kwargs):
return self.v1beta1_ext.read_namespaced_replica_set(
return self.v1_apps.read_namespaced_replica_set(
name=name,
namespace=namespace
)
Expand Down Expand Up @@ -715,7 +715,7 @@ def create_replicaset(self, name, namespace, replicas, image,
container_spec["command"] = list(command)

manifest = {
"apiVersion": "extensions/v1beta1",
"apiVersion": "apps/v1",
"kind": "ReplicaSet",
"metadata": {
"name": name,
Expand Down Expand Up @@ -748,7 +748,7 @@ def create_replicaset(self, name, namespace, replicas, image,
if not self._spec.get("serviceaccounts"):
del manifest["spec"]["template"]["spec"]["serviceAccountName"]

self.v1beta1_ext.create_namespaced_replica_set(
self.v1_apps.create_namespaced_replica_set(
namespace=namespace,
body=manifest
)
Expand All @@ -766,7 +766,7 @@ def create_replicaset(self, name, namespace, replicas, image,

@atomic.action_timer("kubernetes.scale_replicaset")
def scale_replicaset(self, name, namespace, replicas, status_wait=True):
self.v1beta1_ext.patch_namespaced_replica_set(
self.v1_apps.patch_namespaced_replica_set(
name=name,
namespace=namespace,
body={"spec": {"replicas": replicas}}
Expand All @@ -789,7 +789,7 @@ def delete_replicaset(self, name, namespace, status_wait=True):
:param namespace: replicaset namespace
:param status_wait: wait for termination if True
"""
self.v1beta1_ext.delete_namespaced_replica_set(
self.v1_apps.delete_namespaced_replica_set(
name=name,
namespace=namespace,
body=k8s_config.V1DeleteOptions()
Expand All @@ -804,7 +804,7 @@ def delete_replicaset(self, name, namespace, status_wait=True):

@atomic.action_timer("kubernetes.get_deployment")
def get_deployment(self, name, namespace, **kwargs):
return self.v1beta1_ext.read_namespaced_deployment_status(
return self.v1_apps.read_namespaced_deployment_status(
name=name,
namespace=namespace
)
Expand Down Expand Up @@ -840,7 +840,7 @@ def create_deployment(self, name, namespace, replicas, image,
container_spec["resources"] = resources

manifest = {
"apiVersion": "extensions/v1beta1",
"apiVersion": "apps/v1",
"kind": "Deployment",
"metadata": {
"name": name,
Expand All @@ -849,6 +849,11 @@ def create_deployment(self, name, namespace, replicas, image,
}
},
"spec": {
"selector": {
"matchLabels": {
"app": app
}
},
"replicas": replicas,
"template": {
"metadata": {
Expand All @@ -868,7 +873,7 @@ def create_deployment(self, name, namespace, replicas, image,
if not self._spec.get("serviceaccounts"):
del manifest["spec"]["template"]["spec"]["serviceAccountName"]

self.v1beta1_ext.create_namespaced_deployment(
self.v1_apps.create_namespaced_deployment(
namespace=namespace,
body=manifest
)
Expand Down Expand Up @@ -912,7 +917,7 @@ def rollout_deployment(self, name, namespace, changes, replicas,
"exclusive keys: image, env, resources."
)

self.v1beta1_ext.patch_namespaced_deployment(
self.v1_apps.patch_namespaced_deployment(
name=name,
namespace=namespace,
body=deployment
Expand All @@ -935,7 +940,7 @@ def delete_deployment(self, name, namespace, status_wait=True):
:param namespace: deployment namespace
:param status_wait: wait for termination if True
"""
self.v1beta1_ext.delete_namespaced_deployment(
self.v1_apps.delete_namespaced_deployment(
name=name,
namespace=namespace,
body=k8s_config.V1DeleteOptions()
Expand Down Expand Up @@ -1201,7 +1206,7 @@ def list_filtered_nodes(self, node_labels=None):

@atomic.action_timer("kubernetes.get_daemonset")
def get_daemonset(self, name, namespace, **kwargs):
return self.v1beta1_ext.read_namespaced_daemon_set(
return self.v1_apps.read_namespaced_daemon_set(
name,
namespace=namespace
)
Expand Down Expand Up @@ -1231,12 +1236,17 @@ def create_daemonset(self, namespace, image,
container_spec["command"] = list(command)

manifest = {
"apiVersion": "extensions/v1beta1",
"apiVersion": "apps/v1",
"kind": "DaemonSet",
"metadata": {
"name": name
},
"spec": {
"selector": {
"matchLabels": {
"app": app
}
},
"template": {
"metadata": {
"name": name,
Expand All @@ -1246,7 +1256,8 @@ def create_daemonset(self, namespace, image,
},
"spec": {
"serviceAccountName": namespace,
"containers": [container_spec]
"containers": [container_spec],
"nodeSelector": node_labels
}
}
}
Expand All @@ -1255,7 +1266,7 @@ def create_daemonset(self, namespace, image,
if not self._spec.get("serviceaccounts"):
del manifest["spec"]["template"]["spec"]["serviceAccountName"]

self.v1beta1_ext.create_namespaced_daemon_set(
self.v1_apps.create_namespaced_daemon_set(
namespace=namespace,
body=manifest
)
Expand Down Expand Up @@ -1316,7 +1327,7 @@ def delete_daemonset(self, name, namespace, status_wait=True):
:param namespace: daemon set namespace
:param status_wait: wait for termination if True
"""
self.v1beta1_ext.delete_namespaced_daemon_set(
self.v1_apps.delete_namespaced_daemon_set(
name,
namespace=namespace,
body=k8s_config.V1DeleteOptions()
Expand Down Expand Up @@ -1389,7 +1400,7 @@ def create_local_pv(self, name, storage_class, size, volume_mode,
"accessModes": access_modes,
"persistentVolumeReclaimPolicy": "Retain",
"storageClassName": storage_class,
"local": {
"hostPath": {
"path": local_path
},
"nodeAffinity": node_affinity
Expand Down