Skip to content
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
51 changes: 17 additions & 34 deletions ocp_resources/backup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,48 +5,31 @@

class Backup(NamespacedResource):
"""
Backup object.
Backup in 'velero' official API:
https://velero.io/docs/v0.7.1/api-types/backup/
"""

api_group = NamespacedResource.ApiGroup.VELERO_IO

def __init__(
self,
name=None,
namespace=None,
included_namespaces=None,
client=None,
teardown=False,
privileged_client=None,
yaml_file=None,
excluded_resources=None,
**kwargs,
):
if not included_namespaces:
raise ValueError("included_namespaces can't be None")

super().__init__(
name=name,
namespace=namespace,
client=client,
teardown=teardown,
privileged_client=privileged_client,
yaml_file=yaml_file,
**kwargs,
)
def __init__(self, included_namespaces=None, excluded_resources=None, **kwargs):
"""
Args:
included_namespaces (list, optional): Namespaces to include in the backup.
If unspecified, all namespaces are included.
excluded_resources (list, optional): Resources to exclude from the backup.
Resources may be shortcuts (e.g. 'po' for 'pods') or fully-qualified.
"""
super().__init__(**kwargs)
self.included_namespaces = included_namespaces
self.excluded_resources = excluded_resources

def to_dict(self):
super().to_dict()
if not self.yaml_file:
self.res.update(
{
"spec": {
"includedNamespaces": self.included_namespaces,
}
}
)

spec_dict = {}
if self.included_namespaces:
spec_dict.update({"includedNamespaces": self.included_namespaces})
if self.excluded_resources:
self.res["spec"]["excludedResources"] = self.excluded_resources
spec_dict.update({"excludedResources": self.excluded_resources})
if spec_dict:
self.res.update({"spec": spec_dict})
36 changes: 7 additions & 29 deletions ocp_resources/cluster_role.py
Original file line number Diff line number Diff line change
@@ -1,51 +1,29 @@
# -*- coding: utf-8 -*-
from ocp_resources.constants import TIMEOUT_4MINUTES
from ocp_resources.resource import Resource


class ClusterRole(Resource):
"""
ClusterRole object
ClusterRole in kubernetes 'authorization-resources' official API:
https://kubernetes.io/docs/reference/kubernetes-api/authorization-resources/cluster-role-v1/
"""

api_group = Resource.ApiGroup.RBAC_AUTHORIZATION_K8S_IO

def __init__(
self,
name=None,
client=None,
rules=None,
teardown=True,
yaml_file=None,
delete_timeout=TIMEOUT_4MINUTES,
**kwargs,
):
def __init__(self, rules=None, **kwargs):
"""
Args:
name (str): Role name.
client (DynamicClient): DynamicClient to use.
rules (list): list of dicts of rules. In the dict:
permissions_to_resources (list): List of string with resource/s to which you want to add permissions to.
Verbs (list): Determine the action/s (permissions) applicable on a specific resource.
Available verbs per resource can be seen with the command 'oc api-resources --sort-by name -o wide'
teardown (bool, default: True): Indicates if this resource would need to be deleted.
yaml_file (yaml, default: None): yaml file for the resource.
delete_timeout (int, default: 4 minutes): timeout associated with delete action.
"""
super().__init__(
client=client,
name=name,
teardown=teardown,
yaml_file=yaml_file,
delete_timeout=delete_timeout,
**kwargs,
)
super().__init__(**kwargs)
self.rules = rules

def to_dict(self):
if not self.rules and not self.yaml_file:
raise ValueError("must send rules or yaml_file")
if not self.res:
super().to_dict()
super().to_dict()
if not self.yaml_file:
if not self.rules:
raise ValueError("must send rules or yaml_file")
self.res["rules"] = self.rules