예제 #1
0
 def Connect(self):
   _CheckTLSSupport()
   with gke.ClusterConnectionInfo(self.cluster_ref) as (ip, ca_certs):
     self.ca_certs = ca_certs
     with gke.MonkeypatchAddressChecking('kubernetes.default', ip) as endpoint:
       self.endpoint = 'https://{}/'.format(endpoint)
       with _OverrideEndpointOverrides(self._api_name, self.endpoint):
         yield self
예제 #2
0
 def testClusterConnectionInfo(self):
     new_api_adapter = self.StartPatch(
         'googlecloudsdk.api_lib.container.api_adapter.NewAPIAdapter')
     opaque_cluster_ref = object()
     gke_api = new_api_adapter.return_value
     mock_cluster = new_api_adapter.return_value.GetCluster.return_value
     ca_data = b'Lol I\'m a ca data file'
     encoded = base64.b64encode(ca_data)
     mock_cluster.masterAuth.clusterCaCertificate = encoded
     mock_cluster.endpoint = '1.1.1.1'
     with gke.ClusterConnectionInfo(opaque_cluster_ref) as (endpoint,
                                                            filename):
         gke_api.GetCluster.assert_called_once_with(opaque_cluster_ref)
         with open(filename, 'rb') as f:
             contents = f.read()
         self.assertEquals(contents, ca_data)
         self.assertEquals(endpoint, '1.1.1.1')
     self.assertFalse(os.path.exists(filename))