class Client(object): def __init__(self, config, provider): ''' Args: config (obj): Object of the configuration data provider (str): String value of the provider that is being used ''' self.config = config self.provider = provider # Choose the type of provider that is being used. Error out if it is not available if provider is "kubernetes": self.connection = KubeKubernetesClient(config) logger.debug("Using Kubernetes Provider KubeClient library") else: raise KubeClientError("No provider by that name.") # Create an object using its respective API def create(self, obj, namespace="default"): self.connection.create(obj, namespace) # Delete an object using its respective API def delete(self, obj, namespace="default"): self.connection.delete(obj, namespace) # Current support: kubernetes only def namespaces(self): return self.connection.namespaces()
def test_delete(mock_class): # Mock the API class mock_class.return_value = FakeClient() mock_class.kind_to_resource_name.return_value = 'Pod' k8s_object = { "apiVersion": "v1", "kind": "Pod", "metadata": { "labels": { "app": "helloapache" }, "name": "helloapache" }, "spec": { "containers": [{ "image": "$image", "name": "helloapache", "ports": [{ "containerPort": 80, "hostPort": 80, "protocol": "TCP" }] }] } } a = KubeKubernetesClient(config) a.delete(k8s_object, "foobar")
def test_delete(mock_class): # Mock the API class mock_class.return_value = FakeClient() mock_class.kind_to_resource_name.return_value = 'Pod' k8s_object = {"apiVersion": "v1", "kind": "Pod", "metadata": {"labels": {"app": "helloapache"}, "name": "helloapache"}, "spec": { "containers": [{"image": "$image", "name": "helloapache", "ports": [{"containerPort": 80, "hostPort": 80, "protocol": "TCP"}]}]}} a = KubeKubernetesClient(config) a.delete(k8s_object, "foobar")
def __init__(self, config, provider): ''' Args: config (obj): Object of the configuration data provider (str): String value of the provider that is being used ''' self.config = config self.provider = provider # Choose the type of provider that is being used. Error out if it is not available if provider is "kubernetes": self.connection = KubeKubernetesClient(config) logger.debug("Using Kubernetes Provider KubeClient library") else: raise KubeClientError("No provider by that name.")
def __init__(self, config, provider): ''' Args: config (obj): Object of the configuration data provider (str): String value of the provider that is being used ''' self.config = config self.provider = provider # Choose the type of provider that is being used. Error out if it is not available if provider is "kubernetes": self.connection = KubeKubernetesClient(config) logger.debug("Using Kubernetes Provider KubeClient library") elif provider is "openshift": self.connection = KubeOpenshiftClient(config) logger.debug("Using OpenShift Provider KubeClient library") else: raise KubeClientError("No provider by that name.")