def setup_k8s_responses(self, mock_config, mock_client, pod_name): os.environ['KUBERNETES_SERVICE_HOST'] = '127.0.0.1' os.environ['KUBERNETES_SERVICE_PORT'] = '9988' os.environ['POD_NAME'] = pod_name configuration = Configuration() configuration.host = 'http://127.0.0.1:9988' configuration.api_key = {'authorization': 'bearer T0ken'} Configuration.set_default(configuration) mock_config.return_value = None pod1 = mock.MagicMock() pod1.metadata.name = 'api-123' pod1.status.phase = 'Running' pod2 = mock.MagicMock() pod2.metadata.name = 'api-234' pod2.status.phase = 'Running' pod3 = mock.MagicMock() pod3.metadata.name = 'api-345' pod3.status.phase = 'Terminating' mock_client.CoreV1Api().list_namespaced_pod().items = [ pod1, pod2, pod3 ]
namespace = fp.read().strip() # Initialise client for the REST API used doing configuration. # # XXX Currently have a workaround here for OpenShift 4.0 beta versions # which disables verification of the certificate. If don't use this the # Python openshift/kubernetes clients will fail. We also disable any # warnings from urllib3 to get rid of the noise in the logs this creates. load_incluster_config() import urllib3 urllib3.disable_warnings() instance = Configuration() instance.verify_ssl = False Configuration.set_default(instance) api_client = DynamicClient(ApiClient()) image_stream_resource = api_client.resources.get( api_version='image.openshift.io/v1', kind='ImageStream') # Helper function for determining the correct name for the image. We # need to do this for references to image streams because of the image # lookup policy often not being correctly setup on OpenShift clusters. def resolve_image_name(name): # If the image name contains a slash, we assume it is already # referring to an image on some image registry. Even if it does # not contain a slash, it may still be hosted on docker.io.