Exemple #1
0
 def make_kubectl_client(self):
     options = self.make_kubectl_options()
     cluster = kubectl.Cluster(
         name=self.cluster_id,
         cert=options.pop('client-certificate'),
         server=options.pop('server'),
     )
     user = kubectl.User(
         name=constants.BCS_USER_NAME,
         token=options['token'])
     context = kubectl.Context(
         name=constants.BCS_USER_NAME,
         user=user,
         cluster=cluster
     )
     kubectl_bin_file, version = get_cluster_proper_kubectl(
         self.access_token, self.project_id, self.cluster_id)
     self.k8s_version = version
     kube_config = kubectl.KubeConfig(contexts=[context])
     with kube_config.as_tempfile() as filename:
         kubectl_client = kubectl.KubectlClusterClient(
             kubectl_bin=kubectl_bin_file,
             kubeconfig=filename,
             **options
         )
         yield kubectl_client
Exemple #2
0
 def make_helm_client(self):
     """组装携带kubeconfig的helm client"""
     options = self.make_kubectl_options()
     cluster = kubectl.Cluster(
         name=self.cluster_id,
         cert=options.pop('client-certificate'),
         server=options.pop('server'),
     )
     user = kubectl.User(name=constants.BCS_USER_NAME,
                         token=options['token'])
     context = kubectl.Context(name=constants.BCS_USER_NAME,
                               user=user,
                               cluster=cluster)
     # NOTE: 这里直接使用helm3 client bin
     kube_config = kubectl.KubeConfig(contexts=[context])
     with kube_config.as_tempfile() as filename:
         helm_client = KubeHelmClient(
             helm_bin=settings.HELM3_BIN,
             kubeconfig=filename,
         )
         yield helm_client