-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #264 from bjwswang/dp
feat: add kubeenv for data processing
- Loading branch information
Showing
13 changed files
with
131 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import os | ||
|
||
from custom_resources import (arcadia_resource_datasets, | ||
arcadia_resource_datasources, | ||
arcadia_resource_versioneddatasets) | ||
from kubernetes import client, config | ||
from kubernetes.client import CustomObjectsApi | ||
|
||
|
||
class NamespacedName: | ||
def __init__(self, namespace, name): | ||
self.namespace = namespace | ||
self.name = name | ||
|
||
def get_namespace(self): | ||
return self.namespace | ||
|
||
def get_name(self): | ||
return self.name | ||
|
||
|
||
class KubeEnv: | ||
def __init__(self): | ||
self.pod_namespace = os.environ.get('POD_NAMESPACE') | ||
self.kubeconfig_path = os.environ.get('KUBECONFIG') | ||
if self.kubeconfig_path: | ||
print("load kubeconfig from ", self.kubeconfig_path) | ||
config.load_kube_config(self.kubeconfig_path) | ||
else: | ||
try: | ||
print("try load kubeconfig from incluster config") | ||
config.load_incluster_config() | ||
except config.ConfigException: | ||
raise RuntimeError( | ||
"Failed to load incluster config. Make sure the code is running inside a Kubernetes cluster.") | ||
|
||
def list_datasources(self, namespace: str, **kwargs): | ||
return CustomObjectsApi().list_namespaced_custom_object( | ||
arcadia_resource_datasources.get_group(), | ||
arcadia_resource_datasources.get_version(), | ||
namespace, | ||
arcadia_resource_datasources.get_name(), | ||
**kwargs | ||
) | ||
|
||
def list_datasets(self, namespace: str, **kwargs): | ||
return CustomObjectsApi().list_namespaced_custom_object( | ||
arcadia_resource_datasets.get_group(), | ||
arcadia_resource_datasets.get_version(), | ||
namespace, arcadia_resource_datasets.get_name(), | ||
**kwargs | ||
) | ||
|
||
def list_versioneddatasets(self, namespace: str, **kwargs): | ||
return CustomObjectsApi().list_namespaced_custom_object( | ||
arcadia_resource_versioneddatasets.get_group(), | ||
arcadia_resource_versioneddatasets.get_version(), | ||
namespace, arcadia_resource_versioneddatasets.get_name(), | ||
**kwargs | ||
) |
30 changes: 30 additions & 0 deletions
30
data-processing/data_manipulation/kube/custom_resources.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
class GroupVersion: | ||
def __init__(self, name, version): | ||
self.name = name | ||
self.version = version | ||
|
||
|
||
class CustomResource: | ||
def __init__(self, group_version, name): | ||
self.group_version = group_version | ||
self.name = name | ||
|
||
def get_group(self): | ||
return self.group_version.name | ||
|
||
def get_version(self): | ||
return self.group_version.version | ||
|
||
def get_name(self): | ||
return self.name | ||
|
||
|
||
# Arcadia | ||
arcadia_group = GroupVersion("arcadia.kubeagi.k8s.com.cn", "v1alpha1") | ||
# CRD Datasource | ||
arcadia_resource_datasources = CustomResource(arcadia_group, "datasources") | ||
# CRD Dataset | ||
arcadia_resource_datasets = CustomResource(arcadia_group, "datasets") | ||
# CRD Versioneddataset | ||
arcadia_resource_versioneddatasets = CustomResource( | ||
arcadia_group, "versioneddatasets") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,7 @@ | |
import re | ||
|
||
import zhipuai | ||
|
||
from common import config | ||
|
||
### | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,8 +25,10 @@ | |
### | ||
|
||
import re | ||
|
||
from common import special_characters | ||
|
||
|
||
### | ||
# 去除不可见字符 | ||
# @author: wangxinbiao | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,7 @@ | |
|
||
import psycopg2.extras | ||
|
||
|
||
async def execute_sql(conn,sql,record_to_select): | ||
''' | ||
执行sql语句 | ||
|