From 4e8a48e4d4e8c6c921bee642c62827630622502d Mon Sep 17 00:00:00 2001 From: wangqi Date: Wed, 30 Nov 2022 16:43:00 +0800 Subject: [PATCH 1/2] feat(module): remove code referring to kubernetes --- .../internal/server/asset/assets.go | 25 +- .../prod/easy-agent-server/example-config.yml | 6 +- chengying-agent/test.go | 1 - chengying-server/go.sum | 201 +- chengying-server/matrix/api/api-schema.go | 4 - chengying-server/matrix/api/cluster-api.go | 620 ++-- .../matrix/{k8s => api}/constant/constant.go | 17 - chengying-server/matrix/api/impl/agent.go | 87 +- chengying-server/matrix/api/impl/cluster.go | 2582 +---------------- chengying-server/matrix/api/impl/common.go | 110 - chengying-server/matrix/api/impl/instance.go | 74 +- chengying-server/matrix/api/impl/product.go | 133 +- .../matrix/api/k8s/cluster-ns-api.go | 116 - .../matrix/api/k8s/impl/cluster-ns.go | 147 - .../matrix/api/k8s/impl/instance.go | 35 - .../matrix/api/k8s/impl/ns-product.go | 76 - .../matrix/api/k8s/instance-api.go | 48 - chengying-server/matrix/api/k8s/ns-product.go | 57 - .../matrix/api/k8s/view/agent-generate.go | 27 - .../matrix/api/k8s/view/clusterinfo-req.go | 43 - .../matrix/api/k8s/view/cookie.go | 21 - .../matrix/api/k8s/view/instane_replica.go | 25 - .../api/k8s/view/namespace-delete-confirm.go | 22 - .../matrix/api/k8s/view/namespace-event.go | 32 - .../matrix/api/k8s/view/namespace-get.go | 27 - .../matrix/api/k8s/view/namespace-ping.go | 24 - .../matrix/api/k8s/view/namespace-save.go | 30 - .../matrix/api/k8s/view/namespace-status.go | 34 - .../matrix/api/k8s/view/ns-product.go | 56 - chengying-server/matrix/api/product-api.go | 8 - .../{k8s => api}/web-socket/web_socket.go | 17 - chengying-server/matrix/config.go | 15 +- chengying-server/matrix/k8s/cluster/c_test.go | 41 - .../matrix/k8s/cluster/generate.go | 132 - .../matrix/k8s/cluster/import_cluster.go | 51 - .../matrix/k8s/cluster/self_build_cluster.go | 76 - .../matrix/k8s/deploy/configmap.go | 133 - chengying-server/matrix/k8s/deploy/dynamic.go | 135 - chengying-server/matrix/k8s/deploy/images.go | 171 -- chengying-server/matrix/k8s/deploy/mole.go | 103 - .../matrix/k8s/deploy/progress.go | 18 - chengying-server/matrix/k8s/deploy/secret.go | 45 - .../matrix/k8s/deploy/workloadprocess.go | 177 -- chengying-server/matrix/k8s/docker/command.go | 171 -- .../matrix/k8s/kube/cluster_ns_client.go | 82 - chengying-server/matrix/k8s/kube/interface.go | 54 - .../matrix/k8s/kube/kube_client.go | 49 - .../matrix/k8s/kube/rest_client.go | 269 -- .../matrix/k8s/model/configmap.go | 57 - chengying-server/matrix/k8s/model/defines.go | 73 - chengying-server/matrix/k8s/model/mole.go | 256 -- .../matrix/k8s/model/namespace.go | 18 - chengying-server/matrix/k8s/model/sa.go | 18 - chengying-server/matrix/k8s/model/secret.go | 62 - .../matrix/k8s/monitor/monitor.go | 22 - chengying-server/matrix/k8s/node/define.go | 35 - .../matrix/k8s/node/node_manager.go | 211 -- .../matrix/k8s/resource/agent_generate.go | 74 - .../k8s/resource/configmap/configmap.go | 71 - .../k8s/resource/deployment/deployment.go | 118 - .../matrix/k8s/resource/dryrun_test.go | 437 --- .../k8s/resource/endpoints/endpoints.go | 33 - .../matrix/k8s/resource/goroutine.go | 245 -- .../matrix/k8s/resource/instance_replica.go | 195 -- .../matrix/k8s/resource/job/job.go | 33 - .../k8s/resource/limitrange/limit_range.go | 47 - .../matrix/k8s/resource/mole/mole.go | 59 - .../k8s/resource/namespace_client_info.go | 145 - .../matrix/k8s/resource/namespace_event.go | 73 - .../matrix/k8s/resource/namespace_init.go | 439 --- .../matrix/k8s/resource/namespace_list.go | 57 - .../matrix/k8s/resource/namespace_ping.go | 74 - .../matrix/k8s/resource/namespace_status.go | 121 - .../matrix/k8s/resource/pod/pod.go | 26 - .../matrix/k8s/resource/products.go | 410 --- .../resource/resourcequota/resourcequota.go | 65 - .../matrix/k8s/resource/role/role.go | 47 - .../k8s/resource/rolebinding/role_binding.go | 47 - .../matrix/k8s/resource/secret/secret.go | 111 - .../matrix/k8s/resource/service/service.go | 65 - .../serviceaccount/service_account.go | 71 - .../matrix/k8s/resource/workload/workload.go | 321 -- .../workloadprocess/workloadprocess.go | 33 - chengying-server/matrix/k8s/util/util.go | 151 - .../matrix/k8s/util/util_darwin.go | 87 - .../matrix/k8s/util/util_linux.go | 101 - .../k8s/xke-service/driver/rke_driver.go | 124 - .../matrix/k8s/xke-service/driver/types.go | 22 - .../k8s/xke-service/rke_config_builder.go | 149 - .../matrix/k8s/xke-service/xke_servicer.go | 46 - .../matrix/model/kube/T10_workload_step.go | 134 - .../matrix/model/kube/T11_workload_part.go | 104 - .../model/kube/T12_workload_definition.go | 167 -- .../kube/T1_deploy_cluster_image_store.go | 105 - .../kube/T2_deploy_cluster_k8s_available.go | 99 - .../model/kube/T3_deploy_cluster_list.go | 118 - .../kube/T4_deploy_cluster_product_rel.go | 85 - .../model/kube/T5_deploy_namespace_client.go | 99 - .../model/kube/T6_deploy_namespace_list.go | 304 -- .../model/kube/T7_deploy_product_list.go | 41 - .../model/kube/T8_import_init_moudle.go | 63 - .../model/kube/T9_deploy_namespace_event.go | 126 - chengying-server/matrix/model/kube/alias.go | 31 - chengying-server/matrix/model/kube/db_test.go | 200 -- chengying-server/matrix/model/kube/init.go | 42 - .../matrix/model/kube/interface.go | 29 - .../matrix/model/kube/union/db_test.go | 51 - .../matrix/model/kube/union/init.go | 32 - .../matrix/model/kube/union/union_T4_T7.go | 148 - .../monitor/cluster_status_monitor.go | 52 +- chengying-server/matrix/monitor/monitor.go | 5 + .../{k8s => }/monitor/resource_monitor.go | 81 +- 112 files changed, 272 insertions(+), 13120 deletions(-) delete mode 100644 chengying-agent/test.go rename chengying-server/matrix/{k8s => api}/constant/constant.go (63%) delete mode 100644 chengying-server/matrix/api/k8s/cluster-ns-api.go delete mode 100644 chengying-server/matrix/api/k8s/impl/cluster-ns.go delete mode 100644 chengying-server/matrix/api/k8s/impl/instance.go delete mode 100644 chengying-server/matrix/api/k8s/impl/ns-product.go delete mode 100644 chengying-server/matrix/api/k8s/instance-api.go delete mode 100644 chengying-server/matrix/api/k8s/ns-product.go delete mode 100644 chengying-server/matrix/api/k8s/view/agent-generate.go delete mode 100644 chengying-server/matrix/api/k8s/view/clusterinfo-req.go delete mode 100644 chengying-server/matrix/api/k8s/view/cookie.go delete mode 100644 chengying-server/matrix/api/k8s/view/instane_replica.go delete mode 100644 chengying-server/matrix/api/k8s/view/namespace-delete-confirm.go delete mode 100644 chengying-server/matrix/api/k8s/view/namespace-event.go delete mode 100644 chengying-server/matrix/api/k8s/view/namespace-get.go delete mode 100644 chengying-server/matrix/api/k8s/view/namespace-ping.go delete mode 100644 chengying-server/matrix/api/k8s/view/namespace-save.go delete mode 100644 chengying-server/matrix/api/k8s/view/namespace-status.go delete mode 100644 chengying-server/matrix/api/k8s/view/ns-product.go rename chengying-server/matrix/{k8s => api}/web-socket/web_socket.go (76%) delete mode 100644 chengying-server/matrix/k8s/cluster/c_test.go delete mode 100644 chengying-server/matrix/k8s/cluster/generate.go delete mode 100644 chengying-server/matrix/k8s/cluster/import_cluster.go delete mode 100644 chengying-server/matrix/k8s/cluster/self_build_cluster.go delete mode 100644 chengying-server/matrix/k8s/deploy/configmap.go delete mode 100644 chengying-server/matrix/k8s/deploy/dynamic.go delete mode 100644 chengying-server/matrix/k8s/deploy/images.go delete mode 100644 chengying-server/matrix/k8s/deploy/mole.go delete mode 100644 chengying-server/matrix/k8s/deploy/progress.go delete mode 100644 chengying-server/matrix/k8s/deploy/secret.go delete mode 100644 chengying-server/matrix/k8s/deploy/workloadprocess.go delete mode 100644 chengying-server/matrix/k8s/docker/command.go delete mode 100644 chengying-server/matrix/k8s/kube/cluster_ns_client.go delete mode 100644 chengying-server/matrix/k8s/kube/interface.go delete mode 100644 chengying-server/matrix/k8s/kube/kube_client.go delete mode 100644 chengying-server/matrix/k8s/kube/rest_client.go delete mode 100644 chengying-server/matrix/k8s/model/configmap.go delete mode 100644 chengying-server/matrix/k8s/model/defines.go delete mode 100644 chengying-server/matrix/k8s/model/mole.go delete mode 100644 chengying-server/matrix/k8s/model/namespace.go delete mode 100644 chengying-server/matrix/k8s/model/sa.go delete mode 100644 chengying-server/matrix/k8s/model/secret.go delete mode 100644 chengying-server/matrix/k8s/monitor/monitor.go delete mode 100644 chengying-server/matrix/k8s/node/define.go delete mode 100644 chengying-server/matrix/k8s/node/node_manager.go delete mode 100644 chengying-server/matrix/k8s/resource/agent_generate.go delete mode 100644 chengying-server/matrix/k8s/resource/configmap/configmap.go delete mode 100644 chengying-server/matrix/k8s/resource/deployment/deployment.go delete mode 100644 chengying-server/matrix/k8s/resource/dryrun_test.go delete mode 100644 chengying-server/matrix/k8s/resource/endpoints/endpoints.go delete mode 100644 chengying-server/matrix/k8s/resource/goroutine.go delete mode 100644 chengying-server/matrix/k8s/resource/instance_replica.go delete mode 100644 chengying-server/matrix/k8s/resource/job/job.go delete mode 100644 chengying-server/matrix/k8s/resource/limitrange/limit_range.go delete mode 100644 chengying-server/matrix/k8s/resource/mole/mole.go delete mode 100644 chengying-server/matrix/k8s/resource/namespace_client_info.go delete mode 100644 chengying-server/matrix/k8s/resource/namespace_event.go delete mode 100644 chengying-server/matrix/k8s/resource/namespace_init.go delete mode 100644 chengying-server/matrix/k8s/resource/namespace_list.go delete mode 100644 chengying-server/matrix/k8s/resource/namespace_ping.go delete mode 100644 chengying-server/matrix/k8s/resource/namespace_status.go delete mode 100644 chengying-server/matrix/k8s/resource/pod/pod.go delete mode 100644 chengying-server/matrix/k8s/resource/products.go delete mode 100644 chengying-server/matrix/k8s/resource/resourcequota/resourcequota.go delete mode 100644 chengying-server/matrix/k8s/resource/role/role.go delete mode 100644 chengying-server/matrix/k8s/resource/rolebinding/role_binding.go delete mode 100644 chengying-server/matrix/k8s/resource/secret/secret.go delete mode 100644 chengying-server/matrix/k8s/resource/service/service.go delete mode 100644 chengying-server/matrix/k8s/resource/serviceaccount/service_account.go delete mode 100644 chengying-server/matrix/k8s/resource/workload/workload.go delete mode 100644 chengying-server/matrix/k8s/resource/workloadprocess/workloadprocess.go delete mode 100644 chengying-server/matrix/k8s/util/util.go delete mode 100644 chengying-server/matrix/k8s/util/util_darwin.go delete mode 100644 chengying-server/matrix/k8s/util/util_linux.go delete mode 100644 chengying-server/matrix/k8s/xke-service/driver/rke_driver.go delete mode 100644 chengying-server/matrix/k8s/xke-service/driver/types.go delete mode 100644 chengying-server/matrix/k8s/xke-service/rke_config_builder.go delete mode 100644 chengying-server/matrix/k8s/xke-service/xke_servicer.go delete mode 100644 chengying-server/matrix/model/kube/T10_workload_step.go delete mode 100644 chengying-server/matrix/model/kube/T11_workload_part.go delete mode 100644 chengying-server/matrix/model/kube/T12_workload_definition.go delete mode 100644 chengying-server/matrix/model/kube/T1_deploy_cluster_image_store.go delete mode 100644 chengying-server/matrix/model/kube/T2_deploy_cluster_k8s_available.go delete mode 100644 chengying-server/matrix/model/kube/T3_deploy_cluster_list.go delete mode 100644 chengying-server/matrix/model/kube/T4_deploy_cluster_product_rel.go delete mode 100644 chengying-server/matrix/model/kube/T5_deploy_namespace_client.go delete mode 100644 chengying-server/matrix/model/kube/T6_deploy_namespace_list.go delete mode 100644 chengying-server/matrix/model/kube/T7_deploy_product_list.go delete mode 100644 chengying-server/matrix/model/kube/T8_import_init_moudle.go delete mode 100644 chengying-server/matrix/model/kube/T9_deploy_namespace_event.go delete mode 100644 chengying-server/matrix/model/kube/alias.go delete mode 100644 chengying-server/matrix/model/kube/db_test.go delete mode 100644 chengying-server/matrix/model/kube/init.go delete mode 100644 chengying-server/matrix/model/kube/interface.go delete mode 100644 chengying-server/matrix/model/kube/union/db_test.go delete mode 100644 chengying-server/matrix/model/kube/union/init.go delete mode 100644 chengying-server/matrix/model/kube/union/union_T4_T7.go rename chengying-server/matrix/{k8s => }/monitor/cluster_status_monitor.go (58%) create mode 100644 chengying-server/matrix/monitor/monitor.go rename chengying-server/matrix/{k8s => }/monitor/resource_monitor.go (89%) diff --git a/chengying-agent/internal/server/asset/assets.go b/chengying-agent/internal/server/asset/assets.go index 01da331..5768037 100644 --- a/chengying-agent/internal/server/asset/assets.go +++ b/chengying-agent/internal/server/asset/assets.go @@ -1,11 +1,9 @@ -// Code generated by go-bindata. +// Code generated for package asset by go-bindata DO NOT EDIT. (@generated) // sources: // templates/easyagent_install_4win.ps1 // templates/install.script.wrapper.sh // templates/install.sidecar.sh // templates/install.sidecar.win.ps1 -// DO NOT EDIT! - package asset import ( @@ -29,21 +27,32 @@ type bindataFileInfo struct { modTime time.Time } +// Name return file name func (fi bindataFileInfo) Name() string { return fi.name } + +// Size return file size func (fi bindataFileInfo) Size() int64 { return fi.size } + +// Mode return file mode func (fi bindataFileInfo) Mode() os.FileMode { return fi.mode } + +// Mode return file modify time func (fi bindataFileInfo) ModTime() time.Time { return fi.modTime } + +// IsDir return file whether a directory func (fi bindataFileInfo) IsDir() bool { - return false + return fi.mode&os.ModeDir != 0 } + +// Sys return file is sys mode func (fi bindataFileInfo) Sys() interface{} { return nil } @@ -371,7 +380,7 @@ func templatesEasyagent_install_4winPs1() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "templates/easyagent_install_4win.ps1", size: 9674, mode: os.FileMode(420), modTime: time.Unix(1558528296, 0)} + info := bindataFileInfo{name: "templates/easyagent_install_4win.ps1", size: 9674, mode: os.FileMode(420), modTime: time.Unix(1669097377, 0)} a := &asset{bytes: bytes, info: info} return a, nil } @@ -441,7 +450,7 @@ func templatesInstallScriptWrapperSh() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "templates/install.script.wrapper.sh", size: 1342, mode: os.FileMode(420), modTime: time.Unix(1621564580, 0)} + info := bindataFileInfo{name: "templates/install.script.wrapper.sh", size: 1342, mode: os.FileMode(420), modTime: time.Unix(1669097377, 0)} a := &asset{bytes: bytes, info: info} return a, nil } @@ -924,7 +933,7 @@ func templatesInstallSidecarSh() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "templates/install.sidecar.sh", size: 11947, mode: os.FileMode(420), modTime: time.Unix(1622447838, 0)} + info := bindataFileInfo{name: "templates/install.sidecar.sh", size: 11947, mode: os.FileMode(420), modTime: time.Unix(1669097377, 0)} a := &asset{bytes: bytes, info: info} return a, nil } @@ -1228,7 +1237,7 @@ func templatesInstallSidecarWinPs1() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "templates/install.sidecar.win.ps1", size: 8926, mode: os.FileMode(420), modTime: time.Unix(1589804254, 0)} + info := bindataFileInfo{name: "templates/install.sidecar.win.ps1", size: 8926, mode: os.FileMode(420), modTime: time.Unix(1669097377, 0)} a := &asset{bytes: bytes, info: info} return a, nil } diff --git a/chengying-agent/prod/easy-agent-server/example-config.yml b/chengying-agent/prod/easy-agent-server/example-config.yml index 5432c5d..057c3d8 100644 --- a/chengying-agent/prod/easy-agent-server/example-config.yml +++ b/chengying-agent/prod/easy-agent-server/example-config.yml @@ -36,10 +36,10 @@ publish.http.uri: /api/v2/instance/%s/%s publish.http.timeout: 30s # databases -mysqldb.host: 172.16.10.74 +mysqldb.host: 172.16.10.191 mysqldb.port: 3306 -mysqldb.user: easyagent -mysqldb.password: dtstack +mysqldb.user: root +mysqldb.password: DT#passw0rd2019 mysqldb.dbname: dtagent #uicdb.host: 127.0.0.1 diff --git a/chengying-agent/test.go b/chengying-agent/test.go deleted file mode 100644 index f1c0b77..0000000 --- a/chengying-agent/test.go +++ /dev/null @@ -1 +0,0 @@ -package chengying_agent diff --git a/chengying-server/go.sum b/chengying-server/go.sum index 6dba97b..3b95f87 100644 --- a/chengying-server/go.sum +++ b/chengying-server/go.sum @@ -1,5 +1,3 @@ -bou.ke/monkey v1.0.2 h1:kWcnsrCNUatbxncxR/ThdYqbytgOIArtYWqcQLQzKLI= -bou.ke/monkey v1.0.2/go.mod h1:OqickVX3tNx6t33n1xvtTtu85YN5s6cKwVug+oHMaIA= cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= cloud.google.com/go v0.38.0/go.mod h1:990N+gfupTy94rShfmMCWGDn0LpTmnzTp2qbd1dvSRU= @@ -7,7 +5,6 @@ cloud.google.com/go v0.44.1/go.mod h1:iSa0KzasP4Uvy3f1mN/7PiObzGgflwredwwASm/v6A cloud.google.com/go v0.44.2/go.mod h1:60680Gw3Yr4ikxnPRS/oxxkBccT6SA1yMk63TGekxKY= cloud.google.com/go v0.45.1/go.mod h1:RpBamKRgapWJb87xiFSdk4g1CME7QZg3uwTez+TSTjc= cloud.google.com/go v0.46.3/go.mod h1:a6bKKbmY7er1mI7TEI4lsAkts/mkhTSZK8w33B4RAg0= -cloud.google.com/go v0.49.0 h1:CH+lkubJzcPYB1Ggupcq0+k8Ni2ILdG2lYjDIgavDBQ= cloud.google.com/go v0.49.0/go.mod h1:hGvAdzcWNbyuxS3nWhD7H2cIJxjRRTRLQVB0bdputVY= cloud.google.com/go/bigquery v1.0.1/go.mod h1:i/xbL2UlR5RvWAURpBYZTtm/cXjCha9lbfbpx4poX+o= cloud.google.com/go/bigquery v1.3.0/go.mod h1:PjpwJnslEMmckchkHFfq+HTD2DmtT67aNFKH1/VBDHE= @@ -20,33 +17,22 @@ dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7 github.com/Azure/azure-pipeline-go v0.2.1/go.mod h1:UGSo8XybXnIGZ3epmeBw7Jdz+HiUVpqIlpz/HKHylF4= github.com/Azure/azure-pipeline-go v0.2.2/go.mod h1:4rQ/NZncSvGqNkkOsNpOU1tgoNuIlp9AfUH5G1tvCHc= github.com/Azure/azure-sdk-for-go v23.2.0+incompatible/go.mod h1:9XXNKU+eRnpl9moKnB4QOLf1HestfXbmab5FXxiDBjc= -github.com/Azure/azure-sdk-for-go v36.1.0+incompatible h1:smHlbChr/JDmsyUqELZXLs0YIgpXecIGdUibuc2983s= github.com/Azure/azure-sdk-for-go v36.1.0+incompatible/go.mod h1:9XXNKU+eRnpl9moKnB4QOLf1HestfXbmab5FXxiDBjc= github.com/Azure/azure-storage-blob-go v0.8.0/go.mod h1:lPI3aLPpuLTeUwh1sViKXFxwl2B6teiRqI0deQUvsw0= -github.com/Azure/go-ansiterm v0.0.0-20170929234023-d6e3b3328b78 h1:w+iIsaOQNcT7OZ575w+acHgRric5iCyQh+xv+KJ4HB8= github.com/Azure/go-ansiterm v0.0.0-20170929234023-d6e3b3328b78/go.mod h1:LmzpDX56iTiv29bbRTIsUNlaFfuhWRQBWjQdVyAevI8= -github.com/Azure/go-autorest v11.2.8+incompatible h1:Q2feRPMlcfVcqz3pF87PJzkm5lZrL+x6BDtzhODzNJM= github.com/Azure/go-autorest v11.2.8+incompatible/go.mod h1:r+4oMnoxhatjLLJ6zxSWATqVooLgysK6ZNox3g/xq24= github.com/Azure/go-autorest/autorest v0.9.0/go.mod h1:xyHB1BMZT0cuDHU7I0+g046+BFDTQ8rEZB0s4Yfa6bI= -github.com/Azure/go-autorest/autorest v0.9.3-0.20191028180845-3492b2aff503 h1:uUhdsDMg2GbFLF5GfQPtLMWd5vdDZSfqvqQp3waafxQ= github.com/Azure/go-autorest/autorest v0.9.3-0.20191028180845-3492b2aff503/go.mod h1:xyHB1BMZT0cuDHU7I0+g046+BFDTQ8rEZB0s4Yfa6bI= github.com/Azure/go-autorest/autorest/adal v0.5.0/go.mod h1:8Z9fGy2MpX0PvDjB1pEgQTmVqjGhiHBW7RJJEciWzS0= -github.com/Azure/go-autorest/autorest/adal v0.8.1-0.20191028180845-3492b2aff503 h1:Hxqlh1uAA8aGpa1dFhDNhll7U/rkWtG8ZItFvRMr7l0= github.com/Azure/go-autorest/autorest/adal v0.8.1-0.20191028180845-3492b2aff503/go.mod h1:Z6vX6WXXuyieHAXwMj0S6HY6e6wcHn37qQMBQlvY3lc= github.com/Azure/go-autorest/autorest/date v0.1.0/go.mod h1:plvfp3oPSKwf2DNjlBjWF/7vwR+cUD/ELuzDCXwHUVA= -github.com/Azure/go-autorest/autorest/date v0.2.0 h1:yW+Zlqf26583pE43KhfnhFcdmSWlm5Ew6bxipnr/tbM= github.com/Azure/go-autorest/autorest/date v0.2.0/go.mod h1:vcORJHLJEh643/Ioh9+vPmf1Ij9AEBM5FuBIXLmIy0g= github.com/Azure/go-autorest/autorest/mocks v0.1.0/go.mod h1:OTyCOPRA2IgIlWxVYxBee2F5Gr4kF2zd2J5cFRaIDN0= github.com/Azure/go-autorest/autorest/mocks v0.2.0/go.mod h1:OTyCOPRA2IgIlWxVYxBee2F5Gr4kF2zd2J5cFRaIDN0= -github.com/Azure/go-autorest/autorest/mocks v0.3.0 h1:qJumjCaCudz+OcqE9/XtEPfvtOjOmKaui4EOpFI6zZc= github.com/Azure/go-autorest/autorest/mocks v0.3.0/go.mod h1:a8FDP3DYzQ4RYfVAxAN3SVSiiO77gL2j2ronKKP0syM= -github.com/Azure/go-autorest/autorest/to v0.3.1-0.20191028180845-3492b2aff503 h1:2McfZNaDqGPjv2pddK547PENIk4HV+NT7gvqRq4L0us= github.com/Azure/go-autorest/autorest/to v0.3.1-0.20191028180845-3492b2aff503/go.mod h1:MgwOyqaIuKdG4TL/2ywSsIWKAfJfgHDo8ObuUk3t5sA= -github.com/Azure/go-autorest/autorest/validation v0.2.1-0.20191028180845-3492b2aff503 h1:RBrGlrkPWapMcLp1M6ywCqyYKOAT5ERI6lYFvGKOThE= github.com/Azure/go-autorest/autorest/validation v0.2.1-0.20191028180845-3492b2aff503/go.mod h1:3EEqHnBxQGHXRYq3HT1WyXAvT7LLY3tl70hw6tQIbjI= -github.com/Azure/go-autorest/logger v0.1.0 h1:ruG4BSDXONFRrZZJ2GUXDiUyVpayPmb1GnWeHDdaNKY= github.com/Azure/go-autorest/logger v0.1.0/go.mod h1:oExouG+K6PryycPJfVSxi/koC6LSNgds39diKLz7Vrc= -github.com/Azure/go-autorest/tracing v0.5.0 h1:TRn4WjSnkcSy5AEG3pnbtFSwNtwzjr4VYyQflFE619k= github.com/Azure/go-autorest/tracing v0.5.0/go.mod h1:r/s2XiOKccPW3HrqB+W0TQzfbtp2fGCgRFtBroKn4Dk= github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= @@ -57,13 +43,9 @@ github.com/Joker/jade v0.0.0-20161230135920-35b3f5bdbcc9/go.mod h1:R1kvvouJogE6S github.com/KyleBanks/depth v1.2.1 h1:5h8fQADFrWtarTdtDudMmGsC7GPbOAu6RVB3ffsVFHc= github.com/KyleBanks/depth v1.2.1/go.mod h1:jzSb9d0L43HxTQfT+oSA1EEp2q+ne2uh6XgeJcm8brE= github.com/MakeNowJust/heredoc v0.0.0-20170808103936-bb23615498cd/go.mod h1:64YHyfSL2R96J44Nlwm39UHepQbyR5q10x7iYa1ks2E= -github.com/Masterminds/goutils v1.1.0 h1:zukEsf/1JZwCMgHiK3GZftabmxiCw4apj3a28RPBiVg= github.com/Masterminds/goutils v1.1.0/go.mod h1:8cTjp+g8YejhMuvIA5y2vz3BpJxksy863GQaJW2MFNU= -github.com/Masterminds/semver/v3 v3.0.1 h1:2kKm5lb7dKVrt5TYUiAavE6oFc1cFT0057UVGT+JqLk= github.com/Masterminds/semver/v3 v3.0.1/go.mod h1:VPu/7SZ7ePZ3QOrcuXROw5FAcLl4a0cBrbBpGY/8hQs= -github.com/Masterminds/sprig/v3 v3.0.0 h1:KSQz7Nb08/3VU9E4ns29dDxcczhOD1q7O1UfM4G3t3g= github.com/Masterminds/sprig/v3 v3.0.0/go.mod h1:NEUY/Qq8Gdm2xgYA+NwJM6wmfdRV9xkh8h/Rld20R0U= -github.com/Microsoft/go-winio v0.4.12 h1:xAfWHN1IrQ0NJ9TBC0KBZoqLjzDTr1ML+4MywiUOryc= github.com/Microsoft/go-winio v0.4.12/go.mod h1:VhR8bwka0BXejwEJY73c50VrPtXAaKcyvVC4A4RozmA= github.com/NYTimes/gziphandler v0.0.0-20170623195520-56545f4a5d46/go.mod h1:3wb06e3pkSAbeQ52E9H9iFoQsEEwGN64994WTCIhntQ= github.com/NYTimes/gziphandler v1.1.1/go.mod h1:n/CVRwUEOgIxrgPvAQhUUr9oeUtvrhMomdKFjzJNB0c= @@ -80,21 +62,15 @@ github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578/go.mod h1:uGdko github.com/Shopify/sarama v1.19.0/go.mod h1:FVkBWblsNy7DGZRfXLU0O9RCGt5g3g3yEuWXgklEdEo= github.com/Shopify/toxiproxy v2.1.4+incompatible/go.mod h1:OXgGpZ6Cli1/URJOF1DMxUHB2q5Ap20/P/eIdh4G0pI= github.com/StackExchange/wmi v0.0.0-20180116203802-5d049714c4a6/go.mod h1:3eOhrUMpNV+6aFIbp5/iudMxNCF27Vw2OZgy4xEx0Fg= -github.com/a-urth/go-bindata v0.0.0-20180209162145-df38da164efc h1:eXJIPWW4y4xjPWda/7ruw5PRsfcbzKTL9EhNQrBRsOU= -github.com/a-urth/go-bindata v0.0.0-20180209162145-df38da164efc/go.mod h1:D0SbCgK4DQtSNzDQzfek273VqkCnHdFCd+q2ueHGRiE= -github.com/agiledragon/gomonkey v2.0.2+incompatible h1:eXKi9/piiC3cjJD1658mEE2o3NjkJ5vDLgYjCQu0Xlw= -github.com/agiledragon/gomonkey v2.0.2+incompatible/go.mod h1:2NGfXu1a80LLr2cmWXGBDaHEjb1idR6+FVlX5T3D9hw= github.com/agiledragon/gomonkey/v2 v2.3.1 h1:k+UnUY0EMNYUFUAQVETGY9uUTxjMdnUkP0ARyJS1zzs= github.com/agiledragon/gomonkey/v2 v2.3.1/go.mod h1:ap1AmDzcVOAz1YpeJ3TCzIgstoaWLA6jbbgxfB4w2iY= github.com/agnivade/levenshtein v1.0.1/go.mod h1:CURSv5d9Uaml+FovSIICkLbAUZ9S4RqaHDIsdSBg7lM= github.com/ajg/form v1.5.1 h1:t9c7v8JUKu/XxOGBU0yjNpaMloxGEJhUkqFRq0ibGeU= github.com/ajg/form v1.5.1/go.mod h1:uL1WgH+h2mgNtvBq0339dVnzXdBETtL2LeUXaIv25UY= github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= -github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751 h1:JYp7IbQjafoB+tBA3gMyHYHrpOtNuDiK/uB5uXxq5wM= github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= github.com/alecthomas/units v0.0.0-20190717042225-c3de453c63f4/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= -github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d h1:UQZhZ2O0vMHr2cI+DC1Mbh0TJxzA3RcLoMsFw+aXw7E= github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d/go.mod h1:rBZYJk541a8SKzHPHnH3zbiI+7dagKZ0cgpgrD7Fyho= github.com/aliyun/aliyun-oss-go-sdk v2.0.4+incompatible/go.mod h1:T/Aws4fEfogEE9v+HPhhw+CntffsBHJ8nXQCwKr0/g8= github.com/andreyvit/diff v0.0.0-20170406064948-c7f18ee00883/go.mod h1:rCTlJbsFo29Kk6CurOXKm700vrz8f0KW0JNfpkRJY/8= @@ -109,7 +85,6 @@ github.com/armon/go-radix v0.0.0-20180808171621-7fddfc383310/go.mod h1:ufUuZ+zHj github.com/armon/go-radix v1.0.0/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgIH9cCH8= github.com/asaskevich/govalidator v0.0.0-20180720115003-f9ffefc3facf/go.mod h1:lB+ZfQJz7igIIfQNfa7Ml4HSf2uFQQRzpGGRXenZAgY= github.com/asaskevich/govalidator v0.0.0-20190424111038-f61b66f89f4a/go.mod h1:lB+ZfQJz7igIIfQNfa7Ml4HSf2uFQQRzpGGRXenZAgY= -github.com/aws/aws-sdk-go v1.25.48 h1:J82DYDGZHOKHdhx6hD24Tm30c2C3GchYGfN0mf9iKUk= github.com/aws/aws-sdk-go v1.25.48/go.mod h1:KmX6BPdI08NWTb3/sm4ZGu5ShLoqVDhKgpiN924inxo= github.com/aymerick/raymond v0.0.0-20161209220724-72acac220747 h1:gu88ZN3sXG5+1mH0W4Ty00jzHA044ND3ogxmJNN6Rik= github.com/aymerick/raymond v0.0.0-20161209220724-72acac220747/go.mod h1:osfaiScAUVup+UC9Nfq76eWqDhXlp+4UYaA8uhTBO6g= @@ -122,7 +97,6 @@ github.com/better0332/zip v0.0.0-20180913033841-455b25ec3929 h1:NbGoruS28Ef/xnXZ github.com/better0332/zip v0.0.0-20180913033841-455b25ec3929/go.mod h1:SY+hnR5X1UEg7ZfR1ZEs2SCs2/dr1RYDT7BX02664uk= github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs= github.com/blang/semver v3.5.0+incompatible/go.mod h1:kRBLl5iJ+tD4TcOOxsy/0fnwebNt5EWlYSAyrTnjyyk= -github.com/blang/semver v3.5.1+incompatible h1:cQNTCjp13qL8KC3Nbxr/y2Bqb63oX6wdnnjpJbkM4JQ= github.com/blang/semver v3.5.1+incompatible/go.mod h1:kRBLl5iJ+tD4TcOOxsy/0fnwebNt5EWlYSAyrTnjyyk= github.com/boombuler/barcode v1.0.0/go.mod h1:paBWMcWSl3LHKBqUq+rly7CNSldXjb2rDl3JlRe0mD8= github.com/bradfitz/gomemcache v0.0.0-20190913173617-a41fca850d0b/go.mod h1:H0wQNHz2YrLsuXOZozoeDmnHXkNCRmMW0gwFWDfEZDA= @@ -149,37 +123,28 @@ github.com/cncf/xds/go v0.0.0-20210922020428-25de7278fc84/go.mod h1:eXthEFrGJvWH github.com/cncf/xds/go v0.0.0-20211011173535-cb28da3451f1/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs= github.com/cockroachdb/datadriven v0.0.0-20190809214429-80d97fb3cbaa/go.mod h1:zn76sxSg3SzpJ0PPJaLDCu+Bu0Lg3sKTORVIj19EIF8= github.com/codahale/hdrhistogram v0.0.0-20161010025455-3a0bb77429bd/go.mod h1:sE/e/2PUdi/liOCUjSTXgM1o87ZssimdTWN964YiIeI= -github.com/containerd/containerd v1.3.0-beta.0.0.20190808172034-23faecfb66ab h1:lLoKpH/jolCo6LOWonSg8psTvcGAF7qklWRhcfvVsqc= github.com/containerd/containerd v1.3.0-beta.0.0.20190808172034-23faecfb66ab/go.mod h1:bC6axHOhabU15QhwfG7w5PipXdVtMXFTttgp+kVtyUA= github.com/coreos/bbolt v1.3.1-coreos.6/go.mod h1:iRUV2dpdMOn7Bo10OQBFzIJO9kkE559Wcmn+qkEiiKk= -github.com/coreos/bbolt v1.3.2/go.mod h1:iRUV2dpdMOn7Bo10OQBFzIJO9kkE559Wcmn+qkEiiKk= -github.com/coreos/bbolt v1.3.3 h1:n6AiVyVRKQFNb6mJlwESEvvLoDyiTzXX7ORAUlkeBdY= github.com/coreos/bbolt v1.3.3/go.mod h1:iRUV2dpdMOn7Bo10OQBFzIJO9kkE559Wcmn+qkEiiKk= github.com/coreos/etcd v3.3.10+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE= github.com/coreos/etcd v3.3.15+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE= -github.com/coreos/etcd v3.3.17+incompatible h1:f/Z3EoDSx1yjaIjLQGo1diYUlQYSBrrAQ5vP8NjwXwo= github.com/coreos/etcd v3.3.17+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE= github.com/coreos/go-etcd v2.0.0+incompatible/go.mod h1:Jez6KQU2B/sWsbdaef3ED8NzMklzPG4d5KIOhIy30Tk= github.com/coreos/go-oidc v2.1.0+incompatible/go.mod h1:CgnwVTmzoESiwO9qyAFEMiHoZ1nMCKZlZ9V6mm3/LKc= github.com/coreos/go-semver v0.2.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk= -github.com/coreos/go-semver v0.3.0 h1:wkHLiw0WNATZnSG7epLsujiMCgPAc9xhjJ4tgnAxmfM= github.com/coreos/go-semver v0.3.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk= github.com/coreos/go-systemd v0.0.0-20180511133405-39ca1b05acc7/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4= github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4= -github.com/coreos/go-systemd v0.0.0-20190719114852-fd7a80b32e1f h1:JOrtw2xFKzlg+cbHpyrpLDmnN1HqhBfnX7WDiW7eG2c= github.com/coreos/go-systemd v0.0.0-20190719114852-fd7a80b32e1f/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4= github.com/coreos/pkg v0.0.0-20160727233714-3ac0863d7acf/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA= github.com/coreos/pkg v0.0.0-20180108230652-97fdf19511ea/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA= -github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f h1:lBNOc5arjvs8E5mO2tbpBpLoyyu8B6e44T7hJy6potg= github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA= github.com/coreos/prometheus-operator v0.36.0/go.mod h1:b1ydz/Rg9TqDtHu2MDXKfiX/Hv0Bogy1iY82fRbhEFg= github.com/cpuguy83/go-md2man v1.0.10/go.mod h1:SmD6nW6nTyfqj6ABTjUi3V3JVMnlJmwcJI5acqYI6dE= github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU= -github.com/cpuguy83/go-md2man/v2 v2.0.0/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU= github.com/creack/pty v1.1.7/go.mod h1:lj5s0c3V2DBrqTV7llrYr5NG6My20zk30Fl46Y7DoTY= github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= github.com/davecgh/go-spew v0.0.0-20151105211317-5215b55f46b2/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= @@ -188,18 +153,14 @@ github.com/dchest/captcha v0.0.0-20170622155422-6a29415a8364 h1:U+BMqUt8LFgyrF0/ github.com/dchest/captcha v0.0.0-20170622155422-6a29415a8364/go.mod h1:QGrK8vMWWHQYQ3QU9bw9Y9OPNfxccGzfb41qjvVeXtY= github.com/dgrijalva/jwt-go v3.2.0+incompatible h1:7qlOGliEKZXTDg6OTjfoBKDXWrumCAMpl/TFQ4/5kLM= github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ= -github.com/dgryski/go-sip13 v0.0.0-20181026042036-e10d5fee7954/go.mod h1:vAd38F8PWV+bWy6jNmig1y/TA+kYO4g3RSRF0IAv0no= github.com/dgryski/go-sip13 v0.0.0-20190329191031-25c5027a8c7b/go.mod h1:vAd38F8PWV+bWy6jNmig1y/TA+kYO4g3RSRF0IAv0no= github.com/docker/distribution v0.0.0-20171011171712-7484e51bf6af/go.mod h1:J2gT2udsDAN96Uj4KfcMRqY0/ypR+oyYUYmja8H+y+w= github.com/docker/distribution v2.7.1+incompatible h1:a5mlkVzth6W5A4fOsS3D2EO5BUmsJpcB+cRlLU7cSug= github.com/docker/distribution v2.7.1+incompatible/go.mod h1:J2gT2udsDAN96Uj4KfcMRqY0/ypR+oyYUYmja8H+y+w= github.com/docker/docker v0.7.3-0.20190327010347-be7ac8be2ae0/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk= -github.com/docker/docker v0.7.3-0.20190808172531-150530564a14 h1:ZkcBCvSGEg1Er3X6a7srm52Czihvc+J1+/CMv6MBA9c= github.com/docker/docker v0.7.3-0.20190808172531-150530564a14/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk= -github.com/docker/go-connections v0.4.0 h1:El9xVISelRB7BuFusrZozjnkIM5YnzCViNKohAFqRJQ= github.com/docker/go-connections v0.4.0/go.mod h1:Gbd7IOopHjR8Iph03tsViu4nIes5XhDvyHbTtUxmeec= github.com/docker/go-units v0.3.3/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk= -github.com/docker/go-units v0.4.0 h1:3uh0PgVws3nIA0Q+MwDC8yjEPf9zjRfZZWXZYDct3Tw= github.com/docker/go-units v0.4.0/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk= github.com/docker/libtrust v0.0.0-20160708172513-aabc10ec26b7 h1:UhxFibDNY/bfvqU5CAUmr9zpesgbU6SWc8/B4mflAE4= github.com/docker/libtrust v0.0.0-20160708172513-aabc10ec26b7/go.mod h1:cyGadeNEkKy96OOhEzfZl+yxihPEzKnqJwvfuSUqbZE= @@ -213,8 +174,6 @@ github.com/eapache/queue v1.1.0/go.mod h1:6eCeP0CKFpHLu8blIFXhExK/dRa7WDZfr6jVFP github.com/edsrzf/mmap-go v1.0.0/go.mod h1:YO35OhQPt3KJa3ryjFM5Bs14WD66h8eGKpfaBNrHW5M= github.com/eknkc/amber v0.0.0-20170716093748-b8bd8b03e4f7 h1:/O1qCNo88112jlIeUWEgQtrbq6NFatCUr+OtZg86Fx4= github.com/eknkc/amber v0.0.0-20170716093748-b8bd8b03e4f7/go.mod h1:0vRUJqYpeSZifjYj7uP3BG/gKcuzL9xWVV/Y+cK33KM= -github.com/elastic/go-licenser v0.4.0 h1:jLq6A5SilDS/Iz1ABRkO6BHy91B9jBora8FwGRsDqUI= -github.com/elastic/go-licenser v0.4.0/go.mod h1:V56wHMpmdURfibNBggaSBfqgPxyT1Tldns1i87iTEvU= github.com/elastic/go-sysinfo v1.0.1/go.mod h1:O/D5m1VpYLwGjCYzEt63g3Z1uO3jXfwyzzjiW90t8cY= github.com/elastic/go-sysinfo v1.1.1/go.mod h1:i1ZYdU10oLNfRzq4vq62BEwD2fH8KaWh6eh0ikPT9F0= github.com/elastic/go-ucfg v0.4.6 h1:Y2lmRGOn2eliyLiW+aTITaB+RnvIPt7W1f5u006/oUw= @@ -261,7 +220,6 @@ github.com/globalsign/mgo v0.0.0-20181015135952-eeefdecb41b8/go.mod h1:xkRDCp4j0 github.com/go-bindata/go-bindata v3.1.2+incompatible/go.mod h1:xK8Dsgwmeed+BBsSy2XTopBn/8uK2HWuGSnA11C3Joo= github.com/go-critic/go-critic v0.3.5-0.20190526074819-1df300866540/go.mod h1:+sE8vrLDS2M0pZkBk0wy6+nLdKexVDrl/jBqQOTDThA= github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU= -github.com/go-ini/ini v1.37.0 h1:/FpMfveJbc7ExTTDgT5nL9Vw+aZdst/c2dOxC931U+M= github.com/go-ini/ini v1.37.0/go.mod h1:ByCAeIL28uOIIG0E3PJtZPDL8WnHpFKFOtgjp+3Ies8= github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as= github.com/go-kit/kit v0.9.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as= @@ -289,7 +247,6 @@ github.com/go-openapi/jsonpointer v0.17.0/go.mod h1:cOnomiV+CVVwFLk0A/MExoFMjwds github.com/go-openapi/jsonpointer v0.17.2/go.mod h1:cOnomiV+CVVwFLk0A/MExoFMjwdsUdVpsRhURCKh+3M= github.com/go-openapi/jsonpointer v0.18.0/go.mod h1:cOnomiV+CVVwFLk0A/MExoFMjwdsUdVpsRhURCKh+3M= github.com/go-openapi/jsonpointer v0.19.2/go.mod h1:3akKfEdA7DF1sugOqz1dVQHBcuDBPKZGEoHC/NkiQRg= -github.com/go-openapi/jsonpointer v0.19.3 h1:gihV7YNZK1iK6Tgwwsxo2rJbD1GTbdm72325Bq8FI3w= github.com/go-openapi/jsonpointer v0.19.3/go.mod h1:Pl9vOtqEWErmShwVjC8pYs9cog34VGT37dQOVbmoatg= github.com/go-openapi/jsonpointer v0.19.5 h1:gZr+CIYByUqjcgeLXnQu2gHYQC9o73G2XUeOFYEICuY= github.com/go-openapi/jsonpointer v0.19.5/go.mod h1:Pl9vOtqEWErmShwVjC8pYs9cog34VGT37dQOVbmoatg= @@ -298,7 +255,6 @@ github.com/go-openapi/jsonreference v0.17.0/go.mod h1:g4xxGn04lDIRh0GJb5QlpE3Hfo github.com/go-openapi/jsonreference v0.17.2/go.mod h1:g4xxGn04lDIRh0GJb5QlpE3HfopLOL6uZrK/VgnsK9I= github.com/go-openapi/jsonreference v0.18.0/go.mod h1:g4xxGn04lDIRh0GJb5QlpE3HfopLOL6uZrK/VgnsK9I= github.com/go-openapi/jsonreference v0.19.2/go.mod h1:jMjeRr2HHw6nAVajTXJ4eiUwohSTlpa0o73RUL1owJc= -github.com/go-openapi/jsonreference v0.19.3 h1:5cxNfTy0UVC3X8JL5ymxzyoUZmo8iZb+jeTWn7tUa8o= github.com/go-openapi/jsonreference v0.19.3/go.mod h1:rjx6GuL8TTa9VaixXglHmQmIL98+wF9xc8zWvFonSJ8= github.com/go-openapi/jsonreference v0.19.6 h1:UBIxjkht+AWIgYzCDSv2GN+E/togfwXUJFRTWhl2Jjs= github.com/go-openapi/jsonreference v0.19.6/go.mod h1:diGHMEHg2IqXZGKxqyvWdfWU/aim5Dprw5bqpKkTvns= @@ -317,7 +273,6 @@ github.com/go-openapi/spec v0.17.0/go.mod h1:XkF/MOi14NmjsfZ8VtAKf8pIlbZzyoTvZsd github.com/go-openapi/spec v0.17.2/go.mod h1:XkF/MOi14NmjsfZ8VtAKf8pIlbZzyoTvZsdfssdxcBI= github.com/go-openapi/spec v0.18.0/go.mod h1:XkF/MOi14NmjsfZ8VtAKf8pIlbZzyoTvZsdfssdxcBI= github.com/go-openapi/spec v0.19.2/go.mod h1:sCxk3jxKgioEJikev4fgkNmwS+3kuYdJtcsZsD5zxMY= -github.com/go-openapi/spec v0.19.3 h1:0XRyw8kguri6Yw4SxhsQA/atC88yqrk0+G4YhI2wabc= github.com/go-openapi/spec v0.19.3/go.mod h1:FpwSN1ksY1eteniUU7X0N/BgJ7a4WvBFVA8Lj9mJglo= github.com/go-openapi/spec v0.20.4 h1:O8hJrt0UMnhHcluhIdUgCLRWyM2x7QkBXRvOs7m+O1M= github.com/go-openapi/spec v0.20.4/go.mod h1:faYFR1CvsJZ0mNsmsphTMSoRrNV3TEDoAM7FOEWeq8I= @@ -333,7 +288,6 @@ github.com/go-openapi/swag v0.17.2/go.mod h1:AByQ+nYG6gQg71GINrmuDXCPWdL640yX49/ github.com/go-openapi/swag v0.18.0/go.mod h1:AByQ+nYG6gQg71GINrmuDXCPWdL640yX49/kXLo40Tg= github.com/go-openapi/swag v0.19.2/go.mod h1:POnQmlKehdgb5mhVOsnJFsivZCEZ/vjK9gh66Z9tfKk= github.com/go-openapi/swag v0.19.4/go.mod h1:POnQmlKehdgb5mhVOsnJFsivZCEZ/vjK9gh66Z9tfKk= -github.com/go-openapi/swag v0.19.5 h1:lTz6Ys4CmqqCQmZPBlbQENR1/GucA2bzYTE12Pw4tFY= github.com/go-openapi/swag v0.19.5/go.mod h1:POnQmlKehdgb5mhVOsnJFsivZCEZ/vjK9gh66Z9tfKk= github.com/go-openapi/swag v0.19.15 h1:D2NRCBzS9/pEY3gP9Nl8aDqGUcPFrwG2p+CNFrLyrCM= github.com/go-openapi/swag v0.19.15/go.mod h1:QYRuS/SOXUCsnplDa677K7+DxSOj6IPNl/eQntq43wQ= @@ -359,19 +313,16 @@ github.com/go-toolsmith/pkgload v1.0.0/go.mod h1:5eFArkbO80v7Z0kdngIxsRXRMTaX4Il github.com/go-toolsmith/strparse v1.0.0/go.mod h1:YI2nUKP9YGZnL/L1/DLFBfixrcjslWct4wyljWhSRy8= github.com/go-toolsmith/typep v1.0.0/go.mod h1:JSQCQMUPdRlMZFswiq3TGpNp1GMktqkR2Ns5AIQkATU= github.com/gobuffalo/flect v0.1.5/go.mod h1:W3K3X9ksuZfir8f/LrfVtWmCDQFfayuylOJ7sz/Fj80= -github.com/gobuffalo/flect v0.2.0/go.mod h1:W3K3X9ksuZfir8f/LrfVtWmCDQFfayuylOJ7sz/Fj80= github.com/gobwas/glob v0.2.3/go.mod h1:d3Ez4x06l9bZtSvzIay5+Yzi0fmZzPgnTbPcKjJAkT8= github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ= github.com/gogo/protobuf v1.2.0/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ= github.com/gogo/protobuf v1.2.1/go.mod h1:hp+jE20tsWTFYpLwKvXlhS1hjn+gTNwPg2I6zVXpSg4= -github.com/gogo/protobuf v1.2.2-0.20190723190241-65acae22fc9d h1:3PaI8p3seN09VjbTYC/QWlUZdZ1qS1zGjy7LH2Wt07I= github.com/gogo/protobuf v1.2.2-0.20190723190241-65acae22fc9d/go.mod h1:SlYgWuQ5SjCEi6WLHjHCa1yvBfUnHcTbrrZtXPKa29o= github.com/gogo/protobuf v1.2.2-0.20190730201129-28a6bbf47e48/go.mod h1:SlYgWuQ5SjCEi6WLHjHCa1yvBfUnHcTbrrZtXPKa29o= github.com/gogo/protobuf v1.3.1 h1:DqDEcV5aeaTmdFBePNpYsp3FlcVH/2ISVVM9Qf8PSls= github.com/gogo/protobuf v1.3.1/go.mod h1:SlYgWuQ5SjCEi6WLHjHCa1yvBfUnHcTbrrZtXPKa29o= github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 h1:DACJavvAHhabrF08vX0COfcOBJRhZ8lUbR+ZWIs0Y5g= github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0/go.mod h1:E/TSTwGwJL78qG/PmXZO1EjYhfJinVAhrmmHX6Z8B9k= -github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b h1:VKtxabqXZkF25pY9ekfRL6a582T4P37/31XEstQ5p58= github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= github.com/golang/groupcache v0.0.0-20160516000752-02826c3e7903/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= github.com/golang/groupcache v0.0.0-20190129154638-5b532d6fd5ef/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= @@ -381,15 +332,12 @@ github.com/golang/groupcache v0.0.0-20191027212112-611e8accdfc9/go.mod h1:cIg4er github.com/golang/mock v1.0.0/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= github.com/golang/mock v1.2.0/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= -github.com/golang/mock v1.3.1 h1:qGJ6qTW+x6xX/my+8YUVl4WNpX9B7+/l2tRsHGZ7f2s= github.com/golang/mock v1.3.1/go.mod h1:sBzyDLLjw3U8JLTeZvSv8jJB+tU5PVekmnlKIyFUx0Y= github.com/golang/mock v1.5.0 h1:jlYHihg//f7RRwuPfptm04yp4s7O6Kw8EZiVYIGcH0g= github.com/golang/mock v1.5.0/go.mod h1:CWnOUgYIOo4TcNZ0wHX3YZCqsaM1I1Jvs6v3mP3KVu8= github.com/golang/protobuf v0.0.0-20161109072736-4bd1920723d7/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= -github.com/golang/protobuf v1.2.0 h1:P3YflyNX/ehuJFLhxviNdFxQPkGK5cDcApsge1SqnvM= github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= -github.com/golang/protobuf v1.3.2 h1:6nsPYzhq5kReh6QImI3k5qWzO4PEbvbIW2cwSfR/6xs= github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/protobuf v1.3.3/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaWz5lYuqw= github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8= @@ -426,14 +374,10 @@ github.com/golangplus/bytes v0.0.0-20160111154220-45c989fe5450/go.mod h1:Bk6SMAO github.com/golangplus/fmt v0.0.0-20150411045040-2a5d6d7d2995/go.mod h1:lJgMEyOkYFkPcDKwRXegd+iM6E7matEszMG5HhwytU8= github.com/golangplus/testing v0.0.0-20180327235837-af21d9c3145e/go.mod h1:0AA//k/eakGydO4jKRoRL2j92ZKSzTgj9tclaCrvXHk= github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= -github.com/google/btree v1.0.0 h1:0udJVsspx3VBr5FwtLhQQtuAsVc79tTq0ocGIPAU6qo= github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= -github.com/google/go-cmp v0.2.0 h1:+dTQ8DZQJz0Mb/HjFlkptS1FeQ4cWSnN941F8aEG4SQ= github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= -github.com/google/go-cmp v0.3.0 h1:crn/baboCvb5fXaQ0IJ1SGTsTVrWpDsCWC8EGETZijY= github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= -github.com/google/go-cmp v0.4.0 h1:xsAVV57WRhGj6kEIi8ReJzQlHHqcBYCElAvkovg3B/4= github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU= @@ -441,7 +385,6 @@ github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/ github.com/google/go-querystring v1.0.0 h1:Xkwi/a1rcvNg1PPYe5vI8GbeBY/jrVuDX5ASuANWTrk= github.com/google/go-querystring v1.0.0/go.mod h1:odCYkC5MyYFN7vkCjXpyrEuKhc/BUO6wN/zVPAxq5ck= github.com/google/gofuzz v0.0.0-20161122191042-44d81051d367/go.mod h1:HP5RmnzzSNb993RKQDq4+1A4ia9nllfqcQFTQJedwGI= -github.com/google/gofuzz v1.0.0 h1:A8PeW59pxE9IoFRqBp37U+mSNaQoZ46F1f0f863XSXw= github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= github.com/google/gofuzz v1.1.0 h1:Hsa8mG0dQ46ij8Sl2AYJDUv1oA9/d6Vk+3LG99Oe02g= github.com/google/gofuzz v1.1.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= @@ -452,17 +395,13 @@ github.com/google/pprof v0.0.0-20190723021845-34ac40c74b70/go.mod h1:zfwlbNMJ+OI github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI= github.com/google/uuid v1.0.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/google/uuid v1.1.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= -github.com/google/uuid v1.1.1 h1:Gkbcsh/GbpXz7lPftLA3P6TYMwjCLYm83jiFQZF/3gY= github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/google/uuid v1.1.2 h1:EVhdT+1Kseyi1/pUmXKaFxYsDNy9RQYkMWRH68J/W7Y= github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= -github.com/googleapis/gax-go v2.0.2+incompatible h1:silFMLAnr330+NRuag/VjIGF7TLp/LBrV2CJKFLWEww= github.com/googleapis/gax-go v2.0.2+incompatible/go.mod h1:SFVmujtThgffbyetf+mdk2eWhX2bMyUtNHzFKcPA9HY= github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg= -github.com/googleapis/gax-go/v2 v2.0.5 h1:sjZBwGj9Jlw33ImPtvFviGYvseOtDM7hkSKB7+Tv3SM= github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5mhpdKc/us6bOk= github.com/googleapis/gnostic v0.0.0-20170426233943-68f4ded48ba9/go.mod h1:sJBsCZ4ayReDTBIg8b9dl28c5xFWyhBTVRp3pOg5EKY= -github.com/googleapis/gnostic v0.0.0-20170729233727-0c5108395e2d h1:7XGaL1e6bYS1yIonGp9761ExpPPV1ui0SAC59Yube9k= github.com/googleapis/gnostic v0.0.0-20170729233727-0c5108395e2d/go.mod h1:sJBsCZ4ayReDTBIg8b9dl28c5xFWyhBTVRp3pOg5EKY= github.com/googleapis/gnostic v0.1.0/go.mod h1:sJBsCZ4ayReDTBIg8b9dl28c5xFWyhBTVRp3pOg5EKY= github.com/googleapis/gnostic v0.2.0/go.mod h1:sJBsCZ4ayReDTBIg8b9dl28c5xFWyhBTVRp3pOg5EKY= @@ -470,9 +409,7 @@ github.com/googleapis/gnostic v0.3.1 h1:WeAefnSUHlBb0iJKwxFDZdbfGwkd7xRNuV+IpXMJ github.com/googleapis/gnostic v0.3.1/go.mod h1:on+2t9HRStVgn95RSsFWFz+6Q0Snyqv1awfrALZdbtU= github.com/gophercloud/gophercloud v0.1.0/go.mod h1:vxM41WHh5uqHVBMZHzuwNOHh8XEoIEcSTewFxm1c5g8= github.com/gophercloud/gophercloud v0.3.0/go.mod h1:vxM41WHh5uqHVBMZHzuwNOHh8XEoIEcSTewFxm1c5g8= -github.com/gophercloud/gophercloud v0.6.0 h1:Xb2lcqZtml1XjgYZxbeayEemq7ASbeTp09m36gQFpEU= github.com/gophercloud/gophercloud v0.6.0/go.mod h1:GICNByuaEBibcjmjvI7QvYJSZEbGkcYwAR7EZK2WMqM= -github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1 h1:EGx4pi6eqNxGaHF6qqu48+N2wcFQ5qg5FXgOdqsJ5d8= github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY= github.com/gopherjs/gopherjs v0.0.0-20191106031601-ce3c9ade29de h1:F7WD09S8QB4LrkEpka0dFPLSotH11HRpCsLIbIcJ7sU= github.com/gopherjs/gopherjs v0.0.0-20191106031601-ce3c9ade29de/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY= @@ -489,17 +426,12 @@ github.com/gostaticanalysis/analysisutil v0.0.0-20190318220348-4088753ea4d3/go.m github.com/gregjones/httpcache v0.0.0-20180305231024-9cad4c3443a7/go.mod h1:FecbI9+v66THATjSRHfNgh1IVFe/9kFxbXtjV0ctIMA= github.com/gregjones/httpcache v0.0.0-20190212212710-3befbb6ad0cc/go.mod h1:FecbI9+v66THATjSRHfNgh1IVFe/9kFxbXtjV0ctIMA= github.com/grpc-ecosystem/go-grpc-middleware v0.0.0-20190222133341-cfaf5686ec79/go.mod h1:FiyG127CGDf3tlThmgyCl78X/SZQqEOJBCDaAfeWzPs= -github.com/grpc-ecosystem/go-grpc-middleware v1.0.0/go.mod h1:FiyG127CGDf3tlThmgyCl78X/SZQqEOJBCDaAfeWzPs= github.com/grpc-ecosystem/go-grpc-middleware v1.0.1-0.20190118093823-f849b5445de4/go.mod h1:FiyG127CGDf3tlThmgyCl78X/SZQqEOJBCDaAfeWzPs= -github.com/grpc-ecosystem/go-grpc-middleware v1.1.0 h1:THDBEeQ9xZ8JEaCLyLQqXMMdRqNr0QAUJTIkQAUtFjg= github.com/grpc-ecosystem/go-grpc-middleware v1.1.0/go.mod h1:f5nM7jw/oeRSadq3xCzHAvxcr8HZnzsqU6ILg/0NiiE= -github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0 h1:Ovs26xHkKqVztRpIrF/92BcuyuQ/YW4NSIpoGtfXNho= github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0/go.mod h1:8NvIoxWQoOIhqOTXgfV/d3M/q6VIi02HzZEHgUlZvzk= github.com/grpc-ecosystem/grpc-gateway v1.3.0/go.mod h1:RSKVYQBd5MCa4OVpNdGskqpgL2+G+NZTnrVHpWWfpdw= -github.com/grpc-ecosystem/grpc-gateway v1.9.0/go.mod h1:vNeuVxBJEsws4ogUvrchl83t/GYV9WGTSLVdBhOQFDY= github.com/grpc-ecosystem/grpc-gateway v1.9.4/go.mod h1:vNeuVxBJEsws4ogUvrchl83t/GYV9WGTSLVdBhOQFDY= github.com/grpc-ecosystem/grpc-gateway v1.9.5/go.mod h1:vNeuVxBJEsws4ogUvrchl83t/GYV9WGTSLVdBhOQFDY= -github.com/grpc-ecosystem/grpc-gateway v1.12.1 h1:zCy2xE9ablevUOrUZc3Dl72Dt+ya2FNAvC2yLYMHzi4= github.com/grpc-ecosystem/grpc-gateway v1.12.1/go.mod h1:8XEsbTttt/W+VvjtQhLACqCisSPWTxCZ7sBRjU6iH9c= github.com/grpc-ecosystem/grpc-gateway v1.16.0/go.mod h1:BDjrQk3hbvj6Nolgz8mAMFbcEtjT1g+wF4CSlocrBnw= github.com/hashicorp/consul/api v1.1.0/go.mod h1:VmuI/Lkw1nC05EYQWNKwWGbkg+FbDBtguAZLlVdkD9Q= @@ -537,13 +469,11 @@ github.com/hashicorp/memberlist v0.1.3/go.mod h1:ajVTdAv/9Im8oMAAj5G31PhhMCZJV2p github.com/hashicorp/memberlist v0.1.5/go.mod h1:ajVTdAv/9Im8oMAAj5G31PhhMCZJV2pPBoIllUwCN7I= github.com/hashicorp/serf v0.8.2/go.mod h1:6hOLApaqBFA1NXqRQAsxw9QxuDEvNxSQRwA/JwenrHc= github.com/hashicorp/serf v0.8.5/go.mod h1:UpNcs7fFbpKIyZaUuSW6EPiH+eZC7OuyFD+wc1oal+k= -github.com/heptio/authenticator v0.0.0-20180409043135-d282f87a1972 h1:Bah0yCXJwqJ7v2QLGdwkQoI/PBXYIBSkyTfirp6nbRk= github.com/heptio/authenticator v0.0.0-20180409043135-d282f87a1972/go.mod h1:Q86X8hc61JXhE5XxYLKmrSRWby/Oe8IIYZIBgmGVkTA= github.com/heroku/docker-registry-client v0.0.0-20211012143308-9463674c8930 h1:mNL9ktJqBuzPTV/QP/fKd4y1uOFvfiv6zhe0G7lg9OA= github.com/heroku/docker-registry-client v0.0.0-20211012143308-9463674c8930/go.mod h1:Yho0S7KhsnHQRCC5lDraYF1SsLMeWtf/tKdufKu3TJA= github.com/hpcloud/tail v1.0.0 h1:nfCOvKYfkgYP8hkirhJocXT2+zOD8yUNjXaWfTlyFKI= github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= -github.com/huandu/xstrings v1.2.0 h1:yPeWdRnmynF7p+lLYz0H2tthW9lqhMJrQV/U7yy4wX0= github.com/huandu/xstrings v1.2.0/go.mod h1:DvyZB1rfVYsBIigL8HwpZgxHwXozlTgGqn63UyNX5k4= github.com/imdario/mergo v0.3.5/go.mod h1:2EnlNZ0deacrJVfApfmtdGgDfMuh/nq6Ok1EcJh5FfA= github.com/imdario/mergo v0.3.6/go.mod h1:2EnlNZ0deacrJVfApfmtdGgDfMuh/nq6Ok1EcJh5FfA= @@ -560,12 +490,10 @@ github.com/jakecoffman/cron v0.0.0-20190106200828-7e2009c226a5 h1:kCvm3G3u+eTRbj github.com/jakecoffman/cron v0.0.0-20190106200828-7e2009c226a5/go.mod h1:6DM2KNNK69jRu0lAHmYK9LYxmqpNjYHOaNp/ZxttD4U= github.com/jessevdk/go-flags v0.0.0-20180331124232-1c38ed7ad0cc/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI= github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI= -github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af h1:pmfjZENx5imkbgOkpRUYLnmbU7UEFbjtDA2hxJ1ichM= github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af/go.mod h1:Nht3zPeWKUH0NzdCt2Blrr5ys8VGpn0CEB0cQHVjt7k= github.com/jmoiron/sqlx v1.2.0 h1:41Ip0zITnmWNR/vHV+S4m+VoUivnWY5E4OJfLZjCJMA= github.com/jmoiron/sqlx v1.2.0/go.mod h1:1FEQNm3xlJgrMD+FBdI9+xvCksHtbpVBBw5dYhBSsks= github.com/joeshaw/multierror v0.0.0-20140124173710-69b34d4ec901/go.mod h1:Z86h9688Y0wesXCyonoVr47MasHilkuLMqGhRZ4Hpak= -github.com/jonboulle/clockwork v0.1.0 h1:VKV+ZcuP6l3yW9doeqz6ziZGgcynBVQO+obU0+0hcPo= github.com/jonboulle/clockwork v0.1.0/go.mod h1:Ii8DK3G1RaLaWxj9trq07+26W01tbo22gdxWY5EU2bo= github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY= github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y= @@ -573,15 +501,12 @@ github.com/jpillora/backoff v1.0.0/go.mod h1:J/6gKK9jxlEcS3zixgDgUAsiuZ7yrSoa/FX github.com/json-iterator/go v0.0.0-20180612202835-f2b4162afba3/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU= github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU= github.com/json-iterator/go v1.1.7/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= -github.com/json-iterator/go v1.1.8 h1:QiWkFLKq0T7mpzwOTu6BzNDbfTE8OLrYhVKYMLF46Ok= github.com/json-iterator/go v1.1.8/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= github.com/json-iterator/go v1.1.9 h1:9yzud/Ht36ygwatGx56VwCZtlI/2AD15T1X2sjSuGns= github.com/json-iterator/go v1.1.9/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= github.com/jsonnet-bundler/jsonnet-bundler v0.2.0/go.mod h1:/by7P/OoohkI3q4CgSFqcoFsVY+IaNbzOVDknEsKDeU= github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU= github.com/jstemmer/go-junit-report v0.9.1/go.mod h1:Brl9GWCQeLvo8nXZwPNNblvFj/XSXhF0NWZEnDohbsk= -github.com/jteeuwen/go-bindata v3.0.7+incompatible h1:91Uy4d9SYVr1kyTJ15wJsog+esAZZl7JmEfTkwmhJts= -github.com/jteeuwen/go-bindata v3.0.7+incompatible/go.mod h1:JVvhzYOiGBnFSYRyV00iY8q7/0PThjIYav1p9h5dmKs= github.com/jtolds/gls v4.20.0+incompatible h1:xdiiI2gbIgH/gLH7ADydsJ1uDOEzR8yvV7C0MuV77Wo= github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU= github.com/juju/errors v0.0.0-20170703010042-c7d06af17c68 h1:d2hBkTvi7B89+OXY8+bBBshPlc+7JYacGrG/dFak8SQ= @@ -607,13 +532,9 @@ github.com/kisielk/errcheck v1.1.0/go.mod h1:EZBBE59ingxPouuu3KfxchcWSUPOHkagtvW github.com/kisielk/errcheck v1.2.0/go.mod h1:/BMXB+zMLi60iA8Vv6Ksmxu/1UDYcXs4uQLJ+jE2L00= github.com/kisielk/gotool v0.0.0-20161130080628-0de1eaf82fa3/go.mod h1:jxZFDH7ILpTPQTk+E2s+z4CUas9lVNjIuKR4c5/zKgM= github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= -github.com/klauspost/compress v0.0.0-20170528132359-f3dce52e0576 h1:R6khN0uOjEbQcphA5ttrwxtOH/xoMU+gou/bByoufZE= -github.com/klauspost/compress v0.0.0-20170528132359-f3dce52e0576/go.mod h1:RyIbtBH6LamlWaDj8nUwkbUhJ87Yi3uG0guNDohfE1A= github.com/klauspost/compress v1.4.0/go.mod h1:RyIbtBH6LamlWaDj8nUwkbUhJ87Yi3uG0guNDohfE1A= github.com/klauspost/compress v1.4.1 h1:8VMb5+0wMgdBykOV96DwNwKFQ+WTI4pzYURP99CcB9E= github.com/klauspost/compress v1.4.1/go.mod h1:RyIbtBH6LamlWaDj8nUwkbUhJ87Yi3uG0guNDohfE1A= -github.com/klauspost/cpuid v0.0.0-20160302075316-09cded8978dc h1:WW8B7p7QBnFlqRVv/k6ro/S8Z7tCnYjJHcQNScx9YVs= -github.com/klauspost/cpuid v0.0.0-20160302075316-09cded8978dc/go.mod h1:Pj4uuM528wm8OyEC2QMXAi2YiTZ96dNQPGgoMS4s3ek= github.com/klauspost/cpuid v0.0.0-20180405133222-e7e905edc00e/go.mod h1:Pj4uuM528wm8OyEC2QMXAi2YiTZ96dNQPGgoMS4s3ek= github.com/klauspost/cpuid v1.2.0 h1:NMpwD2G9JSFOE1/TJjGSo5zG7Yb2bTe7eq1jH+irmeE= github.com/klauspost/cpuid v1.2.0/go.mod h1:Pj4uuM528wm8OyEC2QMXAi2YiTZ96dNQPGgoMS4s3ek= @@ -622,18 +543,15 @@ github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxv github.com/konsorten/go-windows-terminal-sequences v1.0.2 h1:DB17ag19krx9CFsz4o3enTrPXyIXCl+2iCXH/aMAp9s= github.com/konsorten/go-windows-terminal-sequences v1.0.2/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc= -github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/pty v1.1.5/go.mod h1:9r2w37qlBe7rQ6e1fg1S/9xpWHSnaqNdHD3WcMdbPDA= -github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= github.com/kylelemons/godebug v0.0.0-20160406211939-eadb3ce320cb/go.mod h1:B69LEHPfb2qLo0BaaOLcbitczOKLWTsrBG9LczfCD4k= github.com/kylelemons/godebug v0.0.0-20170820004349-d65d576e9348/go.mod h1:B69LEHPfb2qLo0BaaOLcbitczOKLWTsrBG9LczfCD4k= github.com/leanovate/gopter v0.2.4/go.mod h1:gNcbPWNEWRe4lm+bycKqxUYoH5uoVje5SkOJ3uoLer8= -github.com/lib/pq v1.0.0 h1:X5PMW56eZitiTeO7tKzZxFCSpbFZJtkMMooicw2us9A= github.com/lib/pq v1.0.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo= github.com/lib/pq v1.3.0 h1:/qkRGz8zljWiDcFvgpwUpwIAPu3r07TDvs3Rws+o/pU= github.com/lib/pq v1.3.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo= @@ -650,7 +568,6 @@ github.com/mailru/easyjson v0.0.0-20180823135443-60711f1a8329/go.mod h1:C1wdFJiN github.com/mailru/easyjson v0.0.0-20190312143242-1de009706dbe/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc= github.com/mailru/easyjson v0.0.0-20190614124828-94de47d64c63/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc= github.com/mailru/easyjson v0.0.0-20190626092158-b2ccc519800e/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc= -github.com/mailru/easyjson v0.7.0 h1:aizVhC/NAAcKWb+5QsU1iNOZb4Yws5UO2I+aIprQITM= github.com/mailru/easyjson v0.7.0/go.mod h1:KAzv3t3aY1NaHWoQz1+4F1ccyAH66Jk7yos7ldAVICs= github.com/mailru/easyjson v0.7.6 h1:8yTIVnZgCoiM1TgqoeTl+LfU5Jg6/xL3QhGQnimLYnA= github.com/mailru/easyjson v0.7.6/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc= @@ -667,21 +584,18 @@ github.com/mattn/go-ieproxy v0.0.0-20191113090002-7c0f6868bffe/go.mod h1:pYabZ6I github.com/mattn/go-isatty v0.0.3/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4= github.com/mattn/go-isatty v0.0.4/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4= github.com/mattn/go-isatty v0.0.6/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s= -github.com/mattn/go-isatty v0.0.8 h1:HLtExJ+uU2HOZ+wI0Tt5DtUDrx8yhUqDcp7fYERX4CE= github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s= github.com/mattn/go-isatty v0.0.12 h1:wuysRhFDzyxgEmMf5xjvJ2M9dZoWAXNNr5LSBS7uHXY= github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU= github.com/mattn/go-runewidth v0.0.2/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU= github.com/mattn/go-runewidth v0.0.4/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU= github.com/mattn/go-runewidth v0.0.6/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI= -github.com/mattn/go-sqlite3 v1.9.0 h1:pDRiWfl+++eC2FEFRy6jXmQlvp4Yh3z1MJKg4UeYM/4= github.com/mattn/go-sqlite3 v1.9.0/go.mod h1:FPy6KqzDD04eiIsT53CuJW3U88zkxoIYsOqkbpncsNc= github.com/mattn/go-sqlite3 v1.12.0 h1:u/x3mp++qUxvYfulZ4HKOvVO0JWhk7HtE8lWhbGz/Do= github.com/mattn/go-sqlite3 v1.12.0/go.mod h1:FPy6KqzDD04eiIsT53CuJW3U88zkxoIYsOqkbpncsNc= github.com/mattn/goveralls v0.0.2/go.mod h1:8d1ZMHsd7fW6IRPKQh46F2WRpyib5/X4FOpevwGNQEw= github.com/matttproud/golang_protobuf_extensions v1.0.1 h1:4hp9jkHxhMHkqkrB3Ix0jegS5sx/RkqARlsWZ6pIwiU= github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0= -github.com/mcuadros/go-version v0.0.0-20180611085657-6d5863ca60fa h1:XvNrttGMJfVrUqblGju4IkjYXwx6l5OAAyjaIsydzsk= github.com/mcuadros/go-version v0.0.0-20180611085657-6d5863ca60fa/go.mod h1:76rfSfYPWj01Z85hUf/ituArm797mNKcvINh1OlsZKo= github.com/microcosm-cc/bluemonday v0.0.0-20161202143824-e79763773ab6 h1:2T48MyyWdAAK0H21T9BNxQTSzQDaamS1t1tAvNHHXjE= github.com/microcosm-cc/bluemonday v0.0.0-20161202143824-e79763773ab6/go.mod h1:hsXNsILzKxV+sX77C5b8FSuKF00vh2OMYv+xgHpAMF4= @@ -691,7 +605,6 @@ github.com/miekg/dns v1.1.22/go.mod h1:bPDLeHnStXmXAq1m/Ch/hvfNHr14JKNPMBo3VZKju github.com/minio/minio-go/v6 v6.0.44/go.mod h1:qD0lajrGW49lKZLtXKtCB4X/qkMf0a5tBvN2PaZg7Gg= github.com/minio/sha256-simd v0.1.1/go.mod h1:B5e1o+1/KgNmWrSQK08Y6Z1Vb5pwIktudl0J58iy0KM= github.com/mitchellh/cli v1.0.0/go.mod h1:hNIlj7HEI86fIcpObd7a0FcrxTWetlwJDGcceTlRvqc= -github.com/mitchellh/copystructure v1.0.0 h1:Laisrj+bAB6b/yJwB5Bt3ITZhGJdqmxquMKeZ+mmkFQ= github.com/mitchellh/copystructure v1.0.0/go.mod h1:SNtv71yrdKgLRyLFxmLdkAbkKEFWgYaq1OVrnRcwhnw= github.com/mitchellh/go-homedir v1.0.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= @@ -704,7 +617,6 @@ github.com/mitchellh/iochan v1.0.0/go.mod h1:JwYml1nuB7xOzsp52dPpHFffvOCDupsG0Qu github.com/mitchellh/mapstructure v0.0.0-20160808181253-ca63d7c062ee/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y= github.com/mitchellh/mapstructure v0.0.0-20180220230111-00c29f56e238/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y= github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y= -github.com/mitchellh/reflectwalk v1.0.0 h1:9D+8oIskB4VJBN5SFlmc27fSlIBZaov1Wpk/IfikLNY= github.com/mitchellh/reflectwalk v1.0.0/go.mod h1:mSTlrgnPZtwu0c4WaC2kGObEpuNDbx0jmZXqmk4esnw= github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg= @@ -715,7 +627,6 @@ github.com/modern-go/reflect2 v1.0.1 h1:9f412s+6RmYXLWZSEzVVgPGK7C2PphHj5RJrvfx9 github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= github.com/monoculum/formam v0.0.0-20170713212123-6292a2420ab5 h1:pQI4XOmm3vmgrCuEJpEV7ZpkAV5lnRl/EMpAP7nz73M= github.com/monoculum/formam v0.0.0-20170713212123-6292a2420ab5/go.mod h1:RKgILGEJq24YyJ2ban8EO0RUVSJlF1pGsEvoLEACr/Q= -github.com/morikuni/aec v0.0.0-20170113033406-39771216ff4c h1:nXxl5PrvVm2L/wCy8dQu6DMTwH4oIuGN8GJDAlqDdVE= github.com/morikuni/aec v0.0.0-20170113033406-39771216ff4c/go.mod h1:BbKIizmSmc5MMPqRYbxO4ZU0S0+P200+tUnFx7PXmsc= github.com/moul/http2curl v1.0.0 h1:dRMWoAtb+ePxMlLkrCbAqh4TlPHXvoGUSQ323/9Zahs= github.com/moul/http2curl v1.0.0/go.mod h1:8UbvGypXm98wA/IqH45anm5Y2Z6ep6O31QGOAZ3H0fQ= @@ -744,9 +655,7 @@ github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+W github.com/onsi/ginkgo v1.7.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= github.com/onsi/ginkgo v1.8.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= github.com/onsi/ginkgo v1.10.1/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= -github.com/onsi/ginkgo v1.10.3 h1:OoxbjfXVZyod1fmWYhI7SEyaD8B00ynP3T+D5GiyHOY= github.com/onsi/ginkgo v1.10.3/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= -github.com/onsi/ginkgo v1.11.0 h1:JAKSXpt1YjtLA7YpPiqO9ss6sNXEsPfSGdwN0UHqzrw= github.com/onsi/ginkgo v1.11.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= github.com/onsi/ginkgo v1.12.0 h1:Iw5WCbBcaAAd0fpRb1c9r5YCylv4XDoCSigm1zLevwU= github.com/onsi/ginkgo v1.12.0/go.mod h1:oUhWkIvk5aDxtKvDDuw8gItl8pKl42LzjC9KZE0HfGg= @@ -755,9 +664,7 @@ github.com/onsi/gomega v1.4.2/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1Cpa github.com/onsi/gomega v1.4.3/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY= github.com/onsi/gomega v1.5.0/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY= github.com/onsi/gomega v1.7.0/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY= -github.com/onsi/gomega v1.7.1 h1:K0jcRCwNQM3vFGh1ppMtDh/+7ApJrjldlX8fA0jDTLQ= github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7JYyY= -github.com/onsi/gomega v1.8.1 h1:C5Dqfs/LeauYDX0jJXIe2SWmwCbGzx9yF8C8xy3Lh34= github.com/onsi/gomega v1.8.1/go.mod h1:Ho0h+IUsWyvy1OpqCwxlQ/21gkhVunqlU8fDGcoTdcA= github.com/onsi/gomega v1.9.0 h1:R1uwffexN6Pr340GtYRIdZmAiN4J+iw6WG4wog1DUXg= github.com/onsi/gomega v1.9.0/go.mod h1:Ho0h+IUsWyvy1OpqCwxlQ/21gkhVunqlU8fDGcoTdcA= @@ -792,7 +699,6 @@ github.com/peterbourgon/diskv v2.0.1+incompatible/go.mod h1:uqqh8zWWbv1HBMNONnaR github.com/phpdave11/gofpdi v1.0.7/go.mod h1:vBmVV0Do6hSBHC8uKUQ71JGW+ZGQq74llk/7bXwjDoI= github.com/pierrec/lz4 v2.0.5+incompatible/go.mod h1:pdkljMzZIN41W+lC3N2tnIh5sFi+IEE17M5jbnwPHcY= github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= -github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I= github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= @@ -801,17 +707,13 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/posener/complete v1.1.1/go.mod h1:em0nMJCgc9GFtwrmVmEMR/ZL6WyhyjMBndrE9hABlRI= github.com/pquerna/cachecontrol v0.0.0-20171018203845-0dec1b30a021/go.mod h1:prYjPmNq4d1NPVmpShWobRqXY3q7Vp+80DqgxxUrUIA= -github.com/prashantv/gostub v1.0.0 h1:wTzvgO04xSS3gHuz6Vhuo0/kvWelyJxwNS0IRBPAwGY= -github.com/prashantv/gostub v1.0.0/go.mod h1:dP1v6T1QzyGJJKFocwAU0lSZKpfjstjH8TlhkEU0on0= github.com/prometheus/alertmanager v0.18.0/go.mod h1:WcxHBl40VSPuOaqWae6l6HpnEOVRIycEJ7i9iYkadEE= github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw= github.com/prometheus/client_golang v0.9.2/go.mod h1:OsXs2jCmiKlQ1lTBmv21f2mNfw4xf/QclQDMrYNZzcM= github.com/prometheus/client_golang v0.9.3-0.20190127221311-3c4408c8b829/go.mod h1:p2iRAGwDERtqlqzRXnrOVns+ignqQo//hLXqYxZYVNs= -github.com/prometheus/client_golang v0.9.3/go.mod h1:/TN21ttK/J9q6uSwhBd54HahCDft0ttaMvbicHlPoso= github.com/prometheus/client_golang v1.0.0/go.mod h1:db9x61etRT2tGnBNRi70OPL5FsnadC4Ky3P0J6CfImo= github.com/prometheus/client_golang v1.2.0/go.mod h1:XMU6Z2MjaRKVu/dC1qupJI9SiNkDYzz3xecMgSW/F+U= github.com/prometheus/client_golang v1.2.1/go.mod h1:XMU6Z2MjaRKVu/dC1qupJI9SiNkDYzz3xecMgSW/F+U= -github.com/prometheus/client_golang v1.4.0 h1:YVIb/fVcOTMSqtqZWSKnHpSLBxu8DKgxq8z6RuBZwqI= github.com/prometheus/client_golang v1.4.0/go.mod h1:e9GMxYsXl05ICDXkRhurwBS4Q3OK1iX/F2sw+iXX5zU= github.com/prometheus/client_golang v1.5.1 h1:bdHYieyGlH+6OLEk2YQha8THib30KP0/yD0YH9m6xcA= github.com/prometheus/client_golang v1.5.1/go.mod h1:e9GMxYsXl05ICDXkRhurwBS4Q3OK1iX/F2sw+iXX5zU= @@ -821,10 +723,8 @@ github.com/prometheus/client_model v0.0.0-20190129233127-fd36f4220a90/go.mod h1: github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= github.com/prometheus/client_model v0.2.0 h1:uq5h0d+GuxiXLJLNABMgp2qUWDPiLvgCzz2dUR+/W/M= github.com/prometheus/client_model v0.2.0/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= -github.com/prometheus/common v0.0.0-20181113130724-41aa239b4cce/go.mod h1:daVV7qP5qjZbuso7PdcryaAu0sAZbrN9i7WWcTMWvro= github.com/prometheus/common v0.0.0-20181126121408-4724e9255275/go.mod h1:daVV7qP5qjZbuso7PdcryaAu0sAZbrN9i7WWcTMWvro= github.com/prometheus/common v0.2.0/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4= -github.com/prometheus/common v0.4.0/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4= github.com/prometheus/common v0.4.1/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4= github.com/prometheus/common v0.7.0/go.mod h1:DjGbpBbp5NYNiECxcL/VnbXCCaQpKd3tt26CguLLsqA= github.com/prometheus/common v0.9.1 h1:KOMtN28tlbam3/7ZKEYKHhKoJZYYj3gMH4uc62x7X7U= @@ -833,7 +733,6 @@ github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R github.com/prometheus/procfs v0.0.0-20181204211112-1dc9a6cbc91a/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk= github.com/prometheus/procfs v0.0.0-20190117184657-bf6a532e95b1/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk= github.com/prometheus/procfs v0.0.0-20190425082905-87a4384529e0/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA= -github.com/prometheus/procfs v0.0.0-20190507164030-5867b95ac084/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA= github.com/prometheus/procfs v0.0.2/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA= github.com/prometheus/procfs v0.0.3/go.mod h1:4A/X28fw3Fc593LaREMrKMqOKvUAntwMDaekg4FpcdQ= github.com/prometheus/procfs v0.0.5/go.mod h1:4A/X28fw3Fc593LaREMrKMqOKvUAntwMDaekg4FpcdQ= @@ -843,7 +742,6 @@ github.com/prometheus/procfs v0.0.8/go.mod h1:7Qr8sr6344vo1JqZ6HhLceV9o3AJ1Ff+Gx github.com/prometheus/prometheus v0.0.0-20180315085919-58e2a31db8de/go.mod h1:oAIUtOny2rjMX0OWN5vPR5/q/twIROJvdqnQKDdil/s= github.com/prometheus/prometheus v1.8.2-0.20200107122003-4708915ac6ef/go.mod h1:7U90zPoLkWjEIQcy/rweQla82OCTUzxVHE51G3OhJbI= github.com/prometheus/prometheus v2.3.2+incompatible/go.mod h1:oAIUtOny2rjMX0OWN5vPR5/q/twIROJvdqnQKDdil/s= -github.com/prometheus/tsdb v0.7.1/go.mod h1:qhTCs0VvXwvX/y3TZrWD7rabWM+ijKTux40TwIPHuXU= github.com/quasilyte/go-consistent v0.0.0-20190521200055-c6f3937de18c/go.mod h1:5STLWrekHfjyYwxBRVRXNOSewLJ3PWfDJd1VyTS21fI= github.com/rancher/kontainer-engine v0.0.4-dev.0.20201202223022-33de45824b08 h1:iNnxIjRXUKre4eptdHO2rleUFyG4PSUkgPRjyAWFWio= github.com/rancher/kontainer-engine v0.0.4-dev.0.20201202223022-33de45824b08/go.mod h1:CofnuNGQefXjvq95fwXNVFJzOdrVW3ZUtQZC9ezQzHQ= @@ -893,11 +791,9 @@ github.com/shurcooL/vfsgen v0.0.0-20180825020608-02ddb050ef6b/go.mod h1:TrYk7fJV github.com/shurcooL/vfsgen v0.0.0-20181202132449-6a9ea43bcacd/go.mod h1:TrYk7fJVaAttu97ZZKrO9UbRa8izdowaMIZcxYMbVaw= github.com/sirupsen/logrus v1.0.5/go.mod h1:pMByvHTf9Beacp5x1UXfOR9xyW/9antXMhjMPG0dEzc= github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo= -github.com/sirupsen/logrus v1.4.2 h1:SPIRibHv4MatM3XXNO2BJeFLZwZ2LvZgfQ5+UNI2im4= github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE= github.com/sirupsen/logrus v1.5.0 h1:1N5EYkVAPEywqZRJd7cwnRtCb6xJx7NH3T3WUTF980Q= github.com/sirupsen/logrus v1.5.0/go.mod h1:+F7Ogzej0PZc/94MaYx/nvG9jOFMD2osvC3s+Squfpo= -github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d h1:zE9ykElWQ6/NYmHa3jpm/yHnI4xSofP+UP6SpjHcSeM= github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc= github.com/smartystreets/assertions v1.0.1 h1:voD4ITNjPL5jjBfgR/r8fPIIBrliWrWHeiJApdr3r4w= github.com/smartystreets/assertions v1.0.1/go.mod h1:kHHU4qYBaI3q23Pp3VPrmWhuIUrLW/7eUrw0BU5VaoM= @@ -905,7 +801,6 @@ github.com/smartystreets/goconvey v0.0.0-20190330032615-68dc04aab96a/go.mod h1:s github.com/smartystreets/goconvey v1.6.4 h1:fv0U8FUIMPNf1L9lnHLvLhgicrIVChEkdzIKYqbNC9s= github.com/smartystreets/goconvey v1.6.4/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA= github.com/soheilhy/cmux v0.1.3/go.mod h1:IM3LyeVVIOuxMH7sFAkER9+bJ4dT7Ms6E4xg4kGIyLM= -github.com/soheilhy/cmux v0.1.4 h1:0HKaf1o97UwFjHH9o5XsHUOF+tqmdA7KEzXLpiyaw0E= github.com/soheilhy/cmux v0.1.4/go.mod h1:IM3LyeVVIOuxMH7sFAkER9+bJ4dT7Ms6E4xg4kGIyLM= github.com/sourcegraph/go-diff v0.5.1/go.mod h1:j2dHj3m8aZgQO8lMTcTnBcXkRRRqi34cd2MNlA9u1mE= github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA= @@ -914,12 +809,10 @@ github.com/spf13/afero v1.1.0/go.mod h1:j4pytiNVoe2o6bmDsKpLACNPDBIoEAkihy7loJ1B github.com/spf13/afero v1.1.2/go.mod h1:j4pytiNVoe2o6bmDsKpLACNPDBIoEAkihy7loJ1B0CQ= github.com/spf13/afero v1.2.2/go.mod h1:9ZxEEn6pIJ8Rxe320qSDBk6AsU0r9pR7Q4OcevTdifk= github.com/spf13/cast v1.2.0/go.mod h1:r2rcYCSwa1IExKTDiTfzaxqT2FNHs8hODu4LnUfgKEg= -github.com/spf13/cast v1.3.0 h1:oget//CVOEoFewqQxwr0Ej5yjygnqGkvggSE/gB35Q8= github.com/spf13/cast v1.3.0/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE= github.com/spf13/cobra v0.0.2/go.mod h1:1l0Ry5zgKvJasoi3XT1TypsSe7PqH0Sj9dhYf7v3XqQ= github.com/spf13/cobra v0.0.3/go.mod h1:1l0Ry5zgKvJasoi3XT1TypsSe7PqH0Sj9dhYf7v3XqQ= github.com/spf13/cobra v0.0.5/go.mod h1:3K3wKZymM7VvHMDS9+Akkh4K60UwM26emMESw8tLCHU= -github.com/spf13/cobra v1.0.0/go.mod h1:/6GTrnGXV9HjY+aR4k0oJ5tcvakLuG6EuKReYlHNrgE= github.com/spf13/jwalterweatherman v0.0.0-20180109140146-7c0cea34c8ec/go.mod h1:cQK4TGJAtQXfYWX+Ddv3mKDzgVb68N+wFjFa4jdeBTo= github.com/spf13/jwalterweatherman v1.0.0/go.mod h1:cQK4TGJAtQXfYWX+Ddv3mKDzgVb68N+wFjFa4jdeBTo= github.com/spf13/pflag v0.0.0-20170130214245-9ff6c6923cff/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4= @@ -929,24 +822,19 @@ github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= github.com/spf13/viper v1.0.2/go.mod h1:A8kyI5cUJhb8N+3pkfONlcEcZbueH6nhAm0Fq7SrnBM= github.com/spf13/viper v1.3.2/go.mod h1:ZiWeW+zYFKm7srdB9IoDzzZXaJaI5eL9QjNiN/DMA2s= -github.com/spf13/viper v1.4.0/go.mod h1:PTJ7Z/lr49W6bUbkmS1V3by4uWynFiR9p7+dSq/yZzE= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.2.0/go.mod h1:qt09Ya8vawLte6SNmTgCsAVtYtaKzEcn8ATUoHMkEqE= github.com/stretchr/testify v0.0.0-20151208002404-e3a8ff8ce365/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= -github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk= github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= -github.com/stretchr/testify v1.5.1 h1:nOGnQDM7FYENwehXlg/kFVnos3rEvtKTjRvOWSzb6H4= github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/swaggo/files v0.0.0-20210815190702-a29dd2bc99b2 h1:+iNTcqQJy0OZ5jk6a5NLib47eqXK8uYcPX+O4+cBpEM= github.com/swaggo/files v0.0.0-20210815190702-a29dd2bc99b2/go.mod h1:lKJPbtWzJ9JhsTN1k1gZgleJWY/cqq0psdoMmaThG3w= -github.com/swaggo/http-swagger v1.2.5 h1:iDWoHpJMLNo4nwGOPXsOoqlB9wB6M4xgjhws8x3KQcs= -github.com/swaggo/http-swagger v1.2.5/go.mod h1:CcoICgY3yVDk2u1LQUCMHbAj0fjlxIX+873psXlIKNA= github.com/swaggo/swag v1.7.9 h1:6vCG5mm43ebDzGlZPMGYrYI4zKFfOr5kicQX8qjeDwc= github.com/swaggo/swag v1.7.9/go.mod h1:gZ+TJ2w/Ve1RwQsA2IRoSOTidHz6DX+PIG8GWvbnoLU= github.com/thanos-io/thanos v0.10.1/go.mod h1:usT/TxtJQ7DzinTt+G9kinDQmRS5sxwu0unVKZ9vdcw= @@ -955,12 +843,10 @@ github.com/timakin/bodyclose v0.0.0-20190721030226-87058b9bfcec/go.mod h1:Qimiff github.com/tjfoc/gmsm v1.4.1 h1:aMe1GlZb+0bLjn+cKTPEvvn9oUEBlJitaZiiBwsbgho= github.com/tjfoc/gmsm v1.4.1/go.mod h1:j4INPkHWMrhJb38G+J6W4Tw0AbuN8Thu3PbdVYhVcTE= github.com/tmc/grpc-websocket-proxy v0.0.0-20170815181823-89b8d40f7ca8/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U= -github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5 h1:LnC5Kc/wtumK+WB441p7ynQJzVuNRJiqddSIE3IlSEQ= github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U= github.com/tv42/httpunix v0.0.0-20150427012821-b75d8614f926/go.mod h1:9ESjWnEqriFuLhtthL60Sar/7RFoluCcXsuvEwTV5KM= github.com/uber/jaeger-client-go v2.20.1+incompatible/go.mod h1:WVhlPFC8FDjOFMMWRy2pZqQJSXxYSwNYOkTr/Z6d3Kk= github.com/uber/jaeger-lib v2.2.0+incompatible/go.mod h1:ComeNDZlWwrWnDv8aPp0Ba6+uUTzImX/AauajbLI56U= -github.com/ugorji/go v1.1.4/go.mod h1:uQMGLiO92mf5W77hV/PUCpI3pbzQx3CRekS0kk+RGrc= github.com/ugorji/go/codec v0.0.0-20181204163529-d75b2dcb6bc8/go.mod h1:VFNgLljTbGfSG7qAOspJ7OScBnGdDN/yBr0sguwnwf0= github.com/ultraware/funlen v0.0.1/go.mod h1:Dp4UiAus7Wdb9KUZsYWZEWiRzGuM2kXM1lPbfaF6xhA= github.com/urfave/cli v1.20.0 h1:fDqGv3UG/4jbVl/QkFwEdddtEDjh/5Ov6X+0B/3bPaw= @@ -971,9 +857,8 @@ github.com/valyala/fasthttp v1.2.0/go.mod h1:4vX61m6KN+xDduDNwXrhIAVZaZaZiQ1luJk github.com/valyala/quicktemplate v1.1.1/go.mod h1:EH+4AkTd43SvgIbQHYu59/cJyxDoOVRUAfrukLPuGJ4= github.com/valyala/tcplisten v0.0.0-20161114210144-ceec8f93295a/go.mod h1:v3UYOV9WzVtRmSR+PDvWpU/qWl4Wa5LApYYX4ZtKbio= github.com/vektah/gqlparser v1.1.2/go.mod h1:1ycwN7Ij5njmMkPPAOaRFY4rET2Enx7IkVv3vaXspKw= +github.com/wangqi811/gomonkey/v2 v2.1.0 h1:ngAFGCFE+yFuM+luf08OAGEmYKhsVklCefh16pwNKFQ= github.com/wangqi811/gomonkey/v2 v2.1.0/go.mod h1:QulvSLbSPdF/X5sag4pbmIMcbgBmtk5SDGgzD5U/lGc= -github.com/wcharczuk/go-chart v1.1.0 h1:aCP+Wgzvw0AqhA7RJpfQpvRUY7IUPGEqqNXS6aXTTCI= -github.com/wcharczuk/go-chart v2.0.1+incompatible h1:0pz39ZAycJFF7ju/1mepnk26RLVLBCWz1STcD3doU0A= github.com/wcharczuk/go-chart/v2 v2.1.0 h1:tY2slqVQ6bN+yHSnDYwZebLQFkphK4WNrVwnt7CJZ2I= github.com/wcharczuk/go-chart/v2 v2.1.0/go.mod h1:yx7MvAVNcP/kN9lKXM/NTce4au4DFN99j6i1OwDclNA= github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f h1:J9EGpcZtP0E/raorCMxlFGSTBrsSlaDGf3jU/qvAE2c= @@ -983,7 +868,6 @@ github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415/go.mod h1: github.com/xeipuuv/gojsonschema v1.2.0 h1:LhYJRs+L4fBtjZUfuSZIKGeVu0QRy8e5Xi7D17UxZ74= github.com/xeipuuv/gojsonschema v1.2.0/go.mod h1:anYRn/JVcOK2ZgGU+IjEV4nwlhoK5sQluxsYJ78Id3Y= github.com/xiang90/probing v0.0.0-20160813154853-07dd2e8dfe18/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU= -github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2 h1:eY9dn8+vbi4tKz5Qo6v2eYzo7kUS51QINcR5jNpbZS8= github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU= github.com/xlab/handysort v0.0.0-20150421192137-fb3537ed64a1/go.mod h1:QcJo0QPSfTONNIgpN5RA8prR7fF8nkF6cTWTcNerRO8= github.com/xlab/treeprint v0.0.0-20180616005107-d6fb6747feb6/go.mod h1:ce1O1j6UtZfjr22oyGxGLbauSBp2YVXpARAosm7dHBg= @@ -997,16 +881,11 @@ github.com/yudai/golcs v0.0.0-20170316035057-ecda9a501e82/go.mod h1:lgjkn3NuSvDf github.com/yudai/pp v2.0.1+incompatible h1:Q4//iY4pNF6yPLZIigmvcl7k/bPgrcTPIFIcmawg5bI= github.com/yudai/pp v2.0.1+incompatible/go.mod h1:PuxR/8QJ7cyCkFp/aUDS+JY727OFEZkTdatxwunjIkc= github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= -github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= github.com/yuin/goldmark v1.4.0/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= -gitlab.prod.dtstack.cn/dt-insight-ops/gomonkey/v2 v2.1.1 h1:8CJqjbC0QJFqcuVR9DvlbE2yJu0T1f7O9CAFr6tC8FE= -gitlab.prod.dtstack.cn/dt-insight-ops/gomonkey/v2 v2.1.1/go.mod h1:TjfwfZj01KmpVqvbYjRSp9GSjYrFjA7tW2AKS8KZRhM= go.elastic.co/apm v1.5.0/go.mod h1:OdB9sPtM6Vt7oz3VXt7+KR96i9li74qrxBGHTQygFvk= go.elastic.co/apm/module/apmhttp v1.5.0/go.mod h1:1FbmNuyD3ddauwzgVwFB0fqY6KbZt3JkV187tGCYYhY= go.elastic.co/apm/module/apmot v1.5.0/go.mod h1:d2KYwhJParTpyw2WnTNy8geNlHKKFX+4oK3YLlsesWE= go.elastic.co/fastjson v1.0.0/go.mod h1:PmeUOMMtLHQr9ZS9J9owrAVg0FkaZDRZJEFTTGHtchs= -go.etcd.io/bbolt v1.3.2/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU= -go.etcd.io/bbolt v1.3.3 h1:MUGmc65QhB3pIlaQ5bB4LwqSj6GIonVJXpZiaKNyaKk= go.etcd.io/bbolt v1.3.3/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU= go.etcd.io/etcd v0.0.0-20191023171146-3cf2f69b5738/go.mod h1:dnLIgRNXwCJa5e+c6mIZCrds/GIG4ncV9HhK5PX7jPg= go.mongodb.org/mongo-driver v1.0.3/go.mod h1:u7ryQJ+DOzQmeO7zB6MHyr8jkEQvC8vH7qLUO4lqsUM= @@ -1016,26 +895,22 @@ go.opencensus.io v0.20.1/go.mod h1:6WKK9ahsWS3RSO+PY9ZHZUfv2irvY6gN279GOPZjmmk= go.opencensus.io v0.20.2/go.mod h1:6WKK9ahsWS3RSO+PY9ZHZUfv2irvY6gN279GOPZjmmk= go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU= go.opencensus.io v0.22.0/go.mod h1:+kGneAE2xo2IficOXnaByMWTGM9T73dGwxeWcUqIpI8= -go.opencensus.io v0.22.2 h1:75k/FF0Q2YM8QYo07VPddOLBslDt1MZOdEslOHvmzAs= go.opencensus.io v0.22.2/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw= go.opentelemetry.io/proto/otlp v0.7.0/go.mod h1:PqfVotwruBrMGOCsRd/89rSnXhoiJIqeYNgFYFoEGnI= go.uber.org/atomic v0.0.0-20181018215023-8dc6146f7569/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE= go.uber.org/atomic v1.3.2/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE= go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE= -go.uber.org/atomic v1.5.0 h1:OI5t8sDa1Or+q8AeE+yKeB/SDYioSHAgcVljj9JIETY= go.uber.org/atomic v1.5.0/go.mod h1:sABNBOSYdrvTF6hTgEIbc7YasKWGhgEQZyfxyTvoXHQ= go.uber.org/atomic v1.6.0 h1:Ezj3JGmsOnG1MoRWQkPBsKLe9DwWD9QeXzTRzzldNVk= go.uber.org/atomic v1.6.0/go.mod h1:sABNBOSYdrvTF6hTgEIbc7YasKWGhgEQZyfxyTvoXHQ= go.uber.org/automaxprocs v1.2.0/go.mod h1:YfO3fm683kQpzETxlTGZhGIVmXAhaw3gxeBADbpZtnU= go.uber.org/multierr v0.0.0-20180122172545-ddea229ff1df/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0= -go.uber.org/multierr v1.1.0 h1:HoEmRHQPVSqub6w2z2d2EOVs2fjyFRGyofhKuyDq0QI= go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0= go.uber.org/multierr v1.5.0 h1:KCa4XfM8CWFCpxXRGok+Q0SS/0XBhMDbHHGABQLvD2A= go.uber.org/multierr v1.5.0/go.mod h1:FeouvMocqHpRaaGuG9EjoKcStLC43Zu/fmqdUMPcKYU= go.uber.org/tools v0.0.0-20190618225709-2cfd321de3ee h1:0mgffUl7nfd+FpvXMVz4IDEaUSmT1ysygQC7qYo7sG4= go.uber.org/tools v0.0.0-20190618225709-2cfd321de3ee/go.mod h1:vJERXedbb3MVM5f9Ejo0C68/HhF8uaILCdgjnY+goOA= go.uber.org/zap v0.0.0-20180814183419-67bc79d13d15/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q= -go.uber.org/zap v1.10.0 h1:ORx85nbTijNz8ljznvCMR1ZBIPKFn3jQrag10X2AsuM= go.uber.org/zap v1.10.0/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q= go.uber.org/zap v1.14.1 h1:nYDKopTbvAPq/NrUVZwT15y2lpROBiLLyoRTbXOYWOo= go.uber.org/zap v1.14.1/go.mod h1:Mb2vm2krFEG5DV0W9qcHBYFtp/Wku1cvYaqPsS/WYfc= @@ -1043,7 +918,6 @@ golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnf golang.org/x/crypto v0.0.0-20181029021203-45a5f77698d3/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20181203042331-505ab145d0a9/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20190211182817-74369b46fc67/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= -golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2 h1:VklqNMn3ovrHsnt90PveolxSbWFaJdECFbxSq0Mqo2M= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20190313024323-a1f597ede03a/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20190320223903-b7391e95e576/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= @@ -1055,12 +929,8 @@ golang.org/x/crypto v0.0.0-20190617133340-57b3e21c3d56/go.mod h1:yigFU9vqHzYiE8U golang.org/x/crypto v0.0.0-20190911031432-227b76d455e7/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20190923035154-9ee001bba392/go.mod h1:/lpIB1dKB+9EgE3H3cr1v9wB50oz8l4C4h62xy7jSTY= golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= -golang.org/x/crypto v0.0.0-20191112222119-e1110fd1c708 h1:pXVtWnwHkrWD9ru3sDxY/qFK/bfc0egRovX91EjWjf4= golang.org/x/crypto v0.0.0-20191112222119-e1110fd1c708/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= -golang.org/x/crypto v0.0.0-20200220183623-bac4c82f6975 h1:/Tl7pH94bvbAAHBdZJT947M/+gp0+CqQXDtMRC0fseo= golang.org/x/crypto v0.0.0-20200220183623-bac4c82f6975/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= -golang.org/x/crypto v0.0.0-20200414173820-0848c9571904 h1:bXoxMPcSLOq08zI3/c5dEBT6lE4eh+jOh886GHrn6V8= -golang.org/x/crypto v0.0.0-20200414173820-0848c9571904/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20201012173705-84dcc777aaee h1:4yd7jl+vXjalO5ztz6Vc1VADv+S/80LGJmyl1ROJ2AI= golang.org/x/crypto v0.0.0-20201012173705-84dcc777aaee/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= @@ -1084,21 +954,14 @@ golang.org/x/lint v0.0.0-20190409202823-959b441ac422/go.mod h1:6SW0HCj/g11FgYtHl golang.org/x/lint v0.0.0-20190909230951-414d861bb4ac/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= golang.org/x/lint v0.0.0-20190930215403-16217165b5de h1:5hukYrvBGR8/eNkX5mdUezrA6JiaEZDtJb9Ei+1LlBs= golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= -golang.org/x/lint v0.0.0-20191125180803-fdd1cda4f05f h1:J5lckAjkw6qYlOZNj90mLYNTEKDvWeuc1yieZ8qUzUE= -golang.org/x/lint v0.0.0-20191125180803-fdd1cda4f05f/go.mod h1:5qLYkcX4OjUUV8bRuDixDT3tpyyb+LUpUlRWLxfhWrs= -golang.org/x/lint v0.0.0-20210508222113-6edffad5e616/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY= golang.org/x/mobile v0.0.0-20190312151609-d3739f865fa6/go.mod h1:z+o9i4GpDbdi3rU15maQ/Ox0txvL9dWGYEHz965HBQE= golang.org/x/mobile v0.0.0-20190719004257-d2bd2a29d028/go.mod h1:E/iHnbuqvinMTCcRqshq8CkpyQDoeVncDDYHnLhea+o= golang.org/x/mod v0.0.0-20190513183733-4bf6d317e70e/go.mod h1:mXi4GBBbnImb6dmsKGUJ2LatrhH/nqhxcFungHvyanc= golang.org/x/mod v0.1.0/go.mod h1:0QHyrYULN0/3qlju5TqG8bIK38QM8yzMo5ekMj3DlcY= -golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg= -golang.org/x/mod v0.2.0 h1:KU7oHjnv3XNWfa5COkzUifxZmxp1TyI7ImMXqFxLwvQ= golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= -golang.org/x/mod v0.3.0 h1:RM4zey1++hCTbCVQfnWeKs9/IEsaBLA8vTkd0WVtmH4= golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.4.2 h1:Gz96sIWK3OalVv/I/qNygP42zyoKp3xptRVCWRFEBvo= golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= -golang.org/x/mod v0.5.1/go.mod h1:5OXOZSfqPIIbmVBIIKWRFfZjPR0E5r58TLhUjH0a2Ro= golang.org/x/net v0.0.0-20170114055629-f2499483f923/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20170915142106-8351a756f30f/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= @@ -1113,7 +976,6 @@ golang.org/x/net v0.0.0-20181220203305-927f97764cc3/go.mod h1:mL1N/T3taQHkDXs73r golang.org/x/net v0.0.0-20190108225652-1e06a53dbb7e/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20190125091013-d26f9f9a57f3/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= -golang.org/x/net v0.0.0-20190311183353-d8887717615a h1:oWX7TPOiFAMXLq8o0ikBYfCJVlRHBcsciT5bXOrH628= golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190320064053-1272bf9dcd53/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= @@ -1130,36 +992,25 @@ golang.org/x/net v0.0.0-20190813141303-74dc4d7220e7/go.mod h1:z5CRVTTTmAJ677TzLL golang.org/x/net v0.0.0-20190827160401-ba9fcec4b297/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20190923162816-aa69164e4478/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20191002035440-2ec189313ef0/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/net v0.0.0-20191004110552-13f9640d40b9 h1:rjwSpXsdiK0dV8/Naq3kAw9ymfAeJIyd0upUIElB+lI= golang.org/x/net v0.0.0-20191004110552-13f9640d40b9/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/net v0.0.0-20191112182307-2180aed22343 h1:00ohfJ4K98s3m6BGUoBd8nyfp4Yl0GoIKvw5abItTjI= golang.org/x/net v0.0.0-20191112182307-2180aed22343/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/net v0.0.0-20200301022130-244492dfa37a h1:GuSPYbZzB5/dcLNCwLQLsg3obCJtX9IJhpXkvY7kzk0= -golang.org/x/net v0.0.0-20200301022130-244492dfa37a/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20200822124328-c89045814202/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= golang.org/x/net v0.0.0-20201010224723-4f7140c49acb/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= -golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4 h1:4nGaVu0QrbjT/AK2PRLuQfQuh6DJve+pELhqTdAj3x0= golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM= golang.org/x/net v0.0.0-20210421230115-4e50805a0758/go.mod h1:72T/g9IO56b78aLF+1Kcs5dz7/ng1VjMUvfKvpfy+jM= golang.org/x/net v0.0.0-20210805182204-aaa1db679c0d h1:20cMwl2fHAzkJMEA+8J4JgqBQcQGzbisXo31MIeenXI= golang.org/x/net v0.0.0-20210805182204-aaa1db679c0d/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= -golang.org/x/net v0.0.0-20220127200216-cd36cc0744dd h1:O7DYs+zxREGLKzKoMQrtrEacpb0ZVXA5rIwylE2Xchk= -golang.org/x/net v0.0.0-20220127200216-cd36cc0744dd/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk= -golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be h1:vEDujvNQGv4jgYKudGeI/+DAX4Jffq6hpD55MmoEvKs= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= -golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45 h1:SVwTIAaPC2U/AvvLNZ2a7OVsmBpC8L5BlwK1whH3hm0= golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d h1:TzXSXBo42m9gQenoE3b9BGiEpg5IG2JkU5FkPIawgtw= golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= -golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f h1:wMNYb4v58l5UBM7MYRLPG6ZhfOqbKu7X5eyFl8ZhKvA= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e h1:vcxGaoTs7kV8m5Np9uUNQin4BrLOthgV7252N8V+FwY= golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20210220032951-036812b2e83c h1:5KslGYwFpkhGh+Q16bwMP3cOontH8FOep7tGV86Y7SQ= golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= @@ -1175,9 +1026,7 @@ golang.org/x/sys v0.0.0-20181116152217-5ac8a444bdc5/go.mod h1:STP8DvDyc/dI5b8T5h golang.org/x/sys v0.0.0-20181122145206-62eef0e2fa9b/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20181205085412-a5c9d58dba9a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190209173611-3b5209105503/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a h1:1BGLXjeY4akVXGgbC9HugT3Jv3hCI0z56oJR5vAMgBU= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223 h1:DH4skfRX4EBpamg7iV4ZlCpblAHI6s6TDM39bFZumv8= golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190310054646-10058d7d4faa/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190312061237-fead79001313/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= @@ -1193,7 +1042,6 @@ golang.org/x/sys v0.0.0-20190624142023-c5567b49c5d0/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20190712062909-fae7ac547cb7/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190726091711-fc99dfbffb4e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190813064441-fde4db37ae7a/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20190826190057-c7b8b68b1456 h1:ng0gs1AKnRRuEMZoTLLlbOd+C17zUDepwGQBb/n+JVg= golang.org/x/sys v0.0.0-20190826190057-c7b8b68b1456/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190922100055-0a153f010e69/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190924154521-2837fb4f24fe/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= @@ -1204,39 +1052,25 @@ golang.org/x/sys v0.0.0-20191112214154-59a1497f0cea/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20191113165036-4c7a9d0fe056/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191120155948-bd437916bb0e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200122134326-e047566fdf82 h1:ywK/j/KkyTHcdyYSZNXGjMwgmDSfjglYZ3vStQ/gSCU= golang.org/x/sys v0.0.0-20200122134326-e047566fdf82/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200202164722-d101bd2416d5 h1:LfCXLvNmTYH9kEmVgqbnsWfruoXZIrh4YBgqVHtDvw0= -golang.org/x/sys v0.0.0-20200202164722-d101bd2416d5/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210420072515-93ed5bcd2bfe/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210510120138-977fb7262007 h1:gG67DSER+11cZvqIMb8S8bt0vZtiN6xWYARwirrOSfE= golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20210521203332-0cec03c779c1 h1:lCnv+lfrU9FRPGf8NeRuWAAPjNnema5WtBinMgs1fD8= -golang.org/x/sys v0.0.0-20210521203332-0cec03c779c1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210809222454-d867a43fc93e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20211102192858-4dd72447c267/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220207234003-57398862261d h1:Bm7BNOQt2Qv7ZqysjeLjgCBanX+88Z/OtdvsrEv1Djc= golang.org/x/sys v0.0.0-20220207234003-57398862261d/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= -golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/text v0.0.0-20160726164857-2910a502d2bf/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.0.0-20170915090833-1cbadb444a80/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= -golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.1-0.20180805044716-cb6730876b98/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= -golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs= golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= -golang.org/x/text v0.3.3 h1:cokOdA+Jmi5PJGXLlLllQSgYigAEfHXJAERHVMaCc2k= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= -golang.org/x/text v0.3.5 h1:i6eZZ+zk0SOf0xgBpEpPD18qWcJda6q1sxt3S0kzyUQ= golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.7 h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk= @@ -1286,21 +1120,13 @@ golang.org/x/tools v0.0.0-20191029041327-9cc4af7d6b2c/go.mod h1:b+2E5dAYhXwXZwtn golang.org/x/tools v0.0.0-20191029190741-b9c20aec41a5/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20191111182352-50fa39b762bc/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20191113191852-77e3bb0ad9e7/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= -golang.org/x/tools v0.0.0-20191115202509-3a792d9c32b2 h1:EtTFh6h4SAKemS+CURDMTDIANuduG5zKEXShyy18bGA= golang.org/x/tools v0.0.0-20191115202509-3a792d9c32b2/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= -golang.org/x/tools v0.0.0-20191125144606-a911d9008d1f/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= -golang.org/x/tools v0.0.0-20200130002326-2f3ba24bd6e7/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= -golang.org/x/tools v0.0.0-20200616195046-dc31b401abb5/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= -golang.org/x/tools v0.0.0-20200624223020-7a9acb0a45bb h1:NyaeMQ3XiyZSnTS7YjPk1ksNbe4EUlrse3jBvmVU2l8= golang.org/x/tools v0.0.0-20200624223020-7a9acb0a45bb/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= -golang.org/x/tools v0.1.1 h1:wGiQel/hW0NnEkJUk8lbzkX2gFJU6PFxf1v5OlCfuOs= -golang.org/x/tools v0.1.1/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/tools v0.1.7 h1:6j8CgantCy3yc8JGBqkDLMKWqZ0RDU2g1HVgacojGWQ= golang.org/x/tools v0.1.7/go.mod h1:LGqMHiF4EqQNHR1JncWGqT5BVaXmza+X+BDGol+dOxo= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE= golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= @@ -1315,12 +1141,9 @@ google.golang.org/api v0.7.0/go.mod h1:WtwebWUNSVBH/HAw79HIFXZNqEvBhG+Ra+ax0hx3E google.golang.org/api v0.8.0/go.mod h1:o4eAsZoiT+ibD93RtjEohWalFOjRDx6CVaqeizhEnKg= google.golang.org/api v0.9.0/go.mod h1:o4eAsZoiT+ibD93RtjEohWalFOjRDx6CVaqeizhEnKg= google.golang.org/api v0.13.0/go.mod h1:iLdEw5Ide6rF15KTC1Kkl0iskquN2gFfn9o9XIsbkAI= -google.golang.org/api v0.14.0 h1:uMf5uLi4eQMRrMKhCplNik4U4H8Z6C1br3zOtAa/aDE= google.golang.org/api v0.14.0/go.mod h1:iLdEw5Ide6rF15KTC1Kkl0iskquN2gFfn9o9XIsbkAI= google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= -google.golang.org/appengine v1.4.0 h1:/wp5JvzpHIxhs/dumFmF7BXTf3Z+dd4uXta4kVyO508= google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= -google.golang.org/appengine v1.5.0 h1:KxkO13IPW4Lslp2bz+KHP2E3gtFlrIGNThxkZQ3g+4c= google.golang.org/appengine v1.5.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= google.golang.org/appengine v1.6.1/go.mod h1:i06prIuMbXzDqacNJfV5OdTW448YApPu5ww/cMBSeb0= google.golang.org/appengine v1.6.5 h1:tycE03LOZYQNhDpS27tcQdAzLCVMaj7QT2SXxebnpCM= @@ -1333,12 +1156,10 @@ google.golang.org/genproto v0.0.0-20190502173448-54afdca5d873/go.mod h1:VzzqZJRn google.golang.org/genproto v0.0.0-20190530194941-fb225487d101/go.mod h1:z3L6/3dTEVtUr6QSP8miRzeRqwQOioJ9I66odjN4I7s= google.golang.org/genproto v0.0.0-20190716160619-c506a9f90610/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc= google.golang.org/genproto v0.0.0-20190801165951-fa694d86fc64/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc= -google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55 h1:gSJIx1SDwno+2ElGhA4+qG2zF97qiUzTM+rQ0klBOcE= google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc= google.golang.org/genproto v0.0.0-20190911173649-1774047e7e51/go.mod h1:IbNlFCBrqXvoKpeg0TB2l7cyZUmoaFKYIwrEpbDKLA8= google.golang.org/genproto v0.0.0-20190927181202-20e1ac93f88c/go.mod h1:IbNlFCBrqXvoKpeg0TB2l7cyZUmoaFKYIwrEpbDKLA8= google.golang.org/genproto v0.0.0-20191108220845-16a3f7862a1a/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc= -google.golang.org/genproto v0.0.0-20191115194625-c23dd37a84c9 h1:6XzpBoANz1NqMNfDXzc2QmHmbb1vyMsvRfoP5rM+K1I= google.golang.org/genproto v0.0.0-20191115194625-c23dd37a84c9/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc= google.golang.org/genproto v0.0.0-20200513103714-09dca8ec2884/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013/go.mod h1:NbSheEEYHJ7i3ixzK3sjbqSGDJWnxyFXZblF3eUsNvo= @@ -1355,9 +1176,7 @@ google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyac google.golang.org/grpc v1.23.1/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg= google.golang.org/grpc v1.24.0/go.mod h1:XDChyiUovWa60DnaeDeZmSW86xtLtjtZbwvSiRnRtcA= google.golang.org/grpc v1.25.1/go.mod h1:c3i+UQWmh7LiEpx4sFZnkU36qjEYZ0imhYfXVyQciAY= -google.golang.org/grpc v1.26.0 h1:2dTRdpdFEEhJYQD8EMLB61nnrzSCTbG38PhqdhvOltg= google.golang.org/grpc v1.26.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= -google.golang.org/grpc v1.27.0 h1:rRYRFMVgRv6E0D70Skyfsr28tDXIuuPZyWGMPdMcnXg= google.golang.org/grpc v1.27.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= google.golang.org/grpc v1.31.0/go.mod h1:N36X2cJ7JwdamYAgDz+s+rVMFjt3numwzf/HckM8pak= google.golang.org/grpc v1.33.1/go.mod h1:fr5YgcSWrqhRRxogOsw7RzIpsmvOZ6IcH4kBYTpR3n0= @@ -1379,11 +1198,9 @@ google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQ google.golang.org/protobuf v1.27.1 h1:SnqbnDw1V7RiZcXPx5MEeqPv2s79L9i7BJUlG/+RurQ= google.golang.org/protobuf v1.27.1/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= gopkg.in/airbrake/gobrake.v2 v2.0.9/go.mod h1:/h5ZAUhDkGaJfjzjKLSjv6zCL6O0LLBxU4K+aSYdM/U= -gopkg.in/alecthomas/kingpin.v2 v2.2.6 h1:jMFz6MfLP0/4fUyZle81rXUoxOBFi19VUFKVDOQfozc= gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo= gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f h1:BLraFXnmrev5lT+xlilqcH8XK9/i0At2xKjWk4p6zsU= gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= @@ -1397,7 +1214,6 @@ gopkg.in/inf.v0 v0.9.0/go.mod h1:cWUDdTG/fYaXco+Dcufb5Vnc6Gp2YChqWtbxRZE0mXw= gopkg.in/inf.v0 v0.9.1 h1:73M5CoZyi3ZLMOyDlQh031Cx6N9NDJ2Vvfl76EDAgDc= gopkg.in/inf.v0 v0.9.1/go.mod h1:cWUDdTG/fYaXco+Dcufb5Vnc6Gp2YChqWtbxRZE0mXw= gopkg.in/ini.v1 v1.42.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= -gopkg.in/ini.v1 v1.51.0 h1:AQvPpx3LzTDM0AjnIRlVFwFFGC+npRopjZxLJj6gdno= gopkg.in/ini.v1 v1.51.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= gopkg.in/mgo.v2 v2.0.0-20190816093944-a6b53ec6cb22 h1:VpOs+IwYnYBaFnrNAeB8UUWtL3vEUnzSCL1nVjPhqrw= gopkg.in/mgo.v2 v2.0.0-20190816093944-a6b53ec6cb22/go.mod h1:yeKp02qBN3iKW1OzL3MGk2IdtZzaj7SFntXj72NppTA= @@ -1410,23 +1226,17 @@ gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWD gopkg.in/yaml.v2 v2.0.0-20170812160011-eb3733d160e7/go.mod h1:JAlM8MvJe8wmxCU4Bli9HhUf9+ttbYbLASfIpnQbh74= gopkg.in/yaml.v2 v2.1.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= -gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.3/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= -gopkg.in/yaml.v2 v2.2.4 h1:/eiJrUcujPVeJ3xlSWaiNi3uSVmDGBK1pDHUHAnao1I= gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= -gopkg.in/yaml.v2 v2.2.5 h1:ymVxjfMaHvXD8RqPRmzHHsB3VvucivSkIAvJFDI5O3c= gopkg.in/yaml.v2 v2.2.5/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= -gopkg.in/yaml.v2 v2.2.8 h1:obN1ZagJSUGI0Ek/LBmuj4SNLPfIny3KsKFopxRdj10= gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= gopkg.in/yaml.v3 v3.0.0-20190905181640-827449938966/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= -gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776 h1:tQIYjPdBoyREyB9XMu+nnTclpTYkz2zFM+lzLJFO4gQ= gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= -gotest.tools v2.2.0+incompatible h1:VsBPFP1AI068pPrMxtb/S8Zkgf9xEmTLJjfM+P5UIEo= gotest.tools v2.2.0+incompatible/go.mod h1:DsYFclhRJ6vuDpmuTbkuFWG+y2sxOXAzmJt81HFBacw= honnef.co/go/tools v0.0.0-20180728063816-88497007e858/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= @@ -1481,7 +1291,6 @@ k8s.io/klog/v2 v2.0.0/go.mod h1:PBfzABfn139FHAV07az/IF9Wp1bkk3vpT2XSJ76fSDE= k8s.io/kube-aggregator v0.18.0/go.mod h1:ateewQ5QbjMZF/dihEFXwaEwoA4v/mayRvzfmvb6eqI= k8s.io/kube-openapi v0.0.0-20190709113604-33be087ad058/go.mod h1:nfDlWeOsu3pUf4yWGL+ERqohP4YsZcBJXWMK+gkzOA4= k8s.io/kube-openapi v0.0.0-20190816220812-743ec37842bf/go.mod h1:1TqjTSzOxsLGIKfj0lK8EeCP7K1iUG65v09OM0/WG5E= -k8s.io/kube-openapi v0.0.0-20191107075043-30be4d16710a h1:UcxjrRMyNx/i/y8G7kPvLyy7rfbeuf1PYyBf973pgyU= k8s.io/kube-openapi v0.0.0-20191107075043-30be4d16710a/go.mod h1:1TqjTSzOxsLGIKfj0lK8EeCP7K1iUG65v09OM0/WG5E= k8s.io/kube-openapi v0.0.0-20200121204235-bf4fb3bd569c h1:/KUFqjjqAcY4Us6luF5RDNZ16KJtb49HfR3ZHB9qYXM= k8s.io/kube-openapi v0.0.0-20200121204235-bf4fb3bd569c/go.mod h1:GRQhZsXIAJ1xR0C9bd8UpWHZ5plfAS9fzPjJuQ6JL3E= @@ -1504,22 +1313,14 @@ rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8 sigs.k8s.io/apiserver-network-proxy/konnectivity-client v0.0.7/go.mod h1:PHgbrJT7lCHcxMU+mDHEm+nx46H4zuuHZkDP6icnhu0= sigs.k8s.io/controller-runtime v0.6.0 h1:Fzna3DY7c4BIP6KwfSlrfnj20DJ+SeMBK8HSFvOk9NM= sigs.k8s.io/controller-runtime v0.6.0/go.mod h1:CpYf5pdNY/B352A1TFLAS2JVSlnGQ5O2cftPHndTroo= -sigs.k8s.io/controller-tools v0.2.4 h1:la1h46EzElvWefWLqfsXrnsO3lZjpkI0asTpX6h8PLA= sigs.k8s.io/controller-tools v0.2.4/go.mod h1:m/ztfQNocGYBgTTCmFdnK94uVvgxeZeE3LtJvd/jIzA= -sigs.k8s.io/controller-tools v0.4.1 h1:VkuV0MxlRPmRu5iTgBZU4UxUX2LiR99n3sdQGRxZF4w= -sigs.k8s.io/controller-tools v0.4.1/go.mod h1:G9rHdZMVlBDocIxGkK3jHLWqcTMNvveypYJwrvYKjWU= -sigs.k8s.io/controller-tools v0.5.0 h1:3u2RCwOlp0cjCALAigpOcbAf50pE+kHSdueUosrC/AE= -sigs.k8s.io/controller-tools v0.6.0 h1:o2Fm1K7CmIp8OVaBtXsWB/ssBAzyoKZPPAGR3VuxaKs= -sigs.k8s.io/controller-tools v0.8.0 h1:uUkfTGEwrguqYYfcI2RRGUnC8mYdCFDqfwPKUcNJh1o= sigs.k8s.io/kustomize v2.0.3+incompatible/go.mod h1:MkjgH3RdOWrievjo6c9T245dYlB5QeXV4WCbnt/PEpU= -sigs.k8s.io/structured-merge-diff v0.0.0-20190525122527-15d366b2352e h1:4Z09Hglb792X0kfOBBJUPFEyvVfQWrYT/l8h5EKA6JQ= sigs.k8s.io/structured-merge-diff v0.0.0-20190525122527-15d366b2352e/go.mod h1:wWxsB5ozmmv/SG7nM11ayaAW51xMvak/t1r0CSlcokI= sigs.k8s.io/structured-merge-diff v0.0.0-20190817042607-6149e4549fca h1:6dsH6AYQWbyZmtttJNe8Gq1cXOeS1BdV3eW37zHilAQ= sigs.k8s.io/structured-merge-diff v0.0.0-20190817042607-6149e4549fca/go.mod h1:IIgPezJWb76P0hotTxzDbWsMYB8APh18qZnxkomBpxA= sigs.k8s.io/structured-merge-diff/v3 v3.0.0-20200116222232-67a7b8c61874/go.mod h1:PlARxl6Hbt/+BC80dRLi1qAmnMqwqDg62YvvVkZjemw= sigs.k8s.io/structured-merge-diff/v3 v3.0.0 h1:dOmIZBMfhcHS09XZkMyUgkq5trg3/jRyJYFZUiaOp8E= sigs.k8s.io/structured-merge-diff/v3 v3.0.0/go.mod h1:PlARxl6Hbt/+BC80dRLi1qAmnMqwqDg62YvvVkZjemw= -sigs.k8s.io/yaml v1.1.0 h1:4A07+ZFc2wgJwo8YNlQpr1rVlgUDlxXHhPJciaPY5gs= sigs.k8s.io/yaml v1.1.0/go.mod h1:UJmg0vDUVViEyp3mgSv9WPwZCDxu4rQW1olrI1uml+o= sigs.k8s.io/yaml v1.2.0 h1:kr/MCeFWJWTwyaHoR9c8EjH9OumOmoF9YGiZd7lFm/Q= sigs.k8s.io/yaml v1.2.0/go.mod h1:yfXDCHCao9+ENCvLSE62v9VSji2MKu5jeNfTrofGhJc= diff --git a/chengying-server/matrix/api/api-schema.go b/chengying-server/matrix/api/api-schema.go index 49b57a5..241fcd0 100644 --- a/chengying-server/matrix/api/api-schema.go +++ b/chengying-server/matrix/api/api-schema.go @@ -19,7 +19,6 @@ package api import ( "dtstack.com/dtstack/easymatrix/go-common/api-base" - "dtstack.com/dtstack/easymatrix/matrix/api/k8s" ) var ApiV2Schema = apibase.Route{ @@ -35,9 +34,6 @@ var ApiV2Schema = apibase.Route{ UserOperationEasyMatrixAPIRoutes, ClusterEasyMatrixAPIRoutes, RoleOperationEasyMatrixAPIRoutes, - k8s.ClusterResourceAPIRoutes, - k8s.NSProductAPIRoutes, - k8s.InstanceApi, DashboardOperationEasyMatrixRoutes, InspectReportEasyMatrixRoutes, TaskOperationEasyMatrixAPIRoutes, diff --git a/chengying-server/matrix/api/cluster-api.go b/chengying-server/matrix/api/cluster-api.go index 5380349..e762937 100644 --- a/chengying-server/matrix/api/cluster-api.go +++ b/chengying-server/matrix/api/cluster-api.go @@ -25,545 +25,267 @@ import ( var ClusterEasyMatrixAPIRoutes = apibase.Route{ Path: "cluster", - SubRoutes: []apibase.Route{{ - Path: "kubernetes", - SubRoutes: []apibase.Route{{ - Path: "imageStore", + SubRoutes: []apibase.Route{ + { + Path: "hosts", SubRoutes: []apibase.Route{{ - //http:://xxxx/api/v2/cluster/kubernetes/imageStore/create + //http:://xxxx/api/v2/cluster/hosts/create Path: "create", - Middlewares: []context.Handler{ - apibase.CheckPermission3, - }, - POST: impl.CreateImageStore, + POST: impl.CreateHostCluster, Docs: apibase.Docs{ POST: &apibase.ApiDoc{ - Name: "创建k8s镜像仓库[EasyMatrix API]", + Name: "创建主机集群[EasyMatrix API]", }, }, }, { - //http:://xxxx/api/v2/cluster/kubernetes/imageStore/update + //http:://xxxx/api/v2/cluster/hosts/update Path: "update", - POST: impl.UpdateImageStore, - Middlewares: []context.Handler{ - apibase.CheckPermission3, - }, + POST: impl.UpdateHostCluster, Docs: apibase.Docs{ POST: &apibase.ApiDoc{ - Name: "编辑k8s镜像仓库[EasyMatrix API]", + Name: "编辑主机集群[EasyMatrix API]", }, }, }, { - //http:://xxxx/api/v2/cluster/kubernetes/imageStore/setDefault - Path: "setDefault", - POST: impl.SetDefaultImageStore, + //http:://xxxx/api/v2/cluster/hosts/alert + Path: "alert", + GET: impl.GetHostClusterAlert, Docs: apibase.Docs{ - POST: &apibase.ApiDoc{ - Name: "设置k8s集群默认镜像仓库[EasyMatrix API]", + GET: &apibase.ApiDoc{ + Name: "获取主机集群主机报警信息[EasyMatrix API]", }, }, }, { Path: "{cluster_id:int}", SubRoutes: []apibase.Route{{ - //http:://xxxx/api/v2/cluster/kubernetes/imageStore/{cluster_id}/clusterInfo - Path: "clusterInfo", - GET: impl.GetImageStoreInfoByClusterId, + //http:://xxxx/api/v2/cluster/hosts/{cluster_id}/info + Path: "info", + GET: impl.GetHostClusterInfo, Docs: apibase.Docs{ GET: &apibase.ApiDoc{ - Name: "通过clusterId获取k8s镜像仓库[EasyMatrix API]", + Name: "获取主机集群信息[EasyMatrix API]", }, }, }, { - //http:://xxxx/api/v2/cluster/kubernetes/imageStore/{cluster_id}/checkDefault - Path: "checkDefault", - GET: impl.CheckDefaultImageStore, + //http:://xxxx/api/v2/cluster/hosts/{cluster_id}/delete + Path: "delete", + POST: impl.DeleteHostCluster, + Docs: apibase.Docs{ + POST: &apibase.ApiDoc{ + Name: "删除主机集群[EasyMatrix API]", + }, + }, + }, { + //http:://xxxx/api/v2/cluster/hosts/{cluster_id}/overview + Path: "overview", + GET: impl.GetHostClusterOverView, Docs: apibase.Docs{ GET: &apibase.ApiDoc{ - Name: "检查集群是否设置默认仓库[EasyMatrix API]", + Name: "获取主机集群总览信息[EasyMatrix API]", }, }, - }}, - }, { - Path: "{store_id:int}", - SubRoutes: []apibase.Route{{ - //http:://xxxx/api/v2/cluster/kubernetes/imageStore/{store_id}/info - Path: "info", - GET: impl.GetImageStoreInfoById, + }, { + //http:://xxxx/api/v2/cluster/hosts/{cluster_id}/performance + Path: "performance", + GET: impl.GetHostClusterPerformance, Docs: apibase.Docs{ GET: &apibase.ApiDoc{ - Name: "通过仓库Id获取k8s镜像仓库[EasyMatrix API]", + Name: "获取主机集群性能趋势[EasyMatrix API]", }, }, }}, }, { - //http:://xxxx/api/v2/cluster/kubernetes/imageStore/delete - Path: "delete", - Middlewares: []context.Handler{ - apibase.CheckPermission3, - }, - POST: impl.DeleteImageStore, + //http:://xxxx/api/v2/cluster/hosts/hosts + Path: "hosts", + GET: impl.GetHostClusterHostList, Docs: apibase.Docs{ - POST: &apibase.ApiDoc{ - Name: "通过仓库Id删除k8s镜像仓库[EasyMatrix API]", + GET: &apibase.ApiDoc{ + Name: "获取主机集群主机列表[EasyMatrix API]", }, }, - }}, - }, { - //http:://xxxx/api/v2/cluster/kubernetes/rketemplate?version=V1.14.3&network_plugin=flannel - Path: "rketemplate", - GET: impl.GetRkeTemplate, - Docs: apibase.Docs{ - POST: &apibase.ApiDoc{ - Name: "获取rke配置模版[EasyMatrix API]", - }, - }, - }, { - //http:://xxxx/api/v2/cluster/kubernetes/create - Path: "create", - Middlewares: []context.Handler{ - apibase.CheckPermission3, - }, - POST: impl.CreateK8sCluster, - Docs: apibase.Docs{ - POST: &apibase.ApiDoc{ - Name: "创建k8s集群[EasyMatrix API]", - }, - }, - }, { - //http:://xxxx/api/v2/cluster/kubernetes/update - Path: "update", - Middlewares: []context.Handler{ - apibase.CheckPermission3, - }, - POST: impl.UpdateK8sCluster, - Docs: apibase.Docs{ - POST: &apibase.ApiDoc{ - Name: "编辑k8s集群[EasyMatrix API]", - }, - }, - }, { - //http:://xxxx/api/v2/cluster/kubernetes/available - Path: "available", - GET: impl.GetK8sAvailable, - Docs: apibase.Docs{ - GET: &apibase.ApiDoc{ - Name: "获取k8s支持列表[EasyMatrix API]", - }, }, - }, { - //http:://xxxx/api/v2/cluster/kubernetes/hosts - Path: "hosts", - GET: impl.GetK8sClusterHostList, - Docs: apibase.Docs{ - GET: &apibase.ApiDoc{ - Name: "获取k8s集群主机列表[EasyMatrix API]", - }, - }, - }, { - //http:://xxxx/api/v2/cluster/kubernetes/installCmd - Path: "installCmd", - GET: impl.GetK8sClusterImportCmd, - Docs: apibase.Docs{ - GET: &apibase.ApiDoc{ - Name: "获取导入命令[EasyMatrix API]", + { + //http:://xxxx/api/v2/cluster/hosts/role + Path: "role", + POST: impl.EditRole, + Docs: apibase.Docs{ + GET: &apibase.ApiDoc{ + Name: "修改主机角色", + }, + }, }, - }, - }, { - Path: "{cluster_id:int}", - SubRoutes: []apibase.Route{{ - //http:://xxxx/api/v2/cluster/kubernetes/{cluster_id}/installLog - Path: "installLog", - GET: impl.GetK8sClusterInstallLog, - Docs: apibase.Docs{ - GET: &apibase.ApiDoc{ - Name: "获取k8s集群安装日志[EasyMatrix API]", + { + //http:://xxxx/api/v2/cluster/hosts/role_list + Path: "role_list", + GET: impl.RoleList, + Docs: apibase.Docs{ + GET: &apibase.ApiDoc{ + Name: "获取主机角色列表", + }, }, }, - }, { - //http:://xxxx/api/v2/cluster/kubernetes/{cluster_id}/info - Path: "info", - GET: impl.GetK8sClusterInfo, - Docs: apibase.Docs{ - GET: &apibase.ApiDoc{ - Name: "获取k8s集群信息[EasyMatrix API]", + { + //http:://xxxx/api/v2/cluster/hosts/role_rename + Path: "role_rename", + POST: impl.RoleRename, + Docs: apibase.Docs{ + GET: &apibase.ApiDoc{ + Name: "修改角色名", + }, }, }, - }, { - //http:://xxxx/api/v2/cluster/kubernetes/{cluster_id}/delete - Path: "delete", - Middlewares: []context.Handler{ - apibase.CheckPermission3, + { + //http:://xxxx/api/v2/cluster/hosts/role_info + Path: "role_info", + GET: impl.RoleInfo, + Docs: apibase.Docs{ + GET: &apibase.ApiDoc{ + Name: "获取集群下机器的角色信息", + }, + }, }, - POST: impl.DeleteK8sCluster, - Docs: apibase.Docs{ - POST: &apibase.ApiDoc{ - Name: "删除k8s集群[EasyMatrix API]", + + { + //http:://xxxx/api/v2/cluster/hosts/role_delete + Path: "role_delete", + POST: impl.RoleDelete, + Docs: apibase.Docs{ + GET: &apibase.ApiDoc{ + Name: "获取主机角色列表", + }, }, }, - }, { - //http:://xxxx/api/v2/cluster/kubernetes/{cluster_id}/overview - Path: "overview", - GET: impl.GetK8sClusterOverView, - Docs: apibase.Docs{ - GET: &apibase.ApiDoc{ - Name: "获取k8s集群总览信息[EasyMatrix API]", + { + //http:://xxxx/api/v2/cluster/hosts/role_add + Path: "role_add", + POST: impl.RoleAdd, + Docs: apibase.Docs{ + GET: &apibase.ApiDoc{ + Name: "角色添加", + }, }, }, - }, { - //http:://xxxx/api/v2/cluster/kubernetes/{cluster_id}/performance - Path: "performance", - GET: impl.GetK8sClusterPerformance, - Docs: apibase.Docs{ - GET: &apibase.ApiDoc{ - Name: "获取K8S集群性能趋势[EasyMatrix API]", + { + //http:://xxxx/api/v2/cluster/hosts/auto_orchestration + Path: "auto_orchestration", + POST: impl.AutoOrchestration, + Docs: apibase.Docs{ + GET: &apibase.ApiDoc{ + Name: "自动编排", + }, }, }, - }, { - Path: "namespace", - SubRoutes: []apibase.Route{{ - //http:://xxxx/api/v2/cluster/kubernetes/{cluster_id}/namespace/list - Path: "list", - GET: impl.GetK8sClusterNameSpaceList, + { + //http:://xxxx/api/v2/cluster/hosts/auto_svcgroup + Path: "auto_svcgroup", + POST: impl.AutoSvcGroup, Docs: apibase.Docs{ GET: &apibase.ApiDoc{ - Name: "获取k8s集群namespace list[EasyKube API]", + Name: "获取实时编排结果", }, }, - }, { - //http:://xxxx/api/v2/cluster/kubernetes/{cluster_id}/namespace/create - Path: "create", - POST: impl.CreateK8sClusterNamespace, + }, + { + //http:://xxxx/api/v2/cluster/hosts/auto_deploy + Path: "auto_deploy", + POST: impl.AutoDeploy, Docs: apibase.Docs{ GET: &apibase.ApiDoc{ - Name: "创建k8s集群namespace[EasyKube API]", + Name: "自动部署", }, }, - }, { - Path: "{namespace_name:string}", - SubRoutes: []apibase.Route{{ - Path: "product", - SubRoutes: []apibase.Route{{ - Path: "{pid:int}", - SubRoutes: []apibase.Route{{ - //http:://xxxx/api/v2/cluster/kubernetes/{cluster_id}/namespace/{namespace_name}/product/{pid}/depends - Path: "depends", - GET: impl.GetK8sClusterProductDepends, - Docs: apibase.Docs{ - GET: &apibase.ApiDoc{ - Name: "获得k8s集群指定namespace下产品依赖[EasyKube API]", - }, - }, - }, { - //http:://xxxx/api/v2/cluster/kubernetes/{cluster_id}/namespace/{namespace_name}/product/{pid}/deploy - Path: "deploy", - POST: impl.DeployK8sProduct, - Docs: apibase.Docs{ - GET: &apibase.ApiDoc{ - Name: "指定k8s集群" + - "ce部署产品[EasyKube API]", - }, - }, - }, { - Middlewares: []context.Handler{ - apibase.CheckPermission1, - }, - //http:://xxxx/api/v2/cluster/kubernetes/{cluster_id}/namespace/{namespace_name}/product/{pid}/stop - Path: "stop", - POST: impl.StopUndeployingK8sProduct, - Docs: apibase.Docs{ - GET: &apibase.ApiDoc{ - Name: "停止卸载k8s产品包[EasyKube API]", - }, - }, - }, { - //http:://xxxx/api/v2/cluster/kubernetes/{cluster_id}/namespace/{namespace_name}/product/{pid}/installLog - Path: "installLog", - GET: impl.GetProductInstallLog, - Docs: apibase.Docs{ - GET: &apibase.ApiDoc{ - Name: "获取产品部署日志[EasyKube API]", - }, - }, - }}, - }}, - }}, - }}, - }}, - }, { - //http:://xxxx/api/v2/cluster/kubernetes/listwatch - Path: "listwatch", - SubRoutes: []apibase.Route{ + }, { - Path: "events", - POST: impl.K8sProductListWatch, + //http:://xxxx/api/v2/cluster/hosts/auto_deploy_cancel + Path: "auto_deploy_cancel", + POST: impl.AutoDeployCancel, Docs: apibase.Docs{ - POST: &apibase.ApiDoc{ - Name: "提交k8s产品部署组件事件信息[EasyMatrix API]", + GET: &apibase.ApiDoc{ + Name: "取消自动部署", }, }, }, - }, - }, - }}, { - Path: "hosts", - SubRoutes: []apibase.Route{{ - //http:://xxxx/api/v2/cluster/hosts/create - Path: "create", - POST: impl.CreateHostCluster, - Docs: apibase.Docs{ - POST: &apibase.ApiDoc{ - Name: "创建主机集群[EasyMatrix API]", + { + //http:://xxxx/api/v2/cluster/hosts/orchestration_history + Path: "orchestration_history", + GET: impl.OrchestrationHistory, + Docs: apibase.Docs{ + GET: &apibase.ApiDoc{ + Name: "获取历史安装记录", + }, + }, }, }, }, { - //http:://xxxx/api/v2/cluster/hosts/update - Path: "update", - POST: impl.UpdateHostCluster, + //http:://xxxx/api/v2/cluster/hostgroups?type=&id= + Path: "hostgroups", + GET: impl.GetHostGroups, Docs: apibase.Docs{ - POST: &apibase.ApiDoc{ - Name: "编辑主机集群[EasyMatrix API]", + GET: &apibase.ApiDoc{ + Name: "获取集群主机分组[EasyMatrix API]", }, }, }, { - //http:://xxxx/api/v2/cluster/hosts/alert - Path: "alert", - GET: impl.GetHostClusterAlert, + //http:://xxxx/api/v2/cluster/list?type=&sort-by=id&sort-dir=desc&limit=10&start=0 + Path: "list", + GET: impl.GetClusterList, Docs: apibase.Docs{ GET: &apibase.ApiDoc{ - Name: "获取主机集群主机报警信息[EasyMatrix API]", + Name: "获取集群列表[EasyMatrix API]", }, }, }, { - Path: "{cluster_id:int}", - SubRoutes: []apibase.Route{{ - //http:://xxxx/api/v2/cluster/hosts/{cluster_id}/info - Path: "info", - GET: impl.GetHostClusterInfo, - Docs: apibase.Docs{ - GET: &apibase.ApiDoc{ - Name: "获取主机集群信息[EasyMatrix API]", - }, - }, - }, { - //http:://xxxx/api/v2/cluster/hosts/{cluster_id}/delete - Path: "delete", - POST: impl.DeleteHostCluster, - Docs: apibase.Docs{ - POST: &apibase.ApiDoc{ - Name: "删除主机集群[EasyMatrix API]", - }, - }, - }, { - //http:://xxxx/api/v2/cluster/hosts/{cluster_id}/overview - Path: "overview", - GET: impl.GetHostClusterOverView, - Docs: apibase.Docs{ - GET: &apibase.ApiDoc{ - Name: "获取主机集群总览信息[EasyMatrix API]", - }, - }, - }, { - //http:://xxxx/api/v2/cluster/hosts/{cluster_id}/performance - Path: "performance", - GET: impl.GetHostClusterPerformance, - Docs: apibase.Docs{ - GET: &apibase.ApiDoc{ - Name: "获取主机集群性能趋势[EasyMatrix API]", - }, - }, - }}, - }, { - //http:://xxxx/api/v2/cluster/hosts/hosts - Path: "hosts", - GET: impl.GetHostClusterHostList, + //http:://xxxx/api/v2/cluster/products + Path: "products", + GET: impl.GetClusterProductList, Docs: apibase.Docs{ GET: &apibase.ApiDoc{ - Name: "获取主机集群主机列表[EasyMatrix API]", - }, - }, - }, - { - //http:://xxxx/api/v2/cluster/hosts/role - Path: "role", - POST: impl.EditRole, - Docs: apibase.Docs{ - GET: &apibase.ApiDoc{ - Name: "修改主机角色", - }, - }, - }, - { - //http:://xxxx/api/v2/cluster/hosts/role_list - Path: "role_list", - GET: impl.RoleList, - Docs: apibase.Docs{ - GET: &apibase.ApiDoc{ - Name: "获取主机角色列表", - }, + Name: "获取集群产品列表[EasyMatrix API]", }, }, - { - //http:://xxxx/api/v2/cluster/hosts/role_rename - Path: "role_rename", - POST: impl.RoleRename, - Docs: apibase.Docs{ - GET: &apibase.ApiDoc{ - Name: "修改角色名", - }, - }, - }, - { - //http:://xxxx/api/v2/cluster/hosts/role_info - Path: "role_info", - GET: impl.RoleInfo, - Docs: apibase.Docs{ - GET: &apibase.ApiDoc{ - Name: "获取集群下机器的角色信息", - }, - }, - }, - - { - //http:://xxxx/api/v2/cluster/hosts/role_delete - Path: "role_delete", - POST: impl.RoleDelete, - Docs: apibase.Docs{ - GET: &apibase.ApiDoc{ - Name: "获取主机角色列表", - }, - }, - }, - { - //http:://xxxx/api/v2/cluster/hosts/role_add - Path: "role_add", - POST: impl.RoleAdd, - Docs: apibase.Docs{ - GET: &apibase.ApiDoc{ - Name: "角色添加", - }, - }, + }, { + //http:://xxxx/api/v2/cluster/productsInfo + Path: "productsInfo", + GET: impl.GetClusterProductsInfo, + Middlewares: []context.Handler{ + apibase.CheckPermission3, }, - { - //http:://xxxx/api/v2/cluster/hosts/auto_orchestration - Path: "auto_orchestration", - POST: impl.AutoOrchestration, - Docs: apibase.Docs{ - GET: &apibase.ApiDoc{ - Name: "自动编排", - }, + Docs: apibase.Docs{ + GET: &apibase.ApiDoc{ + Name: "获取集群产品详情[EasyMatrix API]", }, }, - { - //http:://xxxx/api/v2/cluster/hosts/auto_svcgroup - Path: "auto_svcgroup", - POST: impl.AutoSvcGroup, - Docs: apibase.Docs{ - GET: &apibase.ApiDoc{ - Name: "获取实时编排结果", - }, + }, { + //http://xxxx/api/v2/cluster/restartServices + Path: "restartServices", + GET: impl.GetRestartServices, + Docs: apibase.Docs{ + GET: &apibase.ApiDoc{ + Name: "获取需要重启服务", }, }, - { - //http:://xxxx/api/v2/cluster/hosts/auto_deploy - Path: "auto_deploy", - POST: impl.AutoDeploy, - Docs: apibase.Docs{ - GET: &apibase.ApiDoc{ - Name: "自动部署", - }, - }, + }, { + //http://xxxx/api/v2/cluster/currExecCount?clusterId=1 + Path: "currExecCount", + GET: impl.GetCurrentExecCount, + Middlewares: []context.Handler{ + apibase.CheckPermission3, }, - { - //http:://xxxx/api/v2/cluster/hosts/auto_deploy_cancel - Path: "auto_deploy_cancel", - POST: impl.AutoDeployCancel, - Docs: apibase.Docs{ - GET: &apibase.ApiDoc{ - Name: "取消自动部署", - }, + Docs: apibase.Docs{ + GET: &apibase.ApiDoc{ + Name: "获取集群当前正在运行的命令数", }, }, - { - //http:://xxxx/api/v2/cluster/hosts/orchestration_history - Path: "orchestration_history", - GET: impl.OrchestrationHistory, - Docs: apibase.Docs{ - GET: &apibase.ApiDoc{ - Name: "获取历史安装记录", - }, + }, { + //http://xxxx/api/v2/cluster/orderList?clusterId=1&operationType=1&object=DTBase&status=success&startTime=2021-05-16 13:13:12&endTime=2021-05-16 13:13:12&page=1&pageSize=10 + Path: "orderList", + GET: impl.OrderList, + Docs: apibase.Docs{ + GET: &apibase.ApiDoc{ + Name: "查看所有命令", }, }, }, - }, { - //http:://xxxx/api/v2/cluster/hostgroups?type=&id= - Path: "hostgroups", - GET: impl.GetHostGroups, - Docs: apibase.Docs{ - GET: &apibase.ApiDoc{ - Name: "获取集群主机分组[EasyMatrix API]", - }, - }, - }, { - //http:://xxxx/api/v2/cluster/list?type=&sort-by=id&sort-dir=desc&limit=10&start=0 - Path: "list", - GET: impl.GetClusterList, - Docs: apibase.Docs{ - GET: &apibase.ApiDoc{ - Name: "获取集群列表[EasyMatrix API]", - }, - }, - }, { - //http:://xxxx/api/v2/cluster/products - Path: "products", - GET: impl.GetClusterProductList, - Docs: apibase.Docs{ - GET: &apibase.ApiDoc{ - Name: "获取集群产品列表[EasyMatrix API]", - }, - }, - }, { - //http:://xxxx/api/v2/cluster/productsInfo - Path: "productsInfo", - GET: impl.GetClusterProductsInfo, - Middlewares: []context.Handler{ - apibase.CheckPermission3, - }, - Docs: apibase.Docs{ - GET: &apibase.ApiDoc{ - Name: "获取集群产品详情[EasyMatrix API]", - }, - }, - }, { - //http://xxxx/api/v2/cluster/restartServices - Path: "restartServices", - GET: impl.GetRestartServices, - Docs: apibase.Docs{ - GET: &apibase.ApiDoc{ - Name: "获取需要重启服务", - }, - }, - }, { - //http://xxxx/api/v2/cluster/currExecCount?clusterId=1 - Path: "currExecCount", - GET: impl.GetCurrentExecCount, - Middlewares: []context.Handler{ - apibase.CheckPermission3, - }, - Docs: apibase.Docs{ - GET: &apibase.ApiDoc{ - Name: "获取集群当前正在运行的命令数", - }, - }, - }, { - //http://xxxx/api/v2/cluster/orderList?clusterId=1&operationType=1&object=DTBase&status=success&startTime=2021-05-16 13:13:12&endTime=2021-05-16 13:13:12&page=1&pageSize=10 - Path: "orderList", - GET: impl.OrderList, - Docs: apibase.Docs{ - GET: &apibase.ApiDoc{ - Name: "查看所有命令", - }, - }, - }, { //http://xxxx/api/v2/cluster/OrderDetail Path: "orderDetail", diff --git a/chengying-server/matrix/k8s/constant/constant.go b/chengying-server/matrix/api/constant/constant.go similarity index 63% rename from chengying-server/matrix/k8s/constant/constant.go rename to chengying-server/matrix/api/constant/constant.go index a99a00f..6ea8c38 100644 --- a/chengying-server/matrix/k8s/constant/constant.go +++ b/chengying-server/matrix/api/constant/constant.go @@ -1,20 +1,3 @@ -// Licensed to Apache Software Foundation(ASF) under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. Apache Software Foundation(ASF) licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - package constant type TemplateFile struct { diff --git a/chengying-server/matrix/api/impl/agent.go b/chengying-server/matrix/api/impl/agent.go index dd01c1a..31cb1e7 100644 --- a/chengying-server/matrix/api/impl/agent.go +++ b/chengying-server/matrix/api/impl/agent.go @@ -24,7 +24,6 @@ import ( "encoding/json" "fmt" "net/url" - "os" "regexp" "strconv" "strings" @@ -39,15 +38,11 @@ import ( "dtstack.com/dtstack/easymatrix/matrix/enums" "dtstack.com/dtstack/easymatrix/matrix/grafana" "dtstack.com/dtstack/easymatrix/matrix/host" - "dtstack.com/dtstack/easymatrix/matrix/k8s/node" - kutil "dtstack.com/dtstack/easymatrix/matrix/k8s/util" - xke_service "dtstack.com/dtstack/easymatrix/matrix/k8s/xke-service" "dtstack.com/dtstack/easymatrix/matrix/log" "dtstack.com/dtstack/easymatrix/matrix/model" "dtstack.com/dtstack/easymatrix/matrix/util" "github.com/kataras/iris/context" uuid "github.com/satori/go.uuid" - "gopkg.in/yaml.v2" ) const ( @@ -320,45 +315,7 @@ func execAgentInstallByPwd(installHost string, params *util.PwdInstallParams, re }() // if node is installed, change roles - err, info := model.DeployHostList.GetHostInfoByIp(installHost) - if err == nil && info.Status == 7 { - - cluster, _ := model.DeployClusterList.GetClusterInfoById(params.ClusterId) - rkeConfig, _ := xke_service.BuildRKEConfigFromRaw(cluster.Yaml.String) - - xke, err := xke_service.NewXkeService() - if err != nil { - return fmt.Sprintf("%v xke init error:", err) - } - // update role - for i := range rkeConfig.Nodes { - if rkeConfig.Nodes[i].Address == installHost { - var rkeRoles []string - for _, r := range strings.Split(params.Role, ",") { - if _, ok := node.RoleToRkeRole[r]; ok { - rkeRoles = append(rkeRoles, node.RoleToRkeRole[r]) - } - } - rkeConfig.Nodes[i].Role = rkeRoles - break - } - } - log.Infof("update k8s with rke config: %v", rkeConfig) - - rkeConfigYaml, err := yaml.Marshal(rkeConfig) - if err != nil { - return fmt.Sprintf("yaml marshal error:%v ", err) - } - err = xke.Create(rkeConfig.ClusterName, string(rkeConfigYaml), cluster.Id) - if err != nil { - return fmt.Sprintf("create rke error:%v ", err) - } else { - _ = model.DeployClusterHostRel.UpdateRolesWithSid(info.SidecarId, params.Role) - return fmt.Sprintf("update roles success:%v ", installHost) - } - } - - err, _ = model.DeployHostList.GetHostInfoByIpAndStatus(installHost, host.InitStatus, host.InitInitializeShOk) + err, _ := model.DeployHostList.GetHostInfoByIpAndStatus(installHost, host.InitStatus, host.InitInitializeShOk) if err == nil { rt = fmt.Sprintf("%v 主机正在接入", installHost) return @@ -993,9 +950,6 @@ func HostInstallStepCluster(sid string, aid int, ctx context.Context) { log.Errorf("\t\t%v", err.Error()) return } - if ctype == model.DEPLOY_CLUSTER_TYPE_KUBERNETES { - agentInstallProcessK8SCluster(cid, aid, sid, roles) - } log.Infof("<--Step HostInstallStepCluster Success sid: %v", sid) log.OutputInfof(sid, "<--Step HostInstallStepCluster Success sid: %v", sid) } @@ -1015,33 +969,6 @@ func agentInstallUpdateClusterHostRel(clusterId int, sid, roles string) error { return nil } -func agentInstallProcessK8SCluster(clusterId, aid int, sid, roles string) error { - info, err := model.DeployClusterList.GetClusterInfoById(clusterId) - if err != nil { - log.Errorf("%v", err) - return err - } - if info.Mode == model.DEPLOY_CLUSTER_MODE_IMPORT { - model.DeployHostList.UpdateStatus(aid, host.K8SNodeInitializeOk, host.K8S_SUCCESS_NODE_INIT) - model.DeployHostList.UpdateSteps(aid, host.K8SNodeInitializeOk) - return nil - } - err = host.AgentInstall.DockerEnvironmentInit(sid) - if err != nil { - log.Errorf("%v", err.Error()) - model.DeployHostList.UpdateStatus(aid, host.K8SDockerInitializeFail, err.Error()) - return err - } - // update host status - model.DeployHostList.UpdateStatus(aid, host.K8SDockerInitializeOk, host.K8S_SUCCESS_DOCKCER_INIT) - model.DeployHostList.UpdateSteps(aid, host.K8SDockerInitializeOk) - - //do rke create in queue - node.NodeManager.AddNode(clusterId, aid, sid, info.Name, roles) - - return nil -} - //1:管控安装成功, -1:管控安装失败, 2:script安装成功, -2:script安装失败, 3:主机初始化成功, -3:主机初始化失败 func AgentInstallCallBack(ctx context.Context) apibase.Result { @@ -1084,18 +1011,6 @@ func AgentInstallCallBack(ctx context.Context) apibase.Result { model.DeployClusterHostRel.InsertClusterHostRel(cid, sid, "") deployment := ctx.Request().Header.Get("Deploy") - // redirect log output - cluster, _ := model.DeployClusterList.GetClusterInfoById(cid) - fileName := kutil.BuildClusterLogName(cluster.Name, cid) - logf, err := os.OpenFile(fileName, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0766) - defer logf.Close() - if err == nil { - log.NewOutputPath(sid, logf) - // defer log.CloseOutputPath(sid) - } else { - log.Errorf(err.Error()) - } - log.OutputInfof(sid, "%v", LINE_LOG) log.OutputInfof(sid, "AgentInstallCallBack: %v", ctx.Request().RequestURI) log.OutputInfof(sid, "Headers: %v", ctx.Request().Header) diff --git a/chengying-server/matrix/api/impl/cluster.go b/chengying-server/matrix/api/impl/cluster.go index be9e01e..cc96fcc 100644 --- a/chengying-server/matrix/api/impl/cluster.go +++ b/chengying-server/matrix/api/impl/cluster.go @@ -18,9 +18,9 @@ package impl import ( - "bytes" sysContext "context" "database/sql" + "dtstack.com/dtstack/easymatrix/matrix/api/constant" "dtstack.com/dtstack/easymatrix/matrix/model/upgrade" "encoding/base64" "encoding/json" @@ -28,9 +28,6 @@ import ( "io/ioutil" "math/rand" "net/http" - "os" - "os/exec" - "path/filepath" "regexp" "sort" "strconv" @@ -39,43 +36,23 @@ import ( "time" "dtstack.com/dtstack/easymatrix/addons/easykube/pkg/view/response" - "dtstack.com/dtstack/easymatrix/addons/easymonitor/pkg/monitor/events" - oldclient "dtstack.com/dtstack/easymatrix/addons/oldkube/pkg/client-go" apibase "dtstack.com/dtstack/easymatrix/go-common/api-base" dbhelper "dtstack.com/dtstack/easymatrix/go-common/db-helper" "dtstack.com/dtstack/easymatrix/matrix/agent" - "dtstack.com/dtstack/easymatrix/matrix/api/k8s/view" + ksocket "dtstack.com/dtstack/easymatrix/matrix/api/web-socket" "dtstack.com/dtstack/easymatrix/matrix/base" "dtstack.com/dtstack/easymatrix/matrix/encrypt/aes" "dtstack.com/dtstack/easymatrix/matrix/enums" "dtstack.com/dtstack/easymatrix/matrix/event" "dtstack.com/dtstack/easymatrix/matrix/grafana" "dtstack.com/dtstack/easymatrix/matrix/host" - clustergenerator "dtstack.com/dtstack/easymatrix/matrix/k8s/cluster" - "dtstack.com/dtstack/easymatrix/matrix/k8s/constant" - kdeploy "dtstack.com/dtstack/easymatrix/matrix/k8s/deploy" - "dtstack.com/dtstack/easymatrix/matrix/k8s/docker" - "dtstack.com/dtstack/easymatrix/matrix/k8s/kube" - kmodel "dtstack.com/dtstack/easymatrix/matrix/k8s/model" - "dtstack.com/dtstack/easymatrix/matrix/k8s/monitor" - "dtstack.com/dtstack/easymatrix/matrix/k8s/resource" - "dtstack.com/dtstack/easymatrix/matrix/k8s/resource/endpoints" - "dtstack.com/dtstack/easymatrix/matrix/k8s/resource/service" - kutil "dtstack.com/dtstack/easymatrix/matrix/k8s/util" - ksocket "dtstack.com/dtstack/easymatrix/matrix/k8s/web-socket" - xke_service "dtstack.com/dtstack/easymatrix/matrix/k8s/xke-service" "dtstack.com/dtstack/easymatrix/matrix/log" "dtstack.com/dtstack/easymatrix/matrix/model" - modelkube "dtstack.com/dtstack/easymatrix/matrix/model/kube" "dtstack.com/dtstack/easymatrix/matrix/util" "dtstack.com/dtstack/easymatrix/schema" - errors2 "github.com/juju/errors" "github.com/kataras/iris/context" "github.com/pkg/errors" uuid "github.com/satori/go.uuid" - "gopkg.in/yaml.v2" - corev1 "k8s.io/api/core/v1" - "k8s.io/apimachinery/pkg/util/intstr" ) const ( @@ -83,242 +60,6 @@ const ( IMAGE_SUFFIX = ".tar" ) -func PushOperatorImage(registry string) { - //推送operator相关的镜像 - log.Infof("prepare push images to registry %v", registry) - ImageDir := filepath.Join(base.WebRoot, IMAGE_DIR) - err := filepath.Walk(ImageDir, func(path string, info os.FileInfo, err error) error { - if err != nil { - return err - } - if ImageDir == path { - return nil - } - if info.IsDir() { - return nil - } - - if !strings.HasSuffix(path, IMAGE_SUFFIX) { - log.Infof("not found image file in: %v", ImageDir) - return nil - } - - log.Infof("find image file: %v", path) - log.Infof("docker load images file %v", path) - LoadImage := fmt.Sprintf("docker load -i %s | grep 'Loaded image'|awk '{print $3}'", path) - log.Debugf("exec docker load command: %v", LoadImage) - cmd := exec.Command("/bin/sh", "-c", LoadImage) - var out bytes.Buffer - cmd.Stdout = &out - if err := cmd.Run(); err != nil { - log.Errorf("docker load image %v error: %v", path, err) - return err - } - //获取镜像原始标签同时去除换行符 - sourceTag := strings.Replace(out.String(), "\n", "", -1) - newTag := registry + "/" + sourceTag - log.Infof("docker load images %v file success, source tag is: %v", path, sourceTag) - - //镜像打标签 - err = docker.Tag(newTag, sourceTag) - if err != nil { - log.Errorf("docker tag error:", err) - return err - } - log.Infof("tag image %v success", newTag) - //推送镜像 - push := exec.Command("docker", "push", newTag) - if err := push.Run(); err != nil { - log.Errorf("push image %v error", err) - return err - } - log.Infof("push image %v success", path) - - return nil - }) - - if err != nil { - log.Errorf("push image error:", err.Error()) - return - } -} - -// k8s-镜像仓库crud -func CreateImageStore(ctx context.Context) apibase.Result { - log.Debugf("[Cluster->CreateImageStore] CreateImageStore from EasyMatrix API ") - - param := model.ImageStore{} - if err := ctx.ReadJSON(¶m); err != nil { - return fmt.Errorf("ReadJSON err: %v", err) - } - //prevent the possibility of not being allowed to login the image store,but the current process must have a default image strore - if param.Name != "skip" { - err := docker.Login(param.Username, param.Address, param.Password) - if err != nil { - return fmt.Errorf("image store login fail") - } - } - id, err := model.ClusterImageStore.InsertImageStore(param) - if err != nil { - return fmt.Errorf("Database err: %v", err) - } - go PushOperatorImage(param.Address) - return map[string]interface{}{ - "id": id, - "clusterId": param.ClusterId, - "name": param.Name, - "alias": param.Alias, - "address": param.Address, - "username": param.Username, - "password": param.Password, - "email": param.Email, - } - -} - -func DeleteImageStore(ctx context.Context) apibase.Result { - log.Debugf("[Cluster->DeleteImageStore] DeleteImageStore from EasyMatrix API ") - - param := struct { - Id []int `json:"id"` - }{} - if err := ctx.ReadJSON(¶m); err != nil { - return fmt.Errorf("ReadJSON err: %v", err) - } - - for _, v := range param.Id { - err := model.ClusterImageStore.DeleteImageStoreById(v) - if err != nil { - return fmt.Errorf("Database err: %v", err) - } - } - return nil -} - -func UpdateImageStore(ctx context.Context) apibase.Result { - log.Debugf("[Cluster->UpdateImageStore] UpdateImageStore from EasyMatrix API ") - param := model.ImageStore{} - if err := ctx.ReadJSON(¶m); err != nil { - return fmt.Errorf("ReadJSON err: %v", err) - } - if param.Name != "skip" { - err := docker.Login(param.Username, param.Address, param.Password) - if err != nil { - return fmt.Errorf("image store login fail") - } - } - err := model.ClusterImageStore.UpdateImageStoreById(param) - if err != nil { - return err - } - store, err := model.ClusterImageStore.GetImageStoreInfoById(param.Id) - if err != nil { - return fmt.Errorf("Database err: %v", err) - } - return map[string]interface{}{ - "id": store.Id, - "clusterId": store.ClusterId, - "name": store.Name, - "alias": store.Alias, - "address": store.Address, - "username": store.Username, - "password": store.Password, - "email": store.Email, - "is_default": store.IsDefault, - } -} - -func GetImageStoreInfoByClusterId(ctx context.Context) apibase.Result { - log.Debugf("[Cluster->GetImageStoreInfoByClusterId] GetImageStoreInfoByClusterId from EasyMatrix API ") - clusterId, err := ctx.Params().GetInt("cluster_id") - if err != nil { - log.Errorf("%v", err) - return err - } - - stores, err := model.ClusterImageStore.GetImageStoreInfoByClusterId(clusterId) - if err != nil { - return fmt.Errorf("Database err: %v", err) - } - list := []map[string]interface{}{} - for _, store := range stores { - list = append(list, map[string]interface{}{ - "id": store.Id, - "clusterId": store.ClusterId, - "name": store.Name, - "alias": store.Alias, - "address": store.Address, - "username": store.Username, - "password": store.Password, - "email": store.Email, - "is_default": store.IsDefault, - }) - } - return map[string]interface{}{ - "count": len(stores), - "list": list, - } -} - -func GetImageStoreInfoById(ctx context.Context) apibase.Result { - log.Debugf("[Cluster->GetImageStoreInfoById] GetImageStoreInfoById from EasyMatrix API ") - id, err := ctx.Params().GetInt("store_id") - if err != nil { - log.Errorf("%v", err) - return err - } - - store, err := model.ClusterImageStore.GetImageStoreInfoById(id) - if err != nil { - return fmt.Errorf("Database err: %v", err) - } - return map[string]interface{}{ - "id": store.Id, - "clusterId": store.ClusterId, - "name": store.Name, - "alias": store.Alias, - "address": store.Address, - "username": store.Username, - "password": store.Password, - "email": store.Email, - "is_default": store.IsDefault, - } -} - -func CheckDefaultImageStore(ctx context.Context) apibase.Result { - log.Debugf("CheckDefaultImageStore: %v", ctx.Request().RequestURI) - - clusterId, err := ctx.Params().GetInt("cluster_id") - if err != nil { - log.Errorf("%v", err) - return err - } - store, err := model.ClusterImageStore.GetDefaultStoreByClusterId(clusterId) - if err != nil && err != sql.ErrNoRows { - return fmt.Errorf("database err:%v", err) - } - exist := store.Id > 0 - return map[string]bool{ - "exist": exist, - } -} - -func SetDefaultImageStore(ctx context.Context) apibase.Result { - log.Debugf("SetDefaultImageStore: %v", ctx.Request().RequestURI) - param := make(map[string]int) - err := ctx.ReadJSON(¶m) - if err != nil { - return fmt.Errorf("read json err:%v", err) - } - err = model.ClusterImageStore.SetDefaultById(param["id"], param["clusterId"]) - if err != nil { - return fmt.Errorf("database err:%v", err) - } - return map[string]string{ - "message": "success", - } -} - // 主机集群crud func CreateHostCluster(ctx context.Context) apibase.Result { log.Debugf("[Cluster->CreateHostCluster] CreateHostCluster from EasyMatrix API ") @@ -2985,2304 +2726,71 @@ func GetClusterList(ctx context.Context) apibase.Result { } } -func GetRkeTemplate(ctx context.Context) apibase.Result { - log.Debugf("GetRkeTemplate: %v", ctx.Request().RequestURI) - paramErrs := apibase.NewApiParameterErrors() - - version := ctx.URLParam("version") - clusterName := ctx.URLParam("cluster") - networkPlugin := ctx.URLParam("network_plugin") - - if version == "" || networkPlugin == "" || clusterName == "" { - paramErrs.AppendError("$", fmt.Errorf("cluster name or version or network_plugin is empty")) - } - paramErrs.CheckAndThrowApiParameterErrors() - - config := xke_service.GetDefaultRKEconfig(version, clusterName, networkPlugin) - - data, err := yaml.Marshal(config) - if err != nil { - return err +func MultiSizeConvert(size1, size2 int64) (string, string) { + sizeUnits := [...]string{"B", "KB", "MB", "GB", "TB"} + f1 := float32(size1) + f2 := float32(size2) + for _, v := range sizeUnits { + if f1 < 1024 && f2 < 1024 { + return fmt.Sprintf("%.2f"+v, f1), fmt.Sprintf("%.2f"+v, f2) + } else { + f1 = f1 / 1024 + f2 = f2 / 1024 + } } - return string(data) + return fmt.Sprintf("%.2f"+sizeUnits[len(sizeUnits)-1], f1), fmt.Sprintf("%.2f"+sizeUnits[len(sizeUnits)-1], f1) } -// k8s集群crud - -func CreateK8sCluster(ctx context.Context) apibase.Result { - log.Debugf("K8sCluster: %v", ctx.Request().RequestURI) - clusterInfoReq := &view.ClusterInfoReq{} - err := ctx.ReadJSON(clusterInfoReq) - if err != nil { // 读取k8s集群信息 - return fmt.Errorf("[cluster] read json %T err: %v", clusterInfoReq, err) - } +func GetClusterProductList(ctx context.Context) apibase.Result { + log.Debugf("GetClusterProductList: %v", ctx.Request().RequestURI) userId, err := ctx.Values().GetInt("userId") if err != nil { log.Errorf("%v", err) return err } - - // example: v1.16.3 转为 v1.16.3-rancher1-1 - clusterInfoReq.Version, err = modelkube.DeployClusterK8sAvailable.GetRealVersion(clusterInfoReq.Version) - if err != nil { - return err - } - cluster := &modelkube.ClusterInfo{ - Name: clusterInfoReq.Name, - Type: clusterInfoReq.Type, - Mode: clusterInfoReq.Mode, - Version: clusterInfoReq.Version, - Desc: clusterInfoReq.Desc, - Tags: clusterInfoReq.Tags, - Configs: sql.NullString{ - String: clusterInfoReq.NetworkPlugin.String(), - Valid: true, - }, - Yaml: sql.NullString{ - String: clusterInfoReq.Yaml, - Valid: true, - }, - Status: clusterInfoReq.Status, - ErrorMsg: clusterInfoReq.ErrorMsg, - CreateUser: clusterInfoReq.CreateUser, - } - id, err := modelkube.DeployClusterList.InsertK8sCluster(cluster) - if err != nil { - return err - } - cluster.Id = id - typ := constant.TYPE_SELF_BUILD - if cluster.Mode == 1 { - typ = constant.TYPE_IMPORT_CLUSTER - } - info := &clustergenerator.GeneratorInfo{ - Type: typ, - HostIp: ctx.Request().Host, - ClusterInfo: cluster, - } - err = clustergenerator.GenerateTemplate(info) - if err != nil { - return err - } - err, userInfo := model.UserList.GetInfoByUserId(userId) if err != nil { log.Errorf("GetInfoByUserId %v", err) return err } - //写入权限 - if userInfo.RoleId != model.ROLE_ADMIN_ID { - err, _ := model.ClusterRightList.InsertUserClusterRight(userId, id) + // 获取所有running的集群 + clusterList := make([]model.ClusterInfo, 0) + if userInfo.RoleId == model.ROLE_ADMIN_ID { + clusterList, err = model.DeployClusterList.GetDeployedClusterList() if err != nil { - log.Errorf(err.Error()) - return fmt.Errorf("can not insert ClusterRight, err : %v", err.Error()) - } - } - - // create log file for websocket read - if !util.IsPathExist(kutil.BuildClusterLogName(cluster.Name, id)) { - os.Create(kutil.BuildClusterLogName(cluster.Name, id)) - } - - defer func() { - if err := addSafetyAuditRecord(ctx, "集群管理", "创建集群", "集群名称:"+cluster.Name); err != nil { - log.Errorf("failed to add safety audit record\n") + return fmt.Errorf("[GetClusterProductList] Get deploy cluster list err:%v", err) } - }() - - return map[string]interface{}{ - "id": id, - "name": cluster.Name, - "desc": cluster.Desc, - "tags": cluster.Tags, - "mode": cluster.Mode, - "version": cluster.Version, - "network_plugin": clusterInfoReq.NetworkPlugin, - "yaml": cluster.Yaml, - } -} - -func DeleteK8sCluster(ctx context.Context) apibase.Result { - log.Debugf("K8sCluster: %v", ctx.Request().RequestURI) - - id, err := ctx.Params().GetInt("cluster_id") - if err != nil { - log.Errorf("%v", err) - return err - } - - err = model.DeployClusterList.DeleteK8sClusterById(id) - if err != nil { - return fmt.Errorf("Database err: %v", err) - } - - err = model.ClusterRightList.DeleteByClusterId(id) - if !errors.Is(err, sql.ErrNoRows) && err != nil { - return fmt.Errorf("Database err: %v", err) - } - - defer func() { - info, err := model.DeployClusterList.GetClusterInfoById(id) + } else { + clusterList, err = model.DeployClusterList.GetDeployedClusterListByUserId(userId) if err != nil { - log.Errorf("%v", err) - return - } - if err := addSafetyAuditRecord(ctx, "集群管理", "删除集群", "集群名称:"+info.Name); err != nil { - log.Errorf("failed to add safety audit record\n") + return fmt.Errorf("[GetDeployedClusterListByUserId] Get deploy cluster list err:%v", err) } - }() - return nil -} - -func UpdateK8sCluster(ctx context.Context) apibase.Result { - log.Debugf("K8sCluster: %v", ctx.Request().RequestURI) - - config := model.K8sConfigInfo{} - if err := ctx.ReadJSON(&config); err != nil { // 读取plugin信息 - return fmt.Errorf("ReadJSON err: %v", err) - } - jsonConfig, err := json.Marshal(config) - if err != nil { - return fmt.Errorf("MarshalJSON err: %v", err) } + list := make([]map[string]interface{}, 0) - cluster := model.K8sCreateInfo{} - if err := ctx.ReadJSON(&cluster); err != nil { // 读取k8s集群信息 - return fmt.Errorf("ReadJSON2 err: %v", err) - } - cluster.Configs = string(jsonConfig) - err = model.DeployClusterList.UpdateK8sCluster(cluster) - if err != nil { - return fmt.Errorf("Database err: %v", err) - } - info, err := model.DeployClusterList.GetClusterInfoById(cluster.Id) - if err != nil { - return fmt.Errorf("Database err: %v", err) - } - defer func() { - if err := addSafetyAuditRecord(ctx, "集群管理", "编辑集群", "集群名称:"+cluster.Name); err != nil { - log.Errorf("failed to add safety audit record\n") + for _, cluster := range clusterList { + // 生成主机模式下的集群产品包信息 + if cluster.Type == "hosts" { + parentProductNames, err := model.DeployClusterProductRel.GetParentProductNameListByClusterIdNamespace(cluster.Id, "") + if err != nil { + return fmt.Errorf("[GetClusterProductList] Get parentProductName list with clusterid err:%v", err) + } + products := make([]string, 0) + subdomain := make(map[string]interface{}, 0) + for _, name := range parentProductNames { + products = append(products, name) + } + subdomain["products"] = products + list = append(list, map[string]interface{}{ + "clusterName": cluster.Name, + "clusterId": cluster.Id, + "clusterType": cluster.Type, + "mode": cluster.Mode, + "subdomain": subdomain, + }) } - }() - return map[string]interface{}{ - "id": info.Id, - "name": info.Name, - "desc": info.Desc, - "tags": info.Tags, - "mode": info.Mode, - "version": info.Version, - "network_plugin": config.NetworkPlugin, - "yaml": info.Yaml.String, - } -} - -func GetK8sClusterInfo(ctx context.Context) apibase.Result { - log.Debugf("K8sCluster: %v", ctx.Request().RequestURI) - id, err := ctx.Params().GetInt("cluster_id") - if err != nil { - log.Errorf("%v", err) - return err - } - - cluster, err := model.DeployClusterList.GetClusterInfoById(id) - if err != nil { - return fmt.Errorf("Database err: %v", err) - } - configs := model.K8sConfigInfo{} - err = json.Unmarshal([]byte(cluster.Configs.String), &configs) - if err != nil { - return fmt.Errorf("json unmarshal err:%v", err) - } - return map[string]interface{}{ - "id": cluster.Id, - "name": cluster.Name, - "desc": cluster.Desc, - "tags": cluster.Tags, - "version": strings.Split(cluster.Version, "-")[0], - "network_plugin": configs.NetworkPlugin, - "yaml": cluster.Yaml.String, - } -} - -func GetK8sAvailable(ctx context.Context) apibase.Result { - paramErrs := apibase.NewApiParameterErrors() - mode, err := ctx.URLParamInt("mode") - if err != nil { - paramErrs.AppendError("$", err) - } - paramErrs.CheckAndThrowApiParameterErrors() - - available, err := modelkube.DeployClusterK8sAvailable.GetClusterK8sAvailableByMode(mode) - if err != nil { - return fmt.Errorf("Database err:%v", err) - } - list := make([]map[string]interface{}, 0) - for _, v := range available { - // 解析数据库中存的properties,分号区分配置项,冒号区分配置名,逗号区分配置选项 - //network_plugin:flannel,canal;hello_plugin:hello - properties := strings.Split(v.Properties, ";") - propertyList := make(map[string]interface{}) - for _, property := range properties { - plugin := strings.Split(property, ":") - propertyList[plugin[0]] = strings.Split(plugin[1], ",") - } - list = append(list, map[string]interface{}{ - "version": strings.Split(v.Version, "-")[0], - "properties": propertyList, - }) } return list - -} - -func GetK8sClusterOverView(ctx context.Context) apibase.Result { - log.Debugf("K8sClusterOverView: %v", ctx.Request().RequestURI) - clusterId, err := ctx.Params().GetInt("cluster_id") - if err != nil { - log.Errorf("%v", err) - return err - } - - cluster, err := model.DeployClusterList.GetClusterInfoById(clusterId) - if err != nil { - return fmt.Errorf("DataBase err:%v", err) - } - - var allocated response.AllocatedResponse - var workload response.WorkLoadResponse - var top5 response.Top5Response - var content apibase.ApiResult - var component response.ComponentResponse - sid, err := model.DeployNodeList.GetDeployNodeSidByClusterIdAndMode(cluster.Id, cluster.Mode) - err, nodeInfo := model.DeployNodeList.GetNodeInfoBySId(sid) - if err != nil || time.Now().Sub(time.Time(nodeInfo.UpdateDate)) > 3*time.Minute { - log.Infof("agent not install or wrong ") - } else { - // 从easykube获取所需k8s数据 - params := agent.ExecRestParams{ - Method: "GET", - Path: "clientgo/workload", - Timeout: "5s", - } - resp, err := agent.AgentClient.ToExecRest(sid, ¶ms, "") - log.Infof("ExecRest Workload Response:%v", resp) - if err != nil { - return fmt.Errorf("ToExecRest workload err:%v", err) - } - decodeResp, err := base64.URLEncoding.DecodeString(resp) - if err != nil { - log.Errorf("client-go response decode err:%v", err) - } - _ = json.Unmarshal(decodeResp, &content) - data, _ := json.Marshal(content.Data) - _ = json.Unmarshal(data, &workload) - - params.Path = "clientgo/top5" - resp, err = agent.AgentClient.ToExecRest(sid, ¶ms, "") - log.Infof("ExecRest Top5 Response:%v", resp) - if err != nil { - return fmt.Errorf("ToExecRest top5 err:%v", err) - } - decodeResp, err = base64.URLEncoding.DecodeString(resp) - if err != nil { - log.Errorf("client-go response decode err:%v", err) - } - _ = json.Unmarshal(decodeResp, &content) - data, _ = json.Marshal(content.Data) - _ = json.Unmarshal(data, &top5) - // 保留两位小数 - for i, v := range top5.MemTop5 { - float, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", v.Usage), 64) - top5.MemTop5[i].Usage = float - } - for i, v := range top5.CpuTop5 { - float, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", v.Usage), 64) - top5.CpuTop5[i].Usage = float - } - - params.Path = "clientgo/allocated" - resp, err = agent.AgentClient.ToExecRest(sid, ¶ms, "") - log.Infof("ExecRest Allocated Response:%v", resp) - if err != nil { - return fmt.Errorf("ToExecRest allocated err:%v", err) - } - decodeResp, err = base64.URLEncoding.DecodeString(resp) - if err != nil { - log.Errorf("client-go response decode err:%v", err) - } - _ = json.Unmarshal(decodeResp, &content) - data, _ = json.Marshal(content.Data) - _ = json.Unmarshal(data, &allocated) - - params.Path = "clientgo/componentStatus" - resp, err = agent.AgentClient.ToExecRest(sid, ¶ms, "") - log.Infof("ExecRest ComponentStatus Response:%v", resp) - if err != nil { - return fmt.Errorf("ToExecRest componentStatus err:%v", err) - } - decodeResp, err = base64.URLEncoding.DecodeString(resp) - if err != nil { - log.Errorf("client-go response decode err:%v", err) - } - _ = json.Unmarshal(decodeResp, &content) - data, _ = json.Marshal(content.Data) - _ = json.Unmarshal(data, &component) - } - - return map[string]interface{}{ - "mode": cluster.Mode, - "version": cluster.Version, - "create_time": cluster.CreateTime.Time, - "create_user": cluster.CreateUser, - "nodes": allocated.Nodes, - "error_nodes": allocated.ErrorNodes, - "mem_size_display": allocated.MemSizeDisplay, - "mem_used_display": allocated.MemUsedDisplay, - "cpu_size_display": allocated.CpuSizeDisplay, - "cpu_used_display": allocated.CpuUsedDisplay, - "pod_size_display": strconv.Itoa(int(allocated.PodSizeDisplay)) + "个", - "pod_used_display": strconv.Itoa(allocated.PodUsedDisplay) + "个", - "workload": workload, - "metrics": top5, - "component": component.List, - } -} - -func GetK8sClusterHostList(ctx context.Context) apibase.Result { - log.Debugf("K8sCluster: %v", ctx.Request().RequestURI) - paramErrs := apibase.NewApiParameterErrors() - clusterId := ctx.URLParam("cluster_id") - if clusterId == "" { - paramErrs.AppendError("$", fmt.Errorf("clusterId is empty")) - } - paramErrs.CheckAndThrowApiParameterErrors() - - group := ctx.URLParam("group") - hostOrIp := ctx.URLParam("host_or_ip") - isRunning := ctx.URLParam("is_running") - status := ctx.URLParam("status") - roles := ctx.URLParam("role") - parentProductName := ctx.URLParam("parent_product_name") - - values := []interface{}{"%" + hostOrIp + "%", "%" + hostOrIp + "%", clusterId, 0} - whereCause := ` AND deploy_cluster_host_rel.clusterId=? AND deploy_cluster_host_rel.is_deleted=? ` - - id, _ := strconv.Atoi(clusterId) - clusterInfo, _ := model.DeployClusterList.GetClusterInfoById(id) - - //产品名筛选 - if parentProductName != "" { - whereCause += ` AND deploy_product_list.parent_product_name=?` - values = append(values, parentProductName) - } - - //主机分组筛选 - if group != "" { - if strconv.Itoa(clusterInfo.Mode) == host.KUBERNETES_MODE { - whereCause += ` AND deploy_node.group IN (` - } else { - whereCause += ` AND deploy_host.group IN (` - } - for i, v := range strings.Split(group, ",") { - if i > 0 { - whereCause += `,` - } - whereCause += `?` - values = append(values, v) - } - whereCause += `)` - } - - //errMssg筛选 - if status != "" { - if strconv.Itoa(clusterInfo.Mode) == host.KUBERNETES_MODE { - whereCause += ` AND deploy_node.errorMsg IN (` - } else { - whereCause += ` AND deploy_host.errorMsg IN (` - } - - for i, v := range strings.Split(status, ",") { - if i > 0 { - whereCause += `,` - } - whereCause += `?` - values = append(values, v) - } - whereCause += `)` - } - - //role筛选 - if roles != "" { - if strings.Contains(roles, "all") { - whereCause += ` And deploy_cluster_host_rel.roles IN ('Etcd,Worker,Control','Etcd,Control,Worker','Worker,Control,Etcd','Worker,Etcd,Control','Control,Worker,Etcd','Control,Etcd,Worker') ` - } else { - whereCause += ` AND (` - for i, v := range strings.Split(roles, ",") { - if i > 0 { - whereCause += ` OR ` - } - whereCause += `deploy_cluster_host_rel.roles Like '%` + v + `%'` - } - whereCause += `)` - } - - } - - // 由表deploy_cluster_host_rel开始左连接 - var baseQuery string - if strconv.Itoa(clusterInfo.Mode) == host.KUBERNETES_MODE { - baseQuery = fmt.Sprintf(`FROM deploy_cluster_host_rel -LEFT JOIN deploy_node ON deploy_cluster_host_rel.sid = deploy_node.sid -LEFT JOIN deploy_instance_list ON deploy_node.sid = deploy_instance_list.sid -LEFT JOIN deploy_product_list ON deploy_instance_list.pid = deploy_product_list.id -LEFT JOIN sidecar_list ON sidecar_list.id = deploy_node.sid -WHERE deploy_node.sid != '' AND (deploy_node.hostname LIKE ? OR deploy_node.ip LIKE ?)%s`, whereCause) - } else { - baseQuery = fmt.Sprintf(`FROM deploy_cluster_host_rel -LEFT JOIN deploy_host ON deploy_cluster_host_rel.sid = deploy_host.sid -LEFT JOIN deploy_node ON deploy_host.ip = deploy_node.ip -LEFT JOIN deploy_instance_list ON deploy_node.sid = deploy_instance_list.sid -LEFT JOIN deploy_product_list ON deploy_instance_list.pid = deploy_product_list.id -LEFT JOIN sidecar_list ON sidecar_list.id = deploy_host.sid -WHERE deploy_host.sid != '' AND (deploy_host.hostname LIKE ? OR deploy_host.ip LIKE ?)%s`, whereCause) - } - - type hostInfo struct { - model.HostInfo - ProductNameList string `json:"product_name_list" db:"product_name_list"` - ProductNameDisplayList string `json:"product_name_display_list" db:"product_name_display_list"` - ProductIdList string `json:"pid_list" db:"pid_list"` - MemSize int64 `json:"mem_size" db:"mem_size"` - MemUsage int64 `json:"mem_usage" db:"mem_usage"` - CpuCores int `json:"-" db:"cpu_cores"` - DiskUsage sql.NullString `json:"disk_usage" db:"disk_usage"` - NetUsage sql.NullString `json:"net_usage" db:"net_usage"` - MemSizeDisplay string `json:"mem_size_display"` - MemUsedDisplay string `json:"mem_used_display"` - DiskSizeDisplay string `json:"disk_size_display"` - DiskUsedDisplay string `json:"disk_used_display"` - FileSizeDisplay string `json:"file_size_display"` - FileUsedDisplay string `json:"file_used_display"` - CpuCoreSizeDisplay string `json:"cpu_core_size_display"` - CpuCoreUsedDisplay string `json:"cpu_core_used_display"` - NetUsageDisplay []model.NetUsageDisplay `json:"net_usage_display,omitempty"` - IsRunning bool `json:"is_running"` - CpuUsagePct float64 `json:"cpu_usage_pct" db:"cpu_usage_pct"` - MemUsagePct float64 `json:"mem_usage_pct" db:"mem_usage_pct"` - DiskUsagePct float64 `json:"disk_usage_pct" db:"disk_usage_pct"` - PodUsedDisplay string `json:"pod_used_display"` - PodSizeDisplay string `json:"pod_size_display"` - PodUsagePct float64 `json:"pod_usage_pct"` - DBRoles string `json:"-" db:"roles"` - JSONRoles map[string]bool `json:"roles"` - RunUser string `json:"run_user"` - } - - var count int - var hostsList []hostInfo - var query string - whoamiCmd := "#!/bin/sh\n whoami" - if strconv.Itoa(clusterInfo.Mode) == host.KUBERNETES_MODE { - query = "SELECT COUNT(DISTINCT deploy_node.sid) " + baseQuery - } else { - query = "SELECT COUNT(DISTINCT deploy_host.sid) " + baseQuery - } - - if err := model.USE_MYSQL_DB().Get(&count, query, values...); err != nil { - log.Errorf("AgentHosts count query: %v, values %v, err: %v", query, values, err) - apibase.ThrowDBModelError(err) - } - if count > 0 { - if strconv.Itoa(clusterInfo.Mode) == host.KUBERNETES_MODE { - query = "SELECT deploy_node.*, " + - "IFNULL(GROUP_CONCAT(DISTINCT(deploy_product_list.product_name)),'') AS product_name_list, " + - "IFNULL(GROUP_CONCAT(DISTINCT(deploy_product_list.product_name_display)),'') AS product_name_display_list, " + - "IFNULL(GROUP_CONCAT(DISTINCT(deploy_product_list.id)),'') AS pid_list," + - "sidecar_list.mem_size, sidecar_list.mem_usage, sidecar_list.disk_usage, sidecar_list.net_usage, " + - "sidecar_list.cpu_cores, sidecar_list.cpu_usage as cpu_usage_pct, sidecar_list.mem_usage/sidecar_list.mem_size as mem_usage_pct, sidecar_list.disk_usage_pct, roles " + - baseQuery + " GROUP BY deploy_node.sid " - } else { - query = "SELECT deploy_host.*, " + - "IFNULL(GROUP_CONCAT(DISTINCT(deploy_product_list.product_name)),'') AS product_name_list, " + - "IFNULL(GROUP_CONCAT(DISTINCT(deploy_product_list.product_name_display)),'') AS product_name_display_list, " + - "IFNULL(GROUP_CONCAT(DISTINCT(deploy_product_list.id)),'') AS pid_list," + - "sidecar_list.mem_size, sidecar_list.mem_usage, sidecar_list.disk_usage, sidecar_list.net_usage, " + - "sidecar_list.cpu_cores, sidecar_list.cpu_usage as cpu_usage_pct, sidecar_list.mem_usage/sidecar_list.mem_size as mem_usage_pct, sidecar_list.disk_usage_pct, roles " + - baseQuery + " GROUP BY deploy_host.sid " - } - - if err := model.USE_MYSQL_DB().Select(&hostsList, query, values...); err != nil { - log.Errorf("AgentHosts query: %v, values %v, err: %v", query, values, err) - apibase.ThrowDBModelError(err) - } - for i, list := range hostsList { - if time.Now().Sub(time.Time(list.UpdateDate)) < 3*time.Minute { - hostsList[i].IsRunning = true - } - hostsList[i].JSONRoles = make(map[string]bool) - for _, v := range strings.Split(hostsList[i].DBRoles, ",") { - hostsList[i].JSONRoles[v] = true - } - hostsList[i].MemSizeDisplay, hostsList[i].MemUsedDisplay = MultiSizeConvert(list.MemSize, list.MemUsage) - - hostsList[i].CpuCoreUsedDisplay = strconv.FormatFloat(list.CpuUsagePct*float64(list.CpuCores)/100, 'f', 2, 64) + "core" - hostsList[i].CpuCoreSizeDisplay = strconv.Itoa(list.CpuCores) + "core" - if list.DiskUsage.Valid { - //hostsList[i].DiskSizeDisplay, hostsList[i].DiskUsedDisplay, hostsList[i].FileSizeDisplay, hostsList[i].FileUsedDisplay = diskUsageConvert(list.DiskUsage.String) - var diskUsages []model.DiskUsage - if err := json.Unmarshal([]byte(list.DiskUsage.String), &diskUsages); err != nil { - return err - } - var diskSize, diskUsed, fileSize, fileUsed int64 - for _, diskUsage := range diskUsages { - if diskUsage.MountPoint != "/" { - fileSize += int64(diskUsage.TotalSpace) - fileUsed += int64(diskUsage.UsedSpace) - // include fileSize/Used - diskSize += int64(diskUsage.TotalSpace) - diskUsed += int64(diskUsage.UsedSpace) - } else { - diskSize += int64(diskUsage.TotalSpace) - diskUsed += int64(diskUsage.UsedSpace) - } - } - hostsList[i].DiskSizeDisplay, hostsList[i].DiskUsedDisplay = MultiSizeConvert(diskSize, diskUsed) - hostsList[i].FileSizeDisplay, hostsList[i].FileUsedDisplay = MultiSizeConvert(fileSize, fileUsed) - } - if list.NetUsage.Valid { - hostsList[i].NetUsageDisplay = netUsageConvert(list.NetUsage.String) - } - if list.IsDeleted == 0 && list.Status > 0 && hostsList[i].IsRunning { - content, err := agent.AgentClient.ToExecCmdWithTimeout(list.SidecarId, "", whoamiCmd, "5s", "", "") - if err != nil { - //exec failed - content = err.Error() - } - user := strings.Replace(content, LINUX_SYSTEM_LINES, "", -1) - hostsList[i].RunUser = user - } - } - } - - //过滤 运行中/停止状态,供共两种状态 - //数据库里没有运行中/停止状态,仅在这个做简单过滤 - result := make([]hostInfo, 0) - ret := strings.Split(isRunning, ",") - if len(isRunning) > 0 && len(ret) == 1 { - for _, v := range hostsList { - if isRunning == strconv.FormatBool(v.IsRunning) { - result = append(result, v) - } - } - } else { - result = hostsList - } - - // 通过client-go获取主机pod资源 - - var podList response.PodListResponse - var content apibase.ApiResult - cluster, err := model.DeployClusterList.GetClusterInfoById(id) - if err != nil { - return fmt.Errorf("Database err:%v", err) - } - sid, err := model.DeployNodeList.GetDeployNodeSidByClusterIdAndMode(cluster.Id, cluster.Mode) - err, nodeInfo := model.DeployNodeList.GetNodeInfoBySId(sid) - if err != nil || time.Now().Sub(time.Time(nodeInfo.UpdateDate)) > 3*time.Minute { - log.Infof("agent not install or wrong ") - for i := range result { - result[i].PodUsagePct = 0 - result[i].PodUsedDisplay = "0个" - result[i].PodSizeDisplay = "0个" - } - } else { - // 从easykube获取所需k8s数据 - params := agent.ExecRestParams{ - Method: "GET", - Path: "clientgo/allocatedPodList", - Timeout: "5s", - } - resp, err := agent.AgentClient.ToExecRest(sid, ¶ms, "") - log.Infof("ExecRest AllocatedPodList Response:%v", resp) - if err != nil { - log.Errorf("ToExecRest podList err:%v", err) - for i := range result { - result[i].PodUsagePct = 0 - result[i].PodUsedDisplay = "0个" - result[i].PodSizeDisplay = "0个" - } - } else { - decodeResp, err := base64.URLEncoding.DecodeString(resp) - if err != nil { - log.Errorf("client-go response decode err:%v", err) - } - _ = json.Unmarshal(decodeResp, &content) - data, _ := json.Marshal(content.Data) - _ = json.Unmarshal(data, &podList) - - podSet := make(map[string]response.NodePod) - for _, nodePod := range podList.List { - podSet[nodePod.LocalIp] = nodePod - } - for i := range result { - result[i].PodUsagePct = podSet[result[i].Ip].PodUsagePct - result[i].PodUsedDisplay = strconv.Itoa(podSet[result[i].Ip].PodUsed) + "个" - result[i].PodSizeDisplay = strconv.Itoa(int(podSet[result[i].Ip].PodSize)) + "个" - } - } - } - - // 重写排序 - pagination := apibase.GetPaginationFromQueryParameters(nil, ctx, nil) - switch pagination.SortBy { - case "pod_usage_pct": - sort.SliceStable(result, func(i, j int) bool { - if pagination.SortDesc { - return result[i].PodUsagePct > result[j].PodUsagePct - } else { - return result[i].PodUsagePct < result[j].PodUsagePct - } - }) - case "cpu_usage_pct": - sort.SliceStable(result, func(i, j int) bool { - if pagination.SortDesc { - return result[i].CpuUsagePct > result[j].CpuUsagePct - } else { - return result[i].CpuUsagePct < result[j].CpuUsagePct - } - }) - case "mem_usage_pct": - sort.SliceStable(result, func(i, j int) bool { - if pagination.SortDesc { - return result[i].MemUsagePct > result[j].MemUsagePct - } else { - return result[i].MemUsagePct < result[j].MemUsagePct - } - }) - } - // 重写分页 - total := len(result) // result总数量 - if pagination.Start > 0 { - if pagination.Start+pagination.Limit < total { - result = result[pagination.Start : pagination.Start+pagination.Limit] - } else if pagination.Start > total { - result = nil - } else { - result = result[pagination.Start:total] - } - } else { - if pagination.Limit == 0 { - result = result[:total] - } else if pagination.Limit < total { - result = result[:pagination.Limit] - } - } - - return map[string]interface{}{ - "hosts": result, - "count": count, - } -} - -func GetK8sClusterImportCmd(ctx context.Context) apibase.Result { - log.Debugf("GetK8sClusterImportCmd: %v", ctx.Request().RequestURI) - clusterId := ctx.URLParam("cluster_id") - clusterName := ctx.URLParam("cluster_name") - if clusterId == "" { - return fmt.Errorf("[cluster]: clusterid is empty") - } - cid, err := strconv.Atoi(clusterId) - if err != nil { - log.Errorf("[cluster]: clusterid is not a number %s, error: %v", clusterId, err) - return err - } - secure := "kubectl apply -f %s" - inSecure := "curl --insecure -sfL %s | kubectl apply -f -" - info := clustergenerator.GeneratorInfo{ - Type: constant.TYPE_IMPORT_CLUSTER, - ClusterInfo: &modelkube.ClusterInfo{ - Id: cid, - Name: clusterName, - }, - } - url, err := clustergenerator.GetTemplateUrl(&info, false) - if err != nil { - return err - } - secure = fmt.Sprintf(secure, url) - inSecure = fmt.Sprintf(inSecure, url) - - url2, err := clustergenerator.GetTemplateUrl(&info, true) - if err != nil { - return err - } - secureV1beta1 := fmt.Sprintf("kubectl apply -f %s", url2) - insecureV1beta1 := fmt.Sprintf("curl --insecure -sfL %s | kubectl apply -f -", url2) - return map[string]interface{}{ - "secure": secure, - "secure_v1beta1": secureV1beta1, - "insecure": inSecure, - "insecure_v1beta1": insecureV1beta1, - } -} - -func GetK8sClusterPerformance(ctx context.Context) apibase.Result { - log.Debugf("HostClusterPerformance: %v", ctx.Request().RequestURI) - - paramErrs := apibase.NewApiParameterErrors() - clusterId := ctx.Params().Get("cluster_id") - if clusterId == "" { - paramErrs.AppendError("$", fmt.Errorf("clusterId is empty")) - } - metric := ctx.URLParam("metric") - if metric == "" { - paramErrs.AppendError("$", fmt.Errorf("metric is empty")) - } - fromTime, err := ctx.URLParamInt64("from") - if err != nil { - paramErrs.AppendError("$", fmt.Errorf("from is empty")) - } - toTime, err := ctx.URLParamInt64("to") - if err != nil { - paramErrs.AppendError("$", fmt.Errorf("to is empty")) - } - paramErrs.CheckAndThrowApiParameterErrors() - - type PerformanceResult struct { - Metric interface{} `json:"metric"` - Values [][]interface{} `json:"values"` - } - type PerformanceData struct { - ResultType string `json:"resultType"` - Result []PerformanceResult `json:"result"` - } - type PerformanceInfo struct { - Status string `json:"status"` - Data PerformanceData `json:"data"` - } - type TimeResult struct { - Metric interface{} `json:"metric"` - Values []interface{} `json:"value"` - } - type TimeData struct { - ResultType string `json:"resultType"` - Result []TimeResult `json:"result"` - } - type TimeInfo struct { - Status string `json:"status"` - Data TimeData `json:"data"` - } - - //cluster没有主机时,返回空数组 - id, _ := strconv.Atoi(clusterId) - relList, _ := model.DeployClusterHostRel.GetClusterHostRelList(id) - if len(relList) == 0 { - return map[string]interface{}{ - "counts": 0, - "lists": []map[string]interface{}{}, - } - } - - // 不支持获得pod数据 - if metric == "pod" { - return map[string]interface{}{ - "counts": 0, - "lists": make([]map[string]interface{}, 0), - } - } - - //向Grafana请求数据 - - url := fmt.Sprintf("http://%v/api/datasources/proxy/1/api/v1/query?query=prometheus_tsdb_lowest_timestamp", grafana.GrafanaURL.Host) - res, _ := http.Get(url) - defer res.Body.Close() - body, _ := ioutil.ReadAll(res.Body) - - //解析json - timeInfo := TimeInfo{} - err = json.Unmarshal(body, &timeInfo) - if err != nil { - log.Errorf("json unmarshal err:%v", err) - } - - //若请求时间小于监控开始时间,同步为开始时间,防止越界 - startTime, _ := strconv.Atoi(timeInfo.Data.Result[0].Values[1].(string)) - startTime /= 1000 - - if fromTime < int64(startTime) { - fromTime = int64(startTime) - } - - var query string - switch metric { // 根据metric选择查询语句 - case "cpu": - query = fmt.Sprintf("sum(100-irate(node_cpu{mode='idle',clusterId='%v',type='kubernetes'}[3m])*100)", clusterId) - case "memory": - query = fmt.Sprintf("(1-sum(node_memory_Buffers{clusterId='%v',type='kubernetes'}%%2Bnode_memory_Cached{clusterId='%v',type='kubernetes'}%%2Bnode_memory_MemFree{clusterId='%v',type='kubernetes'})/sum(node_memory_MemTotal{clusterId='%v',type='kubernetes'}))*100", clusterId, clusterId, clusterId, clusterId) - case "disk": - query = fmt.Sprintf("(1-sum(node_filesystem_free{clusterId='%v',type='kubernetes',fstype!~'rootfs|selinuxfs|autofs|rpc_pipefs|tmpfs|udev|none|devpts|sysfs|debugfs|fuse.*'})/sum(node_filesystem_size{clusterId='%v',type='kubernetes',fstype!~'rootfs|selinuxfs|autofs|rpc_pipefs|tmpfs|udev|none|devpts|sysfs|debugfs|fuse.*'}))*100", clusterId, clusterId) - } - - url = fmt.Sprintf("http://%v/api/datasources/proxy/1/api/v1/query_range?query=%v&start=%v&end=%v&step=%v", - grafana.GrafanaURL.Host, query, fromTime, toTime, (toTime-fromTime)/60) // 每次传回60个点 - res, _ = http.Get(url) - body, _ = ioutil.ReadAll(res.Body) - - //解析json - info := PerformanceInfo{} - err = json.Unmarshal(body, &info) - if err != nil { - log.Errorf("json unmarshal err:%v", err) - } - - // 转化格式 - list := make([]map[string]interface{}, 0) - if len(info.Data.Result) > 0 { - for _, v := range info.Data.Result[0].Values { - value, err := strconv.ParseFloat(v[1].(string), 64) - if err != nil { - log.Errorf("ParseFloat err:%v", err) - } - list = append(list, map[string]interface{}{ - "date": time.Unix(int64(v[0].(float64)), 0).Format("2006-01-02 15:04:05"), - "value": value, - }) - } - } - - return map[string]interface{}{ - "counts": len(list), - "lists": list, - } -} - -func MultiSizeConvert(size1, size2 int64) (string, string) { - sizeUnits := [...]string{"B", "KB", "MB", "GB", "TB"} - f1 := float32(size1) - f2 := float32(size2) - for _, v := range sizeUnits { - if f1 < 1024 && f2 < 1024 { - return fmt.Sprintf("%.2f"+v, f1), fmt.Sprintf("%.2f"+v, f2) - } else { - f1 = f1 / 1024 - f2 = f2 / 1024 - } - } - return fmt.Sprintf("%.2f"+sizeUnits[len(sizeUnits)-1], f1), fmt.Sprintf("%.2f"+sizeUnits[len(sizeUnits)-1], f1) -} - -func GetClusterProductList(ctx context.Context) apibase.Result { - log.Debugf("GetClusterProductList: %v", ctx.Request().RequestURI) - userId, err := ctx.Values().GetInt("userId") - if err != nil { - log.Errorf("%v", err) - return err - } - err, userInfo := model.UserList.GetInfoByUserId(userId) - if err != nil { - log.Errorf("GetInfoByUserId %v", err) - return err - } - // 获取所有running的集群 - clusterList := make([]model.ClusterInfo, 0) - if userInfo.RoleId == model.ROLE_ADMIN_ID { - clusterList, err = model.DeployClusterList.GetDeployedClusterList() - if err != nil { - return fmt.Errorf("[GetClusterProductList] Get deploy cluster list err:%v", err) - } - } else { - clusterList, err = model.DeployClusterList.GetDeployedClusterListByUserId(userId) - if err != nil { - return fmt.Errorf("[GetDeployedClusterListByUserId] Get deploy cluster list err:%v", err) - } - } - list := make([]map[string]interface{}, 0) - - for _, cluster := range clusterList { - // 生成主机模式下的集群产品包信息 - if cluster.Type == "hosts" { - parentProductNames, err := model.DeployClusterProductRel.GetParentProductNameListByClusterIdNamespace(cluster.Id, "") - if err != nil { - return fmt.Errorf("[GetClusterProductList] Get parentProductName list with clusterid err:%v", err) - } - products := make([]string, 0) - subdomain := make(map[string]interface{}, 0) - for _, name := range parentProductNames { - products = append(products, name) - } - subdomain["products"] = products - list = append(list, map[string]interface{}{ - "clusterName": cluster.Name, - "clusterId": cluster.Id, - "clusterType": cluster.Type, - "mode": cluster.Mode, - "subdomain": subdomain, - }) - } else if cluster.Type == "kubernetes" { - // 获取指定k8s集群下的namespace列表 - cluster_nslist, err := modelkube.DeployNamespaceList.GetLike("", cluster.Id, constant.NAMESPACE_VALID, true) - if err != nil { - return fmt.Errorf("[GetClusterProductList] Get namespace list with clusterid err:%v", err) - } - - subdomain := make(map[string]interface{}, 0) - // 获取namespace下部署过的父级产品包名称 - for _, v := range cluster_nslist { - parentProductNames, err := model.DeployClusterProductRel.GetParentProductNameListByClusterIdNamespace(cluster.Id, v.Namespace) - if err != nil { - return fmt.Errorf("[GetClusterProductList] Get parentProductName list with clusterid and namespace err:%v", err) - } - - products := make([]string, 0) - // 防止没有部署应用的namespace在前端展示 - if len(parentProductNames) == 0 { - continue - } - for _, name := range parentProductNames { - products = append(products, name) - } - subdomain[v.Namespace] = products - } - // 防止新增加的k8s集群在没有部署应用情况下在前端展示 - if len(subdomain) == 0 { - continue - } - list = append(list, map[string]interface{}{ - "clusterName": cluster.Name, - "clusterId": cluster.Id, - "clusterType": cluster.Type, - "mode": cluster.Mode, - "subdomain": subdomain, - }) - } - } - return list -} - -func GetK8sClusterNameSpaceList(ctx context.Context) apibase.Result { - log.Debugf("GetK8sClusterNameSpaceList: %v", ctx.Request().RequestURI) - - clusterId, err := ctx.Params().GetInt("cluster_id") - if err != nil { - log.Errorf("%v", err) - return err - } - cluster, err := model.DeployClusterList.GetClusterInfoById(clusterId) - if err != nil { - return err - } - if cluster.Type == "kubernetes" && cluster.Mode == 1 { - rsp, err := resource.NamespaceList(&cluster) - if err != nil { - return err - } - return rsp - } - - //the original way - content := oldclient.ContentResponse{} - namespaces := oldclient.NamespaceListResponse{} - clientParam := agent.ExecRestParams{ - Method: "GET", - Path: "clientgo/namespace/list", - Timeout: "5s", - } - - sid, _ := model.DeployNodeList.GetDeployNodeSidByClusterIdAndMode(clusterId, cluster.Mode) - resp, err := agent.AgentClient.ToExecRest(sid, &clientParam, "") - if err != nil { - return fmt.Errorf("ToExecRest namespace create err:%v", err) - } - - decodeResp, err := base64.URLEncoding.DecodeString(resp) - if err != nil { - log.Errorf("client-go response decode err:%v", err) - } - _ = json.Unmarshal(decodeResp, &content) - data, _ := json.Marshal(content.Data) - _ = json.Unmarshal(data, &namespaces) - - filter := []oldclient.Namespace{} - for _, namespace := range namespaces.Namespaces { - if strings.HasPrefix(namespace.Name, kmodel.NAMESPACE_PREFIX) { - filter = append(filter, namespace) - } - } - - return map[string]interface{}{ - "clusterName": cluster.Name, - "clusterId": cluster.Id, - "clusterType": cluster.Type, - "namespaces": filter, - } -} - -func CreateK8sClusterNamespace(ctx context.Context) apibase.Result { - log.Debugf("CreateK8sClusterNamespace: %v", ctx.Request().RequestURI) - - clusterId, err := ctx.Params().GetInt("cluster_id") - if err != nil { - log.Errorf("%v", err) - return err - } - cluster, err := model.DeployClusterList.GetClusterInfoById(clusterId) - if err != nil { - return err - } - - param := make(map[string]interface{}) - if err := ctx.ReadJSON(¶m); err != nil { - return fmt.Errorf("ReadJSON err: %v", err) - } - - body, _ := json.Marshal(param) - content := oldclient.ContentResponse{} - namespace := oldclient.Namespace{} - clientParam := agent.ExecRestParams{ - Method: "POST", - Path: "clientgo/namespace/create", - Body: body, - Timeout: "5s", - } - - sid, _ := model.DeployNodeList.GetDeployNodeSidByClusterIdAndMode(clusterId, cluster.Mode) - resp, err := agent.AgentClient.ToExecRest(sid, &clientParam, "") - if err != nil { - return fmt.Errorf("ToExecRest namespace create err:%v", err) - } - - decodeResp, err := base64.URLEncoding.DecodeString(resp) - if err != nil { - log.Errorf("client-go response decode err:%v", err) - } - _ = json.Unmarshal(decodeResp, &content) - if content.Code != 0 { - return fmt.Errorf(content.Msg) - } - data, _ := json.Marshal(content.Data) - _ = json.Unmarshal(data, &namespace) - return namespace.Name -} - -func K8sProductListWatch(ctx context.Context) apibase.Result { - param := events.Event{} - if err := ctx.ReadJSON(¶m); err != nil { - return fmt.Errorf("ReadJSON err: %v", err) - } - return monitor.HandleResourceM(¶m) -} - -//func GetK8sClusterProductDepends(ctx context.Context) apibase.Result { -// log.Debugf("GetK8sClusterProductDepends: %v", ctx.Request().RequestURI) -// -// cid, err := ctx.Params().GetInt("cluster_id") -// if err != nil { -// return fmt.Errorf("cluster_id is empty") -// } -// pid, err := ctx.Params().GetInt("pid") -// if err != nil { -// return fmt.Errorf("pid is empty") -// } -// namespace := ctx.Params().Get("namespace_name") -// if namespace == "" { -// return fmt.Errorf("namespace is empty") -// } -// -// info, err := model.DeployProductList.GetProductInfoById(pid) -// if err != nil { -// return fmt.Errorf("database err:%v", err) -// } -// originSchema, err := schema.Unmarshal(info.Schema) -// if err != nil { -// log.Errorf("schema unmarshal err:%v", err.Error()) -// return err -// } -// // 获取该部署产品包下服务组件依赖其它产品包的信息,如DTUic依赖DTBase的redis,如:{"DTBase":["redis"]} -// baseMap := make(map[string][]string) -// for _, config := range originSchema.Service { -// if config.BaseProduct == "" || config.BaseAtrribute != BASE_SERVICE_BRIDGE { -// continue -// } -// if _, ok := baseMap[config.BaseProduct]; ok { -// baseMap[config.BaseProduct] = append(baseMap[config.BaseProduct], config.BaseService) -// } else { -// baseMap[config.BaseProduct] = []string{config.BaseService} -// } -// } -// -// // 获取所有上传了的产品包的id和产品包的名称,显示格式如:{product_id:"DTBase",2:"DTUic"} -// productMap, err := model.DeployProductList.GetProductPidAndNameMap() -// if err != nil { -// log.Errorf("database err:%v", err.Error()) -// return err -// } -// // 获取所有集群信息列表 -// clusterList, err := model.DeployClusterList.GetClusterList() -// if err != nil { -// log.Errorf("database err:%v", err.Error()) -// return err -// } -// -// candidates := make([]map[string]interface{}, 0) -// hasDepends := false -// if len(baseMap) > 0 { -// hasDepends = true -// for _, cluster := range clusterList { -// relList, err := model.DeployClusterProductRel.GetProductListByClusterId(cluster.Id, model.PRODUCT_STATUS_DEPLOYED) -// if err != nil { -// log.Errorf("database err:%v", err.Error()) -// return err -// } -// -// // 获取集群下部署成功的产品包信息如:{"DTBase":[product_id]} -// relMap := make(map[string][]int) -// for _, productRel := range relList { // make deployed product map -// if _, ok := relMap[productRel.ProductName]; ok { -// relMap[productRel.ProductName] = append(relMap[productRel.ProductName], productRel.ID) -// } else { -// relMap[productRel.ProductName] = []int{productRel.ID} -// } -// } -// -// isCandidate := true -// for baseProductName, baseServiceNames := range baseMap { // check isCandidate -// if len(relMap[baseProductName]) == 0 { -// isCandidate = false -// break -// } -// for _, pid := range relMap[baseProductName] { -// if !isCandidate { -// break -// } -// serviceNameSet, err := model.DeployInstanceList.GetServiceNameByClusterIdAndPid(cluster.Id, pid) -// if err != nil { -// log.Errorf("database err:%v", err.Error()) -// return err -// } -// -// for _, baseServiceName := range baseServiceNames { -// if !serviceNameSet[baseServiceName] { -// isCandidate = false -// break -// } -// } -// } -// } -// if isCandidate { -// candidates = append(candidates, map[string]interface{}{ -// "clusterId": cluster.Id, -// "clusterName": cluster.Name, -// }) -// } -// } -// } -// -// // 检索产品包依赖的集群 -// target, err := model.DeployKubeBaseProduct.GetByPidAndClusterIdAndNamespace(pid, cid, namespace) -// if err != nil && err != sql.ErrNoRows { -// log.Errorf("database err:%v", err.Error()) -// return err -// } -// -// message := "" -// // isTargetError=true表示若先前部署的产品包依赖集群,不存在候选依赖集群列表中,表示旧的依赖集群被移除了 -// isTargetError := true -// for _, candidate := range candidates { -// if target.BaseClusterId == candidate["clusterId"] { -// isTargetError = false -// break -// } -// } -// if hasDepends && len(candidates) == 0 { -// message = "检测到该产品依赖的组件在所有集群中不存在,请先部署依赖组件" -// for product := range baseMap { -// message += " " + product -// } -// } else if isTargetError && target.BaseClusterId != 0 { -// baseCluster, _ := model.DeployClusterList.GetClusterInfoById(target.BaseClusterId) -// message = "检测到该产品依赖的组件在多个集群中存在,旧依赖集群 " + baseCluster.Name + " 中的产品可能发生迁移或卸载,请手动选择一个依赖集群" -// } else { -// message = "检测到该产品依赖的组件在多个集群中存在,请手动选择一个依赖集群" -// } -// -// return map[string]interface{}{ -// "namespace": namespace, -// "clusterId": cid, -// "productName": productMap[pid], -// "candidates": candidates, -// "hasDepends": hasDepends, -// "message": message, -// "targets": map[string]interface{}{ -// "clusterId": target.BaseClusterId, -// }, -// } -//} - -func GetK8sClusterProductDepends(ctx context.Context) apibase.Result { - log.Debugf("GetK8sClusterProductDepends: %v", ctx.Request().RequestURI) - - cid, err := ctx.Params().GetInt("cluster_id") - if err != nil { - return fmt.Errorf("cluster_id is empty") - } - pid, err := ctx.Params().GetInt("pid") - if err != nil { - return fmt.Errorf("pid is empty") - } - namespace := ctx.Params().Get("namespace_name") - if namespace == "" { - return fmt.Errorf("namespace is empty") - } - - info, err := model.DeployProductList.GetProductInfoById(pid) - if err != nil { - return fmt.Errorf("database err:%v", err) - } - originSchema, err := schema.Unmarshal(info.Schema) - if err != nil { - log.Errorf("schema unmarshal err:%v", err.Error()) - return fmt.Errorf("schema json unmarshal err:%v", err) - } - // 获取该部署产品包下服务组件依赖其它产品包的信息,如DTUic依赖DTBase的redis,如:{"DTBase":["redis"]} - baseMap := make(map[string][]string) - for _, config := range originSchema.Service { - if config.BaseProduct == "" || config.BaseService == "" || config.BaseAtrribute == BASE_SERVICE_OPTIONAL { - continue - } - if _, ok := baseMap[config.BaseProduct]; ok { - baseMap[config.BaseProduct] = append(baseMap[config.BaseProduct], config.BaseService) - } else { - baseMap[config.BaseProduct] = []string{config.BaseService} - } - } - - // 获取当前集群下部署成功的产品包列表 - relList, err := model.DeployClusterProductRel.GetProductListByClusterId(cid, model.PRODUCT_STATUS_DEPLOYED) - if err != nil { - log.Errorf("[GetK8sClusterProductDepends->GetProductListByClusterId] database err:%v", err.Error()) - return fmt.Errorf("[GetK8sClusterProductDepends->GetProductListByClusterId] database err: %v", err) - } - - // 获取namespace空间下对应部署的产品包,如{ns1:["product1","product2"]} - relnsMap := make(map[string][]model.DeployProductListInfo) - for _, product := range relList { - if _, ok := relnsMap[product.Namespace]; ok { - relnsMap[product.Namespace] = append(relnsMap[product.Namespace], product) - } else { - relnsMap[product.Namespace] = []model.DeployProductListInfo{product} - } - } - - // 候选列表 - candidates := make([]map[string]interface{}, 0) - hasDepends := false - if len(baseMap) > 0 { - hasDepends = true - for relns, relproducts := range relnsMap { - isCandidate := false - count := 0 - // 排除不存在需要依赖产品包的命名空间 - for _, relproduct := range relproducts { - if _, ok := baseMap[relproduct.ProductName]; ok { - count++ - } - } - // 只有符合产品包中依赖的产品包信息的namespace才能进入候选 - if count == len(baseMap) { - isCandidate = true - for _, relproduct := range relproducts { - serviceNameSet, err := model.DeployInstanceList.GetServiceNameByClusterIdAndPid(cid, relproduct.ID, relproduct.Namespace) - if err != nil { - log.Errorf("[GetK8sClusterProductDepends->GetServiceNameByClusterIdAndPid]database err:%v", err.Error()) - return fmt.Errorf("[GetK8sClusterProductDepends->GetServiceNameByClusterIdAndPid]database err:%v", err) - } - - // 依赖的服务是否都部署 - for _, baseServiceName := range baseMap[relproduct.ProductName] { - if !serviceNameSet[baseServiceName] { - isCandidate = false - break - } - } - } - } - - if isCandidate { - candidates = append(candidates, map[string]interface{}{ - "relynamespace": relns, - }) - } - } - } - - // 检索产品包依赖的集群记录 - targetrecord, err := model.DeployKubeBaseProduct.GetByPidAndClusterIdAndNamespace(pid, cid, namespace) - if err != nil && err != sql.ErrNoRows { - log.Errorf("[GetK8sClusterProductDepends->GetByPidAndClusterIdAndNamespace] database err:%v", err.Error()) - return fmt.Errorf("[GetK8sClusterProductDepends->GetByPidAndClusterIdAndNamespace] database err:%v", err) - } - - message := "" - - // isTargetNotExist=true表示先前部署的产品包依赖所依赖的namespace不存在候选依赖namespace列表中,表示旧的依赖namespace被移除了 - isTargetNotExist := true - for _, candidate := range candidates { - if targetrecord.RelyNamespace == candidate["relynamespace"] { - isTargetNotExist = false - break - } - } - - if hasDepends && len(candidates) == 0 { - message = "检测到该产品依赖的组件在当前集群中不存,请先部署依赖组件" - for product := range baseMap { - message += " " + product - } - } else if isTargetNotExist && targetrecord.RelyNamespace != "" { - message = "检测到该产品依赖的组件在当前集群中存在,旧依赖namespace " + targetrecord.RelyNamespace + " 中的产品可能发生迁移或卸载,请手动选择一个依赖namespace" - targetrecord.RelyNamespace = "" - } else if hasDepends && len(candidates) > 0 { - message = "检测到该产品依赖的组件在当前集群下存在,请手动选择一个依赖的namespace" - } else { - message = "检测到该产品不存在依赖的组件或者依赖方式为option" - } - // 判断当前部署的namespace是否存在依赖的产品包,若存在则默认选择当前namespace - if targetrecord.RelyNamespace == "" { - for _, candidate := range candidates { - if namespace == candidate["relynamespace"] { - targetrecord.RelyNamespace = namespace - } - } - } - - return map[string]interface{}{ - "namespace": namespace, - "clusterId": cid, - "productName": info.ProductName, - "candidates": candidates, - "hasDepends": hasDepends, - "message": message, - "targets": map[string]interface{}{ - "relynamespace": targetrecord.RelyNamespace, - }, - } -} - -type k8sDeployParam struct { - UncheckedServices []string `json:"unchecked_services,omitempty"` - ClusterId int `json:"clusterId"` - Pid int `json:"pid"` - Namespace string `json:"namespace,omitempty"` - RelyNamespace string `json:"relynamespace,omitempty"` -} - -func DeployK8sProduct(ctx context.Context) apibase.Result { - log.Debugf("DeployK8sProduct: %v", ctx.Request().RequestURI) - productName := ctx.Params().Get("product_name") - productVersion := ctx.Params().Get("product_version") - if productName == "" || productVersion == "" { - return fmt.Errorf("product_name or product_version is empty") - } - userId, err := ctx.Values().GetInt("userId") - if err != nil { - return fmt.Errorf("get userId err: %v", err) - } - param := k8sDeployParam{} - if err = ctx.ReadJSON(¶m); err != nil { - return fmt.Errorf("ReadJSON err: %v", err) - } - if param.ClusterId == 0 { - param.ClusterId, err = GetCurrentClusterId(ctx) - if err != nil { - log.Errorf("%v", err) - return err - } - } - log.Infof("deploy product_name:%v, product_version: %v, userId: %v, clusterId: %v", productName, productVersion, userId, param.ClusterId) - defer func() { - info, err := model.DeployClusterList.GetClusterInfoById(param.ClusterId) - if err != nil { - log.Errorf("%v\n", err) - return - } - if err := addSafetyAuditRecord(ctx, "部署向导", "产品部署", "集群名称:"+info.Name+", "+productName+productVersion); err != nil { - log.Errorf("failed to add safety audit record\n") - } - }() - return DealK8SDeploy(param.Namespace, param.UncheckedServices, userId, param.ClusterId, param.RelyNamespace, param.Pid) -} - -// get current product's baseservice config and sets as the baseservice's config -// clusterId: the current cluster -// baseClusterId: the relied host type cluster -// sc: the current product -func inheritK8sBaseService(clusterId int, relyNamespace string, sc *schema.SchemaConfig, s sqlxer) error { - var err error - for _, name := range sc.GetBaseService() { - baseProduct := sc.Service[name].BaseProduct - //baseProductVersion := sc.Service[name].BaseProductVersion - baseService := sc.Service[name].BaseService - baseAtrri := sc.Service[name].BaseAtrribute - baseConfigMap, ips, hosts, version, bsvc, err_ := getBaseServicInfo(s, baseProduct, baseService, baseAtrri, relyNamespace, clusterId) - if err_ != nil { - err = errors2.Wrap(err, fmt.Errorf("get base service %v(BaseProduct:%v, BaseService:%v) error:%v", name, baseProduct, baseService, err_)) - continue - } - err_ = sc.SetBaseService(name, baseConfigMap, ips, hosts, version) - if err_ != nil { - err = errors2.Wrap(err, fmt.Errorf("set base service %v(BaseProduct:%v, BaseService:%v) error:%v", name, baseProduct, baseService, err_)) - continue - } - // it's for plugin - if bsvc != nil { - //sc.Service[name].Instance = bsvc.Instance - svc := sc.Service[name] - svc.Instance = bsvc.Instance - sc.Service[name] = svc - } - } - return err -} - -func getK8SBaseServicInfo(s sqlxer, baseProduct, baseProductVersion, baseService, baseAttri string, clusterID int) (configMap schema.ConfigMap, ips, hosts []string, version string, err error) { - var product []byte - //don't care if product is parsed. get the product schema and then modify it. - //so i can get the baseproduct's modify when it is changed and saved even if it is not deployed - query := "SELECT p.product FROM " + model.TBL_DEPLOY_PRODUCT_LIST + " AS p LEFT JOIN " + - model.TBL_DEPLOY_CLUSTER_PRODUCT_REL + " AS r ON p.id = r.pid " + - "WHERE p.product_name = ? AND r.clusterId = ? AND r.is_deleted = 0" - if err = s.Get(&product, query, baseProduct, clusterID); err != nil { - if err != sql.ErrNoRows { - log.Errorf("get product schema from deploy_product list err : %v", err) - } - dns := kmodel.BuildResourceName("service", "DTinsight", baseProduct, baseService) - if baseAttri == BASE_SERVICE_OPTIONAL { - configMap = nil - ips = append(ips, dns) - hosts = append(hosts, dns) - err = nil - } - return - } - sc, err := schema.Unmarshal(product) - if err != nil { - return - } - var infoList []model.SchemaFieldModifyInfo - query = "SELECT service_name, field_path, field FROM " + model.DeploySchemaFieldModify.TableName + " WHERE product_name=? AND cluster_id=?" - if err = s.Select(&infoList, query, baseProduct, clusterID); err != nil { - log.Errorf("query base service modify field err : %v", err) - return - } - for _, info := range infoList { - sc.SetField(info.ServiceName+"."+info.FieldPath, info.Field) - } - dns := kmodel.BuildResourceName("service", sc.ParentProductName, baseProduct, baseService) - ips = append(ips, dns) - hosts = append(hosts, dns) - baseSvc := sc.Service[baseService] - configMap = baseSvc.Config - version = baseSvc.Version - return -} - -// 给非依赖服务组件设置ip和host为servicename以及修改变更后的一些字段配置信息 -func setSchemaFieldDNS(clusterId int, sc *schema.SchemaConfig, s sqlxer, namespace string) error { - var infoList []model.SchemaFieldModifyInfo - var dns string - query := "SELECT service_name, field_path, field FROM " + model.DeploySchemaFieldModify.TableName + " WHERE product_name=? AND cluster_id=? AND namespace=?" - if err := model.USE_MYSQL_DB().Select(&infoList, query, sc.ProductName, clusterId, namespace); err != nil { - return err - } - for _, modify := range infoList { - sc.SetField(modify.ServiceName+"."+modify.FieldPath, modify.Field) - } - for name, svc := range sc.Service { - if svc.BaseProduct != "" || svc.BaseService != "" { - continue - } - // k8s模式下使用云服务主机资源 - var ipList string - query = "SELECT ip_list FROM " + model.DeployServiceIpList.TableName + " WHERE product_name=? AND service_name=? AND cluster_id=? AND namespace=?" - if err := s.Get(&ipList, query, sc.ProductName, name, clusterId, namespace); err != nil && err != sql.ErrNoRows { - log.Errorf("[ServiceGroup->setSchemaFieldDNS] k8s use cloud mode database err:%v", err) - return fmt.Errorf("k8s use cloud mode database err:%v", err) - } - - if svc.Instance != nil && svc.Instance.UseCloud && ipList != "" { - ips := strings.Split(ipList, IP_LIST_SEP) - var hosts []string - hosts = ips - sc.SetServiceAddr(name, ips, hosts) - } else { - // 非使用云服务主机设置服务为service name - switch sc.DeployType { - case "workload": - // 获取workload的类型信息 - wl, err := modelkube.WorkloadDefinition.Get(name, "") - if err != nil { - return fmt.Errorf("get workload type error: %v", err) - } - if wl == nil { - // 若shcema产品包中的服务名不存在对应的workload type那么就用默认的命名规则 - buildMoleResourceServiceName("service", sc.ParentProductName, sc.ProductName, name, namespace, sc) - continue - } - // 根据workload的id获取对应部署的k8s资源类型为deployment还是sts - parts, err := modelkube.WorkloadPart.Select(wl.Id) - if err != nil { - return fmt.Errorf("get workload_part error: %v", err) - } - if parts == nil { - return fmt.Errorf("get the part of workload type %s is null, please check the workload type", name) - } - //根据workload_part的ID获取对应service类型的steps - workloadstep := []modelkube.WorloadStepSchema{} - wkstep_query := "select * from workload_step where type='service' and workloadpart_id=?" - if err := model.USE_MYSQL_DB().Select(&workloadstep, wkstep_query, parts[0].Id); err != nil { - log.Errorf("get workload_step error:%v, sql:%v\n", err, wkstep_query) - return fmt.Errorf("get workload_step error:%v, sql:%v\n", err, wkstep_query) - } - if workloadstep == nil { - // 若shcema产品包中的服务名存在对应的workload type且对应的workload type没有定义对应的service资源,则使用默认的命名规则 - buildMoleResourceServiceName("service", sc.ParentProductName, sc.ProductName, name, namespace, sc) - continue - } - - switch parts[0].Type { - case "statefulset": - var stepSvcName string - /* - 一个statefulset资源有可能存在两种service类型headless和cluster,若存在一种service类型即cluster类型的 - 则直接获取该workload服务组件对应的service name,若存在两中类型的service则获取headless类型的service name - */ - if len(workloadstep) < 2 { - dns = kmodel.BuildWorkloadServiceName(sc.ProductName, name, parts[0].Name, workloadstep[0].Name, namespace) - } else { - for _, stepSvc := range workloadstep { - if exist := strings.Contains(stepSvc.Object, "clusterIP"); exist { - stepSvcName = stepSvc.Name - } - } - svcName := kmodel.BuildWorkloadServiceName(sc.ProductName, name, parts[0].Name, stepSvcName, namespace) - //statefulset类型资源默认获取第一个pod为主角色 - podName := kmodel.BuildWorkloadPodName(sc.ProductName, name, parts[0].Name, "0") - dns = podName + "." + svcName - } - if dns != "" { - ips := strings.Split(dns, IP_LIST_SEP) - sc.SetServiceAddr(name, ips, ips) - } - default: - dns := kmodel.BuildWorkloadServiceName(sc.ProductName, name, parts[0].Name, workloadstep[0].Name, namespace) - if dns != "" { - ips := strings.Split(dns, IP_LIST_SEP) - sc.SetServiceAddr(name, ips, ips) - } - } - default: - dns = kmodel.BuildResourceNameWithNamespace("service", sc.ParentProductName, sc.ProductName, name, namespace) - if dns != "" { - ips := strings.Split(dns, IP_LIST_SEP) - sc.SetServiceAddr(name, ips, ips) - } - } - - } - } - return nil -} - -func buildMoleResourceServiceName(resourceType, parentProductName, productName, serviceName, namespace string, sc *schema.SchemaConfig) { - dns := kmodel.BuildResourceNameWithNamespace(resourceType, parentProductName, productName, serviceName, namespace) - if dns != "" { - ips := strings.Split(dns, IP_LIST_SEP) - sc.SetServiceAddr(serviceName, ips, ips) - } -} - -// 处理当前集群指定namespace下产品包的参数修改信息 -func setSchemafieldModifyInfo(clusterid int, sc *schema.SchemaConfig, namespace string) error { - var infoList []model.SchemaFieldModifyInfo - - query := "SELECT service_name, field_path, field FROM " + model.DeploySchemaFieldModify.TableName + " WHERE cluster_id=? AND namespace=?" - if err := model.USE_MYSQL_DB().Select(&infoList, query, clusterid, namespace); err != nil { - return err - } - for _, modify := range infoList { - if _, ok := sc.Service[modify.ServiceName]; ok { - sc.SetField(modify.ServiceName+"."+modify.FieldPath, modify.Field) - } - } - return nil -} - -// 修改当前集群下指定namespace中的产品包依赖服务的ip地址信息 -func BaseServiceAddrModify(clusterid int, sc *schema.SchemaConfig, namespace string) error { - productName := sc.ProductName - for _, svcName := range sc.GetBaseService() { - err, svcipsTbsc := model.DeployServiceIpList.GetServiceIpListByName(productName, svcName, clusterid, namespace) - if err != nil { - if err == sql.ErrNoRows { - continue - } - log.Errorf("get serviceiplist wiht productname %s, servicename %s, clusterid %d fail, error: %v", productName, svcName, clusterid, err) - return err - } - ips := strings.Split(svcipsTbsc.IpList, IP_LIST_SEP) - sc.SetServiceAddr(svcName, ips, ips) - } - return nil -} - -func DealK8SDeploy(namespace string, uncheckedServices []string, userId, clusterId int, relynamespace string, pid int) (rlt interface{}) { - - tx := model.USE_MYSQL_DB().MustBegin() - defer func() { - - if _, ok := rlt.(error); ok { - tx.Rollback() - } - if r := recover(); r != nil { - tx.Rollback() - rlt = r - } - }() - cluster, err := model.DeployClusterList.GetClusterInfoById(clusterId) - if err != nil { - return fmt.Errorf("database err:%v", err) - } - - // create log file for websocket read - if !util.IsPathExist(kutil.BuildProductLogName(cluster.Name, namespace, clusterId, pid)) { - os.Create(kutil.BuildProductLogName(cluster.Name, namespace, clusterId, pid)) - } - - product, err := model.DeployProductList.GetProductInfoById(pid) - if err != nil { - return fmt.Errorf("database err:%v", err) - } - - var productListInfo model.DeployProductListInfo - query := "SELECT id, product, parent_product_name FROM " + model.DeployProductList.TableName + " WHERE product_name=? AND product_version=?" - if err := tx.Get(&productListInfo, query, product.ProductName, product.ProductVersion); err != nil { - return err - } - - sc, err := schema.Unmarshal(productListInfo.Product) - if err != nil { - return err - } - if err = inheritK8sBaseService(clusterId, relynamespace, sc, tx); err != nil { - return err - } - if err = setSchemaFieldDNS(clusterId, sc, tx, namespace); err != nil { - return err - } - //if the depened service is deployed in the same cluster. - //and if the depened service ip is modified in one product. - //all the other product depends on the base service will use the modified service ip. - //but alse can modified again - //if err = setBaseServiceAddr(baseClusterId, sc, tx); err != nil { - // return err - //} - if err = setSchemafieldModifyInfo(clusterId, sc, namespace); err != nil { - return err - } - if err = BaseServiceAddrModify(clusterId, sc, namespace); err != nil { - return err - } - if err = handleUncheckedServicesCore(sc, uncheckedServices); err != nil { - return err - } - if err = sc.CheckServiceAddr(); err != nil { - log.Errorf("%v", err) - return err - } - //if need storage, but no storageclass is set. can't be deployed - if err = sc.CheckStorage(); err != nil { - return err - } - if sc.DeployType == "workload" && cluster.Mode == 0 { - return fmt.Errorf("Self-built cluster is not compatible with Workload deployment") - } - err = model.DeployClusterProductRel.CheckProductReadyForDeploy(product.ProductName) - if err != nil { - return fmt.Errorf("database err:%v", err) - } - //store, err := model.ClusterImageStore.GetDefaultStoreByClusterId(clusterId) - store, err := model.ClusterImageStore.GetStoreByClusterIdAndNamespace(clusterId, namespace) - if err != nil { - return fmt.Errorf("DealK8SDeploy GetStoreByClusterIdAndNamespace database err:%v", err) - } - - currentProductRel, _ := model.DeployClusterProductRel.GetByPidAndClusterIdNamespacce(productListInfo.ID, clusterId, namespace) - if currentProductRel.Status == model.PRODUCT_STATUS_DEPLOYING || currentProductRel.Status == model.PRODUCT_STATUS_UNDEPLOYING { - return fmt.Errorf("product is deploying or undeploying, can't deploy again") - } - - deployUUID := uuid.NewV4() - rel := model.ClusterProductRel{ - Pid: productListInfo.ID, - ClusterId: clusterId, - Status: model.PRODUCT_STATUS_DEPLOYING, - DeployUUID: deployUUID.String(), - UserId: userId, - Namespace: namespace, - } - oldProductListInfo, err := model.DeployClusterProductRel.GetCurrentProductByProductNameClusterIdNamespace(product.ProductName, clusterId, namespace) - if err == nil { - query = "UPDATE " + model.DeployClusterProductRel.TableName + " SET pid=?, user_id=?, `status`=?, `deploy_uuid`=?, namespace=?, deploy_time=NOW() WHERE pid=? AND clusterId=? AND is_deleted=0 AND namespace=?" - if _, err := tx.Exec(query, productListInfo.ID, userId, model.PRODUCT_STATUS_DEPLOYING, deployUUID, namespace, oldProductListInfo.ID, clusterId, namespace); err != nil { - log.Errorf("%v", err) - return err - } - } else if err == sql.ErrNoRows { - query = "INSERT INTO " + model.DeployClusterProductRel.TableName + " (pid, clusterId, deploy_uuid, user_id, deploy_time, status, namespace) VALUES" + - " (:pid, :clusterId, :deploy_uuid, :user_id, NOW(), :status, :namespace)" - if _, err = tx.NamedExec(query, &rel); err != nil { - log.Errorf("%v", err) - return err - } - } else { - log.Errorf("%v", err) - return err - } - // 将产品包中未选择的服务的列表写入deploy_unchecked_service - if len(uncheckedServices) > 0 { - uncheckedServiceInfo := model.DeployUncheckedServiceInfo{ClusterId: clusterId, Pid: productListInfo.ID, UncheckedServices: strings.Join(uncheckedServices, ","), Namespace: namespace} - query = "INSERT INTO " + model.DeployUncheckedService.TableName + " (pid, cluster_id, unchecked_services, namespace) VALUES" + - " (:pid, :cluster_id, :unchecked_services, :namespace) ON DUPLICATE KEY UPDATE unchecked_services=:unchecked_services,namespace=:namespace, update_time=NOW()" - if _, err = tx.NamedExec(query, &uncheckedServiceInfo); err != nil { - log.Errorf("%v", err) - return err - } - } else { - query = "DELETE FROM " + model.DeployUncheckedService.TableName + " WHERE pid=? AND cluster_id=? AND namespace=?" - if _, err = tx.Exec(query, productListInfo.ID, clusterId, namespace); err != nil && err != sql.ErrNoRows { - log.Errorf("%v", err) - return err - } - } - productHistoryInfo := model.DeployProductHistoryInfo{ - ClusterId: clusterId, - DeployUUID: deployUUID, - ProductName: product.ProductName, - ProductNameDisplay: productListInfo.ProductNameDisplay, - ProductVersion: product.ProductVersion, - Status: model.PRODUCT_STATUS_DEPLOYING, - ParentProductName: productListInfo.ParentProductName, - UserId: userId, - Namespace: namespace, - ProductType: 1, - } - sc.ParentProductName = productListInfo.ParentProductName - - query = "INSERT INTO " + model.DeployProductHistory.TableName + " (cluster_id, product_name, product_name_display, deploy_uuid, product_version, `status`, parent_product_name, deploy_start_time, user_id, namespace, product_type) " + - "VALUES (:cluster_id, :product_name, :product_name_display, :deploy_uuid, :product_version, :status , :parent_product_name, NOW(), :user_id, :namespace, :product_type)" - if _, err := tx.NamedExec(query, &productHistoryInfo); err != nil { - log.Errorf("%v", err) - return err - } - if err := tx.Commit(); err != nil { - log.Errorf("%v", err) - return err - } - - //所有的list 接口用到接收的 uuid 参数 都要在该表中有记录 用以判断该 uuid 类型 - err = model.DeployUUID.InsertOne(deployUUID.String(), "", model.ManualDeployUUIDType, pid) - if err != nil { - log.Errorf("%v", err) - return nil - } - - // TODO push docker image - go k8sDeploy(sc, deployUUID, pid, uncheckedServices, clusterId, namespace, store, relynamespace, cluster.Name) - - return map[string]interface{}{"deploy_uuid": deployUUID} -} - -func k8sDeploy(sc *schema.SchemaConfig, deployUUID uuid.UUID, pid int, uncheckedServices []string, clusterId int, namespace string, store model.ImageStore, relynamespace, clusterName string) error { - var err error - var query string - - fileName := kutil.BuildProductLogName(clusterName, namespace, clusterId, pid) - logf, err := os.OpenFile(fileName, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0766) - defer logf.Close() - if err == nil { - log.NewOutputPath(deployUUID.String(), logf) - // defer log.CloseOutputPath(deployUUID.String()) - } else { - log.Errorf(err.Error()) - } - - log.OutputInfof(deployUUID.String(), "%v", LINE_LOG) - - // lock product with clusterId namespace - lock := model.KubeProductLock{ - ClusterId: clusterId, - Pid: pid, - Namespace: namespace, - IsDeploy: 1, - } - err = model.DeployKubeProductLock.InsertOrUpdateRecord(lock) - if err != nil { - log.Errorf("%v", err) - return err - } - //temp code - var baseproduct int - useCloudService := map[string]schema.ServiceConfig{} - for name, svc := range sc.Service { - if svc.BaseProduct != "" && svc.BaseService != "" { - baseproduct = baseproduct + 1 - continue - } - if svc.Instance.UseCloud { - useCloudService[name] = svc - delete(sc.Service, name) - } - } - - defer func() { - // unlock product with clusterId namespace - lock := model.KubeProductLock{ - ClusterId: clusterId, - Pid: pid, - Namespace: namespace, - IsDeploy: 0, - } - // wait deploy - //time.Sleep(5 * time.Second) - model.DeployKubeProductLock.InsertOrUpdateRecord(lock) - - //tmp code - for name, svc := range useCloudService { - sc.Service[name] = svc - } - - if err != nil { - status := model.PRODUCT_STATUS_DEPLOY_FAIL - query = "UPDATE " + model.DeployProductHistory.TableName + " SET `status`=?, deploy_end_time=NOW() WHERE deploy_uuid=? AND cluster_id=?" - if _, err1 := model.DeployProductHistory.GetDB().Exec(query, status, deployUUID, clusterId); err1 != nil { - log.Errorf("%v", err1.Error()) - } - query = "UPDATE " + model.DeployClusterProductRel.TableName + " SET status=?, update_time=NOW() WHERE pid=? AND clusterId=? AND namespace=? AND is_deleted=0" - if _, err := model.DeployClusterProductRel.GetDB().Exec(query, status, pid, clusterId, namespace); err != nil { - log.Errorf("%v", err) - } - } - - if err_p := sc.ParseVariable(); err_p == nil { - productParsed, err_j := json.Marshal(sc) - if err_j != nil { - log.Errorf("%v, %v", err_j.Error(), productParsed) - } - query = "UPDATE " + model.DeployClusterProductRel.TableName + " SET product_parsed=?, update_time=NOW() WHERE pid=? AND clusterId=? AND namespace=? AND is_deleted=0" - if _, errq := model.DeployClusterProductRel.GetDB().Exec(query, productParsed, pid, clusterId, namespace); errq != nil { - log.Errorf("%v", errq.Error()) - } - } else { - log.Errorf("%v", err_p.Error()) - } - }() - - log.Infof("cluster %v installing new instance and rolling update ...", clusterId) - log.OutputInfof(deployUUID.String(), "cluster %v installing new instance and rolling update ...", clusterName) - //imageStore, err := model.ClusterImageStore.GetDefaultStoreByClusterId(clusterId) - //if err != nil { - // log.Errorf("%v", err) - // return err - //} - //push images - err = kdeploy.PushImages(store, sc, deployUUID.String()) - if err != nil { - log.Errorf("%v", err) - } - //import cluster to interact witht apiserver - var cache kube.ClientCache - namspaceInfo, err := modelkube.DeployNamespaceList.Get(namespace, clusterId) - if err != nil { - return err - } - if namspaceInfo != nil { - cache, err = kube.ClusterNsClientCache.GetClusterNsClient(strconv.Itoa(clusterId)).GetClientCache(kube.ImportType(namspaceInfo.Type)) - if err != nil { - return err - } - } - - //temp code - if len(useCloudService) != 0 { - for name, cloudsvc := range useCloudService { - - ipAndPortList := cloudsvc.ServiceAddr.IP - servicePortList := make([]corev1.ServicePort, 0, len(ipAndPortList)) - endpointsAddressList := []corev1.EndpointAddress{} - endpointsPortList := []corev1.EndpointPort{} - for i, str := range ipAndPortList { - ipAndPort := strings.Split(str, ":") - ip := ipAndPort[0] - var port int32 - if len(ipAndPort) == 1 { - port = 80 - } else { - ipInt, _ := strconv.Atoi(ipAndPort[1]) - port = int32(ipInt) - } - - servicePort := corev1.ServicePort{ - Name: "port" + strconv.Itoa(i), - Protocol: "TCP", - Port: port, - TargetPort: intstr.FromInt(int(port)), - } - - servicePortList = append(servicePortList, servicePort) - - endpointsAddressList = append(endpointsAddressList, corev1.EndpointAddress{IP: ip}) - endpointsPortList = append(endpointsPortList, corev1.EndpointPort{Port: port}) - - } - - svc := service.New() - svc.Name = fmt.Sprintf("%s-%s-%s", "cloudsvc", strings.ToLower(sc.ProductName), strings.ToLower(name)) - svc.Namespace = namespace - svc.Spec.Ports = servicePortList - - endpoints := endpoints.New() - endpoints.Name = svc.Name - endpoints.Namespace = namespace - endpoints.Subsets = []corev1.EndpointSubset{ - { - Addresses: endpointsAddressList, - Ports: endpointsPortList, - }, - } - - cache.GetClient(namespace).Apply(sysContext.TODO(), svc) - cache.GetClient(namespace).Apply(sysContext.TODO(), endpoints) - - instancelist := model.DeployInstanceInfo{ - ClusterId: clusterId, - Namespace: namespace, - Pid: pid, - Ip: cloudsvc.ServiceAddr.IP[0], - ServiceName: name, - Status: "running", - HealthState: 1, - } - inst := model.DeployInstanceInfo{} - getquery := "select * from " + model.DeployInstanceList.TableName + " where cluster_id= ? and namespace= ? and pid= ? and service_name= ?" - if err := model.USE_MYSQL_DB().Get(&inst, getquery, clusterId, namespace, pid, name); err == sql.ErrNoRows { - insertquery := "INSERT INTO " + model.DeployInstanceList.TableName + " (cluster_id,namespace,pid,ip,service_name,status,health_state) VALUES" + - " (:cluster_id, :namespace , :pid, :ip ,:service_name, :status, :health_state)" - if _, err = model.USE_MYSQL_DB().NamedExec(insertquery, &instancelist); err != nil { - log.Errorf("%v", err) - return err - } - } else { - updatequery := "update " + model.DeployInstanceList.TableName + " set ip= :ip where cluster_id= :cluster_id and namespace= :namespace and pid= :pid and service_name= :service_name" - if _, err = model.USE_MYSQL_DB().NamedExec(updatequery, &instancelist); err != nil { - log.Errorf("%v", err) - return err - } - } - - //err, _, _ := model.DeployInstanceList.NewPodInstanceRecord(clusterId,pid,0,1,namespace,cloudsvc.ServiceAddr.IP[0],"","",name,"","","running","",nil) - //if err != nil { - // return fmt.Errorf("k8s use cloud database NewPodInstanceRecord error: %v",err) - //} - } - } - - if len(sc.Service) == 0 || len(sc.Service) == baseproduct { - err = model.DeployClusterProductRel.UpdateStatusWithNamespace(clusterId, pid, namespace, model.PRODUCT_STATUS_DEPLOYED) - if err != nil { - log.Errorf("nothing changed, update the product deploy status fail, error %v", err) - return err - } - query := "UPDATE " + model.DeployProductHistory.TableName + " SET `status`=?, deploy_end_time=NOW() WHERE deploy_uuid=? AND cluster_id=? AND namespace=?" - if _, err := model.DeployProductHistory.GetDB().Exec(query, model.PRODUCT_STATUS_DEPLOYED, deployUUID.String(), clusterId, namespace); err != nil { - log.Errorf("nothing changed, update the history status fail, error %v", err) - } - return nil - } - //tmpcode - //////////////////////////// - - // deploy secret - //log.OutputInfof(deployUUID.String(), "starting apply secret...") - //err = kdeploy.ApplyImageSecret(cache, clusterId, namespace, store) - //if err != nil { - // log.Errorf("%v", err) - // log.OutputInfof(deployUUID.String(), "apply secret error:%v", err) - // return err - //} - //log.OutputInfof(deployUUID.String(), "apply secret success") - - if sc.DeployType == "workload" { - - ifchanged := false - ifchanged, err = kdeploy.ApplyWorkloadProcess(cache, sc, uncheckedServices, namespace, deployUUID.String(), pid, clusterId, &store) - if err != nil { - log.OutputInfof(deployUUID.String(), "apply workload error %v", err) - return err - } - log.OutputInfof(deployUUID.String(), "apply workload success") - // if the workload exist on k8s, compare current with last, if all workload is not changed, success deployed directly - if !ifchanged { - err = model.DeployClusterProductRel.UpdateStatusWithNamespace(clusterId, pid, namespace, model.PRODUCT_STATUS_DEPLOYED) - if err != nil { - log.Errorf("nothing changed, update the product deploy status fail, error %v", err) - return err - } - query := "UPDATE " + model.DeployProductHistory.TableName + " SET `status`=?, deploy_end_time=NOW() WHERE deploy_uuid=? AND cluster_id=? AND namespace=?" - if _, err := model.DeployProductHistory.GetDB().Exec(query, model.PRODUCT_STATUS_DEPLOYED, deployUUID.String(), clusterId, namespace); err != nil { - log.Errorf("nothing changed, update the history status fail, error %v", err) - } - } - return nil - } - - // deploy configMap - log.OutputInfof(deployUUID.String(), "starting apply configMap...") - err = kdeploy.ApplyConfigMaps(cache, sc, clusterId, namespace) - if err != nil { - log.Errorf("%v", err) - log.OutputInfof(deployUUID.String(), "apply configMap error:%v", err) - return err - } - log.OutputInfof(deployUUID.String(), "apply configMap success") - - // deploy mole - log.OutputInfof(deployUUID.String(), "starting apply mole...") - err = kdeploy.ApplyMole(cache, sc, uncheckedServices, clusterId, pid, namespace, deployUUID.String(), store.Alias) - if err != nil { - log.Errorf("%v", err) - log.OutputInfof(deployUUID.String(), "apply mole error:%v", err) - return err - } - log.OutputInfof(deployUUID.String(), "apply mole success") - if relynamespace != "" { - kubeBase := model.KubeBaseProduct{ - Pid: pid, - ClusterId: clusterId, - Namespace: namespace, - RelyNamespace: relynamespace, - } - err = model.DeployKubeBaseProduct.InsertRecord(kubeBase) - if err != nil { - log.Errorf("%v", err.Error()) - return err - } - } - return nil -} - -// Undeploy success situation: -// 1 mole not exist -// 2 instance list is null -// 3 instance list delete success -func K8sUndeploy(clusterId int, sc *schema.SchemaConfig, deployUUID uuid.UUID, pid int, namespace string) { - var err error - var query string - var cache kube.ClientCache - namspaceInfo, err := modelkube.DeployNamespaceList.Get(namespace, clusterId) - if err != nil { - log.Errorf("[cluster]: get namespaceinfo with ns %s, clusterid %d ,occur error", namespace, clusterId) - } - if namspaceInfo != nil { - cache, err = kube.ClusterNsClientCache.GetClusterNsClient(strconv.Itoa(clusterId)).GetClientCache(kube.ImportType(namspaceInfo.Type)) - if err != nil { - log.Errorf("[cluster]: get client cache in clusterid %d, type %s", clusterId, namspaceInfo.Type) - } - } - defer func() { - if err != nil { - status := model.PRODUCT_STATUS_UNDEPLOY_FAIL - query = "UPDATE " + model.DeployClusterProductRel.TableName + " SET status=?, update_time=NOW() WHERE pid=? AND clusterId=? AND namespace=? AND is_deleted=0" - if _, err := model.DeployClusterProductRel.GetDB().Exec(query, status, pid, clusterId, namespace); err != nil { - log.Errorf("%v", err) - } - query = "UPDATE " + model.DeployProductHistory.TableName + " SET `status`=?, deploy_end_time=NOW() WHERE deploy_uuid=? AND cluster_id=? AND namespace=?" - if _, err := model.DeployProductHistory.GetDB().Exec(query, status, deployUUID, clusterId, namespace); err != nil { - log.Errorf("%v", err) - } - } - }() - - log.Infof("cluster %v undeploy instance ...", clusterId) - var obj interface{} - if sc.DeployType == "workload" { - workloadProcess, _ := kdeploy.GetWorkloadProcess(cache, sc, namespace) - if workloadProcess != nil { - obj = workloadProcess - } - } else { - mole, _ := kdeploy.GetMole(cache, sc, clusterId, namespace) - if mole != nil { - obj = mole - } - } - if obj == nil { - //1, Mole 不存在,强行卸载成功 - log.Infof("target mole not exist, clear deploy history...") - query := "UPDATE " + model.DeployProductHistory.TableName + " SET `status`=?, deploy_end_time=NOW() WHERE deploy_uuid=? and status=?" - if _, err := model.DeployProductHistory.GetDB().Exec(query, model.PRODUCT_STATUS_UNDEPLOYED, deployUUID, model.PRODUCT_STATUS_UNDEPLOYING); err != nil { - log.Errorf("%v", err) - } - query = "UPDATE " + model.DeployClusterProductRel.TableName + " SET status=?, is_deleted=?, update_time=NOW() WHERE pid=? AND clusterId=? AND namespace=?" - if _, err := model.DeployClusterProductRel.GetDB().Exec(query, model.PRODUCT_STATUS_UNDEPLOYED, 1, pid, clusterId, namespace); err != nil { - log.Errorf("%v", err) - } - // delete instance list - err = model.DeployInstanceList.DeleteByClusterIdPidNamespace(pid, clusterId, namespace) - if err != nil { - log.Errorf("clear old instance err %v", err.Error()) - } - // delete service ip list - err = model.DeployServiceIpList.DeleteByClusterIdNamespaceProduct(namespace, sc.ProductName, clusterId) - if err != nil { - log.Errorf("clear old service ip list err %v", err.Error()) - } - return - } - instanceList, _ := model.DeployInstanceList.GetInstanceListByClusterIdNamespace(clusterId, pid, namespace) - for _, instance := range instanceList { - instanceRecordInfo := &model.DeployInstanceRecordInfo{ - DeployUUID: deployUUID, - InstanceId: instance.ID, - Sid: instance.Sid, - Ip: instance.Ip, - ProductName: sc.ProductName, - ProductVersion: sc.ProductVersion, - ProductNameDisplay: sc.ProductNameDisplay, - Group: instance.Group, - ServiceName: instance.ServiceName, - ServiceVersion: instance.ServiceVersion, - ServiceNameDisplay: instance.ServiceName, - Status: model.INSTANCE_STATUS_UNINSTALLING, - Progress: 0, - } - err, _, _ = model.DeployInstanceRecord.CreateOrUpdate(instanceRecordInfo) - - if err != nil { - log.Errorf("update instance record uninstalling fail,err: %v", err) - return - } - } - - if sc.DeployType == "workload" { - kdeploy.DeleteWorkloadProcess(cache, sc.ProductName, namespace) - } else { - if err = kdeploy.DeleteMole(cache, sc.ProductName, namespace, clusterId); err != nil { - log.Errorf("%v undeploy error: %v", deployUUID, err) - return - } - } - - if len(instanceList) == 0 { - //没有历史服务残留,强行卸载成功 - query := "UPDATE " + model.DeployProductHistory.TableName + " SET `status`=?, deploy_end_time=NOW() WHERE deploy_uuid=? and status=?" - if _, err := model.DeployProductHistory.GetDB().Exec(query, model.PRODUCT_STATUS_UNDEPLOYED, deployUUID, model.PRODUCT_STATUS_UNDEPLOYING); err != nil { - log.Errorf("%v", err) - } - query = "UPDATE " + model.DeployClusterProductRel.TableName + " SET status=?, is_deleted=?, update_time=NOW() WHERE pid=? AND clusterId=? AND namespace=?" - if _, err := model.DeployClusterProductRel.GetDB().Exec(query, model.PRODUCT_STATUS_UNDEPLOYED, 1, pid, clusterId, namespace); err != nil { - log.Errorf("%v", err) - } - } - log.Infof("undeploy %v(%v) success", sc.ProductName, sc.ProductVersion) -} - -func StopUndeployingK8sProduct(ctx context.Context) apibase.Result { - log.Debugf("StopUndeployingK8sProduct: %v", ctx.Request().RequestURI) - - clusterId, err := ctx.Params().GetInt("cluster_id") - if err != nil { - return fmt.Errorf("cluster_id is empty") - } - pid, err := ctx.Params().GetInt("pid") - if err != nil { - return fmt.Errorf("pid is empty") - } - namespace := ctx.Params().Get("namespace_name") - //if namespace == "" { - // return fmt.Errorf("namespace is empty") - //} - - productRel, err := model.DeployClusterProductRel.GetByPidAndClusterIdNamespacce(pid, clusterId, namespace) - if err != nil { - log.Errorf("%v", err) - return err - } - status := model.PRODUCT_STATUS_UNDEPLOY_FAIL - query := "UPDATE " + model.DeployClusterProductRel.TableName + " SET status=?, update_time=NOW() WHERE pid=? AND clusterId=? AND namespace=? AND is_deleted=0" - if _, err := model.DeployClusterProductRel.GetDB().Exec(query, status, pid, clusterId, namespace); err != nil { - log.Errorf("%v", err) - return err - } - query = "UPDATE " + model.DeployProductHistory.TableName + " SET `status`=?, deploy_end_time=NOW() WHERE deploy_uuid=? AND cluster_id=? AND namespace=?" - if _, err := model.DeployProductHistory.GetDB().Exec(query, status, productRel.DeployUUID, clusterId, namespace); err != nil { - log.Errorf("%v", err) - return err - } - return nil -} - -func GetK8sClusterInstallLog(ctx context.Context) apibase.Result { - log.Debugf("GetK8sClusterInstallLog: %v", ctx.Request().RequestURI) - - clusterId, err := ctx.Params().GetInt("cluster_id") - if err != nil { - log.Errorf("%v", err) - return err - } - cluster, err := model.DeployClusterList.GetClusterInfoById(clusterId) - if err != nil { - return fmt.Errorf("clusterId is empty") - } - - ws, err := ksocket.NewSocket(ctx) - if err != nil { - return err - } - - go ksocket.SocketWriter(ws, time.Unix(0, 0), kutil.BuildClusterLogName(cluster.Name, cluster.Id)) - ksocket.SocketReader(ws) - return nil -} - -func GetProductInstallLog(ctx context.Context) apibase.Result { - log.Debugf("GetProductInstallLog: %v", ctx.Request().RequestURI) - - clusterId, err := ctx.Params().GetInt("cluster_id") - if err != nil { - return fmt.Errorf("cluster_id is empty") - } - pid, err := ctx.Params().GetInt("pid") - if err != nil { - return fmt.Errorf("pid is empty") - } - namespace := ctx.Params().Get("namespace_name") - if namespace == "" { - return fmt.Errorf("namespace is empty") - } - cluster, err := model.DeployClusterList.GetClusterInfoById(clusterId) - if err != nil { - return fmt.Errorf("clusterId is empty") - } - - ws, err := ksocket.NewSocket(ctx) - if err != nil { - return err - } - - go ksocket.SocketWriter(ws, time.Unix(0, 0), kutil.BuildProductLogName(cluster.Name, namespace, cluster.Id, pid)) - ksocket.SocketReader(ws) - - return nil } func GetClusterProductsInfo(ctx context.Context) apibase.Result { diff --git a/chengying-server/matrix/api/impl/common.go b/chengying-server/matrix/api/impl/common.go index c120291..0a59199 100644 --- a/chengying-server/matrix/api/impl/common.go +++ b/chengying-server/matrix/api/impl/common.go @@ -20,13 +20,9 @@ package impl import ( "database/sql" "dtstack.com/dtstack/easymatrix/go-common/api-base" - "dtstack.com/dtstack/easymatrix/matrix/base" "dtstack.com/dtstack/easymatrix/matrix/log" "dtstack.com/dtstack/easymatrix/matrix/model" - modelkube "dtstack.com/dtstack/easymatrix/matrix/model/kube" - "encoding/json" "fmt" - enhanceyaml "github.com/ghodss/yaml" "github.com/kataras/iris/context" "io/ioutil" "strconv" @@ -150,109 +146,3 @@ func GetSafetyAuditList(ctx context.Context) apibase.Result { func addSafetyAuditRecord(ctx context.Context, module, operation, content string) error { return model.SafetyAuditList.InsertSafetyAuditRecord(ctx.GetCookie("em_username"), module, operation, ctx.RemoteAddr(), content) } - -// WorkloadDefinaInit -// @Description workload加载接口 -// @Summary workload加载接口 -// @Tags product -// @Accept application/json -// @Produce application/json -// @Success 200 {object} string "{"msg":"ok","code":0,"data":null}" -// @Router /api/v2/product/workloadinit [get] -func WorkloadDefinaInit(ctx context.Context) (rlt apibase.Result) { - var msg string - // 获取目录下workload yaml文件到切片中 - files := []string{} - - workloadfile_path := base.WebRoot + "/workload-definition" - wkfiles, err := ioutil.ReadDir(workloadfile_path) - if err != nil { - log.Errorf("open file error: %v", err) - return err - } - for _, f := range wkfiles { - if f.IsDir() { - continue - } - files = append(files, workloadfile_path+"/"+f.Name()) - } - - // 遍历workload yaml文件进行解析入库 - if len(files) != 0 { - for _, file := range files { - conf := new(modelkube.WorkloadDefinitionYaml) - tx := model.USE_MYSQL_DB().MustBegin() - - yamlFile, err := ioutil.ReadFile(file) - if err != nil { - log.Errorf("[WorkloadDefinaInit] read workload yaml %v err:%v", file, err) - return fmt.Errorf("[WorkloadDefinaInit] read workload yaml %v err:%v", file, err) - } - - js, err := enhanceyaml.YAMLToJSON(yamlFile) - if err != nil { - log.Errorf("[WorkloadDefinaInit] %v to json err: %v\n", file, err) - return fmt.Errorf("[WorkloadDefinaInit] %v to json err: %v\n", file, err) - } - - err = json.Unmarshal(js, conf) - if err != nil { - log.Errorf("[WorkloadDefinaInit] unmarshal json error %v:", err) - return fmt.Errorf("[WorkloadDefinaInit] unmarshal json error %v:", err) - } - // workload definition表用到的参数 - wkdef_version := conf.ApiVersion - wkdef_name := conf.Metadata.Name - wkdef_params, err := json.Marshal(conf.Spec.Params) - if err != nil { - log.Errorf("[WorkloadDefinaInit] marshal workloaddefinition_params json error %v:", err) - return fmt.Errorf("[WorkloadDefinaInit] marshal workloaddefinition_params json error %v:", err) - } - // workload part表用到的参数 - wkpart_name := conf.Spec.WorkloadPatrs[0].Baseworkload.Name - wkpart_type := conf.Spec.WorkloadPatrs[0].Baseworkload.Type - wkpart_parameters, err := json.Marshal(conf.Spec.WorkloadPatrs[0].Baseworkload.Parameters) - if err != nil { - log.Errorf("[WorkloadDefinaInit] marshal workloadpart_parameters json error %v:", err) - return fmt.Errorf("[WorkloadDefinaInit] marshal workloadpart_parameters json error %v:", err) - } - // workload definition表处理 - workload_id, err := modelkube.WorkloadDefinition.InsertOrUpdate(tx, wkdef_name, wkdef_version, string(wkdef_params)) - if err != nil { - log.Errorf("[WorkloadDefinaInit] insert or update workload definifion error:%v", err) - return fmt.Errorf("[WorkloadDefinaInit] insert or update workload definifion error:%v", err) - } - // workload part表处理 - workloadPartId, err := modelkube.WorkloadPart.InsertOrUpdate(tx, wkpart_name, wkpart_type, string(wkpart_parameters), workload_id) - if err != nil { - log.Errorf("[WorkloadDefinaInit] insert or update workload part error:%v", err) - return fmt.Errorf("[WorkloadDefinaInit] insert or update workload part error:%v", err) - } - - // workload step表处理 - for _, step := range conf.Spec.WorkloadPatrs[0].Steps { - wkstep_name := step.Name - wkstep_type := step.Type - wkstep_action := step.Action - wkstep_object, err := json.Marshal(step.Object) - if err != nil { - log.Errorf("[WorkloadDefinaInit] marshal workload_step object json error %v:", err) - return err - } - err = modelkube.WorkloadStep.InsertOrUpdate(tx, wkstep_name, wkstep_type, wkstep_action, string(wkstep_object), workloadPartId) - if err != nil { - log.Errorf("[WorkloadDefinaInit] insert or update workload step error:%v", err) - return fmt.Errorf("[WorkloadDefinaInit] insert or update workload step error:%v", err) - } - } - if err := tx.Commit(); err != nil { - tx.Rollback() - return err - } - } - } else { - msg = workloadfile_path + "目录下不存在workload定义文件!" - } - - return msg -} diff --git a/chengying-server/matrix/api/impl/instance.go b/chengying-server/matrix/api/impl/instance.go index dd3b7e7..ad6cabe 100644 --- a/chengying-server/matrix/api/impl/instance.go +++ b/chengying-server/matrix/api/impl/instance.go @@ -41,12 +41,8 @@ import ( "dtstack.com/dtstack/easymatrix/matrix/event" "dtstack.com/dtstack/easymatrix/matrix/harole" "dtstack.com/dtstack/easymatrix/matrix/instance" - kdeploy "dtstack.com/dtstack/easymatrix/matrix/k8s/deploy" - "dtstack.com/dtstack/easymatrix/matrix/k8s/kube" - kmodel "dtstack.com/dtstack/easymatrix/matrix/k8s/model" "dtstack.com/dtstack/easymatrix/matrix/log" "dtstack.com/dtstack/easymatrix/matrix/model" - modelkube "dtstack.com/dtstack/easymatrix/matrix/model/kube" "dtstack.com/dtstack/easymatrix/matrix/util" "dtstack.com/dtstack/easymatrix/schema" "github.com/kataras/iris/context" @@ -1098,7 +1094,6 @@ func InstanceServiceConfig(ctx context.Context) apibase.Result { instanceIdStr := ctx.Params().Get("id") configfile := ctx.FormValue("configfile") instanceId, err := strconv.Atoi(instanceIdStr) - namespace := ctx.GetCookie(COOKIE_CURRENT_K8S_NAMESPACE) if instanceIdStr == "" || err != nil { paramErrs.AppendError("$", fmt.Errorf("id is empty")) @@ -1117,43 +1112,6 @@ func InstanceServiceConfig(ctx context.Context) apibase.Result { return err } - // 区分主机模式和k8s模式在deploy_cluster_product_rel表中查询 - var productRel model.ClusterProductRel - - productRel, err = model.DeployClusterProductRel.GetByPidAndClusterIdNamespace(info.Pid, info.ClusterId, namespace) - if err != nil && !errors.Is(err, sql.ErrNoRows) { - log.Errorf("[InstanceServiceConfig] get namespace by pid and clusterid error: %v", err) - return fmt.Errorf("[InstanceServiceConfig] get namespace by pid and clusterid error: %v", err) - } - if errors.Is(err, sql.ErrNoRows) { - smoothUpgradeProductRel, err := model.DeployClusterSmoothUpgradeProductRel.GetByPidAndClusterIdNamespace(info.Pid, info.ClusterId, namespace) - if err != nil { - log.Errorf("[InstanceServiceConfig] get namespace by pid and clusterid error: %v", err) - return fmt.Errorf("[InstanceServiceConfig] get namespace by pid and clusterid error: %v", err) - } - productRel = model.ClusterProductRel{ - Id: smoothUpgradeProductRel.Id, - Pid: smoothUpgradeProductRel.Pid, - ClusterId: smoothUpgradeProductRel.ClusterId, - Namespace: smoothUpgradeProductRel.Namespace, - ProductParsed: smoothUpgradeProductRel.ProductParsed, - Status: smoothUpgradeProductRel.Status, - DeployUUID: smoothUpgradeProductRel.DeployUUID, - AlertRecover: smoothUpgradeProductRel.AlertRecover, - UserId: smoothUpgradeProductRel.UserId, - IsDeleted: smoothUpgradeProductRel.IsDeleted, - UpdateTime: smoothUpgradeProductRel.UpdateTime, - DeployTime: smoothUpgradeProductRel.DeployTime, - CreateTime: smoothUpgradeProductRel.CreateTime, - } - } - - //productRel, err = model.DeployClusterProductRel.GetByPidAndClusterId(info.Pid, info.ClusterId) - //if err != nil { - // log.Errorf("%v", err) - // return err - //} - if cluster.Type == model.DEPLOY_CLUSTER_TYPE_HOSTS { res, err := model.DeployInstanceList.GetInstanceServiceConfig(instanceId, configfile) if err != nil { @@ -1162,37 +1120,7 @@ func InstanceServiceConfig(ctx context.Context) apibase.Result { } return map[string]interface{}{"result": res} } - - sc, err := schema.Unmarshal(productRel.ProductParsed) - if err != nil { - return err - } - nsTbsc, err := modelkube.DeployNamespaceList.Get(productRel.Namespace, info.ClusterId) - if err != nil { - return err - } - cache, err := kube.ClusterNsClientCache.GetClusterNsClient(strconv.Itoa(info.ClusterId)).GetClientCache(kube.ImportType(nsTbsc.Type)) - if err != nil { - return err - } - resp, err := kdeploy.GetConfigMaps(cache, sc, cluster.Id, productRel.Namespace, info.ServiceName) - if err != nil { - return err - } - configMap, err := kmodel.ConvertConfigMap(resp) - if err != nil { - return err - } - targetFile := "" - // Files with the same name are not supported temporarily - if sc.DeployType == "workload" { - targetFile = configfile[strings.LastIndex(configfile, "/")+1:] - } else { - targetFile = strings.Replace(configfile, "/", "_", -1) - } - - return map[string]interface{}{"result": configMap.Data[targetFile]} - + return nil } func InstanceEvent(ctx context.Context) apibase.Result { diff --git a/chengying-server/matrix/api/impl/product.go b/chengying-server/matrix/api/impl/product.go index 2556f06..e960f9e 100644 --- a/chengying-server/matrix/api/impl/product.go +++ b/chengying-server/matrix/api/impl/product.go @@ -2005,7 +2005,6 @@ func Service(ctx context.Context) apibase.Result { paramErrs := apibase.NewApiParameterErrors() productName := ctx.Params().Get("product_name") productVersion := ctx.Params().Get("product_version") - relyNamespace := ctx.URLParam("relynamespace") if productName == "" { paramErrs.AppendError("$", fmt.Errorf("product_name is empty")) } @@ -2027,12 +2026,6 @@ func Service(ctx context.Context) apibase.Result { baseService string `json:"baseService"` } - clusterinfo, err := model.DeployClusterList.GetClusterInfoById(clusterId) - if err != nil { - log.Errorf("[Product->Service] Get cluster info error:%v", err) - return fmt.Errorf("Get cluster info error:%v", err) - } - info, err := model.DeployProductList.GetByProductNameAndVersion(productName, productVersion) if err != nil { return err @@ -2045,14 +2038,8 @@ func Service(ctx context.Context) apibase.Result { } // 获取该产品包下服务组件依赖对应服务的相关配置信息,主要用于获取依赖组件的版本号 - if clusterinfo.Type == model.DEPLOY_CLUSTER_TYPE_KUBERNETES { - if err = inheritK8sBaseService(clusterId, relyNamespace, sc, model.USE_MYSQL_DB()); err != nil { - log.Errorf("[Product->Service] inheritK8sBaseService error:%v", err) - } - } else { - if err = inheritBaseService(clusterId, sc, model.USE_MYSQL_DB()); err != nil { - log.Errorf("[Product->Service] inheritBaseService err: %+v", err) - } + if err = inheritBaseService(clusterId, sc, model.USE_MYSQL_DB()); err != nil { + log.Errorf("[Product->Service] inheritBaseService err: %+v", err) } services := make([]serviceRes, 0) @@ -2084,9 +2071,6 @@ func ServiceGroup(ctx context.Context) apibase.Result { productName := ctx.Params().Get("product_name") productVersion := ctx.Params().Get("product_version") uncheckedServices := strings.Split(ctx.URLParam("unchecked_services"), ",") - // k8s模式下产品包依赖的namespace - relyNamespace := ctx.URLParam("relynamespace") - namespace := ctx.URLParam("namespace") if productName == "" { paramErrs.AppendError("$", fmt.Errorf("product_name is empty")) } @@ -2154,52 +2138,18 @@ func ServiceGroup(ctx context.Context) apibase.Result { } return res } - cluster, err := model.DeployClusterList.GetClusterInfoById(clusterId) - if err != nil { - log.Errorf("[Product->ServiceGroup] get clusterinfo err : %v", err) - return fmt.Errorf("[ServiceGroup] get current cluster err:%v", err) - } // do not judge if is kubenetes type by product info. // now the product name and version identify a product, but as the kubenets type import, //it is not a good way to identify a product only by product name and version - if cluster.Type == model.DEPLOY_CLUSTER_TYPE_KUBERNETES { - if err = inheritK8sBaseService(clusterId, relyNamespace, sc, model.USE_MYSQL_DB()); err != nil { - log.Errorf("[Product->ServiceGroup] inheritK8sBaseService err: %v", err) - return fmt.Errorf("[ServiceGroup] inheritK8sBaseService err: %v", err) - } - if err = setSchemaFieldDNS(clusterId, sc, model.USE_MYSQL_DB(), namespace); err != nil { - log.Errorf("[Product->ServiceGroup] setSchemaFieldDNS err %v", err) - return fmt.Errorf("[ServiceGroup] setSchemaFieldDNS err %v", err) - } - //beacause of the dtbase and all the product's depends is bridge. - //if the baseservice is deployed in the same cluster. - //and if the service's baseservice ip is modified. - //then, all the product in the cluster will deploy can see the change of the baseservice - - //if the baseserivce is deployed in the other cluster. - //then, all the product will show the ip of the baseservice pod's hostip - //all of the service need to deploy will need to modify - //if err = setBaseServiceAddr(baseClusterId, sc, model.USE_MYSQL_DB()); err != nil { - // log.Errorf("[Product->ServiceGroup] setBaseServiceAddr err: %v", err) - // return err - //} - if err = setSchemafieldModifyInfo(clusterId, sc, namespace); err != nil { - log.Errorf("[product->ServiceGroup] service config modify fail,err: %v", err) - return fmt.Errorf("[ServiceGroup] service config modify fail,err: %v", err) - } - if err = BaseServiceAddrModify(clusterId, sc, namespace); err != nil { - log.Errorf("[product->ServiceGroup] set base service addr with modified fail,err: %v", err) - return fmt.Errorf("[erviceGroup] set base service addr with modified fail,err: %v", err) - } - } else { - if err = inheritBaseService(clusterId, sc, model.USE_MYSQL_DB()); err != nil { - log.Errorf("[Product->ServiceGroup] inheritBaseService warn: %+v", err) - } - if err = setSchemaFieldServiceAddr(clusterId, sc, model.USE_MYSQL_DB(), ""); err != nil { - log.Errorf("[Product->ServiceGroup] setSchemaFieldServiceAddr err: %v", err) - return err - } + + if err = inheritBaseService(clusterId, sc, model.USE_MYSQL_DB()); err != nil { + log.Errorf("[Product->ServiceGroup] inheritBaseService warn: %+v", err) + } + if err = setSchemaFieldServiceAddr(clusterId, sc, model.USE_MYSQL_DB(), ""); err != nil { + log.Errorf("[Product->ServiceGroup] setSchemaFieldServiceAddr err: %v", err) + return err } + if err = handleUncheckedServicesCore(sc, uncheckedServices); err != nil { log.Errorf("[Product->ServiceGroup] handleUncheckedServicesCore warn: %+v", err) } @@ -2354,9 +2304,6 @@ func ServiceGroupFile(ctx context.Context) apibase.Result { paramErrs := apibase.NewApiParameterErrors() productName := ctx.Params().Get("product_name") productVersion := ctx.Params().Get("product_version") - // k8s模式下产品包依赖的namespace - relyNamespace := ctx.URLParam("relynamespace") - namespace := ctx.URLParam("namespace") serviceName := ctx.URLParam("servicename") fileName := ctx.URLParam("file") if productName == "" { @@ -2388,39 +2335,15 @@ func ServiceGroupFile(ctx context.Context) apibase.Result { paramErrs.AppendError("$", fmt.Errorf("serviceName %s not exist", serviceName)) } paramErrs.CheckAndThrowApiParameterErrors() - cluster, err := model.DeployClusterList.GetClusterInfoById(clusterId) - if err != nil { - log.Errorf("[Product->ServiceGroup] get clusterinfo err : %v", err) - return fmt.Errorf("[ServiceGroup] get current cluster err:%v", err) - } - if cluster.Type == model.DEPLOY_CLUSTER_TYPE_KUBERNETES { - // k8s的未测试过 - if err = inheritK8sBaseService(clusterId, relyNamespace, sc, model.USE_MYSQL_DB()); err != nil { - log.Errorf("[Product->ServiceGroup] inheritK8sBaseService err: %v", err) - return fmt.Errorf("[ServiceGroup] inheritK8sBaseService err: %v", err) - } - if err = setSchemaFieldDNS(clusterId, sc, model.USE_MYSQL_DB(), namespace); err != nil { - log.Errorf("[Product->ServiceGroup] setSchemaFieldDNS err %v", err) - return fmt.Errorf("[ServiceGroup] setSchemaFieldDNS err %v", err) - } - if err = setSchemafieldModifyInfo(clusterId, sc, namespace); err != nil { - log.Errorf("[product->ServiceGroup] service config modify fail,err: %v", err) - return fmt.Errorf("[ServiceGroup] service config modify fail,err: %v", err) - } - if err = BaseServiceAddrModify(clusterId, sc, namespace); err != nil { - log.Errorf("[product->ServiceGroup] set base service addr with modified fail,err: %v", err) - return fmt.Errorf("[erviceGroup] set base service addr with modified fail,err: %v", err) - } - } else { - if err = inheritBaseService(clusterId, sc, model.USE_MYSQL_DB()); err != nil { - log.Errorf("[Product->ServiceGroup] inheritBaseService warn: %+v", err) - } - if err = setSchemaFieldServiceAddr(clusterId, sc, model.USE_MYSQL_DB(), ""); err != nil { - log.Errorf("[Product->ServiceGroup] setSchemaFieldServiceAddr err: %v", err) - return err - } + if err = inheritBaseService(clusterId, sc, model.USE_MYSQL_DB()); err != nil { + log.Errorf("[Product->ServiceGroup] inheritBaseService warn: %+v", err) + } + if err = setSchemaFieldServiceAddr(clusterId, sc, model.USE_MYSQL_DB(), ""); err != nil { + log.Errorf("[Product->ServiceGroup] setSchemaFieldServiceAddr err: %v", err) + return err } + var ( svc = sc.Service[serviceName] _, userInfo = model.UserList.GetInfoByUserId(1) @@ -5228,11 +5151,7 @@ func Deploy(ctx context.Context) apibase.Result { log.Errorf("delete notify event error: %v", err) } }() - if cluster.Type == model.DEPLOY_CLUSTER_TYPE_KUBERNETES { - return DealK8SDeploy(param.Namespace, param.UncheckedServices, userId, param.ClusterId, param.RelyNamespace, param.Pid) - } else { - return DealDeploy(productName, productVersion, param.SourceVersion, param.UncheckedServices, userId, param.ClusterId, param.DeployMode, param.FinalUpgrade) - } + return DealDeploy(productName, productVersion, param.SourceVersion, param.UncheckedServices, userId, param.ClusterId, param.DeployMode, param.FinalUpgrade) } func DeployForDevOps(ctx context.Context) apibase.Result { @@ -5262,11 +5181,7 @@ func DeployForDevOps(ctx context.Context) apibase.Result { log.Errorf("delete notify event error: %v", err) } }() - if cluster.Type == model.DEPLOY_CLUSTER_TYPE_KUBERNETES { - return DealK8SDeploy(param.Namespace, param.UncheckedServices, userId, param.ClusterId, param.RelyNamespace, param.Pid) - } else { - return DealDeploy(productName, productVersion, "", param.UncheckedServices, userId, param.ClusterId, param.DeployMode, false) - } + return DealDeploy(productName, productVersion, "", param.UncheckedServices, userId, param.ClusterId, param.DeployMode, false) } func DealDeploy(productName, productVersion, sourceVersion string, uncheckedServices []string, userId, clusterId int, installMode int, finalUpgrade bool) (rlt interface{}) { @@ -5608,15 +5523,7 @@ func DealUndeploy(productName, productVersion, namespace string, userId, cluster return err } - cluster, err := model.DeployClusterList.GetClusterInfoById(clusterId) - if err != nil { - return err - } - if cluster.Type == model.DEPLOY_CLUSTER_TYPE_KUBERNETES { - go K8sUndeploy(clusterId, sc, deployUUID, productListInfo.ID, namespace) - } else { - go undeploy(clusterId, sc, deployUUID, productListInfo.ID) - } + go undeploy(clusterId, sc, deployUUID, productListInfo.ID) //维护deploy_product_select_history表 卸载的时候维护 例如自动部署了 a b c 手动卸载了 b 回显应该回显 a b err = model.ProductSelectHistory.RemovePidByClusterId(strconv.Itoa(productListInfo.ID), clusterId) diff --git a/chengying-server/matrix/api/k8s/cluster-ns-api.go b/chengying-server/matrix/api/k8s/cluster-ns-api.go deleted file mode 100644 index 614fd26..0000000 --- a/chengying-server/matrix/api/k8s/cluster-ns-api.go +++ /dev/null @@ -1,116 +0,0 @@ -// Licensed to Apache Software Foundation(ASF) under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. Apache Software Foundation(ASF) licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -package k8s - -import ( - apibase "dtstack.com/dtstack/easymatrix/go-common/api-base" - "dtstack.com/dtstack/easymatrix/matrix/api/k8s/impl" - "github.com/kataras/iris/context" -) - -var ClusterResourceAPIRoutes = apibase.Route{ - Path: "cluster/manage", - SubRoutes: []apibase.Route{ - { - Path: "namespaces", - GET: impl.NameSpaceListStatus, - Docs: apibase.Docs{ - Desc: "query namespaces situation", - }, - SubRoutes: []apibase.Route{ - { - Path: "{namespace:string}", - GET: impl.NamespaceStatus, - Docs: apibase.Docs{ - Desc: "query namespace situation", - }, - }, - }, - }, - { - Path: "namespace", - SubRoutes: []apibase.Route{ - { - Path: "save", - POST: impl.NamespaceSave, - Middlewares: []context.Handler{ - apibase.CheckPermission3, - }, - Docs: apibase.Docs{ - Desc: "save data about the client in different namespace that represents different permissions", - }, - }, - { - Path: "agent/generate", - POST: impl.AgentGenerate, - Docs: apibase.Docs{ - Desc: "generate agent mode import yaml", - }, - }, - { - Path: "ping", - POST: impl.NamespacePing, - Docs: apibase.Docs{ - Desc: "test the agent mode if connect", - }, - }, - }, - }, - { - Path: "{namespace:string}", - SubRoutes: []apibase.Route{ - { - Path: "get", - GET: impl.NamespaceGet, - Docs: apibase.Docs{ - Desc: "get namespace client info", - }, - }, - { - Path: "events", - GET: impl.NamespaceEvent, - Docs: apibase.Docs{ - Desc: "get namespace event", - }, - }, - { - Path: "delete", - POST: impl.NamespaceDelete, - Middlewares: []context.Handler{ - apibase.CheckPermission3, - }, - Docs: apibase.Docs{ - Desc: "delete namespace client info", - }, - SubRoutes: []apibase.Route{ - { - Path: "confirm", - GET: impl.NamespaceDeleteConfirm, - Middlewares: []context.Handler{ - apibase.CheckPermission3, - }, - Docs: apibase.Docs{ - Desc: "Confirm whether it can be deleted", - }, - }, - }, - }, - }, - }, - }, -} diff --git a/chengying-server/matrix/api/k8s/impl/cluster-ns.go b/chengying-server/matrix/api/k8s/impl/cluster-ns.go deleted file mode 100644 index 9ca1907..0000000 --- a/chengying-server/matrix/api/k8s/impl/cluster-ns.go +++ /dev/null @@ -1,147 +0,0 @@ -// Licensed to Apache Software Foundation(ASF) under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. Apache Software Foundation(ASF) licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -package impl - -import ( - apibase "dtstack.com/dtstack/easymatrix/go-common/api-base" - "dtstack.com/dtstack/easymatrix/matrix/api/k8s/view" - "dtstack.com/dtstack/easymatrix/matrix/k8s/resource" - "dtstack.com/dtstack/easymatrix/matrix/log" - "fmt" - "github.com/kataras/iris/context" - "strconv" -) - -func NamespaceSave(ctx context.Context) apibase.Result{ - log.Debugf("[cluster-ns]: %s",ctx.Request().RequestURI) - requestInfo := &view.NamespaceSaveReq{} - err := ctx.ReadJSON(requestInfo) - if err != nil{ - return fmt.Errorf("read json to NamespaceSaveReq error:%v",err) - } - - clusterid := ctx.GetCookie(view.ClusterId) - userName := ctx.GetCookie(view.User) - return resource.Save(ctx,clusterid,userName,requestInfo) -} - -func NamespaceStatus(ctx context.Context) apibase.Result{ - log.Debugf("[cluster-ns]: %s",ctx.Request().RequestURI) - ns := ctx.Params().Get("namespace") - status := ctx.URLParam("status") - desc := ctx.URLParam("desc") - typ := ctx.URLParam("type") - clusterid := ctx.GetCookie(view.ClusterId) - resp,err := resource.GetNamespaceStatus(ctx,ns,clusterid,status,desc,typ) - if err != nil{ - return err - } - return resp -} - -func NameSpaceListStatus(ctx context.Context) apibase.Result{ - log.Debugf("[cluster-ns]: %s",ctx.Request().RequestURI) - clusterid := ctx.GetCookie(view.ClusterId) - status := ctx.URLParam("status") - desc := ctx.URLParam("desc") - typ := ctx.URLParam("type") - resp,err := resource.GetNamespaceListStatus(ctx,clusterid,status,desc,typ) - if err != nil{ - return err - } - return resp -} - -func AgentGenerate(ctx context.Context) apibase.Result{ - log.Debugf("[cluster-ns]: %s",ctx.Request().RequestURI) - req := &view.AgentGenerateReq{} - if err := ctx.ReadJSON(req); err != nil{ - return fmt.Errorf("read json to AgentGenerateReq error :%v",err) - } - clusterid := ctx.GetCookie(view.ClusterId) - var cid int - if clusterid == ""{ - return fmt.Errorf("AgentGenerate Get cluster id error from cookie") - } - cid, _= strconv.Atoi(clusterid) - rsp,err := resource.AgentGenerate(req,cid) - if err != nil{ - return err - } - return rsp -} - -func NamespaceGet(ctx context.Context) apibase.Result{ - log.Debugf("[cluster-ns]: %s",ctx.Request().RequestURI) - ns := ctx.Params().Get("namespace") - clusterid := ctx.GetCookie(view.ClusterId) - resp,err := resource.NamespaceGet(ns,clusterid) - if err != nil{ - return err - } - return resp -} - -func NamespaceDeleteConfirm(ctx context.Context) apibase.Result{ - log.Debugf("[cluster-ns]: %s",ctx.Request().RequestURI) - ns := ctx.Params().Get("namespace") - clusterid := ctx.GetCookie(view.ClusterId) - if err := resource.NamespaceDeleteConfirm(ns,clusterid);err != nil{ - return &view.NamespaceDeleteConfirmRsp{Status: false} - } - return &view.NamespaceDeleteConfirmRsp{Status: true} -} - -func NamespaceDelete(ctx context.Context) apibase.Result{ - log.Debugf("[cluster-ns]: %s",ctx.Request().RequestURI) - ns := ctx.Params().Get("namespace") - clusterid := ctx.GetCookie(view.ClusterId) - return resource.NamespaceDelete(ctx,ns,clusterid) -} - -func NamespacePing(ctx context.Context) apibase.Result{ - log.Debugf("[cluster-ns]: %s",ctx.Request().RequestURI) - clusterid := ctx.GetCookie(view.ClusterId) - req := &view.NamespacePingReq{} - if err := ctx.ReadJSON(req); err != nil{ - return fmt.Errorf("read json to NamespacepingReq error :%v",err) - } - return resource.NamespacePing(ctx,clusterid,req) -} - -func NamespaceEvent(ctx context.Context) apibase.Result{ - log.Debugf("[cluster-ns]: %s",ctx.Request().RequestURI) - clusterid := ctx.GetCookie(view.ClusterId) - namespace := ctx.Params().Get("namespace") - limit := ctx.URLParam("limit") - start := ctx.URLParam("start") - si,err := strconv.Atoi(start) - if err != nil{ - return fmt.Errorf("the start %s is not valid",start) - } - li,err := strconv.Atoi(limit) - if err != nil{ - return fmt.Errorf("the limit %s is not valid",limit) - } - result,err := resource.NamsapceEvent(clusterid,namespace,li,si) - if err != nil{ - return err - } - return result - -} diff --git a/chengying-server/matrix/api/k8s/impl/instance.go b/chengying-server/matrix/api/k8s/impl/instance.go deleted file mode 100644 index c9f5eac..0000000 --- a/chengying-server/matrix/api/k8s/impl/instance.go +++ /dev/null @@ -1,35 +0,0 @@ -// Licensed to Apache Software Foundation(ASF) under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. Apache Software Foundation(ASF) licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -package impl - -import ( - apibase "dtstack.com/dtstack/easymatrix/go-common/api-base" - "dtstack.com/dtstack/easymatrix/matrix/api/k8s/view" - "dtstack.com/dtstack/easymatrix/matrix/k8s/resource" - "github.com/kataras/iris/context" -) -func InstanceReplica(ctx context.Context) apibase.Result{ - req := &view.InstanceReplicaReq{} - ctx.ReadJSON(req) - productName := ctx.Params().Get("product_name") - serviceName := ctx.Params().Get("servce_name") - req.ProductName =productName - req.ServiceName = serviceName - clusterid := ctx.GetCookie(view.ClusterId) - return resource.InstanceReplica(ctx,clusterid,req) -} diff --git a/chengying-server/matrix/api/k8s/impl/ns-product.go b/chengying-server/matrix/api/k8s/impl/ns-product.go deleted file mode 100644 index 349ff10..0000000 --- a/chengying-server/matrix/api/k8s/impl/ns-product.go +++ /dev/null @@ -1,76 +0,0 @@ -// Licensed to Apache Software Foundation(ASF) under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. Apache Software Foundation(ASF) licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -package impl - -import ( - apibase "dtstack.com/dtstack/easymatrix/go-common/api-base" - "dtstack.com/dtstack/easymatrix/matrix/api/k8s/view" - "dtstack.com/dtstack/easymatrix/matrix/k8s/resource" - "dtstack.com/dtstack/easymatrix/matrix/log" - "github.com/kataras/iris/context" -) - -func GetParentProducts(ctx context.Context) apibase.Result{ - log.Debugf("[ns-product]: %s",ctx.Request().RequestURI) - ns := ctx.Params().Get("namespace") - clusterid := ctx.GetCookie(view.ClusterId) - rsp,err := resource.GetParentProductList(ns,clusterid) - if err != nil{ - return err - } - return rsp -} - -func GetProducts(ctx context.Context) apibase.Result{ - log.Debugf("[ns-product]: %s",ctx.Request().RequestURI) - parentProduct := ctx.Params().Get("parent_product_name") - namespace := ctx.Params().Get("namespace") - clusterid := ctx.GetCookie(view.ClusterId) - rsp,err := resource.GetProductList(namespace,clusterid,parentProduct) - if err != nil{ - return err - } - return rsp -} -// -func GetServiceList(ctx context.Context) apibase.Result{ - log.Debugf("[ns-product]: %s",ctx.Request().RequestURI) - namespace := ctx.Params().Get("namespace") - parentProduct := ctx.Params().Get("parent_product_name") - productName := ctx.Params().Get("product_name") - clusterid := ctx.GetCookie(view.ClusterId) - rsp,err := resource.GetServiceList(namespace,clusterid,parentProduct,productName) - if err != nil{ - return err - } - return rsp -} - -func GetService(ctx context.Context) apibase.Result{ - log.Debugf("[ns-product]: %s",ctx.Request().RequestURI) - namespace := ctx.Params().Get("namespace") - parentProduct := ctx.Params().Get("parent_product_name") - productName := ctx.Params().Get("product_name") - servicename := ctx.Params().Get("service_name") - clusterid := ctx.GetCookie(view.ClusterId) - rsp,err := resource.GetService(ctx,namespace,clusterid,parentProduct,productName,servicename) - if err != nil{ - return err - } - return rsp -} diff --git a/chengying-server/matrix/api/k8s/instance-api.go b/chengying-server/matrix/api/k8s/instance-api.go deleted file mode 100644 index f3ca406..0000000 --- a/chengying-server/matrix/api/k8s/instance-api.go +++ /dev/null @@ -1,48 +0,0 @@ -// Licensed to Apache Software Foundation(ASF) under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. Apache Software Foundation(ASF) licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -package k8s - -import ( - apibase "dtstack.com/dtstack/easymatrix/go-common/api-base" - "dtstack.com/dtstack/easymatrix/matrix/api/k8s/impl" - "github.com/kataras/iris/context" -) - -var InstanceApi = apibase.Route{ - Path: "instance", - SubRoutes: []apibase.Route{ - { - Path: "{product_name:string}", - SubRoutes: []apibase.Route{ - { - Path: "{servce_name:string}", - SubRoutes: []apibase.Route{ - { - Path: "replica", - POST: impl.InstanceReplica, - Middlewares: []context.Handler{ - apibase.CheckPermission3, - }, - }, - }, - }, - }, - }, - }, - -} diff --git a/chengying-server/matrix/api/k8s/ns-product.go b/chengying-server/matrix/api/k8s/ns-product.go deleted file mode 100644 index aa99b5c..0000000 --- a/chengying-server/matrix/api/k8s/ns-product.go +++ /dev/null @@ -1,57 +0,0 @@ -// Licensed to Apache Software Foundation(ASF) under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. Apache Software Foundation(ASF) licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -package k8s - -import ( - apibase "dtstack.com/dtstack/easymatrix/go-common/api-base" - "dtstack.com/dtstack/easymatrix/matrix/api/k8s/impl" -) - -var NSProductAPIRoutes = apibase.Route{ - Path: "product/manage", - SubRoutes: []apibase.Route{ - { - Path: "{namespace:string}", - GET: impl.GetParentProducts, - Docs: apibase.Docs{ - Desc: "get deployed parent product name in namespace", - }, - SubRoutes: []apibase.Route{ - { - Path: "{parent_product_name:string}", - GET: impl.GetProducts, - Docs: apibase.Docs{ - Desc: "get deployed product named in parent product", - }, - SubRoutes: []apibase.Route{ - { - Path: "{product_name:string}", - GET: impl.GetServiceList, - SubRoutes: []apibase.Route{ - { - Path: "{service_name:string}", - GET: impl.GetService, - }, - }, - }, - }, - }, - }, - }, - }, -} diff --git a/chengying-server/matrix/api/k8s/view/agent-generate.go b/chengying-server/matrix/api/k8s/view/agent-generate.go deleted file mode 100644 index 7664fa2..0000000 --- a/chengying-server/matrix/api/k8s/view/agent-generate.go +++ /dev/null @@ -1,27 +0,0 @@ -// Licensed to Apache Software Foundation(ASF) under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. Apache Software Foundation(ASF) licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -package view - -type AgentGenerateReq struct { - Namespace string `json:"namespace"` - RegistryId int `json:"registry_id"` -} - -type AgentGenerateRsp struct { - Yaml string `json:"yaml"` -} diff --git a/chengying-server/matrix/api/k8s/view/clusterinfo-req.go b/chengying-server/matrix/api/k8s/view/clusterinfo-req.go deleted file mode 100644 index ee6b1cc..0000000 --- a/chengying-server/matrix/api/k8s/view/clusterinfo-req.go +++ /dev/null @@ -1,43 +0,0 @@ -// Licensed to Apache Software Foundation(ASF) under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. Apache Software Foundation(ASF) licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -package view - -import "fmt" - -type ClusterInfoReq struct { - Id int `json:"id"` - Name string `json:"name"` - Type string `json:"type"` - Mode int `json:"mode"` - Version string `json:"version"` - Desc string `json:"desc"` - Tags string `json:"tags"` - Configs string `json:"configs"` - Yaml string `json:"yaml"` - Status int `json:"status"` - ErrorMsg string `json:"errorMsg"` - CreateUser string `json:"create_user"` - NetworkPlugin NetWorkPlugin `json:"network_plugin"` -} - - -type NetWorkPlugin string - -func (n NetWorkPlugin) String() string{ - return fmt.Sprintf("{\"network_plugin\":\"%s\"}",string(n)) -} diff --git a/chengying-server/matrix/api/k8s/view/cookie.go b/chengying-server/matrix/api/k8s/view/cookie.go deleted file mode 100644 index b28dcb4..0000000 --- a/chengying-server/matrix/api/k8s/view/cookie.go +++ /dev/null @@ -1,21 +0,0 @@ -// Licensed to Apache Software Foundation(ASF) under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. Apache Software Foundation(ASF) licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -package view - -var ClusterId = "em_current_cluster_id" -var User = "em_username" diff --git a/chengying-server/matrix/api/k8s/view/instane_replica.go b/chengying-server/matrix/api/k8s/view/instane_replica.go deleted file mode 100644 index 106cf79..0000000 --- a/chengying-server/matrix/api/k8s/view/instane_replica.go +++ /dev/null @@ -1,25 +0,0 @@ -// Licensed to Apache Software Foundation(ASF) under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. Apache Software Foundation(ASF) licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -package view - -type InstanceReplicaReq struct { - Replica int `json:"replica"` - ProductName string - ServiceName string - Namespace string `json:"namespace"` -} diff --git a/chengying-server/matrix/api/k8s/view/namespace-delete-confirm.go b/chengying-server/matrix/api/k8s/view/namespace-delete-confirm.go deleted file mode 100644 index 9f4d985..0000000 --- a/chengying-server/matrix/api/k8s/view/namespace-delete-confirm.go +++ /dev/null @@ -1,22 +0,0 @@ -// Licensed to Apache Software Foundation(ASF) under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. Apache Software Foundation(ASF) licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -package view - -type NamespaceDeleteConfirmRsp struct { - Status bool `json:"status"` -} diff --git a/chengying-server/matrix/api/k8s/view/namespace-event.go b/chengying-server/matrix/api/k8s/view/namespace-event.go deleted file mode 100644 index cd3d383..0000000 --- a/chengying-server/matrix/api/k8s/view/namespace-event.go +++ /dev/null @@ -1,32 +0,0 @@ -// Licensed to Apache Software Foundation(ASF) under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. Apache Software Foundation(ASF) licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -package view - -type NamespaceEventRsp struct { - Size int `json:"size"` - Events []NamespaceEvent `json:"events"` -} - -type NamespaceEvent struct { - Id int `json:"id"` - Time string `json:"time"` - Type string `json:"type"` - Reason string `json:"reason"` - Resource string `json:"resource"` - Message string `json:"message"` -} diff --git a/chengying-server/matrix/api/k8s/view/namespace-get.go b/chengying-server/matrix/api/k8s/view/namespace-get.go deleted file mode 100644 index d0b7df4..0000000 --- a/chengying-server/matrix/api/k8s/view/namespace-get.go +++ /dev/null @@ -1,27 +0,0 @@ -// Licensed to Apache Software Foundation(ASF) under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. Apache Software Foundation(ASF) licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -package view - -type NamespaceGetRsp struct { - Id int `json:"id"` - Type string `json:"type"` - Namespace string `json:"namespace"` - Registry int `json:"registry"` - Yaml string `json:"yaml"` - FileName string `json:"file_name"` -} diff --git a/chengying-server/matrix/api/k8s/view/namespace-ping.go b/chengying-server/matrix/api/k8s/view/namespace-ping.go deleted file mode 100644 index 53d0e40..0000000 --- a/chengying-server/matrix/api/k8s/view/namespace-ping.go +++ /dev/null @@ -1,24 +0,0 @@ -// Licensed to Apache Software Foundation(ASF) under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. Apache Software Foundation(ASF) licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -package view - -type NamespacePingReq struct { - Namespace string `json:"namespace"` - Ip string `json:"ip"` - Port string `json:"port"` -} diff --git a/chengying-server/matrix/api/k8s/view/namespace-save.go b/chengying-server/matrix/api/k8s/view/namespace-save.go deleted file mode 100644 index ad62207..0000000 --- a/chengying-server/matrix/api/k8s/view/namespace-save.go +++ /dev/null @@ -1,30 +0,0 @@ -// Licensed to Apache Software Foundation(ASF) under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. Apache Software Foundation(ASF) licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -package view - -type NamespaceSaveReq struct { - Id int `json:"id" db:"id"` - Type string `json:"type" db:"type"` - Namespace string `json:"namespace" db:"namespace"` - RegistryId int `json:"registry_id" db:"registry_id"` - Yaml string `json:"yaml"` - FileName string `json:"file_name"` - Ip string `json:"ip" db:"ip"` - Port string `json:"port" db"port"` - -} diff --git a/chengying-server/matrix/api/k8s/view/namespace-status.go b/chengying-server/matrix/api/k8s/view/namespace-status.go deleted file mode 100644 index 43ecec3..0000000 --- a/chengying-server/matrix/api/k8s/view/namespace-status.go +++ /dev/null @@ -1,34 +0,0 @@ -// Licensed to Apache Software Foundation(ASF) under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. Apache Software Foundation(ASF) licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -package view - -type NamespaceStatusRsp struct { - Id int `json:"id"` - Namespace string `json:"namespace"` - Status string `json:"status"` - CpuUsed string `json:"cpu_used"` - CpuTotal string `json:"cpu_total"` - CpuPercent float64 `json:"cpu_percent"` - MemUsed string `json:"memory_used"` - MemTotal string `json:"memory_total"` - MemPercent float64 `json:"mem_percent"` - User string `json:"user"` - UpdateTime string `json:"update_time"` - Type string `json:"type"` -} - diff --git a/chengying-server/matrix/api/k8s/view/ns-product.go b/chengying-server/matrix/api/k8s/view/ns-product.go deleted file mode 100644 index 3529a63..0000000 --- a/chengying-server/matrix/api/k8s/view/ns-product.go +++ /dev/null @@ -1,56 +0,0 @@ -// Licensed to Apache Software Foundation(ASF) under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. Apache Software Foundation(ASF) licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -package view - -type NamespacedProductsRsp struct { - Size int `json:"size"` - Products Products `json:"products"` -} - -type Products map[ParentProductName]ParentProduct - -type ParentProduct map[ProudctName]Product - -type Product map[ServiceName]*Service - -type Service struct { - Version string `json:"version"` - Group string `json:"group"` - HealthState string `json:"health_state"` - HealthStateCount int `json:"health_state_count"` - ServiceStatus string `json:"service_status"` - ServiecStatusCount int `json:"service_status_count"` - IsJob bool - WorkloadType string -} - -type ServiceName string -type ProudctName string -type ParentProductName string - -func (sn ServiceName) String() string{ - return string(sn) -} - -func (pn ProudctName)String() string{ - return string(pn) -} - -func (ppn ParentProductName)String() string{ - return string(ppn) -} diff --git a/chengying-server/matrix/api/product-api.go b/chengying-server/matrix/api/product-api.go index d336fb4..cdd9910 100644 --- a/chengying-server/matrix/api/product-api.go +++ b/chengying-server/matrix/api/product-api.go @@ -40,14 +40,6 @@ var ProductOperationEasyMatrixAPIRoutes = apibase.Route{ Name: "上传产品包接口[EasyMatrix API]", }, }, - }, { - Path: "workloadinit", - GET: impl.WorkloadDefinaInit, - Docs: apibase.Docs{ - POST: &apibase.ApiDoc{ - Name: "workload加载接口", - }, - }, }, { Path: "uploadAsync", POST: impl.UploadAsync, diff --git a/chengying-server/matrix/k8s/web-socket/web_socket.go b/chengying-server/matrix/api/web-socket/web_socket.go similarity index 76% rename from chengying-server/matrix/k8s/web-socket/web_socket.go rename to chengying-server/matrix/api/web-socket/web_socket.go index 0f204b7..95aa593 100644 --- a/chengying-server/matrix/k8s/web-socket/web_socket.go +++ b/chengying-server/matrix/api/web-socket/web_socket.go @@ -1,20 +1,3 @@ -// Licensed to Apache Software Foundation(ASF) under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. Apache Software Foundation(ASF) licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - package web_socket import ( diff --git a/chengying-server/matrix/config.go b/chengying-server/matrix/config.go index 797d723..6bdee71 100644 --- a/chengying-server/matrix/config.go +++ b/chengying-server/matrix/config.go @@ -31,12 +31,9 @@ import ( "dtstack.com/dtstack/easymatrix/matrix/harole" "dtstack.com/dtstack/easymatrix/matrix/health" "dtstack.com/dtstack/easymatrix/matrix/host" - "dtstack.com/dtstack/easymatrix/matrix/k8s/monitor" - "dtstack.com/dtstack/easymatrix/matrix/k8s/resource" "dtstack.com/dtstack/easymatrix/matrix/log" "dtstack.com/dtstack/easymatrix/matrix/model" - modelkube "dtstack.com/dtstack/easymatrix/matrix/model/kube" - "dtstack.com/dtstack/easymatrix/matrix/model/kube/union" + "dtstack.com/dtstack/easymatrix/matrix/monitor" "dtstack.com/dtstack/easymatrix/matrix/task" "fmt" "github.com/elastic/go-ucfg" @@ -160,19 +157,9 @@ func ParseConfig(configFile string) error { if err := model.ConfigureMysqlDatabase(db.Host, db.Port, db.User, db.Password, db.DbName); err != nil { return err } - if err := modelkube.Build(); err != nil { - return err - } - if err := union.Build(); err != nil { - return err - } - if err := resource.InitResource(); err != nil { - return err - } if err := resetDeployStatus(); err != nil { return err } - impl.WorkloadDefinaInit(nil) agentConfig := &config.Agent apiconf := &config.Api diff --git a/chengying-server/matrix/k8s/cluster/c_test.go b/chengying-server/matrix/k8s/cluster/c_test.go deleted file mode 100644 index afb296f..0000000 --- a/chengying-server/matrix/k8s/cluster/c_test.go +++ /dev/null @@ -1,41 +0,0 @@ -// Licensed to Apache Software Foundation(ASF) under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. Apache Software Foundation(ASF) licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -package cluster - -import ( - "dtstack.com/dtstack/easymatrix/matrix/k8s/constant" - modelkube "dtstack.com/dtstack/easymatrix/matrix/model/kube" - "fmt" - "testing" -) - -func Test1(t *testing.T) { - info := &GeneratorInfo{ - Type: constant.TYPE_SELF_BUILD, - ClusterInfo: &modelkube.ClusterInfo{ - Id: 135, - Name: "em_mao_self", - }, - } - bts,_:=GetTemplateFile(info,false) - fmt.Println(string(bts)) -} - -func Test2(t *testing.T) { - -} diff --git a/chengying-server/matrix/k8s/cluster/generate.go b/chengying-server/matrix/k8s/cluster/generate.go deleted file mode 100644 index 0b74d9a..0000000 --- a/chengying-server/matrix/k8s/cluster/generate.go +++ /dev/null @@ -1,132 +0,0 @@ -// Licensed to Apache Software Foundation(ASF) under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. Apache Software Foundation(ASF) licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -package cluster - -import ( - "dtstack.com/dtstack/easymatrix/matrix/asset" - "dtstack.com/dtstack/easymatrix/matrix/host" - "dtstack.com/dtstack/easymatrix/matrix/k8s/constant" - "dtstack.com/dtstack/easymatrix/matrix/k8s/util" - "dtstack.com/dtstack/easymatrix/matrix/log" - modelkube "dtstack.com/dtstack/easymatrix/matrix/model/kube" - "encoding/base64" - "fmt" - "strconv" - "text/template" -) - -type GeneratorInfo struct { - Type constant.GenerateType - HostIp string - *modelkube.ClusterInfo -} - - -type Generator interface { - Generate() (map[string][]byte,error) - GetFileNames() []constant.TemplateFile -} -// import cluster and self_build_cluster is different -func getGenerater(info *GeneratorInfo) (Generator,error){ - //import cluster - switch info.Type { - case constant.TYPE_IMPORT_CLUSTER: - return &ImportClusterGenerator{},nil - case constant.TYPE_SELF_BUILD: - return &SelfBuilClusterGenerator{ - ClusterId: strconv.Itoa(info.Id), - CallBackIp: info.HostIp, - Aid: -1, - },nil - default: - return nil ,fmt.Errorf("[generate]: unknown mode %d",info.Mode) - } -} - -func GenerateTemplate(info *GeneratorInfo) error{ - gen,err := getGenerater(info) - if err != nil{ - return err - } - yamls,err := gen.Generate() - if err != nil{ - return err - } - for filename ,yaml := range yamls{ - token := generateToken(strconv.Itoa(info.Id),filename) - f,err := util.NewFile(constant.CLUSTER_TEMPLATE_DIR,token+constant.TEMPLATE_SUFFIX) - if err != nil{ - return err - } - defer f.Close() - _,err = f.Write(yaml) - if err != nil{ - log.Errorf("write yaml to file %s fail,error : %v",constant.CLUSTER_TEMPLATE_DIR+token+constant.TEMPLATE_SUFFIX,err) - return err - } - } - return nil -} - -func GetTemplateUrl(info *GeneratorInfo, old bool) ([]byte,error){ - gen,err := getGenerater(info) - if err != nil{ - return nil,err - } - files := gen.GetFileNames() - for _, file := range files{ - if file.Old == old{ - token := generateToken(strconv.Itoa(info.Id),file.FileName) - return []byte(host.AgentInstall.StaticHost + constant.TEMPLATES_FILE_SERVER_PREFIX + token + constant.TEMPLATE_SUFFIX), nil - } - } - return nil,fmt.Errorf("the template url of old %v is not found %+v %+v",old,*info,*info.ClusterInfo) -} - -func GetTemplateFile(info *GeneratorInfo, old bool) ([]byte, error){ - gen,err := getGenerater(info) - if err != nil{ - return nil, err - } - files := gen.GetFileNames() - for _, file := range files{ - if file.Old == old{ - token := generateToken(strconv.Itoa(info.Id),file.FileName) - return []byte(constant.CLUSTER_TEMPLATE_DIR+token+constant.TEMPLATE_SUFFIX),nil - } - } - return nil, fmt.Errorf("the template file for old %v is not found %+v %+v",old,*info,*info.ClusterInfo) -} - -func ReadAndParseTemplate(tplFile string) (*template.Template,error){ - bts,err := asset.Asset(tplFile) - if err != nil{ - log.Errorf("[generate]: read template %s error : %v",tplFile,err) - return nil,err - } - tpl,err := template.New(tplFile).Parse(string(bts)) - if err != nil{ - log.Errorf("[generate]: parse template %s error: %v",tplFile,err) - return nil,err - } - return tpl,nil -} - -func generateToken(clusterId,filename string) string { - return base64.StdEncoding.EncodeToString([]byte(clusterId + filename)) -} diff --git a/chengying-server/matrix/k8s/cluster/import_cluster.go b/chengying-server/matrix/k8s/cluster/import_cluster.go deleted file mode 100644 index dd1efb4..0000000 --- a/chengying-server/matrix/k8s/cluster/import_cluster.go +++ /dev/null @@ -1,51 +0,0 @@ -// Licensed to Apache Software Foundation(ASF) under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. Apache Software Foundation(ASF) licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -package cluster - -import ( - "dtstack.com/dtstack/easymatrix/matrix/asset" - "dtstack.com/dtstack/easymatrix/matrix/k8s/constant" - "dtstack.com/dtstack/easymatrix/matrix/log" -) - -var importClusterTemplateFiles = []constant.TemplateFile{ - constant.TPL_CLUSTER_RESOURCE, - constant.TPL_CLUSTER_RESOURCE_V1BETA1, -} - -type ImportClusterGenerator struct { - -} - -func (g *ImportClusterGenerator) Generate() (map[string][]byte,error){ - yamls := make(map[string][]byte,len(importClusterTemplateFiles)) - asset.ResetImportClusterTemplateWithLocalFile() - for _,tplName := range importClusterTemplateFiles{ - bts,err := asset.Asset(tplName.FileName) - if err != nil{ - log.Errorf("[import_cluster]: read cluster resource %s, error : %v",tplName.FileName,err) - return nil ,err - } - yamls[tplName.FileName] = bts - } - return yamls,nil -} - -func (g *ImportClusterGenerator) GetFileNames() []constant.TemplateFile{ - return importClusterTemplateFiles -} diff --git a/chengying-server/matrix/k8s/cluster/self_build_cluster.go b/chengying-server/matrix/k8s/cluster/self_build_cluster.go deleted file mode 100644 index dafcb40..0000000 --- a/chengying-server/matrix/k8s/cluster/self_build_cluster.go +++ /dev/null @@ -1,76 +0,0 @@ -// Licensed to Apache Software Foundation(ASF) under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. Apache Software Foundation(ASF) licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -package cluster - -import ( - "bytes" - "dtstack.com/dtstack/easymatrix/matrix/asset" - "dtstack.com/dtstack/easymatrix/matrix/host" - "dtstack.com/dtstack/easymatrix/matrix/k8s/constant" - "dtstack.com/dtstack/easymatrix/matrix/log" - "text/template" -) - -var selfBuildTemplateFiles = []constant.TemplateFile{ - constant.TPL_SELF_BUILD, -} -type SelfBuilClusterGenerator struct { - ClusterId string - CallBackIp string - Aid int -} - -func (g *SelfBuilClusterGenerator) GetFileNames() []constant.TemplateFile{ - return selfBuildTemplateFiles -} - -func (g *SelfBuilClusterGenerator) Generate() (map[string][]byte,error){ - yamls := make(map[string][]byte,len(selfBuildTemplateFiles)) - asset.ResetSelfBuildTemplateWithLocalFile() - for _, tplName := range selfBuildTemplateFiles{ - tpl,err := ReadAndParseTemplate(tplName.FileName) - if err != nil{ - return nil,err - } - bts,err := g.execute(tpl) - if err != nil{ - return nil, err - } - yamls[tplName.FileName] = bts - } - return yamls,nil -} - -func (g *SelfBuilClusterGenerator) execute(tpl *template.Template) ([]byte,error){ - callback, err := host.AgentInstall.GetAgentCallBack(g.Aid,g.CallBackIp) - if err != nil{ - return nil,err - } - callback = callback+"&Mode=0&Deploy=daemonset&ClusterId="+g.ClusterId - var buf bytes.Buffer - err = tpl.Execute(&buf,map[string]string{ - "SERVER": host.AgentInstall.AgentHost, - "CALLBACK": callback, - }) - if err != nil{ - log.Errorf("[self_build_cluster]: template execute error : %v",err) - return nil ,err - } - return buf.Bytes(),nil -} - diff --git a/chengying-server/matrix/k8s/deploy/configmap.go b/chengying-server/matrix/k8s/deploy/configmap.go deleted file mode 100644 index 1b6aadb..0000000 --- a/chengying-server/matrix/k8s/deploy/configmap.go +++ /dev/null @@ -1,133 +0,0 @@ -// Licensed to Apache Software Foundation(ASF) under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. Apache Software Foundation(ASF) licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -package deploy - -import ( - "context" - "dtstack.com/dtstack/easymatrix/addons/operator/pkg/controller/workload/support" - "dtstack.com/dtstack/easymatrix/addons/operator/pkg/util" - "dtstack.com/dtstack/easymatrix/matrix/base" - "dtstack.com/dtstack/easymatrix/matrix/k8s/kube" - "dtstack.com/dtstack/easymatrix/matrix/k8s/model" - "dtstack.com/dtstack/easymatrix/matrix/k8s/resource/configmap" - modelkube "dtstack.com/dtstack/easymatrix/matrix/model/kube" - "dtstack.com/dtstack/easymatrix/schema" - "encoding/json" - corev1 "k8s.io/api/core/v1" - kschema "k8s.io/apimachinery/pkg/runtime/schema" - "path/filepath" - "strings" -) - -func ApplyConfigMaps(cache kube.ClientCache,sc *schema.SchemaConfig, clusterId int, namespace string) error { - - baseDir := filepath.Join(base.WebRoot, sc.ProductName, sc.ProductVersion) - for svcName, svc := range sc.Service { - cfgFiles := map[string]string{} - if svc.Instance != nil && len(svc.Instance.ConfigPaths) > 0 { - err := sc.ParseServiceVariable(svcName) - if err != nil { - return err - } - contents, err := sc.ParseServiceConfigFiles(baseDir, svcName) - if err != nil { - return err - } - for index, content := range contents { - cfgFile := svc.Instance.ConfigPaths[index] - cfgFile = strings.Replace(cfgFile, "/", "_", -1) - cfgFiles[cfgFile] = string(content[:]) - } - configMap := model.MakeConfigMap(namespace, sc.ParentProductName, sc.ProductName, svcName, cfgFiles) - if cache != nil{ - err := cache.GetClient(namespace).Apply(context.Background(),configMap) - if err != nil{ - return err - } - }else{ - gvr := &kschema.GroupVersionResource{ - Group: model.CONFIGMAP_GROUP, - Version: model.CONFIGMAP_VERSION, - Resource: model.CONFIGMAP_RESOURCE, - } - configBytes, err := json.Marshal(configMap) - if err != nil { - return err - } - configDynamic := NewDynamic(configBytes, gvr, model.CONFIGMAP_KIND) - err = ApplyDynamicResource(configDynamic, clusterId) - if err != nil { - return err - } - } - - } - } - return nil -} - -func GetConfigMaps(cache kube.ClientCache,sc *schema.SchemaConfig, clusterId int, namespace, serviceName string) (interface{}, error) { - var conf *corev1.ConfigMap - if sc.DeployType == "workload"{ - svc := sc.Service[serviceName] - workloadVersion := strings.Split(svc.Workload,"@") - wlTyp := workloadVersion[0] - wlversion := "" - if len(workloadVersion) ==2 { - wlversion = workloadVersion[1] - } - def, err := modelkube.WorkloadDefinition.Get(wlTyp,wlversion) - if err != nil || def == nil{ - return nil, err - } - parts,err := modelkube.WorkloadPart.Select(def.Id) - if err != nil || parts == nil{ - return nil, err - } - steps, err := modelkube.WorkloadStep.SelectType(parts[0].Id,support.CreateTypeConfigmap) - if err != nil || steps == nil{ - return nil, err - } - conf = configmap.New() - conf.Name = util.BuildStepName(util.BuildBaseName(util.BuildWorkloadName(sc.ProductName,serviceName),parts[0].Name),steps[0].Name) - conf.Namespace = namespace - }else{ - conf = model.MakeConfigMap(namespace, sc.ParentProductName, sc.ProductName, serviceName, nil) - } - if cache != nil{ - exist,err := cache.GetClient(namespace).Get(context.Background(),conf) - if err != nil{ - return nil,err - } - if !exist{ - return nil,nil - } - return conf,nil - } - gvr := &kschema.GroupVersionResource{ - Group: model.CONFIGMAP_GROUP, - Version: model.CONFIGMAP_VERSION, - Resource: model.CONFIGMAP_RESOURCE, - } - configBytes, err := json.Marshal(conf) - if err != nil { - return nil, err - } - configDynamic := NewDynamic(configBytes, gvr, model.CONFIGMAP_KIND) - return GetDynamicResource(configDynamic, clusterId) -} diff --git a/chengying-server/matrix/k8s/deploy/dynamic.go b/chengying-server/matrix/k8s/deploy/dynamic.go deleted file mode 100644 index 96ef517..0000000 --- a/chengying-server/matrix/k8s/deploy/dynamic.go +++ /dev/null @@ -1,135 +0,0 @@ -// Licensed to Apache Software Foundation(ASF) under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. Apache Software Foundation(ASF) licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -package deploy - -import ( - oldclient "dtstack.com/dtstack/easymatrix/addons/oldkube/pkg/client-go" - "dtstack.com/dtstack/easymatrix/matrix/agent" - "dtstack.com/dtstack/easymatrix/matrix/log" - "dtstack.com/dtstack/easymatrix/matrix/model" - "encoding/base64" - "encoding/json" - "fmt" - "k8s.io/apimachinery/pkg/runtime/schema" -) - -func ApplyDynamicResource(d *oldclient.DynamicData, clusterId int) error { - log.Infof("k8s deploy apply dynamic resource ...") - body, err := json.Marshal(d) - if err != nil { - return fmt.Errorf("json marshal error:%v", err) - } - log.Infof("%v", string(body[:])) - - content := oldclient.ContentResponse{} - clientParam := agent.ExecRestParams{ - Method: "POST", - Path: "clientgo/dynamic/apply", - Body: body, - Timeout: "5s", - } - cluster, _ := model.DeployClusterList.GetClusterInfoById(clusterId) - sid, _ := model.DeployNodeList.GetDeployNodeSidByClusterIdAndMode(clusterId, cluster.Mode) - resp, err := agent.AgentClient.ToExecRest(sid, &clientParam, "") - if err != nil { - return fmt.Errorf("ToExecRest dynamic apply err:%v", err) - } - decodeResp, err := base64.URLEncoding.DecodeString(resp) - if err != nil { - log.Errorf("client-go response decode err:%v", err) - } - _ = json.Unmarshal(decodeResp, &content) - if content.Code != 0 { - return fmt.Errorf(content.Msg) - } - return nil -} - -func NewDynamic(data []byte, gvr *schema.GroupVersionResource, kind string) *oldclient.DynamicData { - d := &oldclient.DynamicData{ - Data: string(data), - Group: gvr.Group, - Resource: gvr.Resource, - Version: gvr.Version, - } - return d -} - -func DeleteDynamicResource(d *oldclient.DynamicData, clusterId int) error { - log.Infof("k8s delete dynamic resource ...") - body, err := json.Marshal(d) - if err != nil { - return fmt.Errorf("json marshal error:%v", err) - } - log.Infof("%v", string(body[:])) - - content := oldclient.ContentResponse{} - clientParam := agent.ExecRestParams{ - Method: "POST", - Path: "clientgo/dynamic/delete", - Body: body, - Timeout: "5s", - } - cluster, _ := model.DeployClusterList.GetClusterInfoById(clusterId) - sid, _ := model.DeployNodeList.GetDeployNodeSidByClusterIdAndMode(clusterId, cluster.Mode) - resp, err := agent.AgentClient.ToExecRest(sid, &clientParam, "") - if err != nil { - return fmt.Errorf("ToExecRest dynamic delete err:%v", err) - } - decodeResp, err := base64.URLEncoding.DecodeString(resp) - if err != nil { - log.Errorf("client-go response decode err:%v", err) - } - _ = json.Unmarshal(decodeResp, &content) - if content.Code != 0 { - return fmt.Errorf(content.Msg) - } - return nil -} - -func GetDynamicResource(d *oldclient.DynamicData, clusterId int) (interface{}, error) { - log.Infof("k8s get dynamic resource ...") - body, err := json.Marshal(d) - if err != nil { - return nil, fmt.Errorf("json marshal error:%v", err) - } - log.Infof("%v", string(body[:])) - - content := oldclient.ContentResponse{} - clientParam := agent.ExecRestParams{ - Method: "POST", - Path: "clientgo/dynamic/get", - Body: body, - Timeout: "5s", - } - cluster, _ := model.DeployClusterList.GetClusterInfoById(clusterId) - sid, _ := model.DeployNodeList.GetDeployNodeSidByClusterIdAndMode(clusterId, cluster.Mode) - resp, err := agent.AgentClient.ToExecRest(sid, &clientParam, "") - if err != nil { - return nil, fmt.Errorf("ToExecRest dynamic get err:%v", err) - } - decodeResp, err := base64.StdEncoding.DecodeString(resp) - if err != nil { - log.Errorf("client-go response decode err:%v", err) - } - _ = json.Unmarshal(decodeResp, &content) - if content.Code != 0 { - return nil, fmt.Errorf(content.Msg) - } - return content.Data, nil -} diff --git a/chengying-server/matrix/k8s/deploy/images.go b/chengying-server/matrix/k8s/deploy/images.go deleted file mode 100644 index 756f87f..0000000 --- a/chengying-server/matrix/k8s/deploy/images.go +++ /dev/null @@ -1,171 +0,0 @@ -// Licensed to Apache Software Foundation(ASF) under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. Apache Software Foundation(ASF) licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -package deploy - -import ( - "dtstack.com/dtstack/easymatrix/matrix/base" - "dtstack.com/dtstack/easymatrix/matrix/k8s/docker" - "dtstack.com/dtstack/easymatrix/matrix/log" - "dtstack.com/dtstack/easymatrix/matrix/model" - "dtstack.com/dtstack/easymatrix/schema" - "os" - "path/filepath" - "strings" -) - -const ( - IMAGE_DIR = "images" - IMAGE_SUFFIX = ".tar" -) - -func PushImages(store model.ImageStore, sc *schema.SchemaConfig, deployUUID string) error { - log.Infof("starting push images to registry %v", store.Address) - log.OutputInfof(deployUUID, "starting push images to registry %v", store.Address) - err := docker.Login(store.Username, store.Address, store.Password) - if err != nil { - log.Errorf("docker login err: %v", err.Error()) - log.OutputInfof(deployUUID, "docker login error: %v", err.Error()) - return err - } - log.Infof("docker login success: %v", store.Address) - log.OutputInfof(deployUUID, "docker login success: %v", store.Address) - //regURL := strings.Split(store.Address, "/")[0] - //hub, err := docker.NewRegClient(regURL, store.Username, store.Password) - //if err != nil { - // log.Errorf("creat registry client err: %v", err.Error()) - // log.OutputInfof(deployUUID, "creat registry client err: %v", err.Error()) - //} - for name := range sc.Service { - baseDir := filepath.Join(base.WebRoot, sc.ProductName, sc.ProductVersion, name, IMAGE_DIR) - if sc.Service[name].Instance == nil || sc.Service[name].Instance.Image == "" { - log.Infof("") - continue - } - if sc.Service[name].BaseProduct != "" || sc.Service[name].BaseService != "" { - continue - } - sourceImg := sc.Service[name].Instance.Image - var SourceTag string - var NewSchemaDefImg string - var AttachImg string - var newImgTag string - log.Infof("push images with images dir: %v", baseDir) - log.OutputInfof(deployUUID, "push images with images dir: %v", baseDir) - err = filepath.Walk(baseDir, func(path string, info os.FileInfo, err error) error { - log.Infof("find file: %v", path) - log.OutputInfof(deployUUID, "find file: %v", path) - if err != nil { - return err - } - if baseDir == path { - return nil - } - if info.IsDir() { - return nil - } - if !strings.HasSuffix(path, IMAGE_SUFFIX) { - log.Infof("not regular image file: %v", path) - log.OutputInfof(deployUUID, "not regular image file: %v", path) - return nil - } - //获取倒入镜像的名称,这里镜像分两种,一种是在schema中定义的镜像名称,另一种是产品包中附带的额外的镜像 - //schema中定义的镜像需要拼接上仓库地址重新赋值给schema文件,附带的镜像则不需要只需推送到仓库即可 - imageName, err := docker.Load(path, deployUUID) - if err != nil { - return err - } - if strings.ToLower(sourceImg) == strings.ToLower(imageName) { - log.OutputInfof(deployUUID, "========= schema defined image are the same as load image") - log.OutputInfof(deployUUID, "========= sourceImg is: %v", sourceImg) - log.OutputInfof(deployUUID, "========= load images is: %v", imageName) - SourceTag = sourceImg - log.OutputInfof(deployUUID, "========= SourceTag is: %v", SourceTag) - NewSchemaDefImg = store.Address + "/" + sourceImg - newImgTag = NewSchemaDefImg - } else { - log.OutputInfof(deployUUID, "========= schema defined image are different from load image") - log.OutputInfof(deployUUID, "========= sourceImg is: %v", sourceImg) - log.OutputInfof(deployUUID, "========= load images is: %v", imageName) - SourceTag = imageName - log.OutputInfof(deployUUID, "========= SourceTag is: %v", SourceTag) - AttachImg = store.Address + "/" + imageName - newImgTag = AttachImg - } - log.Infof("load image %v success", path) - log.OutputInfof(deployUUID, "load image %v success", path) - - log.OutputInfof(deployUUID, "tag %s to %s", SourceTag, newImgTag) - err = docker.Tag(newImgTag, SourceTag) - if err != nil { - //the image can be changed in the front, should not affect the other image's push - log.OutputInfof(deployUUID, "use the declare image %s in the front", sourceImg) - return nil - } - log.Infof("tag %s to %s success", SourceTag, newImgTag) - log.OutputInfof(deployUUID, "tag %s to %s success", SourceTag, newImgTag) - //var exists bool - //imgName := strings.SplitN(strings.Split(newImgTag, ":")[0], "/", 2)[1] - //imgTag := strings.Split(newImgTag, ":")[1] - //if hub != nil { - // tags, err := hub.Tags(imgName) - // if err != nil { - // log.Infof("search image tag err: %v", err) - // } - // for _, tag := range tags { - // if tag == imgTag { - // exists = true - // break - // } - // } - // if !exists { - // log.OutputInfof(deployUUID, "the image %v does not exist in the docker repository,start pushing the image ...", newImg) - // err = docker.Push(newImg, deployUUID) - // if err != nil { - // return err - // } - // log.Infof("push image %v success", path) - // log.OutputInfof(deployUUID, "push image %v success", path) - // } else { - // log.OutputInfof(deployUUID, "the image %v exists in the docker repository,skip pushing the image!", newImg) - // } - //} else { - // err = docker.Push(newImg, deployUUID) - // if err != nil { - // return err - // } - // log.Infof("push image %v success", path) - // log.OutputInfof(deployUUID, "push image %v success", path) - //} - err = docker.Push(newImgTag, deployUUID) - if err != nil { - return err - } - - log.Infof("push image %v success", newImgTag) - log.OutputInfof(deployUUID, "push image %v success", newImgTag) - sc.Service[name].Instance.Image = NewSchemaDefImg - return nil - }) - if err != nil { - log.Errorf("push images err: %v", err.Error()) - log.OutputInfof(deployUUID, "push images error: %v", err.Error()) - return err - } - } - return nil -} diff --git a/chengying-server/matrix/k8s/deploy/mole.go b/chengying-server/matrix/k8s/deploy/mole.go deleted file mode 100644 index b385448..0000000 --- a/chengying-server/matrix/k8s/deploy/mole.go +++ /dev/null @@ -1,103 +0,0 @@ -// Licensed to Apache Software Foundation(ASF) under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. Apache Software Foundation(ASF) licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -package deploy - -import ( - "context" - "dtstack.com/dtstack/easymatrix/matrix/k8s/kube" - k8sModel "dtstack.com/dtstack/easymatrix/matrix/k8s/model" - "dtstack.com/dtstack/easymatrix/schema" - "encoding/json" - kschema "k8s.io/apimachinery/pkg/runtime/schema" -) - -func ApplyMole(cache kube.ClientCache,sc *schema.SchemaConfig, uncheckedServices []string, clusterId, pid int, namespace, deployUUID, secret string) error { - moleCR := k8sModel.NewMole(sc.ProductName, namespace) - if err := k8sModel.FillSchema(moleCR,sc, uncheckedServices, clusterId, pid, deployUUID, secret);err != nil{ - return err - } - if cache != nil{ - // the mole'status can directly update, if not set, status will be set to "" when update - // it will occurs the product deploy success, but the instance's process almost %30 - existing := moleCR.DeepCopy() - exist,err := cache.GetClient(namespace).Get(context.TODO(),existing) - if err != nil{ - return err - } - if exist{ - moleCR.Status = existing.Status - } - return cache.GetClient(namespace).Apply(context.TODO(),moleCR) - } - gvr := &kschema.GroupVersionResource{ - Group: k8sModel.MOLE_GROUP, - Version: k8sModel.MOLE_VERSION, - Resource: k8sModel.MOLE_RESOURCE, - } - moleBytes, err := json.Marshal(moleCR) - if err != nil { - return err - } - moleDynamic := NewDynamic(moleBytes, gvr, k8sModel.MOLE_KIND) - err = ApplyDynamicResource(moleDynamic, clusterId) - return err -} - -func DeleteMole(cache kube.ClientCache, productName, namespace string, clusterId int) error { - moleCR := k8sModel.NewMole(productName, namespace) - if cache != nil{ - return cache.GetClient(namespace).Delete(context.Background(),moleCR) - } - gvr := &kschema.GroupVersionResource{ - Group: k8sModel.MOLE_GROUP, - Version: k8sModel.MOLE_VERSION, - Resource: k8sModel.MOLE_RESOURCE, - } - moleBytes, err := json.Marshal(moleCR) - if err != nil { - return err - } - moleDynamic := NewDynamic(moleBytes, gvr, k8sModel.MOLE_KIND) - err = DeleteDynamicResource(moleDynamic, clusterId) - return err -} - -func GetMole(cache kube.ClientCache,sc *schema.SchemaConfig, clusterId int, namespace string) (interface{}, error) { - moleCR := k8sModel.NewMole(sc.ProductName, namespace) - if cache != nil{ - exist,err := cache.GetClient(namespace).Get(context.Background(),moleCR) - if err != nil{ - return nil, err - } - if !exist{ - return nil,nil - } - return moleCR,nil - } - gvr := &kschema.GroupVersionResource{ - Group: k8sModel.MOLE_GROUP, - Version: k8sModel.MOLE_VERSION, - Resource: k8sModel.MOLE_RESOURCE, - } - moleBytes, err := json.Marshal(moleCR) - if err != nil { - return nil, err - } - moleDynamic := NewDynamic(moleBytes, gvr, k8sModel.MOLE_KIND) - return GetDynamicResource(moleDynamic, clusterId) -} diff --git a/chengying-server/matrix/k8s/deploy/progress.go b/chengying-server/matrix/k8s/deploy/progress.go deleted file mode 100644 index da94733..0000000 --- a/chengying-server/matrix/k8s/deploy/progress.go +++ /dev/null @@ -1,18 +0,0 @@ -// Licensed to Apache Software Foundation(ASF) under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. Apache Software Foundation(ASF) licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -package deploy diff --git a/chengying-server/matrix/k8s/deploy/secret.go b/chengying-server/matrix/k8s/deploy/secret.go deleted file mode 100644 index f485111..0000000 --- a/chengying-server/matrix/k8s/deploy/secret.go +++ /dev/null @@ -1,45 +0,0 @@ -// Licensed to Apache Software Foundation(ASF) under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. Apache Software Foundation(ASF) licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -package deploy - -import ( - "context" - "dtstack.com/dtstack/easymatrix/matrix/k8s/kube" - k8sModel "dtstack.com/dtstack/easymatrix/matrix/k8s/model" - sqlModel "dtstack.com/dtstack/easymatrix/matrix/model" - "encoding/json" - kschema "k8s.io/apimachinery/pkg/runtime/schema" -) - -func ApplyImageSecret(cache kube.ClientCache,clusterId int, namespace string, store sqlModel.ImageStore) error { - secret := k8sModel.NewDockerConfigSecret(namespace, store) - gvr := &kschema.GroupVersionResource{ - Group: k8sModel.SECRET_GROUP, - Version: k8sModel.SECRET_VERSION, - Resource: k8sModel.SECRET_RESOURCE, - } - secretBytes, err := json.Marshal(secret) - if err != nil { - return err - } - secretDynamic := NewDynamic(secretBytes, gvr, k8sModel.SECRET_KIND) - if cache == nil{ - return ApplyDynamicResource(secretDynamic, clusterId) - } - return cache.GetClient(namespace).Apply(context.Background(),secret) -} diff --git a/chengying-server/matrix/k8s/deploy/workloadprocess.go b/chengying-server/matrix/k8s/deploy/workloadprocess.go deleted file mode 100644 index df61d23..0000000 --- a/chengying-server/matrix/k8s/deploy/workloadprocess.go +++ /dev/null @@ -1,177 +0,0 @@ -// Licensed to Apache Software Foundation(ASF) under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. Apache Software Foundation(ASF) licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -package deploy - -import ( - "context" - workloadv1beta1 "dtstack.com/dtstack/easymatrix/addons/operator/pkg/apis/workload/v1beta1" - workloadprocessrc "dtstack.com/dtstack/easymatrix/addons/operator/pkg/controller/workloadprocess/reconciler" - "dtstack.com/dtstack/easymatrix/addons/operator/pkg/util" - "dtstack.com/dtstack/easymatrix/matrix/k8s/kube" - "dtstack.com/dtstack/easymatrix/matrix/k8s/resource/workload" - "dtstack.com/dtstack/easymatrix/matrix/k8s/resource/workloadprocess" - "dtstack.com/dtstack/easymatrix/matrix/log" - "dtstack.com/dtstack/easymatrix/matrix/model" - modelkube "dtstack.com/dtstack/easymatrix/matrix/model/kube" - "dtstack.com/dtstack/easymatrix/schema" - "encoding/json" - "fmt" - "strings" -) - -func ApplyWorkloadProcess(cache kube.ClientCache, sc *schema.SchemaConfig, uncheckedSvc []string, - namespace string, deployuuid string, pid int, clusterID int, store *model.ImageStore) (bool, error) { - - process := workloadprocess.New() - process.Name = strings.ToLower(sc.ProductName) - process.Namespace = namespace - process.Spec.ProductName = sc.ProductName - process.Spec.ProductId = pid - process.Spec.DeployUUId = deployuuid - process.Spec.ParentProductName = sc.ParentProductName - process.Spec.ProductVersion = sc.ProductVersion - process.Spec.ClusterId = clusterID - existing := process.DeepCopy() - exist, err := cache.GetClient(namespace).Get(context.TODO(), existing) - if err != nil { - return false, err - } - if exist { - process.Spec.LastDeployUUId = existing.Spec.DeployUUId - } - undeploy := make(map[string]bool, len(uncheckedSvc)) - for _, svcName := range uncheckedSvc { - undeploy[svcName] = true - } - ifChanged := false - - // 处理workload类型产品包中的依赖组件为非workload类型的服务组件 - workloadService := map[string]schema.ServiceConfig{} - for name, svc := range sc.Service { - if svc.Workload != "" { - workloadService[name] = svc - } - } - - for svcName, svc := range workloadService { - if undeploy[svcName] { - continue - } - //use the desired version, workload:version - workloadVersion := strings.Split(svc.Workload, "@") - wlTyp := workloadVersion[0] - wlversion := "" - if len(workloadVersion) == 2 { - wlversion = workloadVersion[1] - } - wl, err := modelkube.WorkloadDefinition.Get(wlTyp, wlversion) - if err != nil { - return false, err - } - if wl == nil { - return false, fmt.Errorf("the workload type %s is not support, please check the workload type", wlTyp) - } - parts, err := modelkube.WorkloadPart.Select(wl.Id) - if err != nil { - return false, err - } - if parts == nil { - return false, fmt.Errorf("the part of workload type %s is nil, please check the workload type", wlTyp) - } - steps := make(map[int][]modelkube.WorloadStepSchema, len(parts)) - for _, part := range parts { - stepTbsc, err := modelkube.WorkloadStep.Select(part.Id) - if err != nil { - return false, err - } - steps[part.Id] = stepTbsc - } - builder := &workload.Builder{ - Def: wl, - Parts: parts, - Steps: steps, - Schema: sc, - ProductName: sc.ProductName, - ServiceName: svcName, - Namespace: namespace, - Store: store, - } - workload, err := builder.Build() - if err != nil { - return false, err - } - if process.Spec.WorkLoads == nil { - process.Spec.WorkLoads = map[string]workloadv1beta1.ServiceWorkload{} - } - process.Spec.WorkLoads[svcName] = workloadv1beta1.ServiceWorkload{ - Version: svc.Version, - Group: svc.Group, - WorkLoad: *workload, - } - - existing := workload.DeepCopy() - existing.Namespace = namespace - existing.Name = util.BuildWorkloadName(sc.ProductName, svcName) - now, err := json.Marshal(existing) - if err != nil { - log.Errorf("[workloadprocess deploy]: marshal to json fail, err %v", err) - return false, err - } - exist, err = cache.GetClient(namespace).Get(context.TODO(), existing) - if err != nil { - return false, err - } - if !exist { - ifChanged = true - } - last := existing.Annotations[workloadprocessrc.LAST_WITHOUT_ANNOTATION] - - if string(now) != last { - ifChanged = true - } - } - if err = cache.GetClient(namespace).Apply(context.TODO(), process); err != nil { - return false, err - } - return ifChanged, nil -} - -func GetWorkloadProcess(cache kube.ClientCache, sc *schema.SchemaConfig, namespace string) (*workloadv1beta1.WorkloadProcess, error) { - process := workloadprocess.New() - process.Name = strings.ToLower(sc.ProductName) - process.Namespace = namespace - exist, err := cache.GetClient(namespace).Get(context.TODO(), process) - if err != nil { - return nil, err - } - if !exist { - return nil, nil - } - return process, nil -} - -func DeleteWorkloadProcess(cache kube.ClientCache, productname, namespace string) error { - process := workloadprocess.New() - process.Namespace = namespace - process.Name = strings.ToLower(productname) - err := cache.GetClient(namespace).Delete(context.TODO(), process) - if err != nil { - return err - } - return nil -} diff --git a/chengying-server/matrix/k8s/docker/command.go b/chengying-server/matrix/k8s/docker/command.go deleted file mode 100644 index 760bfbb..0000000 --- a/chengying-server/matrix/k8s/docker/command.go +++ /dev/null @@ -1,171 +0,0 @@ -// Licensed to Apache Software Foundation(ASF) under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. Apache Software Foundation(ASF) licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -package docker - -import ( - "bufio" - "dtstack.com/dtstack/easymatrix/matrix/log" - "fmt" - "github.com/heroku/docker-registry-client/registry" - "io" - "net/http" - "os" - "os/exec" - "strings" -) - -func Login(username, address, password string) error { - log.Debugf("docker login ...") - login := exec.Command("docker", "login", "-u", username, address, "-p", password) - login.Stdout = os.Stdout - login.Stderr = os.Stderr - if err := login.Run(); err != nil { - return err - } - return nil -} - -func OutputStdLog(std io.Reader, deployUUID string) { - //实时循环读取输出流中的一行内容 - reader := bufio.NewReader(std) - for { - line, err2 := reader.ReadString('\n') - if err2 != nil || io.EOF == err2 { - break - } - log.OutputInfof(deployUUID, "%v", line) - } -} - -func OutputStdLogWithRet(std io.Reader, deployUUID string, output *[]string) { - //实时循环读取输出流中的一行内容 - reader := bufio.NewReader(std) - for { - line, err2 := reader.ReadString('\n') - if err2 != nil || io.EOF == err2 { - break - } - *output = append(*output, line) - log.OutputInfof(deployUUID, "%v", line) - } -} - -/* -b2d5eeeaba3a: Loading layer [==================================================>] 5.88MB/5.88MB -b5d14f4aebad: Loading layer [==================================================>] 18.24MB/18.24MB -35e4637a9d6c: Loading layer [==================================================>] 3.072kB/3.072kB -7ff80c2c03d5: Loading layer [==================================================>] 4.096kB/4.096kB -6e8309ec6bfd: Loading layer [==================================================>] 3.584kB/3.584kB -a7c11ed26fd5: Loading layer [==================================================>] 7.168kB/7.168kB -7f598054d646: Loading layer [==================================================>] 2.048kB/2.048kB -53062ac1a12b: Loading layer [==================================================>] 3.072kB/3.072kB -92c327b8726e: Loading layer [==================================================>] 1.672MB/1.672MB -0a91289117b4: Loading layer [==================================================>] 3.072kB/3.072kB -20fa73f7ad0f: Loading layer [==================================================>] 5.489MB/5.489MB -464db9ec72d8: Loading layer [==================================================>] 3.433MB/3.433MB -3f666b083f1c: Loading layer [==================================================>] 130kB/130kB -5e7458eed436: Loading layer [==================================================>] 3.584kB/3.584kB -b860ae2f768f: Loading layer [==================================================>] 4.608kB/4.608kB -88e637af7547: Loading layer [==================================================>] 4.608kB/4.608kB -Loaded image: easymanager/manage-front:2.11.5-rel -*/ -func Load(file, deployUuid string) (string, error) { - log.Debugf("docker load ...") - load := exec.Command("docker", "load", "-i", file) - stdout, err := load.StdoutPipe() - output := []string{} - var image string - if err == nil { - go OutputStdLogWithRet(stdout, deployUuid, &output) - } - stderr, err := load.StderrPipe() - if err == nil { - go OutputStdLog(stderr, deployUuid) - } - if err := load.Run(); err != nil { - return "", err - } - - for _, line := range output { - if strings.Contains(line, "Loaded image:") { - images := strings.Split(line, ": ") - if len(images) == 2 { - image = images[1] - } - break - } - } - - if image != "" { - image = strings.Replace(image, "\n", "", -1) - } - - return image, nil -} - -func Tag(new, old string) error { - tag := exec.Command("docker", "tag", old, new) - tag.Stdout = os.Stdout - tag.Stderr = os.Stderr - if err := tag.Run(); err != nil { - return err - } - return nil -} - -func Push(image, deployUuid string) error { - push := exec.Command("docker", "push", image) - stdout, err := push.StdoutPipe() - if err == nil { - go OutputStdLog(stdout, deployUuid) - } - stderr, err := push.StderrPipe() - if err == nil { - go OutputStdLog(stderr, deployUuid) - } - if err := push.Run(); err != nil { - return err - } - return nil -} - -func newTransport(transport http.RoundTripper, registryURL, username, password string) *registry.Registry { - transport = registry.WrapTransport(transport, registryURL, username, password) - registry := ®istry.Registry{ - URL: registryURL, - Client: &http.Client{ - Transport: transport, - }, - Logf: registry.Log, - } - return registry -} - -func NewRegClient(registryURL, username, password string) (*registry.Registry, error) { - transport := http.DefaultTransport - url := fmt.Sprintf("http://%s", registryURL) - registry := newTransport(transport, url, username, password) - if err := registry.Ping(); err != nil { - url = fmt.Sprintf("https://%s", registryURL) - registry = newTransport(transport, url, username, password) - if err := registry.Ping(); err != nil { - return nil, err - } - } - return registry, nil -} diff --git a/chengying-server/matrix/k8s/kube/cluster_ns_client.go b/chengying-server/matrix/k8s/kube/cluster_ns_client.go deleted file mode 100644 index 16309c8..0000000 --- a/chengying-server/matrix/k8s/kube/cluster_ns_client.go +++ /dev/null @@ -1,82 +0,0 @@ -// Licensed to Apache Software Foundation(ASF) under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. Apache Software Foundation(ASF) licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -package kube - -import ( - "fmt" - "sync" -) - -var ClusterNsClientCache = &clusterNsClientCache{} - -type NsClientCacheEnhance struct { - kubeClient *KubeClientCache - restClient *RestClientCache -} - -func (c *NsClientCacheEnhance) GetClientCache(typ ImportType) (ClientCache,error){ - switch typ { - case IMPORT_KUBECONFIG: - return c.kubeClient,nil - case IMPORT_AGENT: - return c.restClient,nil - default: - return nil,fmt.Errorf("[cluster_ns_client]: unknow import type %v",typ) - } -} - -func (c *NsClientCacheEnhance) DeleteNsClient(namespace string){ - c.kubeClient.DeleteClient(namespace) - c.restClient.DeleteClient(namespace) -} - -func (c *NsClientCacheEnhance) PutNsClient(cache ClientCache){ - kubeC, ok := cache.(*KubeClientCache) - if ok{ - c.kubeClient = kubeC - }else { - restC := cache.(*RestClientCache) - c.restClient = restC - } -} - -type clusterNsClientCache struct { - clusterNsClient map[string]*NsClientCacheEnhance - mu sync.RWMutex -} - -func (c *clusterNsClientCache)GetClusterNsClient(clusterName string) *NsClientCacheEnhance{ - c.mu.RLock() - nsClientCache,konw := c.clusterNsClient[clusterName] - c.mu.RUnlock() - if konw{ - return nsClientCache - } - c.mu.Lock() - defer c.mu.Unlock() - if c.clusterNsClient == nil{ - c.clusterNsClient = make(map[string]*NsClientCacheEnhance) - } - c.clusterNsClient[clusterName] = &NsClientCacheEnhance{ - kubeClient: &KubeClientCache{}, - restClient: &RestClientCache{}, - } - return c.clusterNsClient[clusterName] -} - - diff --git a/chengying-server/matrix/k8s/kube/interface.go b/chengying-server/matrix/k8s/kube/interface.go deleted file mode 100644 index 1ea9726..0000000 --- a/chengying-server/matrix/k8s/kube/interface.go +++ /dev/null @@ -1,54 +0,0 @@ -// Licensed to Apache Software Foundation(ASF) under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. Apache Software Foundation(ASF) licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -package kube - -import ( - "context" - "dtstack.com/dtstack/easymatrix/addons/easykube/pkg/client/base" - "k8s.io/apimachinery/pkg/runtime" -) - -type Client interface { - Apply(ctx context.Context, object runtime.Object) error - Create(ctx context.Context, object runtime.Object) error - Update(ctx context.Context, object runtime.Object) error - Delete(ctx context.Context, object runtime.Object) error - Get(ctx context.Context, object runtime.Object) (bool,error) - List(ctx context.Context, object runtime.Object, namespace string) error - Status(ctx context.Context, object runtime.Object) error - DryRun(action base.DryRunAction,object runtime.Object) error -} - -type ClientCache interface { - Connect(connectStr,workspace string) error - GetClient(workspace string) Client - DeleteClient(workspace string) - Copy() ClientCache - //need to update? - //UpdateClient(connectStr,workspace string) error -} - -type ImportType string - -func (i ImportType) String() string{ - return string(i) -} -var ( - IMPORT_KUBECONFIG ImportType = "kubeconfig" - IMPORT_AGENT ImportType = "agent" -) diff --git a/chengying-server/matrix/k8s/kube/kube_client.go b/chengying-server/matrix/k8s/kube/kube_client.go deleted file mode 100644 index 3daf262..0000000 --- a/chengying-server/matrix/k8s/kube/kube_client.go +++ /dev/null @@ -1,49 +0,0 @@ -// Licensed to Apache Software Foundation(ASF) under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. Apache Software Foundation(ASF) licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -package kube - -import "dtstack.com/dtstack/easymatrix/addons/easykube/pkg/client/base" - -type KubeClientCache struct { - c *base.ClientCache -} - -func (c *KubeClientCache) GetClient(workspace string) Client{ - if c.c == nil{ - c.c = &base.ClientCache{} - } - return c.c.GetClient(workspace) -} - -func (c *KubeClientCache) Connect(kubeconfig,workspace string) error{ - if c.c == nil{ - c.c = &base.ClientCache{} - } - return c.c.Connect(kubeconfig,workspace) -} - -func (c *KubeClientCache) DeleteClient(workspace string){ - if c.c == nil{ - c.c = &base.ClientCache{} - } - c.c.DeleteClient(workspace) -} - -func (c KubeClientCache) Copy() ClientCache{ - return &c -} diff --git a/chengying-server/matrix/k8s/kube/rest_client.go b/chengying-server/matrix/k8s/kube/rest_client.go deleted file mode 100644 index 56f2b30..0000000 --- a/chengying-server/matrix/k8s/kube/rest_client.go +++ /dev/null @@ -1,269 +0,0 @@ -// Licensed to Apache Software Foundation(ASF) under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. Apache Software Foundation(ASF) licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -package kube - -import ( - "context" - "dtstack.com/dtstack/easymatrix/addons/easykube/pkg/client/base" - "dtstack.com/dtstack/easymatrix/addons/easykube/pkg/view/request" - monitorevents "dtstack.com/dtstack/easymatrix/addons/easymonitor/pkg/monitor/events" - apibase "dtstack.com/dtstack/easymatrix/go-common/api-base" - "dtstack.com/dtstack/easymatrix/matrix/log" - "dtstack.com/dtstack/easymatrix/matrix/util" - "encoding/json" - "fmt" - "k8s.io/apimachinery/pkg/runtime" - "net/http" - "net/url" - "sync" - "time" -) - -var ( - maxTryCount = 3 - baseurl = "/api/v1/kube/resource/" - Post = "POST" - Get = "GET" -) - -type RestClientCache struct { - workspaceClient map[string]*RestClient - mu sync.RWMutex -} - -type RestClient struct { - workspace string - c *util.Client -} - -func newClient(host, workspace string) (*RestClient, error) { - parsedUrl, err := url.Parse(host) - if err != nil { - log.Errorf("parse url error : %s", host) - return nil, err - } - client := util.NewClient(util.NewHTTPClient(util.GetTlsConfig())) - client.BaseURL = parsedUrl - - return &RestClient{ - workspace: workspace, - c: client, - }, nil -} - -func (c *RestClientCache) Connect(server, workspace string) error { - client, err := newClient(server, workspace) - if err != nil { - return err - } - c.mu.Lock() - defer c.mu.Unlock() - if c.workspaceClient == nil { - c.workspaceClient = make(map[string]*RestClient) - } - c.workspaceClient[workspace] = client - return nil -} - -func (c *RestClientCache) GetClient(workspace string) Client { - c.mu.RLock() - defer c.mu.RUnlock() - if c.workspaceClient == nil { - return nil - } - return c.workspaceClient[workspace] -} - -func (c *RestClientCache) DeleteClient(workspace string) { - c.mu.Lock() - defer c.mu.Unlock() - if c.workspaceClient == nil { - return - } - delete(c.workspaceClient, workspace) -} - -func (c RestClientCache) Copy() ClientCache { - return &c -} - -func (c *RestClient) Apply(ctx context.Context, object runtime.Object) error { - url := baseurl + "apply" - method := Post - body := toResouce(object) - _, err := c.rest(method, url, nil, body) - return err -} - -func (c *RestClient) Status(ctx context.Context, object runtime.Object) error { - url := baseurl + "status" - method := Post - body := toResouce(object) - _, err := c.rest(method, url, nil, body) - return err -} - -func (c *RestClient) Create(ctx context.Context, object runtime.Object) error { - url := baseurl + "create" - method := Post - body := toResouce(object) - _, err := c.rest(method, url, nil, body) - return err -} - -func (c *RestClient) Update(ctx context.Context, object runtime.Object) error { - url := baseurl + "update" - method := Post - body := toResouce(object) - _, err := c.rest(method, url, nil, body) - return err -} - -func (c *RestClient) Delete(ctx context.Context, object runtime.Object) error { - url := baseurl + "delete" - method := Post - body := toResouce(object) - _, err := c.rest(method, url, nil, body) - return err -} - -func (c *RestClient) Get(ctx context.Context, object runtime.Object) (bool, error) { - url := baseurl + "get" - method := Post - body := toResouce(object) - rspdata, err := c.rest(method, url, nil, body) - if err != nil { - return false, err - } - if rspdata == nil { - return false, nil - } - bts, err := json.Marshal(rspdata) - if err != nil { - log.Errorf("[rest_client]: mashal get rspdata %+v error %v", rspdata, err) - return false, err - } - err = json.Unmarshal(bts, object) - if err != nil { - log.Errorf("[rest_client]: unmashl %s to obj %T error %v", string(bts), object, err) - return false, err - } - return true, nil -} - -func (c *RestClient) List(ctx context.Context, object runtime.Object, namespace string) error { - url := baseurl + "list" - method := Post - gvks, _, _ := base.Schema.ObjectKinds(object) - gvk := gvks[0] - body := &request.ResourceList{ - Namespace: namespace, - Group: gvk.Group, - Kind: gvk.Kind, - Version: gvk.Version, - } - rspdata, err := c.rest(method, url, nil, body) - if err != nil { - return err - } - bts, err := json.Marshal(rspdata) - if err != nil { - log.Errorf("[rest_client]: mashal list rspdata %+v error %v", rspdata, err) - return err - } - err = json.Unmarshal(bts, object) - if err != nil { - log.Errorf("[rest_client]: unmashl %s to obj %T error %v", string(bts), object, err) - return err - } - return nil -} - -func (c *RestClient) DryRun(action base.DryRunAction, object runtime.Object) error { - url := baseurl + "dryrun" - method := Post - body := toResouce(object) - body.Action = action - _, err := c.rest(method, url, nil, body) - return err -} - -func (c *RestClient) Events(events *[]monitorevents.Event) error { - url := baseurl + "events" - method := Get - resp, err := c.rest(method, url, nil, nil) - if err != nil { - return err - } - bts, err := json.Marshal(resp) - if err != nil { - log.Errorf("[rest_client]: mashal array rspdata %+v error %v", resp, err) - return err - } - err = json.Unmarshal(bts, events) - if err != nil { - log.Errorf("[rest_client]: unmashl %s to monitorevents error %v", string(bts), err) - return err - } - return nil -} - -func (c *RestClient) rest(method, url string, params map[string]string, body interface{}) (interface{}, error) { - var err error - var req *http.Request - resp := &apibase.ApiResult{} - tryCount := 1 - for { - if tryCount >= maxTryCount { - break - } - req, err = c.c.NewRequest(method, url, params, body, "") - if err != nil { - log.Errorf("new request uri %s error: %v", url, err) - return nil, err - } - _, err = c.c.Do(req, resp) - if err != nil && tryCount < maxTryCount { - tryCount++ - time.Sleep(1 * time.Second) - continue - } - if err != nil { - log.Errorf("[rest client]: request to %s error :%v", url, err) - return nil, err - } - if resp.Code != 0 { - return nil, fmt.Errorf("error from agent :%v", resp.Data) - } - return resp.Data, nil - } - return nil, fmt.Errorf("try three times, last error : %v", err) -} - -func toResouce(object runtime.Object) *request.Resource { - data, _ := json.Marshal(object) - gvks, _, _ := base.Schema.ObjectKinds(object) - gvk := gvks[0] - return &request.Resource{ - Data: data, - Group: gvk.Group, - Kind: gvk.Kind, - Version: gvk.Version, - } - -} diff --git a/chengying-server/matrix/k8s/model/configmap.go b/chengying-server/matrix/k8s/model/configmap.go deleted file mode 100644 index e67ff9d..0000000 --- a/chengying-server/matrix/k8s/model/configmap.go +++ /dev/null @@ -1,57 +0,0 @@ -// Licensed to Apache Software Foundation(ASF) under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. Apache Software Foundation(ASF) licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -package model - -import ( - "encoding/json" - "k8s.io/api/core/v1" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" -) - -func MakeConfigMap(namespace, parentProductName, productName, serviceName string, configFiles map[string]string) *v1.ConfigMap { - //boolTrue := true - return &v1.ConfigMap{ - ObjectMeta: metav1.ObjectMeta{ - Name: BuildResourceName("configmap", parentProductName, productName, serviceName), - Namespace: namespace, - Labels: makeLabels(productName, serviceName), - }, - Data: configFiles, - } -} - -func ConvertConfigMap(data interface{}) (*v1.ConfigMap, error) { - configBytes, err := json.Marshal(data) - if err != nil { - return nil, err - } - conf := &v1.ConfigMap{} - err = json.Unmarshal(configBytes, conf) - if err != nil { - return nil, err - } - return conf, nil -} - -func makeLabels(productName, serviceName string) map[string]string { - labels := map[string]string{} - labels["product_name"] = productName - labels["service_name"] = productName - - return labels -} diff --git a/chengying-server/matrix/k8s/model/defines.go b/chengying-server/matrix/k8s/model/defines.go deleted file mode 100644 index 5a1cd5b..0000000 --- a/chengying-server/matrix/k8s/model/defines.go +++ /dev/null @@ -1,73 +0,0 @@ -// Licensed to Apache Software Foundation(ASF) under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. Apache Software Foundation(ASF) licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -package model - -import ( - "fmt" - "strings" -) - -var ( - SECRET_VERSION = "v1" - SECRET_KIND = "Secret" - SECRET_GROUP = "" - SECRET_RESOURCE = "secrets" - - CONFIGMAP_KIND = "ConfigMap" - CONFIGMAP_GROUP = "" - CONFIGMAP_VERSION = "v1" - CONFIGMAP_RESOURCE = "configmaps" - - MOLE_VERSION = "v1" - MOLE_KIND = "Mole" - MOLE_GROUP = "operator.dtstack.com" - MOLE_RESOURCE = "moles" - - NAMESPACE_VERSION = "v1" - NAMESPACE_GROUP = "" - NAMESPACE_KIND = "Namespace" - NAMESPACELIST_KIND = "NamespaceList" - - NAMESPACE_PREFIX = "dtstack-" - - SupportResources = map[string]struct{}{ - "cpu": {}, - "memory": {}, - } -) - -func BuildResourceName(resourceType, parentProductName, productName, serviceName string) string { - return fmt.Sprintf("%v-%v-%v-%v", resourceType, ConvertDNSRuleName(parentProductName), ConvertDNSRuleName(productName), ConvertDNSRuleName(serviceName)) -} -func ConvertDNSRuleName(s string) string { - s = strings.Replace(s, "_", "", -1) - s = strings.ToLower(s) - return s -} - -func BuildResourceNameWithNamespace(resourceType, parentProductName, productName, serviceName, namespace string) string { - return fmt.Sprintf("%v-%v-%v-%v.%v", resourceType, ConvertDNSRuleName(parentProductName), ConvertDNSRuleName(productName), ConvertDNSRuleName(serviceName), namespace) -} - -func BuildWorkloadServiceName(productName, serviceName, partName, stepName, namespace string) string { - return fmt.Sprintf("%v-%v-%v-%v.%v", ConvertDNSRuleName(productName), ConvertDNSRuleName(serviceName), ConvertDNSRuleName(partName), ConvertDNSRuleName(stepName), namespace) -} - -func BuildWorkloadPodName(productName, serviceName, partName, stsnumber string) string { - return fmt.Sprintf("%v-%v-%v-%v", ConvertDNSRuleName(productName), ConvertDNSRuleName(serviceName), ConvertDNSRuleName(partName), stsnumber) -} diff --git a/chengying-server/matrix/k8s/model/mole.go b/chengying-server/matrix/k8s/model/mole.go deleted file mode 100644 index ef0080b..0000000 --- a/chengying-server/matrix/k8s/model/mole.go +++ /dev/null @@ -1,256 +0,0 @@ -// Licensed to Apache Software Foundation(ASF) under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. Apache Software Foundation(ASF) licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -package model - -import ( - molev1 "dtstack.com/dtstack/easymatrix/addons/operator/pkg/apis/mole/v1" - "dtstack.com/dtstack/easymatrix/addons/operator/pkg/controller/model" - "dtstack.com/dtstack/easymatrix/matrix/log" - "dtstack.com/dtstack/easymatrix/matrix/workload" - "dtstack.com/dtstack/easymatrix/schema" - "encoding/json" - "fmt" - corev1 "k8s.io/api/core/v1" - apires "k8s.io/apimachinery/pkg/api/resource" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "strings" -) - -//type StatusPhase string -// -//type Instance struct { -// ConfigPaths []string `json:"config_path,omitempty"` -// Logs []string `json:"logs,omitempty"` -// DataDir []string `json:"data_dir,omitempty"` -// Environment map[string]string `json:"environment,omitempty"` -// Cmd string `json:"cmd,omitempty,omitempty"` -// PrometheusPort string `json:"prometheus_port,omitempty"` -// Ingress *MoleIngress `json:"ingress,omitempty"` -// Service *MoleService `json:"service,omitempty"` -// Deployment *MoleDeployment `json:"deployment,omitempty"` -// Resources corev1.ResourceRequirements `json:"resources,omitempty"` -// PostDeploy string `json:"post_deploy,omitempty"` -//} -// -//type ServiceConfig struct { -// ServiceDisplay string `json:"service_display,omitempty"` -// IsDeployIngress bool `json:"is_deploy_ingress,omitempty"` -// IsJob bool `json:"is_job,omitempty"` -// Version string `json:"version,omitempty"` -// Instance Instance `json:"instance,omitempty"` -// Group string `json:"group,omitempty"` -// DependsOn []string `json:"depends_on,omitempty"` -// BaseProduct string `json:"base_product"` -// BaseService string `json:"base_service,omitempty"` -// BaseParsed bool `json:"base_parsed,omitempty"` -// BaseAttribute string `json:"base_attribute,omitempty"` -//} -// -//type SchemaConfig struct { -// Pid int `json:"pid,omitempty"` -// ClusterId int `json:"cluster_id,omitempty"` -// DeployUUid string `json:"deploy_uuid,omitempty"` -// ParentProductName string `json:"parent_product_name,omitempty"` -// ProductName string `json:"product_name,omitempty"` -// ProductNameDisplay string `json:"product_name_display,omitempty"` -// ProductVersion string `json:"product_version,omitempty"` -// ImagePullSecret string `json:"imagePullSecret,omitempty"` -// Service map[string]ServiceConfig `json:"service"` -//} -// -//type MoleIngress struct { -// Annotations map[string]string `json:"annotations,omitempty"` -// Labels map[string]string `json:"labels,omitempty"` -// Hostname string `json:"hostname,omitempty"` -// Path string `json:"path,omitempty"` -// Enabled bool `json:"enabled,omitempty"` -// TLSEnabled bool `json:"tlsEnabled,omitempty"` -// TLSSecretName string `json:"tlsSecretName,omitempty"` -// TargetPort string `json:"targetPort,omitempty"` -//} -// -//type MoleService struct { -// Annotations map[string]string `json:"annotations,omitempty"` -// Labels map[string]string `json:"labels,omitempty"` -// Type corev1.ServiceType `json:"type,omitempty"` -// Ports []corev1.ServicePort `json:"ports,omitempty"` -//} -// -//type MoleDeployment struct { -// Annotations map[string]string `json:"annotations,omitempty"` -// Labels map[string]string `json:"labels,omitempty"` -// Replicas int32 `json:"replicas,omitempty"` -// Image string `json:"image,omitempty"` -// Ports []int `json:"ports,omitempty"` -// Containers []SideContainer `json:"containers,omitempty"` -// NodeSelector map[string]string `json:"nodeSelector,omitempty"` -// Tolerations []corev1.Toleration `json:"tolerations,omitempty"` -// Affinity *corev1.Affinity `json:"affinity,omitempty"` -// SecurityContext *corev1.PodSecurityContext `json:"securityContext,omitempty"` -// TerminationGracePeriodSeconds int64 `json:"terminationGracePeriodSeconds,omitempty"` -//} -// -//type SideContainer struct { -// Image string `json:"image,omitempty"` -// Name string `json:"name,omitempty"` -//} -// -//type MoleSpec struct { -// Product SchemaConfig `json:"product,omitempty"` -//} -// -//type MoleStatus struct { -// Phase StatusPhase `json:"phase"` -// Message string `json:"message"` -//} -// -//type Mole struct { -// metav1.TypeMeta `json:",inline"` -// metav1.ObjectMeta `json:"metadata,omitempty"` -// -// Spec MoleSpec `json:"spec,omitempty"` -// Status MoleStatus `json:"status,omitempty"` -//} - -func NewMole(productName, namespace string) *molev1.Mole { - return &molev1.Mole{ - TypeMeta: metav1.TypeMeta{ - Kind: MOLE_KIND, - APIVersion: MOLE_GROUP + "/" + MOLE_VERSION, - }, - ObjectMeta: metav1.ObjectMeta{ - Name: BuildMoleName(productName), - Namespace: namespace, - }, - } - -} - -func FillSchema(m *molev1.Mole, sc *schema.SchemaConfig, uncheckedServices []string, clusterId, pid int, deployUUID, secret string) error{ - m.Spec.Product.Pid = pid - m.Spec.Product.ClusterId = clusterId - m.Spec.Product.DeployUUid = deployUUID - m.Spec.Product.ProductName = sc.ProductName - m.Spec.Product.ProductVersion = sc.ProductVersion - m.Spec.Product.ParentProductName = sc.ParentProductName - m.Spec.Product.ProductNameDisplay = sc.ProductNameDisplay - m.Spec.Product.ImagePullSecret = secret - - uncheckedSet := make(map[string]bool) - for _, serviceName := range uncheckedServices { - uncheckedSet[serviceName] = true - } - a, _ := json.Marshal(sc.Service) - log.Debugf("%+v", string(a)) - m.Spec.Product.Service = make(map[string]molev1.ServiceConfig) - for name, config := range sc.Service { - - if uncheckedSet[name] || config.BaseProduct != "" { - continue - } - if config.Instance == nil { - continue - } - if config.Workload == workload.PLUGIN{ - continue - } - moleConfig := molev1.ServiceConfig{} - moleConfig.DependsOn = config.DependsOn - moleConfig.ServiceDisplay = config.ServiceDisplay - moleConfig.Group = config.Group - moleConfig.Version = config.Version - moleConfig.IsDeployIngress = config.IsDeployIngress - moleConfig.Instance.ConfigPaths = config.Instance.ConfigPaths - moleConfig.IsJob = config.IsJob - moleConfig.Instance.PostDeploy = config.Instance.PostDeploy - moleConfig.Instance.Deployment = new(molev1.MoleDeployment) - moleConfig.Instance.Deployment.Image = config.Instance.Image - moleConfig.Instance.Deployment.Replicas = int32(config.Instance.Replica) - moleConfig.Instance.Deployment.Ports = config.Instance.Ports - moleConfig.Instance.Logs = config.Instance.Logs - moleConfig.Instance.Logs = config.Instance.Logs - moleConfig.Instance.PrometheusPort = config.Instance.PrometheusPort - - containers := make([]molev1.MoleContainer,0,len(config.Instance.PluginInit )) - if config.Instance.PluginInit != nil{ - moleConfig.Instance.Environment = map[string]string{} - for _, init := range config.Instance.PluginInit{ - bindPath := strings.Split(init,":") - pluginName := bindPath[0] - pluginSvc := sc.Service[pluginName] - pluginPath := pluginSvc.Instance.PluginPath - if len(pluginPath) == 0{ - pluginPath = "/plugin" - } - containers = append(containers,molev1.MoleContainer{ - Image: pluginSvc.Instance.Image, - Name: pluginName, - }) - moleConfig.Instance.Environment[pluginName] = pluginPath + ":" + bindPath[1] - } - } - moleConfig.Instance.Deployment.Containers = containers - - if config.Instance.HostAlias != nil && len(*config.Instance.HostAlias) != 0{ - if moleConfig.Instance.Environment == nil{ - moleConfig.Instance.Environment = map[string]string{} - } - moleConfig.Instance.Environment[model.EnvHostAlias] = *config.Instance.HostAlias - } - - requests := corev1.ResourceList{} - for r, q := range config.Instance.ResourceRequest { - if _, support := SupportResources[r]; !support { - log.Infof("request %s is not supported resource,wo now support 'cpu' and 'memory',please check", r) - continue - } - quility,err := apires.ParseQuantity(*q) - if err != nil{ - log.Errorf("service %s request %s value %s can not parse, err: %v",name,r,*q,err) - return fmt.Errorf("service %s limit %s value %s can not parse, err: %v",name,r,*q,err) - } - requests[corev1.ResourceName(r)] = quility - } - limits := corev1.ResourceList{} - for r, l := range config.Instance.ResourceLimit { - if _, support := SupportResources[r]; !support { - log.Infof("limit %s is not supported resource,wo now support 'cpu' and 'memory',please check", r) - continue - } - quility,err := apires.ParseQuantity(*l) - if err != nil{ - log.Errorf("service %s limit %s value %s can not parse, err: %v",name,r,*l,err) - return fmt.Errorf("service %s limit %s value %s can not parse, err: %v",name,r,*l,err) - } - limits[corev1.ResourceName(r)] = quility - } - moleConfig.Instance.Resources.Limits = limits - moleConfig.Instance.Resources.Requests = requests - - if config.Instance.Hostname != "" { - moleConfig.Instance.Ingress.Hostname = config.Instance.Hostname - } - - m.Spec.Product.Service[name] = moleConfig - } - return nil -} - -func BuildMoleName(productName string) string { - return ConvertDNSRuleName(productName) -} diff --git a/chengying-server/matrix/k8s/model/namespace.go b/chengying-server/matrix/k8s/model/namespace.go deleted file mode 100644 index 89eb2dc..0000000 --- a/chengying-server/matrix/k8s/model/namespace.go +++ /dev/null @@ -1,18 +0,0 @@ -// Licensed to Apache Software Foundation(ASF) under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. Apache Software Foundation(ASF) licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -package model diff --git a/chengying-server/matrix/k8s/model/sa.go b/chengying-server/matrix/k8s/model/sa.go deleted file mode 100644 index 89eb2dc..0000000 --- a/chengying-server/matrix/k8s/model/sa.go +++ /dev/null @@ -1,18 +0,0 @@ -// Licensed to Apache Software Foundation(ASF) under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. Apache Software Foundation(ASF) licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -package model diff --git a/chengying-server/matrix/k8s/model/secret.go b/chengying-server/matrix/k8s/model/secret.go deleted file mode 100644 index 3d3ad5d..0000000 --- a/chengying-server/matrix/k8s/model/secret.go +++ /dev/null @@ -1,62 +0,0 @@ -// Licensed to Apache Software Foundation(ASF) under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. Apache Software Foundation(ASF) licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -package model - -import ( - sqlModel "dtstack.com/dtstack/easymatrix/matrix/model" - "encoding/base64" - "encoding/json" - v1 "k8s.io/api/core/v1" - v2 "k8s.io/apimachinery/pkg/apis/meta/v1" -) - -func getDockerConfigAuth(store sqlModel.ImageStore) map[string]interface{} { - src := []byte(store.Username + ":" + store.Password) - maxLen := base64.StdEncoding.EncodedLen(len(src)) - dst := make([]byte, maxLen) - base64.StdEncoding.Encode(dst, src) - - return map[string]interface{}{ - "auths": map[string]interface{}{ - store.Address: map[string]interface{}{ - "username": store.Username, - "password": store.Password, - "auth": string(dst), - }, - }, - } -} - -func getDockerConfigData(store sqlModel.ImageStore) map[string][]byte { - src, _ := json.Marshal(getDockerConfigAuth(store)) - - return map[string][]byte{ - v1.DockerConfigJsonKey: src, - } -} - -func NewDockerConfigSecret(namespace string, store sqlModel.ImageStore) *v1.Secret { - return &v1.Secret{ - ObjectMeta: v2.ObjectMeta{ - Name: store.Alias, //pull image secret name - Namespace: namespace, - }, - Data: getDockerConfigData(store), - Type: v1.SecretTypeDockerConfigJson, - } -} diff --git a/chengying-server/matrix/k8s/monitor/monitor.go b/chengying-server/matrix/k8s/monitor/monitor.go deleted file mode 100644 index 0f7a67a..0000000 --- a/chengying-server/matrix/k8s/monitor/monitor.go +++ /dev/null @@ -1,22 +0,0 @@ -// Licensed to Apache Software Foundation(ASF) under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. Apache Software Foundation(ASF) licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -package monitor - -func StartMonitot() { - go StartClusterStatusM() -} diff --git a/chengying-server/matrix/k8s/node/define.go b/chengying-server/matrix/k8s/node/define.go deleted file mode 100644 index 8d69883..0000000 --- a/chengying-server/matrix/k8s/node/define.go +++ /dev/null @@ -1,35 +0,0 @@ -// Licensed to Apache Software Foundation(ASF) under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. Apache Software Foundation(ASF) licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -package node - -type Node struct { - Aid int `json:"aid"` - ClusterId int `json:"clusterId"` - Sid string `json:"sid"` - Roles string `json:"roles"` - Name string `json:"name"` -} - -type HostNode struct { - Status int `db:"status" json:"status"` - Steps int `db:"steps" json:"steps"` - Ip string `db:"ip" json:"ip"` - Roles string `db:"roles" json:"roles"` - Yaml string `db:"yaml" json:"yaml"` - Version string `db:"version" json:"version"` -} diff --git a/chengying-server/matrix/k8s/node/node_manager.go b/chengying-server/matrix/k8s/node/node_manager.go deleted file mode 100644 index 409ff7d..0000000 --- a/chengying-server/matrix/k8s/node/node_manager.go +++ /dev/null @@ -1,211 +0,0 @@ -// Licensed to Apache Software Foundation(ASF) under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. Apache Software Foundation(ASF) licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -package node - -import ( - "dtstack.com/dtstack/easymatrix/matrix/host" - "dtstack.com/dtstack/easymatrix/matrix/k8s/constant" - "dtstack.com/dtstack/easymatrix/matrix/k8s/xke-service" - "dtstack.com/dtstack/easymatrix/matrix/log" - "dtstack.com/dtstack/easymatrix/matrix/model" - "dtstack.com/dtstack/easymatrix/matrix/model/kube" - "fmt" - "gopkg.in/yaml.v2" - "strings" - clustergenerator "dtstack.com/dtstack/easymatrix/matrix/k8s/cluster" - modelkube "dtstack.com/dtstack/easymatrix/matrix/model/kube" -) - -const ( - NODE_ROLE_CONTROL = "controlplane" - NODE_ROLE_ETCD = "etcd" - NODE_ROLE_WORKER = "worker" -) - -var ( - AllNodeRoles = []string{NODE_ROLE_CONTROL, NODE_ROLE_ETCD, NODE_ROLE_WORKER} - RoleToRkeRole = map[string]string{ - "Etcd": NODE_ROLE_ETCD, - "Worker": NODE_ROLE_WORKER, - "Control": NODE_ROLE_CONTROL, - } -) - -const ( - MaxNodeCache = 64 -) - -var NodeManager *nodeManager - -func init() { - NodeManager = &nodeManager{nodeQ: make(chan Node, MaxNodeCache)} - go NodeManager.nodeHandler() -} - -type nodeManager struct { - nodeQ chan Node -} - -func (this *nodeManager) AddNode(clusterId, aid int, sid, name, roles string) { - this.nodeQ <- Node{ - ClusterId: clusterId, Sid: sid, Roles: roles, Aid: aid, Name: name, - } -} - -func (this *nodeManager) nodeHandler() { - for { - node, ok := <-this.nodeQ - - if !ok { - return - } - //if !this.IsClusterReady(node) { - // model.DeployHostList.UpdateStatus(node.Aid, host.K8SNodeInitializeFail, host.K8S_SUCCESS_DOCKCER_INIT) - // model.DeployHostList.UpdateSteps(node.Aid, host.K8SNodeInitializeFail) - // continue - //} - err := this.freshCluster(node) - if err != nil { - log.Errorf("freshCluster err: %v", err.Error()) - } - } -} - -func (this *nodeManager) IsClusterReady(node Node) bool { - list, err := model.DeployClusterHostRel.GetClusterHostRelList(node.ClusterId) - - if err != nil { - log.Errorf("%v", err.Error()) - return false - } - rolesMap := make(map[string]int) - - for _, rel := range list { - roles := strings.Split(rel.Roles, ",") - for _, role := range roles { - if _, ok := RoleToRkeRole[role]; !ok { - log.Errorf("role is not legal: %v", role) - continue - } - rkeRole := RoleToRkeRole[role] - if _, ok := rolesMap[rkeRole]; ok { - rolesMap[rkeRole] = rolesMap[rkeRole] + 1 - } else { - rolesMap[rkeRole] = 1 - } - } - } - count := 0 - log.Infof("cluster roles: %v", rolesMap) - for _, role := range AllNodeRoles { - if _, ok := rolesMap[role]; ok { - count += 1 - } - } - if count == len(AllNodeRoles) { - log.Infof("\t\tcluster is ready to install, clusterId: %v", node.ClusterId) - return true - } - log.Infof("\t\tcluster is not ready to install, clusterId: %v", node.ClusterId) - return false -} - -func (this *nodeManager) freshCluster(node Node) error { - log.Infof("-->Step freshCluster, cluser: %v", node) - log.OutputInfof(node.Sid, "-->Step freshCluster, cluser: %v", node) - query := "SELECT h.status, h.steps, h.ip, roles, yaml, deploy_cluster_list.version " + - "FROM deploy_cluster_list " + - "LEFT JOIN deploy_cluster_host_rel ON deploy_cluster_list.id = deploy_cluster_host_rel.clusterId " + - "LEFT JOIN deploy_host as h ON deploy_cluster_host_rel.sid = h.sid " + - "WHERE deploy_cluster_list.id = ? and deploy_cluster_list.is_deleted = 0 and h.status >= ? and h.isDeleted = 0" - hostList := make([]HostNode, 0) - if err := model.USE_MYSQL_DB().Select(&hostList, query, node.ClusterId, host.K8SDockerInitializeOk); err != nil { - return err - } - rkeConfig, err := xke_service.BuildRKEConfigFromRaw(hostList[0].Yaml) - if err != nil { - return err - } - - sshKeyPath := xke_service.DEFALT_CONFIG_RKE_SSH_KEY_PATH - sshPort := xke_service.DEFALT_CONFIG_RKE_SSH_PORT - sshUser := xke_service.DEFALT_CONFIG_RKE_SSH_USER - for _, hn := range hostList { - //remove later - var rkeRoles []string - for _, r := range strings.Split(hn.Roles, ",") { - if _, ok := RoleToRkeRole[r]; ok { - rkeRoles = append(rkeRoles, RoleToRkeRole[r]) - } - } - xke_service.AddNodeToConfig(rkeConfig, hn.Ip, sshPort, strings.Join(rkeRoles, ","), sshKeyPath, sshUser) - } - - // 保留不带 rancher 后缀的 version 保存到数据库 - tmpConfig := rkeConfig - tmpConfigYaml, err := yaml.Marshal(tmpConfig) - if err != nil { - return err - } - - // example: v1.16.3 转为 v1.16.3-rancher1-1 - rkeConfig.Version, err = kube.DeployClusterK8sAvailable.GetRealVersion(hostList[0].Version) - if err != nil { - return fmt.Errorf("database err: %v", err) - } - - xke, err := xke_service.NewXkeService() - if err != nil { - return err - } - log.Infof("create k8s with rke config: %v", rkeConfig) - - rkeConfigYaml, err := yaml.Marshal(rkeConfig) - if err != nil { - return err - } - - err = xke.Create(rkeConfig.ClusterName, string(rkeConfigYaml), node.ClusterId) - if err != nil { - model.DeployHostList.UpdateStatus(node.Aid, host.K8SNodeInitializeFail, err.Error()) - return err - } - model.DeployHostList.UpdateStatus(node.Aid, host.K8SNodeInitializeOk, host.K8S_SUCCESS_NODE_INIT) - model.DeployHostList.UpdateSteps(node.Aid, host.K8SNodeInitializeOk) - - model.DeployClusterList.UpdateYamlById(node.ClusterId, string(tmpConfigYaml)) - info := &clustergenerator.GeneratorInfo{ - Type: constant.TYPE_SELF_BUILD, - ClusterInfo: &modelkube.ClusterInfo{ - Id: node.ClusterId, - Name: node.Name, - }, - } - selfBuild, err := clustergenerator.GetTemplateFile(info,false) - if err != nil { - return err - } - err = xke.DeployWithF(rkeConfig.ClusterName, string(selfBuild)) - if err != nil { - model.DeployHostList.UpdateStatus(node.Aid, host.K8SNodeDeploymentFailed, err.Error()) - return err - } - log.Infof("<--Step freshCluster success, cluser: %v", node.ClusterId) - log.OutputInfof(node.Sid, "<--Step freshCluster success, cluser: %v", node.ClusterId) - return nil -} diff --git a/chengying-server/matrix/k8s/resource/agent_generate.go b/chengying-server/matrix/k8s/resource/agent_generate.go deleted file mode 100644 index 4f73b7b..0000000 --- a/chengying-server/matrix/k8s/resource/agent_generate.go +++ /dev/null @@ -1,74 +0,0 @@ -// Licensed to Apache Software Foundation(ASF) under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. Apache Software Foundation(ASF) licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -package resource - -import ( - "bytes" - "dtstack.com/dtstack/easymatrix/matrix/api/k8s/view" - "dtstack.com/dtstack/easymatrix/matrix/k8s/cluster" - "dtstack.com/dtstack/easymatrix/matrix/k8s/constant" - "dtstack.com/dtstack/easymatrix/matrix/k8s/resource/secret" - "dtstack.com/dtstack/easymatrix/matrix/log" - modelkube "dtstack.com/dtstack/easymatrix/matrix/model/kube" - "encoding/base64" - "text/template" -) -var importClusterNsTemplateFiles = constant.TPL_NS_RESOURCE - -func AgentGenerate(req *view.AgentGenerateReq, clusterId int) (*view.AgentGenerateRsp,error){ - tpl, err := cluster.ReadAndParseTemplate(importClusterNsTemplateFiles.FileName) - if err != nil{ - return nil,err - } - registry := "" - dockerConfigJson := "" - tbsc,err := modelkube.DeployClusterImageStore.GetById(req.RegistryId) - clusterImageStore, err := modelkube.DeployClusterImageStore.GetByClusterId(clusterId) - if err != nil{ - return nil,err - } - if tbsc != nil{ - registry = tbsc.Address+"/" - se,err := secret.GetDockerConfigJson(clusterImageStore,req.Namespace,tbsc.Alias) - if err != nil{ - return nil,err - } - dockerConfigJson = base64.StdEncoding.EncodeToString(se.Data[".dockerconfigjson"]) - } - bts,err := generateTplFile(tpl,dockerConfigJson,req.Namespace,registry) - if err != nil{ - return nil,err - } - return &view.AgentGenerateRsp{ - Yaml: string(bts), - },nil -} - -func generateTplFile(tpl *template.Template, secret,namespace,registry string) ([]byte,error){ - var buf bytes.Buffer - err := tpl.Execute(&buf,map[string]string{ - "NAME_SPACE": namespace, - "REGISTRY": registry, - "IMAGE_SECRET":secret, - }) - if err != nil{ - log.Errorf("[import_cluster_ns]: template execute error : %v",err) - return nil,err - } - return buf.Bytes(),nil -} diff --git a/chengying-server/matrix/k8s/resource/configmap/configmap.go b/chengying-server/matrix/k8s/resource/configmap/configmap.go deleted file mode 100644 index bb7fe0a..0000000 --- a/chengying-server/matrix/k8s/resource/configmap/configmap.go +++ /dev/null @@ -1,71 +0,0 @@ -// Licensed to Apache Software Foundation(ASF) under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. Apache Software Foundation(ASF) licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -package configmap - -import ( - "context" - "dtstack.com/dtstack/easymatrix/addons/easykube/pkg/client/base" - "dtstack.com/dtstack/easymatrix/matrix/k8s/kube" - "dtstack.com/dtstack/easymatrix/matrix/log" - "encoding/json" - corev1 "k8s.io/api/core/v1" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/runtime/schema" -) - -var GVK = schema.GroupVersionKind{ - Group: "", - Version: "v1", - Kind: "ConfigMap", -} - -func New() *corev1.ConfigMap{ - return &corev1.ConfigMap{} -} - -func Ping(client kube.Client, namespace string) error{ - ping := &corev1.ConfigMap{ - ObjectMeta: metav1.ObjectMeta{ - Namespace: namespace, - Name: "dtstack-dryru", - }, - } - if _,err := client.Get(context.Background(),ping);err != nil{ - return err - } - - if err := client.DryRun(base.Create,ping);err != nil{ - return err - } - return nil -} - -func ToObject(bts []byte) (*corev1.ConfigMap,error){ - r,err := base.Schema.New(GVK) - if err != nil{ - log.Errorf("[configmap]: new object error: %v",err) - return nil,err - } - err = json.Unmarshal(bts,r) - if err!= nil{ - log.Errorf("[configmap]: json %s unmarshal error: %v",string(bts),err) - return nil,err - } - configmap := r.(*corev1.ConfigMap) - return configmap,nil -} diff --git a/chengying-server/matrix/k8s/resource/deployment/deployment.go b/chengying-server/matrix/k8s/resource/deployment/deployment.go deleted file mode 100644 index cbe4245..0000000 --- a/chengying-server/matrix/k8s/resource/deployment/deployment.go +++ /dev/null @@ -1,118 +0,0 @@ -// Licensed to Apache Software Foundation(ASF) under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. Apache Software Foundation(ASF) licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -package deployment - -import ( - "context" - "dtstack.com/dtstack/easymatrix/addons/easykube/pkg/client/base" - "dtstack.com/dtstack/easymatrix/matrix/k8s/kube" - "dtstack.com/dtstack/easymatrix/matrix/log" - "encoding/json" - appsv1 "k8s.io/api/apps/v1" - corev1 "k8s.io/api/core/v1" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/runtime" - "k8s.io/apimachinery/pkg/runtime/schema" -) - -var GVK = schema.GroupVersionKind{ - Group: "apps", - Version: "v1", - Kind: "Deployment", -} - -func New() *appsv1.Deployment{ - return &appsv1.Deployment{} -} - -func Convert(obj runtime.Object) *appsv1.Deployment{ - return obj.(*appsv1.Deployment) -} - -func Get(ctx context.Context,client kube.Client,namespace,name string) (*appsv1.Deployment,error){ - deploy := &appsv1.Deployment{ - ObjectMeta: metav1.ObjectMeta{ - Name: name, - Namespace: namespace, - }, - } - exist,err := client.Get(ctx,deploy) - if err != nil{ - return nil,err - } - if !exist{ - return nil,nil - } - return deploy,nil -} - - -func ToObject(bts []byte)(*appsv1.Deployment,error){ - r,err := base.Schema.New(GVK) - if err != nil{ - log.Errorf("[deployment]: new object error: %v",err) - return nil,err - } - err = json.Unmarshal(bts,r) - if err!= nil{ - log.Errorf("[deployment]: json %s unmarshal error: %v",string(bts),err) - return nil,err - } - deploy := r.(*appsv1.Deployment) - return deploy,nil -} - -func Ping(client kube.Client, namespace string) error{ - ping := &appsv1.Deployment{ - ObjectMeta: metav1.ObjectMeta{ - Namespace: namespace, - Name: "dtstack-dryru", - }, - Spec: appsv1.DeploymentSpec{ - Selector: &metav1.LabelSelector{ - MatchLabels: map[string]string{ - "app": "dtstack-dryru", - }, - }, - Template: corev1.PodTemplateSpec{ - ObjectMeta: metav1.ObjectMeta{ - Name: "dtstack-dryru", - Labels: map[string]string{ - "app": "dtstack-dryru", - }, - }, - Spec: corev1.PodSpec{ - Containers: []corev1.Container{ - { - Name: "dtstack-dryru", - Image: "dtstack-dryru", - }, - }, - }, - }, - }, - } - if _,err := client.Get(context.Background(),ping);err != nil{ - return err - } - - if err := client.DryRun(base.Create,ping);err != nil{ - return err - } - return nil -} diff --git a/chengying-server/matrix/k8s/resource/dryrun_test.go b/chengying-server/matrix/k8s/resource/dryrun_test.go deleted file mode 100644 index 12d79e3..0000000 --- a/chengying-server/matrix/k8s/resource/dryrun_test.go +++ /dev/null @@ -1,437 +0,0 @@ -// Licensed to Apache Software Foundation(ASF) under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. Apache Software Foundation(ASF) licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -package resource - -import ( - "context" - "encoding/json" - "fmt" - "testing" - - "dtstack.com/dtstack/easymatrix/addons/easykube/pkg/client/base" - commonlog "dtstack.com/dtstack/easymatrix/go-common/log" - "dtstack.com/dtstack/easymatrix/matrix/api/k8s/view" - clustergenerator "dtstack.com/dtstack/easymatrix/matrix/k8s/cluster" - "dtstack.com/dtstack/easymatrix/matrix/k8s/constant" - "dtstack.com/dtstack/easymatrix/matrix/k8s/kube" - "dtstack.com/dtstack/easymatrix/matrix/k8s/resource/deployment" - "dtstack.com/dtstack/easymatrix/matrix/log" - "dtstack.com/dtstack/easymatrix/matrix/model" - modelkube "dtstack.com/dtstack/easymatrix/matrix/model/kube" - "dtstack.com/dtstack/easymatrix/matrix/model/kube/union" - "github.com/jmoiron/sqlx" - corev1 "k8s.io/api/core/v1" - "k8s.io/apimachinery/pkg/runtime" -) - -var kubeconfig = `apiVersion: v1 -clusters: -- cluster: - certificate-authority-data: LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSUZWRENDQXp3Q0NRQ3ZTQlZyUVQ1ZGpEQU5CZ2txaGtpRzl3MEJBUXNGQURCc01Rc3dDUVlEVlFRR0V3SkQKVGpFUk1BOEdBMVVFQ0F3SVdtaGxhbWxoYm1jeEVUQVBCZ05WQkFjTUNFaGhibWQ2YUc5MU1SQXdEZ1lEVlFRSwpEQWQ0WkdWMmIzQnpNUkF3RGdZRFZRUUxEQWQ0WkdWMmIzQnpNUk13RVFZRFZRUUREQXBrZEhOMFlXTnJMbU51Ck1CNFhEVEl3TVRFd01USXhNVGd5TmxvWERUTXdNVEF6TURJeE1UZ3lObG93YkRFTE1Ba0dBMVVFQmhNQ1EwNHgKRVRBUEJnTlZCQWdNQ0Zwb1pXcHBZVzVuTVJFd0R3WURWUVFIREFoSVlXNW5lbWh2ZFRFUU1BNEdBMVVFQ2d3SAplR1JsZG05d2N6RVFNQTRHQTFVRUN3d0hlR1JsZG05d2N6RVRNQkVHQTFVRUF3d0taSFJ6ZEdGamF5NWpiakNDCkFpSXdEUVlKS29aSWh2Y05BUUVCQlFBRGdnSVBBRENDQWdvQ2dnSUJBTHh3MWgzcXptTXE4YUErY01vWFQvM0UKRVVBdzRQNUhCZGZYa2VVa1J1ZjV3VHUvdTBvRHFyUnVRNlcwMFJWS09BUFFQVDZpRVhCQkdyKzdTRGhISi8yTAo4VzBnNDRnaDB5N2lWREE1UmErV2dFS2Y4YmRvT3grUkMzME4wb3JyRmtZbDRCR3p2UWtDQXlOV1lZU1lheGxDCkFEeDdoQldhMzFQb0FaT3MxN0pBM3Y0a1lUVzhzTVBHQzFtdnhCSHJ4cGswK3NxeFFLQjl2TzlaZ05zbXpQcXAKdUNsT0xQbkxjdkFrSjFMSXNIS3c4bXo3TlFnVnpVV3hzWEFTMVFnaTdXWlNwRUVINGsySmtQRTRLNU5Mc2g2Mgo0d3hPS0lRRS83TFFsaVlCRlpIZnFYTHZpU0F5MW94SklTbnp4UmdmOFZVSmUrMUxKbGE0UHp6UDZuVUI2cGxUCnlKODQ2Z0QxQStxTmM1endlN2RtMytHSFVJNVVRNXhZejNZRDdQclRIWlJJd3p3SzVzeXNTM28rTEFOL1duYjgKSnlVK2haNG5hcEZUUzh0SVlLWGQ5V0pWUldYNWNzdkd2MXZSY1daK0tySGRtVi9Mc1oxbG04RFd1ODFLV0EyZQpKSmdvMlMrZ3R0RFBEenZqMHVnbUNEVFVRZGpsYjVQWnhFdWI4cVYvUXViMTBCQ3JJSkNZenJHMm91dld6TVJLCmJIUEE0OWtIVVYrR3BSdW8vNDZZYUw2T3haVjRQcnJjWFU1MVlQTVNZRnJiWU1iT2g1b1NxTnkyY1lrdjRhTkUKMDNzQUllclJHMzYvaktnelYzNFFkZGJvTEI5Yk1sZThEaGJQZ3JEV2VGcTdJRlpBVlYwOUcwdGx6R1hNaDE5YQpLZm8yVnNMRDZMT1dLTGwvOUNVRkFnTUJBQUV3RFFZSktvWklodmNOQVFFTEJRQURnZ0lCQUNvM3ZYcHBJTk9TCkxkSEpTRXRYT3haSi9kMEw4aXZQaEUwZzlRb0h0NUNNUUZWMGlKcVpzZzVLQURDckJSUG42ZnBVZDFhaDROZWoKWW5lUWxzbEpUOFFJN1RIQ1ZiTzBuOUtsbEVxWEJ5c2gxeDdkTGVXdFVaczRxLzB2QVlxbTc3aWYyaVpWTEFzNgprMk81NmhpelNwN2svZC90SXd3a1k3dTN4UkF2b2RWWEM3cnA1ZmViSTRWcDZLUFMwbjF4Yk8wSXBqUzd3KzhPClkxMjFXdmtxUUQyckhCMkUySFJSSWdGTEF2eVFqY01hak9KMzRSUnh4VDljUzFIWEUzVUdDVVl2bHc1NnMySmMKMWYvMXNXYTJNaHFiUUdzVDZJS3dVOXZ2SlArQktoWnBsWnpicUlnZHZyZHVHNWFCbEpnNlNCQTZsUThSTDhnNQp6MmpscGFaTE5jUmYySkdTUm5TTzlDZzJTcU5va2wwaDRRZVRCZEFNeGhPVnk0MmxOc1grLzVOWVhuM0RXRWo1CmoybTV0SFpRU3ptY3BZZmNlY0ZpRXdud3BwOVdMbWlsb0N3SHVON2FNYU9ZakpSVnVPcWJoTXZMUjFLTnpWVm0KUFdVblZJa3FBY2p0TXVKVFh6clZGV081VXEvazF0WkIzdGhNNEd4c1JZcElDbEJmS3c3emFIaGxsZmNvNE53eQprbWVDeENWMnVLZ3AxYkJlZ0hReTVEc3E4OFI5Qkh1b0g0aWpEbzlUTGRpU2NXT0o1TkFEOUJ5K2F3VGpsUk1qCmtrVHgyMFRZdm1VdEF6T2N5R0xCOENEWERwS1B4b1ZBdVREMGFKMy9na3p0aHZQQ1dDamxINGI2cXVMS3lwVHgKOU85OVRZWGw3Y2VNSXZIc2I3L3l4L01KUG9RbUZjcUgKLS0tLS1FTkQgQ0VSVElGSUNBVEUtLS0tLQ== - server: https://172.16.8.88/k8s/clusters/c-vckqj - name: dtstack -- cluster: - certificate-authority-data: LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSUN3akNDQWFxZ0F3SUJBZ0lCQURBTkJna3Foa2lHOXcwQkFRc0ZBREFTTVJBd0RnWURWUVFERXdkcmRXSmwKTFdOaE1CNFhEVEl3TVRFd05UQXlNekF3T0ZvWERUTXdNVEV3TXpBeU16QXdPRm93RWpFUU1BNEdBMVVFQXhNSAphM1ZpWlMxallUQ0NBU0l3RFFZSktvWklodmNOQVFFQkJRQURnZ0VQQURDQ0FRb0NnZ0VCQUsyQmpTMEdYVmo5ClNZQWpjTFhYWUR2bXo2OStHdWkvbHQ4WHp0aC9ZdG4rU1NxR2NXSms4NzhLaHI5RGdRQ1hNR3VtZXZtbUhFemIKYVVsY29oQXU0Q0NaS0VmYmxncFY2ZzFqNGtreVFxS2hTSG84VDBhU2VLOW53dDZZMzQ4MXVxTG9UWHhubFhPKwpZblJOWjVsQnlVTWRXb2JmSGhzRGJQM2lLcXdkU3NYckhxYWJlNmFDdk5tMlpIelNJbnc1eG0wakZHWXJvS0M5Cll3a3FVYmpWMDEzRXV1bzV1dzdKZ2l1eFdFcDhoSjJ1WEFKNkp3OGZEeml5aUxIay9qTGVyTFM2UnN5dWNtYXEKWUJPclIvS2pmTllGV1hlTWlqNzF3NXZqRTJFcG1DUnRLMFdtRjFpU3gyUFo2ZlBtYmVSd2lpRUVScXFFZGhYbQpqeGZNRnRWSzUzY0NBd0VBQWFNak1DRXdEZ1lEVlIwUEFRSC9CQVFEQWdLa01BOEdBMVVkRXdFQi93UUZNQU1CCkFmOHdEUVlKS29aSWh2Y05BUUVMQlFBRGdnRUJBSTRxcUxnVFRJa1VQbGtJUWRGdjlNNmRseHpJTlZmU0xXU2QKdEJuZGV6NUVmelBRaVBOdHQzbDlHNklrZmpYSGJUcU1rN0NsTWkvUnZtVDlDcjMwc093NHY4WVNOQTFyYjBHYwp2VURJdEl0ZGoyVW8wSUtzQ2dsN0psalhMcVNvd01jczMwQy9IQXJGdU9pSTlsS2VBdlVIeFhFTG5ST1hxaGozCjhoTG5kS0dTak8rYXRFVSs1b0ZFa0pydS9hcDdjTGxWSWVQVmh3eHpuM2pSS2dmRDVXTmI4aHRpRzg1YjMrNVIKMGt4eGFjNlRyaDBKQkh5cVpRSlVWMUg2djk3NXdqNnZJNU5NcDNvbnlVZjJxaGJzSjVIWEJJRDh2NEtUQms3MQoxVnliMzFwY3NjZEVibGNPTFlveTFyR1VDT1QxMzNmbFlyTldwc2VXcFJ6Y2NPUE1WYVE9Ci0tLS0tRU5EIENFUlRJRklDQVRFLS0tLS0K - server: https://172.16.8.160:6443 - name: dtstack-172-16-8-160 -- cluster: - certificate-authority-data: LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSUN3akNDQWFxZ0F3SUJBZ0lCQURBTkJna3Foa2lHOXcwQkFRc0ZBREFTTVJBd0RnWURWUVFERXdkcmRXSmwKTFdOaE1CNFhEVEl3TVRFd05UQXlNekF3T0ZvWERUTXdNVEV3TXpBeU16QXdPRm93RWpFUU1BNEdBMVVFQXhNSAphM1ZpWlMxallUQ0NBU0l3RFFZSktvWklodmNOQVFFQkJRQURnZ0VQQURDQ0FRb0NnZ0VCQUsyQmpTMEdYVmo5ClNZQWpjTFhYWUR2bXo2OStHdWkvbHQ4WHp0aC9ZdG4rU1NxR2NXSms4NzhLaHI5RGdRQ1hNR3VtZXZtbUhFemIKYVVsY29oQXU0Q0NaS0VmYmxncFY2ZzFqNGtreVFxS2hTSG84VDBhU2VLOW53dDZZMzQ4MXVxTG9UWHhubFhPKwpZblJOWjVsQnlVTWRXb2JmSGhzRGJQM2lLcXdkU3NYckhxYWJlNmFDdk5tMlpIelNJbnc1eG0wakZHWXJvS0M5Cll3a3FVYmpWMDEzRXV1bzV1dzdKZ2l1eFdFcDhoSjJ1WEFKNkp3OGZEeml5aUxIay9qTGVyTFM2UnN5dWNtYXEKWUJPclIvS2pmTllGV1hlTWlqNzF3NXZqRTJFcG1DUnRLMFdtRjFpU3gyUFo2ZlBtYmVSd2lpRUVScXFFZGhYbQpqeGZNRnRWSzUzY0NBd0VBQWFNak1DRXdEZ1lEVlIwUEFRSC9CQVFEQWdLa01BOEdBMVVkRXdFQi93UUZNQU1CCkFmOHdEUVlKS29aSWh2Y05BUUVMQlFBRGdnRUJBSTRxcUxnVFRJa1VQbGtJUWRGdjlNNmRseHpJTlZmU0xXU2QKdEJuZGV6NUVmelBRaVBOdHQzbDlHNklrZmpYSGJUcU1rN0NsTWkvUnZtVDlDcjMwc093NHY4WVNOQTFyYjBHYwp2VURJdEl0ZGoyVW8wSUtzQ2dsN0psalhMcVNvd01jczMwQy9IQXJGdU9pSTlsS2VBdlVIeFhFTG5ST1hxaGozCjhoTG5kS0dTak8rYXRFVSs1b0ZFa0pydS9hcDdjTGxWSWVQVmh3eHpuM2pSS2dmRDVXTmI4aHRpRzg1YjMrNVIKMGt4eGFjNlRyaDBKQkh5cVpRSlVWMUg2djk3NXdqNnZJNU5NcDNvbnlVZjJxaGJzSjVIWEJJRDh2NEtUQms3MQoxVnliMzFwY3NjZEVibGNPTFlveTFyR1VDT1QxMzNmbFlyTldwc2VXcFJ6Y2NPUE1WYVE9Ci0tLS0tRU5EIENFUlRJRklDQVRFLS0tLS0K - server: https://172.16.8.166:6443 - name: dtstack-172-16-8-166 -- cluster: - certificate-authority-data: LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSUN3akNDQWFxZ0F3SUJBZ0lCQURBTkJna3Foa2lHOXcwQkFRc0ZBREFTTVJBd0RnWURWUVFERXdkcmRXSmwKTFdOaE1CNFhEVEl3TVRFd05UQXlNekF3T0ZvWERUTXdNVEV3TXpBeU16QXdPRm93RWpFUU1BNEdBMVVFQXhNSAphM1ZpWlMxallUQ0NBU0l3RFFZSktvWklodmNOQVFFQkJRQURnZ0VQQURDQ0FRb0NnZ0VCQUsyQmpTMEdYVmo5ClNZQWpjTFhYWUR2bXo2OStHdWkvbHQ4WHp0aC9ZdG4rU1NxR2NXSms4NzhLaHI5RGdRQ1hNR3VtZXZtbUhFemIKYVVsY29oQXU0Q0NaS0VmYmxncFY2ZzFqNGtreVFxS2hTSG84VDBhU2VLOW53dDZZMzQ4MXVxTG9UWHhubFhPKwpZblJOWjVsQnlVTWRXb2JmSGhzRGJQM2lLcXdkU3NYckhxYWJlNmFDdk5tMlpIelNJbnc1eG0wakZHWXJvS0M5Cll3a3FVYmpWMDEzRXV1bzV1dzdKZ2l1eFdFcDhoSjJ1WEFKNkp3OGZEeml5aUxIay9qTGVyTFM2UnN5dWNtYXEKWUJPclIvS2pmTllGV1hlTWlqNzF3NXZqRTJFcG1DUnRLMFdtRjFpU3gyUFo2ZlBtYmVSd2lpRUVScXFFZGhYbQpqeGZNRnRWSzUzY0NBd0VBQWFNak1DRXdEZ1lEVlIwUEFRSC9CQVFEQWdLa01BOEdBMVVkRXdFQi93UUZNQU1CCkFmOHdEUVlKS29aSWh2Y05BUUVMQlFBRGdnRUJBSTRxcUxnVFRJa1VQbGtJUWRGdjlNNmRseHpJTlZmU0xXU2QKdEJuZGV6NUVmelBRaVBOdHQzbDlHNklrZmpYSGJUcU1rN0NsTWkvUnZtVDlDcjMwc093NHY4WVNOQTFyYjBHYwp2VURJdEl0ZGoyVW8wSUtzQ2dsN0psalhMcVNvd01jczMwQy9IQXJGdU9pSTlsS2VBdlVIeFhFTG5ST1hxaGozCjhoTG5kS0dTak8rYXRFVSs1b0ZFa0pydS9hcDdjTGxWSWVQVmh3eHpuM2pSS2dmRDVXTmI4aHRpRzg1YjMrNVIKMGt4eGFjNlRyaDBKQkh5cVpRSlVWMUg2djk3NXdqNnZJNU5NcDNvbnlVZjJxaGJzSjVIWEJJRDh2NEtUQms3MQoxVnliMzFwY3NjZEVibGNPTFlveTFyR1VDT1QxMzNmbFlyTldwc2VXcFJ6Y2NPUE1WYVE9Ci0tLS0tRU5EIENFUlRJRklDQVRFLS0tLS0K - server: https://172.16.8.169:6443 - name: dtstack-172-16-8-169 -contexts: -- context: - cluster: dtstack - user: dtstack - name: dtstack -- context: - cluster: dtstack-172-16-8-160 - user: dtstack - name: dtstack-172-16-8-160 -- context: - cluster: dtstack-172-16-8-166 - user: dtstack - name: dtstack-172-16-8-166 -- context: - cluster: dtstack-172-16-8-169 - user: dtstack - name: dtstack-172-16-8-169 -- context: - cluster: dtstack-172-16-8-160 - user: test - name: test -current-context: dtstack -kind: Config -preferences: {} -users: -- name: dtstack - user: - token: kubeconfig-user-mtrk8.c-vckqj:jk8k6n72dpxtllmtd4p99kwkkxthxsqg6562b9r2t2v7bdkf2jft9n -- name: test - user: - token: eyJhbGciOiJSUzI1NiIsImtpZCI6IjNhTjhlRFZNQl9ld2xGRDhpQ1F3czJDamtHUGNMTVlua2JBVW0yYUhDT1EifQ.eyJpc3MiOiJrdWJlcm5ldGVzL3NlcnZpY2VhY2NvdW50Iiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9uYW1lc3BhY2UiOiJkZXYiLCJrdWJlcm5ldGVzLmlvL3NlcnZpY2VhY2NvdW50L3NlY3JldC5uYW1lIjoiZGVmYXVsdC10b2tlbi1kajl0NiIsImt1YmVybmV0ZXMuaW8vc2VydmljZWFjY291bnQvc2VydmljZS1hY2NvdW50Lm5hbWUiOiJkZWZhdWx0Iiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9zZXJ2aWNlLWFjY291bnQudWlkIjoiOGM4ZTVhZGQtOGYwZi00NDdkLTg3YjAtMTc1ZmQxYTJmYWQ1Iiwic3ViIjoic3lzdGVtOnNlcnZpY2VhY2NvdW50OmRldjpkZWZhdWx0In0.bxqYVW0HOklhEZxNXECMQy1MqmdGzW4D2MLJ6fnXeAAXolkYPVIgf69eOO0P9JDxtX0HALQz9P982CqnuP0U7M3_OkJUptr55ixQXnkYbPn8L18ZxGdQ0R8tqymoqdfZAmUzzNf1lk9BIRaX_DAJwJmwKWUdrSGdJaS2lPcsXILP0GcC0tbwK6PP3GL2ZKKKlQsDy8Hbw2DdgXkMnx6NyU2BlsW2CWfEDc0__XUfY-0TSA4Evy7DnrD-US06992BF63zirhp8Y_kNd-8VQY83oNCo9vrKwOJYU0s0UP_3BgZpaKUSyrn4alKoj69hz4sXnnARwhbgJxKF_qBYqy47Q` -var testkube = ` -apiVersion: v1 -clusters: -- cluster: - certificate-authority-data: LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSUN3akNDQWFxZ0F3SUJBZ0lCQURBTkJna3Foa2lHOXcwQkFRc0ZBREFTTVJBd0RnWURWUVFERXdkcmRXSmwKTFdOaE1CNFhEVEl3TVRFd05UQXlNekF3T0ZvWERUTXdNVEV3TXpBeU16QXdPRm93RWpFUU1BNEdBMVVFQXhNSAphM1ZpWlMxallUQ0NBU0l3RFFZSktvWklodmNOQVFFQkJRQURnZ0VQQURDQ0FRb0NnZ0VCQUsyQmpTMEdYVmo5ClNZQWpjTFhYWUR2bXo2OStHdWkvbHQ4WHp0aC9ZdG4rU1NxR2NXSms4NzhLaHI5RGdRQ1hNR3VtZXZtbUhFemIKYVVsY29oQXU0Q0NaS0VmYmxncFY2ZzFqNGtreVFxS2hTSG84VDBhU2VLOW53dDZZMzQ4MXVxTG9UWHhubFhPKwpZblJOWjVsQnlVTWRXb2JmSGhzRGJQM2lLcXdkU3NYckhxYWJlNmFDdk5tMlpIelNJbnc1eG0wakZHWXJvS0M5Cll3a3FVYmpWMDEzRXV1bzV1dzdKZ2l1eFdFcDhoSjJ1WEFKNkp3OGZEeml5aUxIay9qTGVyTFM2UnN5dWNtYXEKWUJPclIvS2pmTllGV1hlTWlqNzF3NXZqRTJFcG1DUnRLMFdtRjFpU3gyUFo2ZlBtYmVSd2lpRUVScXFFZGhYbQpqeGZNRnRWSzUzY0NBd0VBQWFNak1DRXdEZ1lEVlIwUEFRSC9CQVFEQWdLa01BOEdBMVVkRXdFQi93UUZNQU1CCkFmOHdEUVlKS29aSWh2Y05BUUVMQlFBRGdnRUJBSTRxcUxnVFRJa1VQbGtJUWRGdjlNNmRseHpJTlZmU0xXU2QKdEJuZGV6NUVmelBRaVBOdHQzbDlHNklrZmpYSGJUcU1rN0NsTWkvUnZtVDlDcjMwc093NHY4WVNOQTFyYjBHYwp2VURJdEl0ZGoyVW8wSUtzQ2dsN0psalhMcVNvd01jczMwQy9IQXJGdU9pSTlsS2VBdlVIeFhFTG5ST1hxaGozCjhoTG5kS0dTak8rYXRFVSs1b0ZFa0pydS9hcDdjTGxWSWVQVmh3eHpuM2pSS2dmRDVXTmI4aHRpRzg1YjMrNVIKMGt4eGFjNlRyaDBKQkh5cVpRSlVWMUg2djk3NXdqNnZJNU5NcDNvbnlVZjJxaGJzSjVIWEJJRDh2NEtUQms3MQoxVnliMzFwY3NjZEVibGNPTFlveTFyR1VDT1QxMzNmbFlyTldwc2VXcFJ6Y2NPUE1WYVE9Ci0tLS0tRU5EIENFUlRJRklDQVRFLS0tLS0K - server: https://172.16.8.160:6443 - name: dtstack-172-16-8-160 -contexts: -- context: - cluster: dtstack-172-16-8-160 - user: test - name: test -current-context: test -kind: Config -preferences: {} -users: -- name: test - user: - token: eyJhbGciOiJSUzI1NiIsImtpZCI6IjNhTjhlRFZNQl9ld2xGRDhpQ1F3czJDamtHUGNMTVlua2JBVW0yYUhDT1EifQ.eyJpc3MiOiJrdWJlcm5ldGVzL3NlcnZpY2VhY2NvdW50Iiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9uYW1lc3BhY2UiOiJ0ZXN0Iiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9zZWNyZXQubmFtZSI6ImRlZmF1bHQtdG9rZW4tajhxczIiLCJrdWJlcm5ldGVzLmlvL3NlcnZpY2VhY2NvdW50L3NlcnZpY2UtYWNjb3VudC5uYW1lIjoiZGVmYXVsdCIsImt1YmVybmV0ZXMuaW8vc2VydmljZWFjY291bnQvc2VydmljZS1hY2NvdW50LnVpZCI6IjYzYjBiMmY4LTZiNzYtNGVjZi05NjZlLTY2Y2NiMjQwZTFhYyIsInN1YiI6InN5c3RlbTpzZXJ2aWNlYWNjb3VudDp0ZXN0OmRlZmF1bHQifQ.FE6HdoTYuCGzwyVJUKLBZXxAubQ88srgmk5gDwe4EUMxT_bzb9QSP7BQFK1sPpNhDXQSRFJd_ACVWKmhssycnFnbkWj7VmaicqrjJfh8-tcyX1MvykMbVGSFY3Czm-RoTFuB47ybbs7DHckwcLZDtlQYQjBORK1H91uWBSR_Knal4MulO7suDu4G_WgmT6OYgZjOmh_g81lxkV3GMNHElxSvDkLOq9bp4Ze949tKhC4uSTL7XR4o23mV8xXdAltOzKc9FPnE1wR5qXzGPhZezXzqhW-T38-hswWp1B3iweK1nFJnT__4jTZW40piLuv0jeIvZgSjsesQLSPKCAgOeA -` - -func Test1(t *testing.T) { - log.ConfigureLogger("/tmp/matrix", 100, 3, 1) - commonlog.Config("/tmp/easykube") - ns := "test" - cache, err := kube.ClusterNsClientCache.GetClusterNsClient("abc").GetClientCache(kube.IMPORT_KUBECONFIG) - if err != nil { - fmt.Println("err1", err.Error()) - return - } - err = cache.Connect(testkube, ns) - if err != nil { - fmt.Println("err2", err.Error()) - return - } - err = deployment.Ping(cache.GetClient(ns), ns) - if err != nil { - fmt.Println("err3", err.Error()) - } -} - -func Test2(t *testing.T) { - log.ConfigureLogger("/tmp/matrix", 100, 3, 1) - commonlog.Config("/tmp/easykube") - ctx := context.Background() - vo := &view.NamespaceSaveReq{ - Type: "kubeconfig", - Namespace: "em-dev", - RegistryId: 20, - Yaml: "apiVersion: v1\nclusters:\n- cluster:\n certificate-authority-data: LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSUZWRENDQXp3Q0NRQ3ZTQlZyUVQ1ZGpEQU5CZ2txaGtpRzl3MEJBUXNGQURCc01Rc3dDUVlEVlFRR0V3SkQKVGpFUk1BOEdBMVVFQ0F3SVdtaGxhbWxoYm1jeEVUQVBCZ05WQkFjTUNFaGhibWQ2YUc5MU1SQXdEZ1lEVlFRSwpEQWQ0WkdWMmIzQnpNUkF3RGdZRFZRUUxEQWQ0WkdWMmIzQnpNUk13RVFZRFZRUUREQXBrZEhOMFlXTnJMbU51Ck1CNFhEVEl3TVRFd01USXhNVGd5TmxvWERUTXdNVEF6TURJeE1UZ3lObG93YkRFTE1Ba0dBMVVFQmhNQ1EwNHgKRVRBUEJnTlZCQWdNQ0Zwb1pXcHBZVzVuTVJFd0R3WURWUVFIREFoSVlXNW5lbWh2ZFRFUU1BNEdBMVVFQ2d3SAplR1JsZG05d2N6RVFNQTRHQTFVRUN3d0hlR1JsZG05d2N6RVRNQkVHQTFVRUF3d0taSFJ6ZEdGamF5NWpiakNDCkFpSXdEUVlKS29aSWh2Y05BUUVCQlFBRGdnSVBBRENDQWdvQ2dnSUJBTHh3MWgzcXptTXE4YUErY01vWFQvM0UKRVVBdzRQNUhCZGZYa2VVa1J1ZjV3VHUvdTBvRHFyUnVRNlcwMFJWS09BUFFQVDZpRVhCQkdyKzdTRGhISi8yTAo4VzBnNDRnaDB5N2lWREE1UmErV2dFS2Y4YmRvT3grUkMzME4wb3JyRmtZbDRCR3p2UWtDQXlOV1lZU1lheGxDCkFEeDdoQldhMzFQb0FaT3MxN0pBM3Y0a1lUVzhzTVBHQzFtdnhCSHJ4cGswK3NxeFFLQjl2TzlaZ05zbXpQcXAKdUNsT0xQbkxjdkFrSjFMSXNIS3c4bXo3TlFnVnpVV3hzWEFTMVFnaTdXWlNwRUVINGsySmtQRTRLNU5Mc2g2Mgo0d3hPS0lRRS83TFFsaVlCRlpIZnFYTHZpU0F5MW94SklTbnp4UmdmOFZVSmUrMUxKbGE0UHp6UDZuVUI2cGxUCnlKODQ2Z0QxQStxTmM1endlN2RtMytHSFVJNVVRNXhZejNZRDdQclRIWlJJd3p3SzVzeXNTM28rTEFOL1duYjgKSnlVK2haNG5hcEZUUzh0SVlLWGQ5V0pWUldYNWNzdkd2MXZSY1daK0tySGRtVi9Mc1oxbG04RFd1ODFLV0EyZQpKSmdvMlMrZ3R0RFBEenZqMHVnbUNEVFVRZGpsYjVQWnhFdWI4cVYvUXViMTBCQ3JJSkNZenJHMm91dld6TVJLCmJIUEE0OWtIVVYrR3BSdW8vNDZZYUw2T3haVjRQcnJjWFU1MVlQTVNZRnJiWU1iT2g1b1NxTnkyY1lrdjRhTkUKMDNzQUllclJHMzYvaktnelYzNFFkZGJvTEI5Yk1sZThEaGJQZ3JEV2VGcTdJRlpBVlYwOUcwdGx6R1hNaDE5YQpLZm8yVnNMRDZMT1dLTGwvOUNVRkFnTUJBQUV3RFFZSktvWklodmNOQVFFTEJRQURnZ0lCQUNvM3ZYcHBJTk9TCkxkSEpTRXRYT3haSi9kMEw4aXZQaEUwZzlRb0h0NUNNUUZWMGlKcVpzZzVLQURDckJSUG42ZnBVZDFhaDROZWoKWW5lUWxzbEpUOFFJN1RIQ1ZiTzBuOUtsbEVxWEJ5c2gxeDdkTGVXdFVaczRxLzB2QVlxbTc3aWYyaVpWTEFzNgprMk81NmhpelNwN2svZC90SXd3a1k3dTN4UkF2b2RWWEM3cnA1ZmViSTRWcDZLUFMwbjF4Yk8wSXBqUzd3KzhPClkxMjFXdmtxUUQyckhCMkUySFJSSWdGTEF2eVFqY01hak9KMzRSUnh4VDljUzFIWEUzVUdDVVl2bHc1NnMySmMKMWYvMXNXYTJNaHFiUUdzVDZJS3dVOXZ2SlArQktoWnBsWnpicUlnZHZyZHVHNWFCbEpnNlNCQTZsUThSTDhnNQp6MmpscGFaTE5jUmYySkdTUm5TTzlDZzJTcU5va2wwaDRRZVRCZEFNeGhPVnk0MmxOc1grLzVOWVhuM0RXRWo1CmoybTV0SFpRU3ptY3BZZmNlY0ZpRXdud3BwOVdMbWlsb0N3SHVON2FNYU9ZakpSVnVPcWJoTXZMUjFLTnpWVm0KUFdVblZJa3FBY2p0TXVKVFh6clZGV081VXEvazF0WkIzdGhNNEd4c1JZcElDbEJmS3c3emFIaGxsZmNvNE53eQprbWVDeENWMnVLZ3AxYkJlZ0hReTVEc3E4OFI5Qkh1b0g0aWpEbzlUTGRpU2NXT0o1TkFEOUJ5K2F3VGpsUk1qCmtrVHgyMFRZdm1VdEF6T2N5R0xCOENEWERwS1B4b1ZBdVREMGFKMy9na3p0aHZQQ1dDamxINGI2cXVMS3lwVHgKOU85OVRZWGw3Y2VNSXZIc2I3L3l4L01KUG9RbUZjcUgKLS0tLS1FTkQgQ0VSVElGSUNBVEUtLS0tLQ==\n server: https://172.16.8.88/k8s/clusters/c-vckqj\n name: dtstack\n- cluster:\n certificate-authority-data: LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSUN3akNDQWFxZ0F3SUJBZ0lCQURBTkJna3Foa2lHOXcwQkFRc0ZBREFTTVJBd0RnWURWUVFERXdkcmRXSmwKTFdOaE1CNFhEVEl3TVRFd05UQXlNekF3T0ZvWERUTXdNVEV3TXpBeU16QXdPRm93RWpFUU1BNEdBMVVFQXhNSAphM1ZpWlMxallUQ0NBU0l3RFFZSktvWklodmNOQVFFQkJRQURnZ0VQQURDQ0FRb0NnZ0VCQUsyQmpTMEdYVmo5ClNZQWpjTFhYWUR2bXo2OStHdWkvbHQ4WHp0aC9ZdG4rU1NxR2NXSms4NzhLaHI5RGdRQ1hNR3VtZXZtbUhFemIKYVVsY29oQXU0Q0NaS0VmYmxncFY2ZzFqNGtreVFxS2hTSG84VDBhU2VLOW53dDZZMzQ4MXVxTG9UWHhubFhPKwpZblJOWjVsQnlVTWRXb2JmSGhzRGJQM2lLcXdkU3NYckhxYWJlNmFDdk5tMlpIelNJbnc1eG0wakZHWXJvS0M5Cll3a3FVYmpWMDEzRXV1bzV1dzdKZ2l1eFdFcDhoSjJ1WEFKNkp3OGZEeml5aUxIay9qTGVyTFM2UnN5dWNtYXEKWUJPclIvS2pmTllGV1hlTWlqNzF3NXZqRTJFcG1DUnRLMFdtRjFpU3gyUFo2ZlBtYmVSd2lpRUVScXFFZGhYbQpqeGZNRnRWSzUzY0NBd0VBQWFNak1DRXdEZ1lEVlIwUEFRSC9CQVFEQWdLa01BOEdBMVVkRXdFQi93UUZNQU1CCkFmOHdEUVlKS29aSWh2Y05BUUVMQlFBRGdnRUJBSTRxcUxnVFRJa1VQbGtJUWRGdjlNNmRseHpJTlZmU0xXU2QKdEJuZGV6NUVmelBRaVBOdHQzbDlHNklrZmpYSGJUcU1rN0NsTWkvUnZtVDlDcjMwc093NHY4WVNOQTFyYjBHYwp2VURJdEl0ZGoyVW8wSUtzQ2dsN0psalhMcVNvd01jczMwQy9IQXJGdU9pSTlsS2VBdlVIeFhFTG5ST1hxaGozCjhoTG5kS0dTak8rYXRFVSs1b0ZFa0pydS9hcDdjTGxWSWVQVmh3eHpuM2pSS2dmRDVXTmI4aHRpRzg1YjMrNVIKMGt4eGFjNlRyaDBKQkh5cVpRSlVWMUg2djk3NXdqNnZJNU5NcDNvbnlVZjJxaGJzSjVIWEJJRDh2NEtUQms3MQoxVnliMzFwY3NjZEVibGNPTFlveTFyR1VDT1QxMzNmbFlyTldwc2VXcFJ6Y2NPUE1WYVE9Ci0tLS0tRU5EIENFUlRJRklDQVRFLS0tLS0K\n server: https://172.16.8.160:6443\n name: dtstack-172-16-8-160\n- cluster:\n certificate-authority-data: LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSUN3akNDQWFxZ0F3SUJBZ0lCQURBTkJna3Foa2lHOXcwQkFRc0ZBREFTTVJBd0RnWURWUVFERXdkcmRXSmwKTFdOaE1CNFhEVEl3TVRFd05UQXlNekF3T0ZvWERUTXdNVEV3TXpBeU16QXdPRm93RWpFUU1BNEdBMVVFQXhNSAphM1ZpWlMxallUQ0NBU0l3RFFZSktvWklodmNOQVFFQkJRQURnZ0VQQURDQ0FRb0NnZ0VCQUsyQmpTMEdYVmo5ClNZQWpjTFhYWUR2bXo2OStHdWkvbHQ4WHp0aC9ZdG4rU1NxR2NXSms4NzhLaHI5RGdRQ1hNR3VtZXZtbUhFemIKYVVsY29oQXU0Q0NaS0VmYmxncFY2ZzFqNGtreVFxS2hTSG84VDBhU2VLOW53dDZZMzQ4MXVxTG9UWHhubFhPKwpZblJOWjVsQnlVTWRXb2JmSGhzRGJQM2lLcXdkU3NYckhxYWJlNmFDdk5tMlpIelNJbnc1eG0wakZHWXJvS0M5Cll3a3FVYmpWMDEzRXV1bzV1dzdKZ2l1eFdFcDhoSjJ1WEFKNkp3OGZEeml5aUxIay9qTGVyTFM2UnN5dWNtYXEKWUJPclIvS2pmTllGV1hlTWlqNzF3NXZqRTJFcG1DUnRLMFdtRjFpU3gyUFo2ZlBtYmVSd2lpRUVScXFFZGhYbQpqeGZNRnRWSzUzY0NBd0VBQWFNak1DRXdEZ1lEVlIwUEFRSC9CQVFEQWdLa01BOEdBMVVkRXdFQi93UUZNQU1CCkFmOHdEUVlKS29aSWh2Y05BUUVMQlFBRGdnRUJBSTRxcUxnVFRJa1VQbGtJUWRGdjlNNmRseHpJTlZmU0xXU2QKdEJuZGV6NUVmelBRaVBOdHQzbDlHNklrZmpYSGJUcU1rN0NsTWkvUnZtVDlDcjMwc093NHY4WVNOQTFyYjBHYwp2VURJdEl0ZGoyVW8wSUtzQ2dsN0psalhMcVNvd01jczMwQy9IQXJGdU9pSTlsS2VBdlVIeFhFTG5ST1hxaGozCjhoTG5kS0dTak8rYXRFVSs1b0ZFa0pydS9hcDdjTGxWSWVQVmh3eHpuM2pSS2dmRDVXTmI4aHRpRzg1YjMrNVIKMGt4eGFjNlRyaDBKQkh5cVpRSlVWMUg2djk3NXdqNnZJNU5NcDNvbnlVZjJxaGJzSjVIWEJJRDh2NEtUQms3MQoxVnliMzFwY3NjZEVibGNPTFlveTFyR1VDT1QxMzNmbFlyTldwc2VXcFJ6Y2NPUE1WYVE9Ci0tLS0tRU5EIENFUlRJRklDQVRFLS0tLS0K\n server: https://172.16.8.166:6443\n name: dtstack-172-16-8-166\n- cluster:\n certificate-authority-data: LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSUN3akNDQWFxZ0F3SUJBZ0lCQURBTkJna3Foa2lHOXcwQkFRc0ZBREFTTVJBd0RnWURWUVFERXdkcmRXSmwKTFdOaE1CNFhEVEl3TVRFd05UQXlNekF3T0ZvWERUTXdNVEV3TXpBeU16QXdPRm93RWpFUU1BNEdBMVVFQXhNSAphM1ZpWlMxallUQ0NBU0l3RFFZSktvWklodmNOQVFFQkJRQURnZ0VQQURDQ0FRb0NnZ0VCQUsyQmpTMEdYVmo5ClNZQWpjTFhYWUR2bXo2OStHdWkvbHQ4WHp0aC9ZdG4rU1NxR2NXSms4NzhLaHI5RGdRQ1hNR3VtZXZtbUhFemIKYVVsY29oQXU0Q0NaS0VmYmxncFY2ZzFqNGtreVFxS2hTSG84VDBhU2VLOW53dDZZMzQ4MXVxTG9UWHhubFhPKwpZblJOWjVsQnlVTWRXb2JmSGhzRGJQM2lLcXdkU3NYckhxYWJlNmFDdk5tMlpIelNJbnc1eG0wakZHWXJvS0M5Cll3a3FVYmpWMDEzRXV1bzV1dzdKZ2l1eFdFcDhoSjJ1WEFKNkp3OGZEeml5aUxIay9qTGVyTFM2UnN5dWNtYXEKWUJPclIvS2pmTllGV1hlTWlqNzF3NXZqRTJFcG1DUnRLMFdtRjFpU3gyUFo2ZlBtYmVSd2lpRUVScXFFZGhYbQpqeGZNRnRWSzUzY0NBd0VBQWFNak1DRXdEZ1lEVlIwUEFRSC9CQVFEQWdLa01BOEdBMVVkRXdFQi93UUZNQU1CCkFmOHdEUVlKS29aSWh2Y05BUUVMQlFBRGdnRUJBSTRxcUxnVFRJa1VQbGtJUWRGdjlNNmRseHpJTlZmU0xXU2QKdEJuZGV6NUVmelBRaVBOdHQzbDlHNklrZmpYSGJUcU1rN0NsTWkvUnZtVDlDcjMwc093NHY4WVNOQTFyYjBHYwp2VURJdEl0ZGoyVW8wSUtzQ2dsN0psalhMcVNvd01jczMwQy9IQXJGdU9pSTlsS2VBdlVIeFhFTG5ST1hxaGozCjhoTG5kS0dTak8rYXRFVSs1b0ZFa0pydS9hcDdjTGxWSWVQVmh3eHpuM2pSS2dmRDVXTmI4aHRpRzg1YjMrNVIKMGt4eGFjNlRyaDBKQkh5cVpRSlVWMUg2djk3NXdqNnZJNU5NcDNvbnlVZjJxaGJzSjVIWEJJRDh2NEtUQms3MQoxVnliMzFwY3NjZEVibGNPTFlveTFyR1VDT1QxMzNmbFlyTldwc2VXcFJ6Y2NPUE1WYVE9Ci0tLS0tRU5EIENFUlRJRklDQVRFLS0tLS0K\n server: https://172.16.8.169:6443\n name: dtstack-172-16-8-169\ncontexts:\n- context:\n cluster: dtstack\n user: dtstack\n name: dtstack\n- context:\n cluster: dtstack-172-16-8-160\n user: dtstack\n name: dtstack-172-16-8-160\n- context:\n cluster: dtstack-172-16-8-166\n user: dtstack\n name: dtstack-172-16-8-166\n- context:\n cluster: dtstack-172-16-8-169\n user: dtstack\n name: dtstack-172-16-8-169\n- context:\n cluster: dtstack-172-16-8-160\n user: test\n name: test\ncurrent-context: dtstack\nkind: Config\npreferences: {}\nusers:\n- name: dtstack\n user:\n token: kubeconfig-user-mtrk8.c-vckqj:jk8k6n72dpxtllmtd4p99kwkkxthxsqg6562b9r2t2v7bdkf2jft9n\n- name: test\n user:\n token: eyJhbGciOiJSUzI1NiIsImtpZCI6IjNhTjhlRFZNQl9ld2xGRDhpQ1F3czJDamtHUGNMTVlua2JBVW0yYUhDT1EifQ.eyJpc3MiOiJrdWJlcm5ldGVzL3NlcnZpY2VhY2NvdW50Iiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9uYW1lc3BhY2UiOiJkZXYiLCJrdWJlcm5ldGVzLmlvL3NlcnZpY2VhY2NvdW50L3NlY3JldC5uYW1lIjoiZGVmYXVsdC10b2tlbi1kajl0NiIsImt1YmVybmV0ZXMuaW8vc2VydmljZWFjY291bnQvc2VydmljZS1hY2NvdW50Lm5hbWUiOiJkZWZhdWx0Iiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9zZXJ2aWNlLWFjY291bnQudWlkIjoiOGM4ZTVhZGQtOGYwZi00NDdkLTg3YjAtMTc1ZmQxYTJmYWQ1Iiwic3ViIjoic3lzdGVtOnNlcnZpY2VhY2NvdW50OmRldjpkZWZhdWx0In0.bxqYVW0HOklhEZxNXECMQy1MqmdGzW4D2MLJ6fnXeAAXolkYPVIgf69eOO0P9JDxtX0HALQz9P982CqnuP0U7M3_OkJUptr55ixQXnkYbPn8L18ZxGdQ0R8tqymoqdfZAmUzzNf1lk9BIRaX_DAJwJmwKWUdrSGdJaS2lPcsXILP0GcC0tbwK6PP3GL2ZKKKlQsDy8Hbw2DdgXkMnx6NyU2BlsW2CWfEDc0__XUfY-0TSA4Evy7DnrD-US06992BF63zirhp8Y_kNd-8VQY83oNCo9vrKwOJYU0s0UP_3BgZpaKUSyrn4alKoj69hz4sXnnARwhbgJxKF_qBYqy47Q", - } - clusterid := "109" - user := "admin@dtstack.com" - Save(ctx, clusterid, user, vo) -} - -func Test3(t *testing.T) { - user := "root" - password := "dtstack" - host := "172.16.10.37" - port := 3306 - dbname := "dtagent" - db, _ := sqlx.Connect("mysql", fmt.Sprintf("%s:%s@tcp(%s:%d)/%s?charset=utf8&loc=Local&parseTime=true", user, password, host, port, dbname)) - model.MYSQLDB = db - err := modelkube.Build() - log.ConfigureLogger("/tmp/matrix", 100, 3, 1) - commonlog.Config("/tmp/easykube") - ctx := context.Background() - err = InitResource() - if err != nil { - fmt.Println("err3", err.Error()) - } - rsp, err := GetNamespaceListStatus(ctx, "85", "", "", "") - if err != nil { - fmt.Println("err", err.Error()) - } - fmt.Println(rsp) -} - -func getConn() { - user := "root" - password := "dtstack" - host := "172.16.10.37" - port := 3306 - dbname := "dtagent" - log.ConfigureLogger("/tmp/matrix", 100, 3, 1) - db, _ := sqlx.Connect("mysql", fmt.Sprintf("%s:%s@tcp(%s:%d)/%s?charset=utf8&loc=Local&parseTime=true", user, password, host, port, dbname)) - model.MYSQLDB = db - err := modelkube.Build() - union.Build() - if err != nil { - fmt.Printf("err: %v \n", err) - } -} - -func Test4(t *testing.T) { - getConn() - log.ConfigureLogger("/tmp/matrix", 100, 3, 1) - commonlog.Config("/tmp/easykube") - ctx := context.Background() - ns := "dt-test-2" - cache, _ := kube.ClusterNsClientCache.GetClusterNsClient("abc").GetClientCache(kube.IMPORT_KUBECONFIG) - cache.Connect(kubeconfig, ns) - namespaceInit(ctx, cache, ns, 21) -} - -//func Test5(t *testing.T) { -// getConn() -// log.ConfigureLogger("/tmp/matrix",100,3,1) -// commonlog.Config("/tmp/easykube") -// ns := "dt-test-2" -// ctx := context.Background() -// cache,_ := kube.ClusterNsClientCache.GetClusterNsClient("85").GetClientCache(kube.IMPORT_KUBECONFIG) -// cache.Connect(kubeconfig,ns) -// resp,err := GetNamespaceStatus(ctx,ns,"85") -// if err != nil{ -// fmt.Println("err: ",err.Error()) -// } -// bts,_:=yaml.Marshal(resp) -// fmt.Println(string(bts)) -//} - -func Test6(t *testing.T) { - getConn() - log.ConfigureLogger("/tmp/matrix", 100, 3, 1) - commonlog.Config("/tmp/easykube") - ns := "em-dev" - clusterid := "111" - ctx := context.Background() - cache, _ := kube.ClusterNsClientCache.GetClusterNsClient(clusterid).GetClientCache(kube.IMPORT_KUBECONFIG) - cache.Connect(kubeconfig, ns) - err := NamespaceDelete(ctx, ns, clusterid) - if err != nil { - fmt.Println("err", err.Error()) - } -} - -func Test7(t *testing.T) { - getConn() - log.ConfigureLogger("/tmp/matrix", 100, 3, 1) - commonlog.Config("/tmp/easykube") - clusterid := "111" - ctx := context.Background() - res, err := GetNamespaceListStatus(ctx, clusterid, "", "true", "") - if err != nil { - fmt.Println("err", err.Error()) - } - bts, _ := json.Marshal(res) - fmt.Println(string(bts)) -} - -func Test8(t *testing.T) { - getConn() - log.ConfigureLogger("/tmp/matrix", 100, 3, 1) - commonlog.Config("/tmp/easykube") - c := model.ClusterInfo{ - Id: 111, - Name: "em-dev", - Type: "kubernets", - Mode: 1, - } - rsp, err := NamespaceList(&c) - if err != nil { - fmt.Println(err.Error()) - } - fmt.Println(rsp) -} - -func Test9(t *testing.T) { - getConn() - log.ConfigureLogger("/tmp/matrix", 100, 3, 1) - commonlog.Config("/tmp/easykube") - req := &view.AgentGenerateReq{ - Namespace: "dev", - RegistryId: 22, - } - rsp, err := AgentGenerate(req) - if err != nil { - fmt.Println("err", err.Error()) - } - fmt.Println(rsp.Yaml) -} - -func Test10(t *testing.T) { - getConn() - log.ConfigureLogger("/tmp/matrix", 100, 3, 1) - commonlog.Config("/tmp/easykube") - //namespace := "em-dev" - clusterid := "112" - status := "" - descStr := "true" - ctx := context.Background() - //rsp,err := GetNamespaceStatus(ctx,namespace,clusterid,status,descStr) - rsp, err := GetNamespaceListStatus(ctx, clusterid, status, descStr, "") - if err != nil { - fmt.Println("err", err.Error()) - } - bts, _ := json.Marshal(rsp) - fmt.Println(string(bts)) -} - -func Test11(t *testing.T) { - getConn() - log.ConfigureLogger("/tmp/matrix", 100, 3, 1) - commonlog.Config("/tmp/easykube") - req := &view.AgentGenerateReq{ - Namespace: "", - } - rsp, err := AgentGenerate(req) - if err != nil { - fmt.Println("err", err.Error()) - return - } - bts, _ := json.Marshal(rsp) - fmt.Println(string(bts)) -} - -func Test12(t *testing.T) { - getConn() - np := &view.NamespacePingReq{ - Namespace: "em-agent", - Ip: "172.16.100.117", - Port: "80", - } - err := NamespacePing(context.Background(), "113", np) - if err != nil { - fmt.Println("err", err.Error()) - } -} - -func Test13(t *testing.T) { - var s runtime.Object = &corev1.ResourceQuota{} - gvks, _, _ := base.Schema.ObjectKinds(s) - gvk := gvks[0] - fmt.Println(gvk.Kind) - fmt.Println(gvk.Version) - fmt.Println(gvk.Group) -} - -func Test14(t *testing.T) { - getConn() - log.ConfigureLogger("/tmp/matrix", 100, 3, 1) - commonlog.Config("/tmp/easykube") - - ns := "em-dev" - cache, _ := kube.ClusterNsClientCache.GetClusterNsClient("112").GetClientCache(kube.IMPORT_KUBECONFIG) - cache.Connect(kubeconfig, ns) - - rsp, err := GetService(context.Background(), "em-dev", "112", "DTinsight", "all", "sql") - if err != nil { - fmt.Println("err", err.Error()) - } - bts, _ := json.Marshal(rsp) - fmt.Println(string(bts)) -} - -func Test15(t *testing.T) { - getConn() - log.ConfigureLogger("/tmp/matrix", 100, 3, 1) - commonlog.Config("/tmp/easykube") - cache, _ := kube.ClusterNsClientCache.GetClusterNsClient("113").GetClientCache(kube.IMPORT_AGENT) - cache.Connect("http://172.16.100.117:80", "em-agent") - res, err := GetNamespaceListStatus(context.Background(), "113", "", "true", "") - if err != nil { - fmt.Println("err", err.Error()) - } - bts, _ := json.Marshal(res) - fmt.Println(string(bts)) -} - -func Test16(t *testing.T) { - getConn() - log.ConfigureLogger("/tmp/matrix", 100, 3, 1) - commonlog.Config("/tmp/easykube") - cache, _ := kube.ClusterNsClientCache.GetClusterNsClient("113").GetClientCache(kube.IMPORT_AGENT) - cache.Connect("http://172.16.100.117:80", "em-agent") - cc, _ := kube.ClusterNsClientCache.GetClusterNsClient("113").GetClientCache(kube.IMPORT_AGENT) - - c := cc.GetClient("em-agent") - cct := c.(*kube.RestClient) - monitorAgent("em-agent", 113, cct) - //cct.Events(&e) - //fmt.Println(cct == nil) - //events := []monitorevents.Event{} - //err := c.Events(&events) - //if err != nil{} - //fmt.Println(err.Error()) - //bts,_:=json.Marshal(e) - //fmt.Println(string(bts)) -} - -// -func Test17(t *testing.T) { - getConn() - log.ConfigureLogger("/tmp/matrix", 100, 3, 1) - commonlog.Config("/tmp/easykube") - cache, _ := kube.ClusterNsClientCache.GetClusterNsClient("113").GetClientCache(kube.IMPORT_AGENT) - cache.Connect("http://172.16.100.117:80", "em-agent") - req := &view.InstanceReplicaReq{ - Namespace: "em-agent", - Replica: 1, - ProductName: "DTUic", - ServiceName: "Uic", - } - err := InstanceReplica(context.Background(), "113", req) - if err != nil { - fmt.Println("err", err.Error()) - } -} - -func Test19(t *testing.T) { - getConn() - log.ConfigureLogger("/tmp/matrix", 100, 3, 1) - commonlog.Config("/tmp/easykube") - cache, _ := kube.ClusterNsClientCache.GetClusterNsClient("135").GetClientCache(kube.IMPORT_AGENT) - cache.Connect("http://172.16.10.234:8899", "dtstack-system") - ns := &corev1.NamespaceList{} - err := cache.GetClient("dtstack-system").List(context.Background(), ns, "") - if err != nil { - fmt.Println("err", err.Error()) - return - } - bts, _ := json.Marshal(ns) - fmt.Println(string(bts)) -} -func Test18(t *testing.T) { - getConn() - log.ConfigureLogger("/tmp/matrix", 100, 3, 1) - commonlog.Config("/tmp/easykube") - cinfo, err := modelkube.DeployClusterList.GetClusterById(131) - if err != nil { - fmt.Println("err", err.Error()) - return - } - gInfo := &clustergenerator.GeneratorInfo{ - Type: constant.TYPE_SELF_BUILD, - HostIp: "172.16.10.37", - ClusterInfo: cinfo, - } - //err = clustergenerator.GenerateTemplate(gInfo) - //if err != nil{ - // fmt.Println("err",err.Error()) - //} - - bts, _ := clustergenerator.GetTemplateFile(gInfo, false) - fmt.Println(string(bts)) -} diff --git a/chengying-server/matrix/k8s/resource/endpoints/endpoints.go b/chengying-server/matrix/k8s/resource/endpoints/endpoints.go deleted file mode 100644 index 2de282e..0000000 --- a/chengying-server/matrix/k8s/resource/endpoints/endpoints.go +++ /dev/null @@ -1,33 +0,0 @@ -// Licensed to Apache Software Foundation(ASF) under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. Apache Software Foundation(ASF) licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -package endpoints - -import ( - corev1 "k8s.io/api/core/v1" - "k8s.io/apimachinery/pkg/runtime/schema" -) - -var GVK = schema.GroupVersionKind{ - Group: "", - Version: "v1", - Kind: "Endpoints", -} - -func New() *corev1.Endpoints{ - return &corev1.Endpoints{} -} diff --git a/chengying-server/matrix/k8s/resource/goroutine.go b/chengying-server/matrix/k8s/resource/goroutine.go deleted file mode 100644 index aefec88..0000000 --- a/chengying-server/matrix/k8s/resource/goroutine.go +++ /dev/null @@ -1,245 +0,0 @@ -// Licensed to Apache Software Foundation(ASF) under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. Apache Software Foundation(ASF) licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -package resource - -import ( - "context" - easymonitor "dtstack.com/dtstack/easymatrix/addons/easymonitor/pkg" - monitorevents "dtstack.com/dtstack/easymatrix/addons/easymonitor/pkg/monitor/events" - "dtstack.com/dtstack/easymatrix/matrix/api/k8s/view" - "dtstack.com/dtstack/easymatrix/matrix/k8s/constant" - "dtstack.com/dtstack/easymatrix/matrix/k8s/kube" - "dtstack.com/dtstack/easymatrix/matrix/k8s/monitor" - "dtstack.com/dtstack/easymatrix/matrix/log" - modelkube "dtstack.com/dtstack/easymatrix/matrix/model/kube" - "fmt" - "strconv" - "strings" - "time" -) - -// load the conncet info for namescpcae client talk with api-server -func InitResource() error{ - - tbscs,err := modelkube.DeployNamespaceList.SelectAll() - if err != nil{ - return err - } - for _,tbsc := range tbscs{ - cache,err:= kube.ClusterNsClientCache.GetClusterNsClient(strconv.Itoa(tbsc.ClusterId)).GetClientCache(kube.ImportType(tbsc.Type)) - if err != nil{ - return err - } - if tbsc.Status == constant.NAMESPACE_NOT_CONNECT || tbsc.Status == constant.NAMESPACE_INVALID{ - continue - } - nsSave := tbsc.NamespaceSaveReq - if tbsc.Type == kube.IMPORT_KUBECONFIG.String(){ - connectInfo,err := modelkube.DeployNamespaceClient.Get(tbsc.Id) - if err!=nil{ - return err - } - if connectInfo == nil{ - continue - } - err = cache.Connect(connectInfo.Yaml,tbsc.Namespace) - if err != nil{ - return err - } - nsSave.Yaml = connectInfo.Yaml - }else{ - ip := tbsc.Ip - port := tbsc.Port - if len(ip) ==0 || len(port) ==0{ - continue - } - if !strings.HasPrefix(ip,"http"){ - ip = "http://"+ip - } - host := ip + ":" +port - err = cache.Connect(host,tbsc.Namespace) - if err != nil{ - return err - } - } - err = StartGoroutines(context.Background(),strconv.Itoa(tbsc.ClusterId),&nsSave) - if err != nil{ - return err - } - } - - go regularCleanEvents() - return nil -} - -func StartGoroutines(ctx context.Context, clusterid string, vo *view.NamespaceSaveReq) error{ - cache,err := kube.ClusterNsClientCache.GetClusterNsClient(clusterid).GetClientCache(kube.ImportType(vo.Type)) - if err != nil{ - return err - } - cid,_ := strconv.Atoi(clusterid) - if client := cache.GetClient(vo.Namespace); client != nil{ - go WatchNamspaceStatus(client,vo.Namespace,cid) - } - - if vo.Type == kube.IMPORT_KUBECONFIG.String(){ - //run monitor - trasmitor := &KubeconfigModeTransmitor{vo.Id} - stopCh := make(chan struct{}) - err := easymonitor.StartMonitorControllerWithTransmitor("",vo.Yaml,vo.Namespace,stopCh,trasmitor) - if err != nil{ - log.Errorf("start monitor with kubeconfig fail, error %v",err) - } - go monitorCheck(vo.Namespace,cid,stopCh) - }else if vo.Type == kube.IMPORT_AGENT.String(){ - if c := cache.GetClient(vo.Namespace); c != nil{ - client := c.(*kube.RestClient) - go monitorAgent(vo.Namespace,cid,client) - } - } - - return nil -} - -type KubeconfigModeTransmitor struct { - NamespaceId int -} - -func (k *KubeconfigModeTransmitor) Push(event monitorevents.Eventer){ - e := event.(*monitorevents.Event) - e.Workspaceid = k.NamespaceId - monitor.HandleResourceM(e) -} - -func (k *KubeconfigModeTransmitor)Process(){ - -} - -func monitorAgent(namespace string, clusterid int,client *kube.RestClient){ - tick := time.NewTicker(time.Second*5) - defer tick.Stop() - tbsc,err := modelkube.DeployNamespaceList.Get(namespace,clusterid) - if err != nil && tbsc == nil{ - return - } - updateTime := tbsc.UpdateTime - for{ - <- tick.C - tbsc,err = modelkube.DeployNamespaceList.Get(namespace,clusterid) - if err != nil { - log.Errorf("[goroutine]: monitorAgent task database err %v",err) - continue - } - if tbsc.UpdateTime != updateTime{ - break - } - events := []monitorevents.Event{} - err := client.Events(&events) - for _,event := range events{ - event.Workspaceid = tbsc.Id - monitor.HandleResourceM(&event) - } - if err != nil{ - continue - } - - } -} - - -func monitorCheck(namespace string, clusterid int, stopCh chan struct{}){ - tick := time.NewTicker(time.Minute) - defer tick.Stop() - tbsc,err := modelkube.DeployNamespaceList.Get(namespace,clusterid) - if err != nil && tbsc == nil{ - return - } - updateTime := tbsc.UpdateTime - for { - <- tick.C - tbsc,err = modelkube.DeployNamespaceList.Get(namespace,clusterid) - if err != nil { - log.Errorf("[goroutine]: monitorCheck task database err %v",err) - continue - } - if tbsc.UpdateTime != updateTime{ - close(stopCh) - break - } - } -} - -func WatchNamspaceStatus(client kube.Client, namespace string, clusterid int){ - tick := time.NewTicker(time.Minute) - defer tick.Stop() - defer func() { - log.Infof("namespace info is updated") - }() - var err error - tbsc, err := modelkube.DeployNamespaceList.Get(namespace,clusterid) - if err != nil && tbsc == nil{ - return - } - updateTime := tbsc.UpdateTime - for { - <- tick.C - tbsc, err = modelkube.DeployNamespaceList.Get(namespace,clusterid) - if err != nil{ - log.Errorf("[goroutine]: watchNamspaceStatus task database err %v",err) - continue - } - //if updatetime changed, maybe the client info has changed.exit the loop - if tbsc.UpdateTime != updateTime{ - break - } - err := ping(client,namespace) - if err != nil{ - tbsc.Status = constant.NAMESPACE_INVALID - modelkube.DeployNamespaceList.UpdateStatus(tbsc) - continue - } - - if tbsc.Status == constant.NAMESPACE_VALID{ - continue - } - tbsc.Status = constant.NAMESPACE_VALID - modelkube.DeployNamespaceList.UpdateStatus(tbsc) - } - -} - -//clean event history before 14 days ago, every 4:00:00 -func regularCleanEvents(){ - regularHour := 3 - now := time.Now() - waitHour := time.Duration(regularHour - 1 - now.Hour()) - waitMinute := time.Duration(59-now.Minute()) - waitSecond := time.Duration(60-now.Second()) - if waitHour < 0{ - waitHour = waitHour + 24 - } - duration := time.Hour * waitHour + time.Minute * waitMinute + time.Second * waitSecond - //regularHour - nowHour - timer := time.NewTimer(duration) - for { - <- timer.C - fmt.Println("time to clean events",time.Now().Format("2006-01-02 15:04:05")) - timer.Reset(time.Hour * 24) - modelkube.DeployNamespaceEvent.CleanHistory(14) - } -} diff --git a/chengying-server/matrix/k8s/resource/instance_replica.go b/chengying-server/matrix/k8s/resource/instance_replica.go deleted file mode 100644 index 6f97888..0000000 --- a/chengying-server/matrix/k8s/resource/instance_replica.go +++ /dev/null @@ -1,195 +0,0 @@ -// Licensed to Apache Software Foundation(ASF) under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. Apache Software Foundation(ASF) licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -package resource - -import ( - "context" - molemodel "dtstack.com/dtstack/easymatrix/addons/operator/pkg/controller/model" - "dtstack.com/dtstack/easymatrix/addons/operator/pkg/controller/workload/support" - "dtstack.com/dtstack/easymatrix/addons/operator/pkg/util" - "dtstack.com/dtstack/easymatrix/matrix/api/k8s/view" - "dtstack.com/dtstack/easymatrix/matrix/k8s/constant" - "dtstack.com/dtstack/easymatrix/matrix/k8s/kube" - "dtstack.com/dtstack/easymatrix/matrix/k8s/resource/deployment" - "dtstack.com/dtstack/easymatrix/matrix/k8s/resource/mole" - "dtstack.com/dtstack/easymatrix/matrix/k8s/resource/resourcequota" - "dtstack.com/dtstack/easymatrix/matrix/k8s/resource/workload" - "dtstack.com/dtstack/easymatrix/matrix/log" - modelkube "dtstack.com/dtstack/easymatrix/matrix/model/kube" - "dtstack.com/dtstack/easymatrix/matrix/model/kube/union" - "dtstack.com/dtstack/easymatrix/schema" - "fmt" - corev1 "k8s.io/api/core/v1" - "k8s.io/apimachinery/pkg/api/resource" - "strconv" - "strings" -) - -func InstanceReplica(ctx context.Context, clusterid string, vo *view.InstanceReplicaReq) error { - - cid, err := strconv.Atoi(clusterid) - if err != nil { - log.Errorf("[instance_replica]: convet %s to int error %v", clusterid, err) - return err - } - tbscs, err := modelkube.DeployNamespaceList.GetLike(vo.Namespace, cid, constant.NAMESPACE_VALID, true) - if err != nil { - return err - } - if tbscs == nil { - return fmt.Errorf("no valid namespaced client exist") - } - // now one cluster only can use one namspaceclient, until the em front modified - tbsc := tbscs[0] - namespace := tbsc.Namespace - cache, err := kube.ClusterNsClientCache.GetClusterNsClient(clusterid).GetClientCache(kube.ImportType(tbsc.Type)) - if err != nil { - return err - } - - unionTbsc, err := union.UnionT4T7.GetProduct(cid, namespace, vo.ProductName) - if err != nil { - return err - } - if unionTbsc == nil { - return fmt.Errorf("[instance_replica]: can not found the deployed product %s in cluster %d, in namespace %s", vo.ProductName, cid, namespace) - } - sc, err := schema.Unmarshal(unionTbsc.Product) - if err != nil { - log.Errorf("[instance_replica]: unmashal product fail, err: %v", err) - return err - } - client := cache.GetClient(namespace) - quota, err := resourcequota.Get(ctx, client, namespace) - if err != nil { - return err - } - svc := sc.Service[vo.ServiceName] - var cpu_limit int64 - var mem_limit int64 - if len(svc.Workload) != 0 { - if svc.Instance != nil && svc.Instance.NeedStorage != nil && *svc.Instance.NeedStorage { - return fmt.Errorf("the service %s need storage, please check the storage is ready and redeploy", vo.ServiceName) - } - wl := workload.New() - wl.Name = util.BuildWorkloadName(vo.ProductName, vo.ServiceName) - wl.Namespace = namespace - exist, err := cache.GetClient(namespace).Get(ctx, wl) - if err != nil { - return err - } - if !exist { - return fmt.Errorf("the service %s in product %s in cluster %s not support replica", vo.ServiceName, vo.ProductName, clusterid) - } - // now, the service corresponds to one type instance, multiple part definitions are not supported - if quota != nil { - part := wl.Spec.WorkLoadParts[0] - for _, step := range part.Steps { - if step.Type == support.BoundTypeContainer || step.Type == support.BoundTypeInitContainer { - limits, err := workload.FieldGet(step.Object.Object, "resources.limits") - if err != nil { - return err - } - m := limits.(map[string]interface{}) - quota, err := resource.ParseQuantity(m["memory"].(string)) - if err != nil { - return err - } - mem_limit = mem_limit + quota.Value() - - quota, err = resource.ParseQuantity(m["cpu"].(string)) - if err != nil { - return err - } - cpu_limit = cpu_limit + quota.Value() - } - } - if err := judgeLimit(quota, cpu_limit, mem_limit, int64(vo.Replica)); err != nil { - return err - } - } - workload.FieldSet(wl.Spec.WorkLoadParts[0].BaseWorkLoad.Parameters.Object, "spec.replicas", vo.Replica) - return cache.GetClient(namespace).Update(ctx, wl) - - } else { - m := mole.New() - m.Namespace = namespace - m.Name = strings.ToLower(vo.ProductName) - exist, err := client.Get(ctx, m) - if err != nil { - return err - } - if !exist { - fmt.Errorf("not found the service %s in product %s in cluster %s", vo.ServiceName, vo.ProductName, clusterid) - } - if quota != nil { - limits := m.Spec.Product.Service[vo.ServiceName].Instance.Resources.Limits - resource_limit_cpu := limits["cpu"] - resource_limit_mem := limits["memory"] - //if there is no limit on the mole, use the default limit set by mole operator - if limits == nil { - name := molemodel.BuildResourceName(molemodel.MoleDeploymentName, m.Spec.Product.ParentProductName, - m.Spec.Product.ProductName, vo.ServiceName) - deploy, err := deployment.Get(ctx, client, namespace, name) - if err != nil { - return err - } - if deploy == nil { - return fmt.Errorf("the service %s is not deployed", vo.ServiceName) - } - cs := deploy.Spec.Template.Spec.Containers - for _, c := range cs { - if c.Name == strings.ToLower(vo.ServiceName) { - resource_limit_cpu = c.Resources.Limits["cpu"] - resource_limit_mem = c.Resources.Limits["memory"] - } - } - } - cpu_limit = resource_limit_cpu.Value() - mem_limit = resource_limit_mem.Value() - if err := judgeLimit(quota, resource_limit_cpu.Value(), resource_limit_mem.Value(), int64(vo.Replica)); err != nil { - return err - } - } - m.Spec.Product.Service[vo.ServiceName].Instance.Deployment.Replicas = int32(vo.Replica) - return cache.GetClient(namespace).Update(ctx, m) - } -} - -func judgeLimit(quota *corev1.ResourceQuota, limtcpu, limitmem, replica int64) error { - r := quota.Status.Hard["limits.cpu"] - cpuTotal := r.Value() - - r = quota.Status.Hard["limits.memory"] - memTotal := r.Value() - - r = quota.Status.Used["limits.cpu"] - cpuUsed := r.Value() - - r = quota.Status.Used["limits.memory"] - memUsed := r.Value() - - if cpuUsed+replica*limtcpu > cpuTotal { - return fmt.Errorf("The cpu resources are insufficient, please check") - } - - if memUsed+replica*limitmem > memTotal { - return fmt.Errorf("The memory resources are insufficient, please check") - } - return nil -} diff --git a/chengying-server/matrix/k8s/resource/job/job.go b/chengying-server/matrix/k8s/resource/job/job.go deleted file mode 100644 index 51c9f0c..0000000 --- a/chengying-server/matrix/k8s/resource/job/job.go +++ /dev/null @@ -1,33 +0,0 @@ -// Licensed to Apache Software Foundation(ASF) under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. Apache Software Foundation(ASF) licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -package job - -import ( - batchv1 "k8s.io/api/batch/v1" - "k8s.io/apimachinery/pkg/runtime/schema" -) - -var GVK = schema.GroupVersionKind{ - Group: "batch", - Version: "v1", - Kind: "Job", -} - -func New() *batchv1.Job{ - return &batchv1.Job{} -} diff --git a/chengying-server/matrix/k8s/resource/limitrange/limit_range.go b/chengying-server/matrix/k8s/resource/limitrange/limit_range.go deleted file mode 100644 index 22638b8..0000000 --- a/chengying-server/matrix/k8s/resource/limitrange/limit_range.go +++ /dev/null @@ -1,47 +0,0 @@ -// Licensed to Apache Software Foundation(ASF) under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. Apache Software Foundation(ASF) licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -package limitrange - -import ( - "context" - "dtstack.com/dtstack/easymatrix/matrix/k8s/kube" - "fmt" - corev1 "k8s.io/api/core/v1" - "k8s.io/apimachinery/pkg/runtime/schema" -) - -var GVK = schema.GroupVersionKind{ - Group: "", - Version: "v1", - Kind: "LimitRange", -} - -func Get(ctx context.Context,client kube.Client, namespace string) (*corev1.LimitRange,error){ - if client == nil{ - return nil,fmt.Errorf("the namespace client is not exist") - } - limitrange := &corev1.LimitRangeList{} - if err := client.List(ctx,limitrange,namespace);err != nil{ - return nil,err - } - if len(limitrange.Items) == 0{ - return nil,nil - } - limirange := limitrange.Items[0] - return &limirange,nil -} diff --git a/chengying-server/matrix/k8s/resource/mole/mole.go b/chengying-server/matrix/k8s/resource/mole/mole.go deleted file mode 100644 index 37b8e03..0000000 --- a/chengying-server/matrix/k8s/resource/mole/mole.go +++ /dev/null @@ -1,59 +0,0 @@ -// Licensed to Apache Software Foundation(ASF) under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. Apache Software Foundation(ASF) licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -package mole - -import ( - "context" - "dtstack.com/dtstack/easymatrix/addons/easykube/pkg/client/base" - "dtstack.com/dtstack/easymatrix/matrix/k8s/kube" - molev1 "dtstack.com/dtstack/easymatrix/addons/operator/pkg/apis/mole/v1" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/runtime/schema" -) - -var GVK = schema.GroupVersionKind{ - Group: "operator.dtstack.com", - Version: "v1", - Kind: "Mole", -} -func New() *molev1.Mole{ - return &molev1.Mole{} -} -func Ping(client kube.Client, namespace string) error { - ping := &molev1.Mole{ - ObjectMeta: metav1.ObjectMeta{ - Name: "dtstack-dryru", - Namespace: namespace, - }, - Spec: molev1.MoleSpec{ - Product: molev1.SchemaConfig{ - Service: map[string]molev1.ServiceConfig{ - "ping": molev1.ServiceConfig{}, - }, - }, - }, - } - if _, err := client.Get(context.Background(), ping); err != nil { - return err - } - - if err := client.DryRun(base.Create, ping); err != nil { - return err - } - return nil -} diff --git a/chengying-server/matrix/k8s/resource/namespace_client_info.go b/chengying-server/matrix/k8s/resource/namespace_client_info.go deleted file mode 100644 index 81d1359..0000000 --- a/chengying-server/matrix/k8s/resource/namespace_client_info.go +++ /dev/null @@ -1,145 +0,0 @@ -// Licensed to Apache Software Foundation(ASF) under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. Apache Software Foundation(ASF) licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -package resource - -import ( - "context" - "dtstack.com/dtstack/easymatrix/matrix/api/k8s/view" - "dtstack.com/dtstack/easymatrix/matrix/k8s/constant" - "dtstack.com/dtstack/easymatrix/matrix/k8s/kube" - "dtstack.com/dtstack/easymatrix/matrix/k8s/resource/deployment" - "dtstack.com/dtstack/easymatrix/matrix/log" - modelkube "dtstack.com/dtstack/easymatrix/matrix/model/kube" - "fmt" - "k8s.io/apimachinery/pkg/api/errors" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "strconv" -) - -func NamespaceGet(namespace,clusterid string) (*view.NamespaceGetRsp,error){ - cid,err := strconv.Atoi(clusterid) - if err != nil{ - log.Errorf("[namespace_client_info]: convert clusterid %s to int error %v",clusterid,err) - return nil,err - } - tbsc,err := modelkube.DeployNamespaceList.Get(namespace,cid) - if err != nil && tbsc == nil{ - return nil, err - } - clientTbsc,err := modelkube.DeployNamespaceClient.Get(tbsc.Id) - if err != nil && tbsc == nil{ - return nil,err - } - imageTbsc,err := modelkube.DeployClusterImageStore.GetById(tbsc.RegistryId) - if err != nil{ - return nil,err - } - reigistryId := tbsc.RegistryId - if imageTbsc == nil{ - reigistryId = -1 - } - return &view.NamespaceGetRsp{ - Id: tbsc.Id, - Type: tbsc.Type, - Namespace: namespace, - Registry: reigistryId, - Yaml: clientTbsc.Yaml, - FileName: clientTbsc.Filename, - },nil -} - -func NamespaceDeleteConfirm(namesapce,clusterid string) error{ - cid,err := strconv.Atoi(clusterid) - if err != nil{ - log.Errorf("[namespace_client_info]: convert clusterid %s to int error %v",clusterid,err) - return err - } - list,err := modelkube.DeployClusterProductRel.SelectNamespacedDeployed(cid,namesapce) - if err != nil{ - return err - } - if len(list) !=0{ - return fmt.Errorf("deployed produtct exist in namespace %s",namesapce) - } - return nil -} - -func NamespaceDelete(ctx context.Context,namespace,clusterid string) error{ - if err := NamespaceDeleteConfirm(namespace,clusterid);err != nil{ - return err - } - cid,err := strconv.Atoi(clusterid) - if err != nil{ - log.Errorf("[namespace_client_info]: convert clusterid %s to int error %v",clusterid,err) - return err - } - tbsc,err := modelkube.DeployNamespaceList.Get(namespace,cid) - if err != nil{ - return err - } - if tbsc == nil{ - return nil - } - if tbsc.Status == constant.NAMESPACE_VALID{ - err = deleteInitResource(ctx,namespace,clusterid) - if err != nil{ - return err - } - - kube.ClusterNsClientCache.GetClusterNsClient(clusterid).DeleteNsClient(namespace) - } - - return modelkube.DeployNamespaceList.Delete(namespace,cid) -} - -//delete the deployment mole-operator -//other init moudles should be deleted, do that when have time -func deleteInitResource(ctx context.Context,namespace,clusterid string)error{ - cid,err := strconv.Atoi(clusterid) - if err != nil{ - log.Errorf("[namespace_client_info]: convert clusterid %s to int error %v",clusterid,err) - return err - } - tbsc,err := modelkube.DeployNamespaceList.Get(namespace,cid) - if err != nil{ - return err - } - if tbsc == nil{ - return nil - } - - cache,err := kube.ClusterNsClientCache.GetClusterNsClient(clusterid).GetClientCache(kube.ImportType(tbsc.Type)) - if err != nil{ - return err - } - d := deployment.New() - d.Namespace = namespace - //set the fixed value for mole operator. - //it should be change when have time - d.Name = "mole-operator" - err = cache.GetClient(namespace).Delete(ctx,d) - if err != nil{ - if err, b := err.(*errors.StatusError); b { - if err.Status().Reason == metav1.StatusReasonNotFound { - return nil - } - } - return err - } - return nil -} diff --git a/chengying-server/matrix/k8s/resource/namespace_event.go b/chengying-server/matrix/k8s/resource/namespace_event.go deleted file mode 100644 index e1c46c6..0000000 --- a/chengying-server/matrix/k8s/resource/namespace_event.go +++ /dev/null @@ -1,73 +0,0 @@ -// Licensed to Apache Software Foundation(ASF) under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. Apache Software Foundation(ASF) licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -package resource - -import ( - "dtstack.com/dtstack/easymatrix/matrix/api/k8s/view" - "dtstack.com/dtstack/easymatrix/matrix/log" - modelkube "dtstack.com/dtstack/easymatrix/matrix/model/kube" - "strconv" -) -func NamsapceEvent(clusterid,namespace string, limit,start int) (*view.NamespaceEventRsp,error){ - cid,err := strconv.Atoi(clusterid) - if err != nil{ - log.Errorf("[namespace_event]: convert %s to int error: %v",clusterid,err) - return nil,err - } - tbsc,err := modelkube.DeployNamespaceList.Get(namespace,cid) - if err != nil{ - return nil,err - } - if tbsc == nil{ - return nil,nil - } - worksapceid := tbsc.Id - events,err := namsapceEventItems(worksapceid,limit,start) - if err!= nil{ - return nil,err - } - count,err := modelkube.DeployNamespaceEvent.SelectCount(worksapceid) - if err != nil{ - return nil,err - } - return &view.NamespaceEventRsp{ - Size: count, - Events: events, - },nil -} -func namsapceEventItems(workspaceid,limit,start int) ([]view.NamespaceEvent,error){ - - tbscs, err := modelkube.DeployNamespaceEvent.PageSelect(workspaceid,start,limit) - if err != nil{ - return nil,err - } - events := make([]view.NamespaceEvent,0,len(tbscs)) - for _,tbsc := range tbscs{ - e := view.NamespaceEvent{ - Id: tbsc.Id, - Time: tbsc.Time.Format("2006-01-02 15:04:05"), - Type: tbsc.Type, - Reason: tbsc.Reason, - Resource: tbsc.Resource, - Message: tbsc.Message, - } - events = append(events,e) - } - return events,nil - -} diff --git a/chengying-server/matrix/k8s/resource/namespace_init.go b/chengying-server/matrix/k8s/resource/namespace_init.go deleted file mode 100644 index f2bdfd4..0000000 --- a/chengying-server/matrix/k8s/resource/namespace_init.go +++ /dev/null @@ -1,439 +0,0 @@ -// Licensed to Apache Software Foundation(ASF) under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. Apache Software Foundation(ASF) licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -package resource - -import ( - "bytes" - "context" - "dtstack.com/dtstack/easymatrix/addons/operator/pkg/controller/model" - "dtstack.com/dtstack/easymatrix/matrix/api/k8s/view" - "dtstack.com/dtstack/easymatrix/matrix/k8s/constant" - "dtstack.com/dtstack/easymatrix/matrix/k8s/kube" - "dtstack.com/dtstack/easymatrix/matrix/k8s/resource/configmap" - "dtstack.com/dtstack/easymatrix/matrix/k8s/resource/deployment" - "dtstack.com/dtstack/easymatrix/matrix/k8s/resource/role" - "dtstack.com/dtstack/easymatrix/matrix/k8s/resource/rolebinding" - "dtstack.com/dtstack/easymatrix/matrix/k8s/resource/secret" - "dtstack.com/dtstack/easymatrix/matrix/k8s/resource/serviceaccount" - "dtstack.com/dtstack/easymatrix/matrix/log" - modelkube "dtstack.com/dtstack/easymatrix/matrix/model/kube" - "fmt" - "html/template" - corev1 "k8s.io/api/core/v1" - "k8s.io/apimachinery/pkg/runtime" - "os" - "strconv" - "strings" -) - -func Save(ctx context.Context, clusterID string, user string, vo *view.NamespaceSaveReq) error { - status := constant.NAMESPACE_NOT_CONNECT - var cache kube.ClientCache - var lastCache kube.ClientCache - var err error - //init clientcache - if vo.Type == kube.IMPORT_KUBECONFIG.String() { - cache, err = kube.ClusterNsClientCache.GetClusterNsClient(clusterID).GetClientCache(kube.IMPORT_KUBECONFIG) - if err != nil { - return err - } - if cache != nil { - lastCache = cache.Copy() - } - if err = kubeconfigClientInit(ctx, cache, vo); err != nil { - return err - } - } else if vo.Type == kube.IMPORT_AGENT.String() { - if len(vo.Ip) != 0 && len(vo.Port) != 0 { - cache, err = kube.ClusterNsClientCache.GetClusterNsClient(clusterID).GetClientCache(kube.IMPORT_AGENT) - if err != nil { - return err - } - if cache != nil { - lastCache = cache.Copy() - } - if err = agentClientInit(ctx, cache, vo); err != nil { - return err - } - } - } else { - return fmt.Errorf("[namespace_init]: unknow import type %s", vo.Type) - } - cid, err := strconv.Atoi(clusterID) - if err != nil { - return fmt.Errorf("[namespace_init]: clusterid %s is illegal", clusterID) - } - // apply init resource - if cache != nil { - namespace := vo.Namespace - registryid := vo.RegistryId - nsTbsc, err := modelkube.DeployNamespaceList.Get(vo.Namespace, cid) - if err != nil { - return err - } - //when input the ip and port, it will in - if vo.Type == kube.IMPORT_AGENT.String() { - if nsTbsc == nil { - return fmt.Errorf("something is wrong, the namespace should be exist") - } - registryid = nsTbsc.RegistryId - } else { - if err := ping(cache.GetClient(namespace), namespace); err != nil { - return err - } - } - //either new or update namespace, apply the optional and required object - //namespaceInit create mole operator deployment - err = namespaceInit(ctx, cache, namespace, registryid, cid) - if err != nil { - if lastCache != nil { - kube.ClusterNsClientCache.GetClusterNsClient(clusterID).PutNsClient(lastCache) - } - return err - } - status = constant.NAMESPACE_VALID - } - - //operate mysql - //add the ip and port is specail - if len(vo.Ip) != 0 && len(vo.Port) != 0 { - nsTbsc, err := modelkube.DeployNamespaceList.Get(vo.Namespace, cid) - if err != nil { - return err - } - if nsTbsc == nil { - return fmt.Errorf("update ip and port something is wrong, the namespace should be exist") - } - nsTbsc.Ip = vo.Ip - nsTbsc.Port = vo.Port - nsTbsc.Status = status - vo = &nsTbsc.NamespaceSaveReq - err = modelkube.DeployNamespaceList.Update(nsTbsc) - if err != nil { - return err - } - } else { - //new namespace,insert namespace record into deploy_namespace_list and deploy_namespace_client - if vo.Id == 0 { - tbsc := &modelkube.DeployNamespaceListSchema{ - ClusterId: cid, - NamespaceSaveReq: *vo, - IsDeleted: 0, - User: user, - Status: status, - } - id, err := modelkube.DeployNamespaceList.Insert(tbsc) - if err != nil { - return err - } - vo.Id = id - nsclientSc := &modelkube.DeployNamespaceClientSchema{ - Yaml: vo.Yaml, - NamespaceId: int(id), - Filename: vo.FileName, - } - if err = modelkube.DeployNamespaceClient.Insert(nsclientSc); err != nil { - return err - } - } else { - //update namespace - nsTbsc, err := modelkube.DeployNamespaceList.Get(vo.Namespace, cid) - if err != nil { - return err - } - if nsTbsc == nil { - return fmt.Errorf("update namespace something is wrong, the namespace should be exist") - } - vo.Ip = nsTbsc.Ip - vo.Port = nsTbsc.Port - nsTbsc.Status = status - nsTbsc.User = user - nsTbsc.NamespaceSaveReq = *vo - err = modelkube.DeployNamespaceList.Update(nsTbsc) - if err != nil { - return err - } - nsclientSc := &modelkube.DeployNamespaceClientSchema{ - Yaml: vo.Yaml, - NamespaceId: nsTbsc.Id, - Filename: vo.FileName, - } - if err = modelkube.DeployNamespaceClient.Update(nsclientSc); err != nil { - return err - } - } - } - //if the namespaced client is built, do some goroutine job(start easymonitor for list and watch pod、deployment、service、event resource) - if cache != nil { - if err = StartGoroutines(ctx, clusterID, vo); err != nil { - return err - } - } - return nil -} - -func agentClientInit(ctx context.Context, cache kube.ClientCache, vo *view.NamespaceSaveReq) error { - ip := vo.Ip - port := vo.Port - if !strings.HasPrefix(ip, "http") { - ip = "http://" + ip - } - host := ip + ":" + port - cache.Connect(host, vo.Namespace) - return nil - -} - -//use kubeconfig to build client with k8s -func kubeconfigClientInit(ctx context.Context, cache kube.ClientCache, vo *view.NamespaceSaveReq) error { - err := cache.Connect(vo.Yaml, vo.Namespace) - if err != nil { - return err - } - return nil -} - -//install dockerconfigjson secret, operator deployment required -//sa,role,rolebinding optional -func namespaceInit(ctx context.Context, cache kube.ClientCache, namespace string, registryId, clusterid int) error { - logType := "promtail" - logServerAddress := "loki:3000" - logImage := "promtail:latest" - - _, exist := os.LookupEnv("LOG_SERVER_ADDRESS") - if exist { - logServerAddress = os.Getenv("LOG_SERVER_ADDRESS") - } - - _, exist = os.LookupEnv("LOG_IMAGE") - if exist { - logImage = os.Getenv("LOG_IMAGE") - if !strings.Contains(logImage, "promtail") { - logType = "filebeat" - } - } - - logSwitch, err := strconv.ParseBool(os.Getenv(model.ENV_LOG_SWITCH)) - if err != nil { - logSwitch = false - } - - c := cache.GetClient(namespace) - // get mole operator resource template(deployment、role、rolebinding、sa)from import_init_moudle table - moudle, err := modelkube.ImportInitMoudle.GetInitMoudle() - if err != nil { - return err - } - // get mole operator k8s resource object(role、rolebinding、sa、configmap) from template - objects, err := generateOptional(moudle, namespace) - if err != nil { - return err - } - //if saName = "",the cluster can't create sa,role and rolebinding, that means the namespace has default sa for use. - saName := "" - for k, obj := range objects { - - if err := c.Apply(ctx, obj); err != nil { - saName = "" - break - } - if k == serviceaccount.GVK.Kind { - sa := serviceaccount.Convert(obj) - saName = sa.Name - } - } - // get mole operator k8s resource object(secret、deployment) from template - tbsc, err := modelkube.DeployClusterImageStore.GetById(registryId) - if err != nil { - return err - } - if tbsc == nil { - return fmt.Errorf("the registry of %d is nil in the database", registryId) - } - - objs, err := generateRequired(moudle, namespace, tbsc, clusterid) - if err != nil { - return err - } - - for k, v := range objs { - if len(saName) != 0 && k == deployment.GVK.Kind { - deploy := deployment.Convert(v) - deploy.Spec.Template.Spec.ServiceAccountName = saName - - currentEnvs := deploy.Spec.Template.Spec.Containers[0].Env - switchEnv := corev1.EnvVar{ - Name: model.ENV_LOG_SWITCH, - Value: strconv.FormatBool(logSwitch), - } - logEnvVars := []corev1.EnvVar{} - if logSwitch { - logEnvVars = []corev1.EnvVar{ - { - Name: "LOG_IMAGE", - Value: fmt.Sprintf("%s/%s", tbsc.Address, logImage), - }, - { - Name: "LOG_TYPE", - Value: logType, - }, - { - Name: "LOG_SERVER_ADDRESS", - Value: logServerAddress, - }, - } - } - currentEnvs = append(currentEnvs, switchEnv) - currentEnvs = append(currentEnvs, logEnvVars...) - deploy.Spec.Template.Spec.Containers[0].Env = currentEnvs - } - if err := c.Apply(ctx, v); err != nil { - return err - } - } - - return nil -} - -func getDefaultWithEnv(key, defaultValue string) string { - v, ok := os.LookupEnv(key) - if !ok { - return defaultValue - } - return v -} - -func createMoleImage(registryUrl string) string { - image := getDefaultWithEnv("MOLE_IMAGE", "easymatrix/operator:apadp1.23.3") - if !strings.HasSuffix(registryUrl, "/") { - registryUrl = registryUrl + "/" - } - if strings.HasPrefix(image, "/") { - image = strings.TrimPrefix(image, "/") - } - return registryUrl + image -} - -//secret of type dockerconfigjson and mole operator is required -func generateRequired(sc *modelkube.ImportInitMoudleSchema, namespace string, tbsc *modelkube.DeployClusterImageStoreSchema, clusterId int) (map[string]runtime.Object, error) { - // dockerconfigjson secret - objects := map[string]runtime.Object{} - //tbsc, err := modelkube.DeployClusterImageStore.GetById(registryId) - clusterImageStore, err := modelkube.DeployClusterImageStore.GetByClusterId(clusterId) - if err != nil { - return nil, err - } - //if tbsc == nil { - // return nil, fmt.Errorf("the registry of %d is nil in the database", registryId) - //} - se, err := secret.GetDockerConfigJson(clusterImageStore, namespace, tbsc.Alias) - if err != nil { - return nil, err - } - objects[secret.GVK.Kind] = se - - // mole operator - var buf bytes.Buffer - if len(sc.Operator) == 0 { - return nil, fmt.Errorf("[namespace_init]: operator is not exist, please check") - } - data := map[string]string{ - "NAME_SPACE": namespace, - "MOLE_IMAGE": createMoleImage(tbsc.Address), - "SECRET_NAME": se.Name, - } - if err := generateTemplate("operator", sc.Operator, data, &buf); err != nil { - return nil, err - } - deploy, err := deployment.ToObject(buf.Bytes()) - if err != nil { - return nil, err - } - objects[deployment.GVK.Kind] = deploy - return objects, nil -} - -//servicaaccount,role and rolebinding is optional. -func generateOptional(sc *modelkube.ImportInitMoudleSchema, namespace string) (map[string]runtime.Object, error) { - - var buf bytes.Buffer - objects := map[string]runtime.Object{} - data := map[string]string{"NAME_SPACE": namespace} - // serviceaccount - if len(sc.ServiceAccount) != 0 { - if err := generateTemplate("sa", sc.ServiceAccount, data, &buf); err != nil { - return nil, err - } - sa, err := serviceaccount.ToObject(buf.Bytes()) - if err != nil { - return nil, err - } - buf.Reset() - objects[serviceaccount.GVK.Kind] = sa - } - //role - if len(sc.Role) != 0 { - if err := generateTemplate("role", sc.Role, data, &buf); err != nil { - return nil, err - } - r, err := role.ToObject(buf.Bytes()) - if err != nil { - return nil, err - } - buf.Reset() - objects[role.GVK.Kind] = r - } - //rolebinding - if len(sc.RoleBinding) != 0 { - if err := generateTemplate("rolebinding", sc.RoleBinding, data, &buf); err != nil { - return nil, err - } - rb, err := rolebinding.ToObject(buf.Bytes()) - if err != nil { - return nil, err - } - buf.Reset() - objects[rolebinding.GVK.Kind] = rb - } - // configmap for log - if len(sc.LogConfig) != 0 { - if err := generateTemplate("logconfig", sc.LogConfig, data, &buf); err != nil { - return nil, err - } - config, err := configmap.ToObject(buf.Bytes()) - if err != nil { - return nil, err - } - objects[configmap.GVK.Kind] = config - } - return objects, nil -} - -func generateTemplate(tplname string, tpl string, data interface{}, buf *bytes.Buffer) error { - t, err := template.New(tplname).Parse(tpl) - if err != nil { - log.Errorf("[namespace_init]: parse %s template error: %v", tplname, err) - return err - } - err = t.Execute(buf, data) - if err != nil { - log.Errorf("[namespace_init] generate %s template error: %v", tplname, err) - return err - } - return nil -} diff --git a/chengying-server/matrix/k8s/resource/namespace_list.go b/chengying-server/matrix/k8s/resource/namespace_list.go deleted file mode 100644 index 8c01aca..0000000 --- a/chengying-server/matrix/k8s/resource/namespace_list.go +++ /dev/null @@ -1,57 +0,0 @@ -// Licensed to Apache Software Foundation(ASF) under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. Apache Software Foundation(ASF) licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -package resource - -import ( - "dtstack.com/dtstack/easymatrix/matrix/k8s/constant" - "dtstack.com/dtstack/easymatrix/matrix/model" - modelkube "dtstack.com/dtstack/easymatrix/matrix/model/kube" - "strconv" -) -type NamespaceListRsp struct { - ClusterName string `json:"cluster_name"` - ClusterId int `json:"cluster_id"` - ClusterType string `json:"cluster_type"` - Namespaces []Namespace `json:"namespaces"` -} - -type Namespace struct { - Name string `json:"namespace"` -} -func NamespaceList(info *model.ClusterInfo) (*NamespaceListRsp,error) { - nstbscs,err := modelkube.DeployNamespaceList.Select(strconv.Itoa(info.Id),constant.NAMESPACE_VALID,"","","") - if err != nil{ - return nil,err - } - if nstbscs == nil { - return nil,nil - } - nsList := []Namespace{} - for _, tbsc := range nstbscs{ - ns := Namespace{ - Name: tbsc.Namespace, - } - nsList = append(nsList,ns) - } - return &NamespaceListRsp{ - ClusterId: info.Id, - ClusterType: info.Type, - ClusterName: info.Name, - Namespaces: nsList, - },nil -} diff --git a/chengying-server/matrix/k8s/resource/namespace_ping.go b/chengying-server/matrix/k8s/resource/namespace_ping.go deleted file mode 100644 index a21b27b..0000000 --- a/chengying-server/matrix/k8s/resource/namespace_ping.go +++ /dev/null @@ -1,74 +0,0 @@ -// Licensed to Apache Software Foundation(ASF) under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. Apache Software Foundation(ASF) licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -package resource - -import ( - "context" - "dtstack.com/dtstack/easymatrix/matrix/api/k8s/view" - "dtstack.com/dtstack/easymatrix/matrix/k8s/kube" - "dtstack.com/dtstack/easymatrix/matrix/k8s/resource/configmap" - "dtstack.com/dtstack/easymatrix/matrix/k8s/resource/deployment" - "dtstack.com/dtstack/easymatrix/matrix/k8s/resource/mole" - "dtstack.com/dtstack/easymatrix/matrix/k8s/resource/resourcequota" - "dtstack.com/dtstack/easymatrix/matrix/k8s/resource/secret" - "dtstack.com/dtstack/easymatrix/matrix/k8s/resource/service" - "strings" -) - -func NamespacePing(ctx context.Context,clusterid string,vo *view.NamespacePingReq) error{ - cache,err := kube.ClusterNsClientCache.GetClusterNsClient(clusterid).GetClientCache(kube.IMPORT_AGENT) - if err != nil{ - return err - } - ip := vo.Ip - port := vo.Port - if !strings.HasPrefix(ip,"http"){ - ip = "http://"+ip - } - host := ip + ":" +port - ns := vo.Namespace - err = cache.Connect(host,ns) - if err != nil{ - return err - } - client := cache.GetClient(ns) - return ping(client,ns) -} - -func ping(client kube.Client, ns string) error{ - var err error - if err = service.Ping(client,ns); err != nil{ - return err - } - if err = secret.Ping(client,ns); err != nil{ - return err - } - if err = resourcequota.Ping(client,ns); err != nil{ - return err - } - if err = mole.Ping(client,ns); err != nil{ - return err - } - if err = deployment.Ping(client,ns); err != nil{ - return err - } - if err = configmap.Ping(client,ns); err != nil{ - return err - } - return nil -} diff --git a/chengying-server/matrix/k8s/resource/namespace_status.go b/chengying-server/matrix/k8s/resource/namespace_status.go deleted file mode 100644 index fc98d57..0000000 --- a/chengying-server/matrix/k8s/resource/namespace_status.go +++ /dev/null @@ -1,121 +0,0 @@ -// Licensed to Apache Software Foundation(ASF) under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. Apache Software Foundation(ASF) licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -package resource - -import ( - "context" - "dtstack.com/dtstack/easymatrix/matrix/api/k8s/view" - "dtstack.com/dtstack/easymatrix/matrix/k8s/constant" - "dtstack.com/dtstack/easymatrix/matrix/k8s/kube" - "dtstack.com/dtstack/easymatrix/matrix/k8s/resource/resourcequota" - modelkube "dtstack.com/dtstack/easymatrix/matrix/model/kube" - corev1 "k8s.io/api/core/v1" - "math" - "strconv" -) - -func GetNamespaceListStatus (ctx context.Context, clusterid,status,desc,typ string)([]view.NamespaceStatusRsp,error){ - - return GetNamespaceStatus(ctx,"",clusterid,status,desc,typ) -} - -//the namespace is support like. so get the namespaced client by namesapce, can't use the namespace input -func GetNamespaceStatus(ctx context.Context, namespace, clusterId, status, descStr, typ string)([]view.NamespaceStatusRsp,error){ - tbscs,err := modelkube.DeployNamespaceList.Select(clusterId,status,descStr,namespace,typ) - if err != nil{ - return nil, err - } - if tbscs == nil{ - return nil, nil - } - return getStatus(ctx,clusterId,tbscs) -} - -func getStatus(ctx context.Context, clusterId string, namespacelist []modelkube.DeployNamespaceListSchema) ([]view.NamespaceStatusRsp,error){ - resp := make([]view.NamespaceStatusRsp,0,len(namespacelist)) - for _,tbsc := range namespacelist{ - var quota *corev1.ResourceQuota - if tbsc.Status == constant.NAMESPACE_VALID{ - clientCache,err := kube.ClusterNsClientCache.GetClusterNsClient(clusterId).GetClientCache(kube.ImportType(tbsc.Type)) - if err != nil{ - return nil, err - } - quota,err = resourcequota.Get(ctx,clientCache.GetClient(tbsc.Namespace),tbsc.Namespace) - if err != nil{ - return nil,err - } - } - - cpuUsed := "--" - cpuTotal := "--" - memUsed := "--" - memTotal := "--" - var cpupercent float64 - var mempercent float64 - - if quota != nil{ - - r := quota.Status.Hard["limits.cpu"] - //this value's unit is m - cpuTotalfloat := float64(r.MilliValue()) - cpuTotal = formatFloat(cpuTotalfloat/1000,2)+"core" - - r = quota.Status.Hard["limits.memory"] - //this value's unit is byte - memTotalfloat := float64(r.Value()) - memTotal = formatFloat(memTotalfloat/1024/1024/1024,2)+"GB" - - r = quota.Status.Used["limits.cpu"] - cpuUsedfloadt := float64(r.MilliValue()) - cpuUsed = formatFloat(cpuUsedfloadt/1000,2)+"core" - - r = quota.Status.Used["limits.memory"] - memUsedfloat := float64(r.Value()) - memUsed = formatFloat(memUsedfloat/1024/1024/1024,2)+"GB" - - cpupercent = (cpuUsedfloadt*100)/cpuTotalfloat - mempercent = (memUsedfloat*100)/memTotalfloat - - } - result := view.NamespaceStatusRsp{ - Id: tbsc.Id, - Namespace: tbsc.Namespace, - Status: tbsc.Status, - CpuUsed: cpuUsed, - CpuTotal: cpuTotal, - CpuPercent: cpupercent, - MemUsed: memUsed, - MemTotal: memTotal, - MemPercent: mempercent, - User: tbsc.User, - UpdateTime: tbsc.UpdateTime.Format(constant.DATE_FORMAT), - Type: tbsc.Type, - - } - resp = append(resp,result) - } - return resp,nil -} - -func formatFloat(num float64, decimal int) string{ - d := float64(1) - if decimal > 0 { - d = math.Pow10(decimal) - } - return strconv.FormatFloat(math.Trunc(num*d)/d, 'f', -1, 64) -} diff --git a/chengying-server/matrix/k8s/resource/pod/pod.go b/chengying-server/matrix/k8s/resource/pod/pod.go deleted file mode 100644 index a080330..0000000 --- a/chengying-server/matrix/k8s/resource/pod/pod.go +++ /dev/null @@ -1,26 +0,0 @@ -// Licensed to Apache Software Foundation(ASF) under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. Apache Software Foundation(ASF) licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -package pod - -import "k8s.io/apimachinery/pkg/runtime/schema" - -var GVK = schema.GroupVersionKind{ - Group: "", - Version: "v1", - Kind: "Pod", -} diff --git a/chengying-server/matrix/k8s/resource/products.go b/chengying-server/matrix/k8s/resource/products.go deleted file mode 100644 index 6d889a2..0000000 --- a/chengying-server/matrix/k8s/resource/products.go +++ /dev/null @@ -1,410 +0,0 @@ -// Licensed to Apache Software Foundation(ASF) under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. Apache Software Foundation(ASF) licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -package resource - -import ( - "context" - molemodel "dtstack.com/dtstack/easymatrix/addons/operator/pkg/controller/model" - "dtstack.com/dtstack/easymatrix/addons/operator/pkg/controller/workload/support" - "dtstack.com/dtstack/easymatrix/addons/operator/pkg/util" - "dtstack.com/dtstack/easymatrix/matrix/api/k8s/view" - "dtstack.com/dtstack/easymatrix/matrix/k8s/kube" - "dtstack.com/dtstack/easymatrix/matrix/k8s/resource/deployment" - "dtstack.com/dtstack/easymatrix/matrix/k8s/resource/endpoints" - "dtstack.com/dtstack/easymatrix/matrix/k8s/resource/job" - "dtstack.com/dtstack/easymatrix/matrix/k8s/resource/workload" - "dtstack.com/dtstack/easymatrix/matrix/log" - modelkube "dtstack.com/dtstack/easymatrix/matrix/model/kube" - "dtstack.com/dtstack/easymatrix/matrix/model/kube/union" - "dtstack.com/dtstack/easymatrix/schema" - batchv1 "k8s.io/api/batch/v1" - "strconv" - "strings" -) - -func GetParentProductList(namespace,clusterid string) (*view.NamespacedProductsRsp,error){ - products,err := getAll(namespace,clusterid) - if err != nil{ - return nil, err - } - for k,_ := range products{ - products[k] = nil - } - return &view.NamespacedProductsRsp{ - Size: len(products), - Products: products, - },nil -} -//get product name below parentproduct -func GetProductList(namespace,clusterid,parentproductName string) (*view.NamespacedProductsRsp,error){ - products,err := getByParentProduct(namespace,clusterid,parentproductName) - if err != nil{ - return nil, err - } - for _,pp := range products{ - for pn,_ := range pp{ - pp[pn] = nil - } - } - return &view.NamespacedProductsRsp{ - Size: len(products), - Products: products, - },nil -} - -func GetServiceList(namespace,clusterid,parentproductName,productName string) (*view.NamespacedProductsRsp,error){ - products,err := getByProduct(namespace,clusterid,parentproductName,productName) - if err != nil{ - return nil, err - } - for _,pp := range products{ - for _,p := range pp{ - for sn,_ := range p{ - p[sn] = nil - } - } - } - return &view.NamespacedProductsRsp{ - Size: len(products), - Products: products, - },nil -} - -func GetService(ctx context.Context,namespace,clusterid, parentproductName, productName, serviceName string) (*view.NamespacedProductsRsp,error){ - products,err := getByService(namespace,clusterid, parentproductName, productName, serviceName) - if err != nil{ - return nil,err - } - cid,err := strconv.Atoi(clusterid) - if err != nil{ - log.Errorf("[resource products]: convert clusterid %s to int error %v",clusterid,err) - } - tbsc,err := modelkube.DeployNamespaceList.Get(namespace,cid) - if err != nil{ - return nil,err - } - if tbsc == nil{ - return nil,nil - } - cache,err := kube.ClusterNsClientCache.GetClusterNsClient(clusterid).GetClientCache(kube.ImportType(tbsc.Type)) - if err != nil{ - return nil,err - } - setServiceStatus(ctx,cache,namespace,&products) - return &view.NamespacedProductsRsp{ - Size: len(products), - Products: products, - },nil -} - -func setServiceStatus(ctx context.Context,cache kube.ClientCache,namespace string, products *view.Products ) error{ - for ppn,pp := range *products{ - for pn,p := range pp{ - for sn,_ := range p{ - svc := p[sn] - // workload type installl - if len(svc.WorkloadType) != 0{ - wl := workload.New() - wl.Name = util.BuildWorkloadName(pn.String(),sn.String()) - wl.Namespace = namespace - _,err := cache.GetClient(namespace).Get(ctx,wl) - if err != nil{ - return err - } - endPointsAdress := map[string]struct{}{} - replica := 0 - for _, part := range wl.Spec.WorkLoadParts{ - typ := part.BaseWorkLoad.Type - if typ == support.WorkloadTypeDeployment || typ == support.WorkloadTypeStatefulset{ - partReplica,err := workload.FieldGet(part.BaseWorkLoad.Parameters.Object,"spec.replicas") - if err != nil{ - return err - } - replica = replica + int(partReplica.(float64)) - for _,step := range part.Steps{ - if step.Type != support.CreateTypeService{ - continue - } - svcName := util.BuildStepName(util.BuildBaseName(wl.Name,part.BaseWorkLoad.Name),step.Name) - endpoints := endpoints.New() - endpoints.Namespace = namespace - endpoints.Name = svcName - exist,err := cache.GetClient(namespace).Get(ctx,endpoints) - if err != nil{ - return err - } - if !exist{ - continue - } - for _, adress := range endpoints.Subsets[0].Addresses{ - endPointsAdress[adress.TargetRef.Name] = struct{}{} - } - } - } - } - ensureHealth(len(endPointsAdress),replica,svc) - continue - } - // the job type of mole install - if svc.IsJob{ - jobName := molemodel.BuildResourceName(molemodel.MoleJobName,ppn.String(),pn.String(),sn.String()) - job := job.New() - job.Name = jobName - job.Namespace = namespace - exist,err := cache.GetClient(namespace).Get(ctx,job) - if err != nil{ - return err - } - if !exist{ - job = nil - } - ensureHealthByJob(job,svc) - continue - } - // the deployment of mole install - svcName := molemodel.BuildResourceName(molemodel.MoleServiceName,ppn.String(),pn.String(),sn.String()) - endpoints := endpoints.New() - endpoints.Namespace = namespace - endpoints.Name = svcName - exist,err := cache.GetClient(namespace).Get(ctx,endpoints) - if err != nil{ - return err - } - succeed := 0 - if exist{ - if len(endpoints.Subsets) >0 && len(endpoints.Subsets[0].Addresses) > 0{ - succeed = len(endpoints.Subsets[0].Addresses) - } - } - - deployName := molemodel.BuildResourceName(molemodel.MoleDeploymentName,ppn.String(),pn.String(),sn.String()) - deploy := deployment.New() - deploy.Namespace = namespace - deploy.Name = deployName - exist,err = cache.GetClient(namespace).Get(ctx,deploy) - if err != nil{ - return err - } - replica := 0 - if exist{ - replica = int(*deploy.Spec.Replicas) - } - ensureHealth(succeed,replica,svc) - } - } - } - return nil -} - -func ensureHealth(succeed int, desired int, svc *view.Service){ - healthState := "unhealthy" - healthStateCount := 0 - serviceStatus := "unavailable" - serviecStatusCount := 0 - if succeed >0 { - serviceStatus = "available" - serviecStatusCount = succeed - } - if serviceStatus == "available"{ - if desired == serviecStatusCount{ - healthState = "healthy" - healthStateCount = serviecStatusCount - }else{ - healthState = "unhealthy" - healthStateCount = desired - serviecStatusCount - } - }else{ - healthState = "unhealthy" - healthStateCount = desired - serviceStatus = "unavailable" - serviecStatusCount = desired - } - svc.HealthState = healthState - svc.HealthStateCount = healthStateCount - svc.ServiceStatus = serviceStatus - svc.ServiecStatusCount = serviecStatusCount -} - -func ensureHealthByJob(job *batchv1.Job, svc *view.Service){ - - svc.ServiceStatus = "available" - svc.ServiecStatusCount = 0 - svc.HealthState = "healthy" - svc.HealthStateCount = 0 - - if job == nil{ - svc.ServiceStatus = "unavailable" - svc.HealthState = "unhealthy" - } - desired := job.Spec.Completions - succeed := job.Status.Succeeded - if desired != nil{ - if *desired == succeed{ - svc.ServiceStatus = "available" - svc.ServiecStatusCount = int(succeed) - svc.HealthState = "healthy" - svc.HealthStateCount = int(succeed) - }else{ - svc.ServiceStatus = "unavailable" - svc.ServiecStatusCount =int(*desired) - svc.HealthState = "unhealthy" - svc.HealthStateCount = int(*desired - succeed) - - } - }else{ - if succeed >0 { - svc.ServiceStatus = "available" - svc.ServiecStatusCount = int(succeed) - svc.HealthState = "healthy" - svc.HealthStateCount = int(succeed) - } - } -} - -//func ensureHealthByEndpoints(endpoints *corev1.Endpoints, replica int, svc *view.Service){ -// -// healthState := "unhealthy" -// healthStateCount := 0 -// serviceStatus := "unavailable" -// serviecStatusCount := 0 -// if endpoints != nil{ -// if len(endpoints.Subsets) >0 && len(endpoints.Subsets[0].Addresses) > 0{ -// serviceStatus = "available" -// serviecStatusCount = len(endpoints.Subsets[0].Addresses) -// } -// } -// if serviceStatus == "available"{ -// if replica == serviecStatusCount{ -// healthState = "healthy" -// healthStateCount = serviecStatusCount -// }else{ -// healthState = "unhealthy" -// healthStateCount = replica - serviecStatusCount -// } -// }else{ -// healthState = "unhealthy" -// healthStateCount = replica -// serviceStatus = "unavailable" -// serviecStatusCount = replica -// } -// svc.HealthState = healthState -// svc.HealthStateCount = healthStateCount -// svc.ServiceStatus = serviceStatus -// svc.ServiecStatusCount = serviecStatusCount -//} - -func getByService(namespace,clusterid, parentproductName, productName, serviceName string) (view.Products,error){ - products,err := getByProduct(namespace,clusterid,parentproductName,productName) - if err != nil{ - return nil, err - } - if serviceName == "all"{ - return products,nil - } - result := view.Products{} - for ppn,pp := range products{ - parentproduct := view.ParentProduct{} - result[ppn] = parentproduct - for pn,p := range pp{ - prouct := view.Product{} - parentproduct[pn] = prouct - for sn,s := range p{ - if strings.Contains(strings.ToLower(string(sn)),strings.ToLower(serviceName)){ - prouct[sn] = s - } - } - } - } - return result,nil -} - -func getByProduct(namespace,clusterid, parentproductName, productName string) (view.Products,error){ - products,err := getByParentProduct(namespace,clusterid,parentproductName) - if err != nil{ - return nil, err - } - if productName == "all"{ - return products,nil - } - reslut := view.Products{} - for ppn,pp := range products{ - parentproduct := view.ParentProduct{} - reslut[ppn] = parentproduct - for pn,p := range pp{ - if string(pn) == productName{ - parentproduct[pn] = p - } - } - } - return reslut,nil -} - -func getByParentProduct(namespace,clusterid, parentproductName string) (view.Products,error){ - products,err := getAll(namespace,clusterid) - if err != nil{ - return nil, err - } - if parentproductName == "all"{ - return products,nil - } - parentProduct := products[view.ParentProductName(parentproductName)] - result := view.Products{} - result[view.ParentProductName(parentproductName)] = parentProduct - return result,nil -} - -func getAll(namespace,clusterid string) (view.Products,error){ - cid,err := strconv.Atoi(clusterid) - if err != nil{ - log.Errorf("[products]: convert clusterid %s to int error %v",clusterid,err) - return nil,err - } - tbscs ,err := union.UnionT4T7.SelectParentProduct(cid,namespace) - if err != nil{ - return nil ,err - } - products := view.Products{} - for _,tbsc := range tbscs{ - config,err := schema.Unmarshal(tbsc.Product) - if err != nil{ - return nil,err - } - parent,exist := products[view.ParentProductName(config.ParentProductName)]; - if !exist{ - parent = view.ParentProduct{} - products[view.ParentProductName(tbsc.ParentProductName)] = parent - } - product := view.Product{} - for k,v := range config.Service{ - if v.Instance == nil{ - continue - } - service := view.Service{ - Version: v.Version, - Group: v.Group, - IsJob: v.IsJob, - } - if len(v.Workload) != 0{ - service.WorkloadType = v.Workload - } - product[view.ServiceName(k)] = &service - } - parent[view.ProudctName(config.ProductName)] = product - } - return products,nil -} diff --git a/chengying-server/matrix/k8s/resource/resourcequota/resourcequota.go b/chengying-server/matrix/k8s/resource/resourcequota/resourcequota.go deleted file mode 100644 index a3bb125..0000000 --- a/chengying-server/matrix/k8s/resource/resourcequota/resourcequota.go +++ /dev/null @@ -1,65 +0,0 @@ -// Licensed to Apache Software Foundation(ASF) under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. Apache Software Foundation(ASF) licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -package resourcequota - -import ( - "context" - "dtstack.com/dtstack/easymatrix/matrix/k8s/kube" - "fmt" - corev1 "k8s.io/api/core/v1" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/runtime/schema" -) - -var GVK = schema.GroupVersionKind{ - Group: "", - Version: "v1", - Kind: "ResourceQuota", -} -func New() *corev1.ResourceQuota{ - return &corev1.ResourceQuota{} -} - -func Get(ctx context.Context,client kube.Client, namespace string) (*corev1.ResourceQuota,error){ - if client == nil{ - return nil,fmt.Errorf("the namespace client is not exist") - } - quotas := &corev1.ResourceQuotaList{} - if err := client.List(ctx,quotas,namespace);err != nil{ - return nil,err - } - if len(quotas.Items) == 0{ - return nil,nil - } - quota := quotas.Items[0] - return "a,nil -} - -func Ping(client kube.Client, namespace string) error{ - ping := &corev1.ResourceQuota{ - ObjectMeta: metav1.ObjectMeta{ - Namespace: namespace, - Name: "dtstack-dryru", - }, - } - if _,err := client.Get(context.Background(),ping);err != nil{ - return err - } - return nil -} - diff --git a/chengying-server/matrix/k8s/resource/role/role.go b/chengying-server/matrix/k8s/resource/role/role.go deleted file mode 100644 index 55ce53f..0000000 --- a/chengying-server/matrix/k8s/resource/role/role.go +++ /dev/null @@ -1,47 +0,0 @@ -// Licensed to Apache Software Foundation(ASF) under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. Apache Software Foundation(ASF) licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -package role - -import ( - "dtstack.com/dtstack/easymatrix/addons/easykube/pkg/client/base" - "dtstack.com/dtstack/easymatrix/matrix/log" - "encoding/json" - "k8s.io/apimachinery/pkg/runtime/schema" - rbacv1 "k8s.io/api/rbac/v1" -) - -var GVK = schema.GroupVersionKind{ - Group: "rbac.authorization.k8s.io", - Version: "v1", - Kind: "Role", -} - -func ToObject(bts []byte)(*rbacv1.Role,error){ - r,err := base.Schema.New(GVK) - if err != nil{ - log.Errorf("[role]: new object error: %v",err) - return nil,err - } - err = json.Unmarshal(bts,r) - if err!= nil{ - log.Errorf("[role]: json %s unmarshal error: %v",string(bts),err) - return nil,err - } - role := r.(*rbacv1.Role) - return role,nil -} diff --git a/chengying-server/matrix/k8s/resource/rolebinding/role_binding.go b/chengying-server/matrix/k8s/resource/rolebinding/role_binding.go deleted file mode 100644 index dfcaaf8..0000000 --- a/chengying-server/matrix/k8s/resource/rolebinding/role_binding.go +++ /dev/null @@ -1,47 +0,0 @@ -// Licensed to Apache Software Foundation(ASF) under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. Apache Software Foundation(ASF) licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -package rolebinding - -import ( - "dtstack.com/dtstack/easymatrix/addons/easykube/pkg/client/base" - "dtstack.com/dtstack/easymatrix/matrix/log" - "encoding/json" - rbacv1 "k8s.io/api/rbac/v1" - "k8s.io/apimachinery/pkg/runtime/schema" -) - -var GVK = schema.GroupVersionKind{ - Group: "rbac.authorization.k8s.io", - Version: "v1", - Kind: "RoleBinding", -} - -func ToObject(bts []byte)(*rbacv1.RoleBinding,error){ - r,err := base.Schema.New(GVK) - if err != nil{ - log.Errorf("[role_binding]: new object error: %v",err) - return nil,err - } - err = json.Unmarshal(bts,r) - if err!= nil{ - log.Errorf("[role_binding]: json %s unmarshal error: %v",string(bts),err) - return nil,err - } - sa := r.(*rbacv1.RoleBinding) - return sa,nil -} diff --git a/chengying-server/matrix/k8s/resource/secret/secret.go b/chengying-server/matrix/k8s/resource/secret/secret.go deleted file mode 100644 index 3cca5ae..0000000 --- a/chengying-server/matrix/k8s/resource/secret/secret.go +++ /dev/null @@ -1,111 +0,0 @@ -// Licensed to Apache Software Foundation(ASF) under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. Apache Software Foundation(ASF) licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -package secret - -import ( - "context" - "dtstack.com/dtstack/easymatrix/addons/easykube/pkg/client/base" - "dtstack.com/dtstack/easymatrix/matrix/k8s/kube" - "dtstack.com/dtstack/easymatrix/matrix/log" - modelkube "dtstack.com/dtstack/easymatrix/matrix/model/kube" - "encoding/base64" - "encoding/json" - corev1 "k8s.io/api/core/v1" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/runtime" - "k8s.io/apimachinery/pkg/runtime/schema" -) -var GVK = schema.GroupVersionKind{ - Group: "", - Version: "v1", - Kind: "Secret", -} - -func Convert(obj runtime.Object) *corev1.Secret{ - return obj.(*corev1.Secret) -} -func GetDockerConfigJson(tbsc *[]modelkube.DeployClusterImageStoreSchema,namespace string, registryName string) (*corev1.Secret,error){ - dockerConfigJson,err := getDockerConfigAuth(tbsc) - if err != nil{ - return nil,err - } - // 生成镜像仓库认证信息的secret - secret := &corev1.Secret{ - ObjectMeta: metav1.ObjectMeta{ - Name: registryName, - Namespace:namespace, - }, - Data: dockerConfigJson, - Type: corev1.SecretTypeDockerConfigJson, - } - return secret,nil -} - -func getDockerConfigAuth(tbsc *[]modelkube.DeployClusterImageStoreSchema) (map[string][]byte,error) { - // 创建多个镜像仓库的认证口令信息 - Dockerconfig := make(map[string]interface{},0) - multiauths := make(map[string]interface{},0) - for _,registry := range *tbsc{ - src := []byte(registry.Username + ":" + registry.Password) - dst := make([]byte, base64.StdEncoding.EncodedLen(len(src))) - base64.StdEncoding.Encode(dst, src) - multiauths[registry.Address]=map[string]interface{}{ - "username": registry.Username, - "password": registry.Password, - "auth": string(dst), - } - - } - Dockerconfig["auths"] = multiauths - //src := []byte(tbsc.Username + ":" + tbsc.Password) - //dst := make([]byte, base64.StdEncoding.EncodedLen(len(src))) - //base64.StdEncoding.Encode(dst, src) - //m := map[string]interface{}{ - // - // "auths": map[string]interface{}{ - // tbsc.Address: map[string]interface{}{ - // "username": tbsc.Username, - // "password": tbsc.Password, - // "auth": string(dst), - // }, - // }, - //} - bts,err := json.Marshal(Dockerconfig) - if err != nil{ - log.Errorf("[secret]: json mashal dockerconfigjson err %v",err) - return nil,err - } - return map[string][]byte{corev1.DockerConfigJsonKey:bts},nil -} - -func Ping(client kube.Client, namespace string) error{ - ping := &corev1.Secret{ - ObjectMeta: metav1.ObjectMeta{ - Namespace: namespace, - Name: "dtstack-dryru", - }, - } - if _,err := client.Get(context.Background(),ping);err != nil{ - return err - } - - if err := client.DryRun(base.Create,ping);err != nil{ - return err - } - return nil -} diff --git a/chengying-server/matrix/k8s/resource/service/service.go b/chengying-server/matrix/k8s/resource/service/service.go deleted file mode 100644 index 2de4178..0000000 --- a/chengying-server/matrix/k8s/resource/service/service.go +++ /dev/null @@ -1,65 +0,0 @@ -// Licensed to Apache Software Foundation(ASF) under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. Apache Software Foundation(ASF) licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -package service - -import ( - "context" - "dtstack.com/dtstack/easymatrix/addons/easykube/pkg/client/base" - "dtstack.com/dtstack/easymatrix/matrix/k8s/kube" - corev1 "k8s.io/api/core/v1" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/runtime/schema" -) -var GVK = schema.GroupVersionKind{ - Group: "", - Version: "v1", - Kind: "Service", -} - -func New() *corev1.Service{ - return &corev1.Service{} -} - -func Ping(client kube.Client, namespace string) error{ - ping := &corev1.Service{ - TypeMeta: metav1.TypeMeta{ - Kind: GVK.Kind, - APIVersion: GVK.Group+"/"+GVK.Version, - }, - ObjectMeta: metav1.ObjectMeta{ - Namespace: namespace, - Name: "dtstack-dryru", - }, - Spec: corev1.ServiceSpec{ - Ports: []corev1.ServicePort{ - { - Port: 5555, - }, - }, - }, - Status: corev1.ServiceStatus{}, - } - if _,err := client.Get(context.Background(),ping);err != nil{ - return err - } - - if err := client.DryRun(base.Create,ping);err != nil{ - return err - } - return nil -} diff --git a/chengying-server/matrix/k8s/resource/serviceaccount/service_account.go b/chengying-server/matrix/k8s/resource/serviceaccount/service_account.go deleted file mode 100644 index 5b5b5cc..0000000 --- a/chengying-server/matrix/k8s/resource/serviceaccount/service_account.go +++ /dev/null @@ -1,71 +0,0 @@ -// Licensed to Apache Software Foundation(ASF) under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. Apache Software Foundation(ASF) licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -package serviceaccount - -import ( - "context" - "dtstack.com/dtstack/easymatrix/addons/easykube/pkg/client/base" - "dtstack.com/dtstack/easymatrix/matrix/k8s/kube" - "dtstack.com/dtstack/easymatrix/matrix/log" - "encoding/json" - corev1 "k8s.io/api/core/v1" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/runtime" - "k8s.io/apimachinery/pkg/runtime/schema" -) - -var GVK = schema.GroupVersionKind{ - Group: "", - Version: "v1", - Kind: "ServiceAccount", -} - -func Convert(obj runtime.Object) *corev1.ServiceAccount{ - return obj.(*corev1.ServiceAccount) -} -func ToObject(bts []byte)(*corev1.ServiceAccount,error){ - r,err := base.Schema.New(GVK) - if err != nil{ - log.Errorf("[service_account]: new object error: %v",err) - return nil,err - } - err = json.Unmarshal(bts,r) - if err!= nil{ - log.Errorf("[service_account]: json %s unmarshal error: %v",string(bts),err) - return nil,err - } - sa := r.(*corev1.ServiceAccount) - return sa,nil -} - -func Ping(client kube.Client, namespace string) error{ - sa := &corev1.ServiceAccount{ - ObjectMeta: metav1.ObjectMeta{ - Namespace: namespace, - Name: "dtstack-dryrun", - }, - } - if _,err := client.Get(context.Background(),sa);err != nil{ - return err - } - - if err := client.DryRun(base.Create,sa);err != nil{ - return err - } - return nil -} diff --git a/chengying-server/matrix/k8s/resource/workload/workload.go b/chengying-server/matrix/k8s/resource/workload/workload.go deleted file mode 100644 index 798887e..0000000 --- a/chengying-server/matrix/k8s/resource/workload/workload.go +++ /dev/null @@ -1,321 +0,0 @@ -// Licensed to Apache Software Foundation(ASF) under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. Apache Software Foundation(ASF) licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -package workload - -import ( - workloadv1beta1 "dtstack.com/dtstack/easymatrix/addons/operator/pkg/apis/workload/v1beta1" - "dtstack.com/dtstack/easymatrix/addons/operator/pkg/util" - "dtstack.com/dtstack/easymatrix/matrix/base" - "dtstack.com/dtstack/easymatrix/matrix/log" - "dtstack.com/dtstack/easymatrix/matrix/model" - modelkube "dtstack.com/dtstack/easymatrix/matrix/model/kube" - matrixSchema "dtstack.com/dtstack/easymatrix/schema" - "encoding/json" - "k8s.io/apimachinery/pkg/runtime/schema" - "path/filepath" - "strconv" - "strings" -) - -var GVK = schema.GroupVersionKind{ - Group: "dtstack.com", - Version: "v1beta1", - Kind: "WorkLoad", -} - -type Builder struct { - Def *modelkube.WorkloadDefinitionSchema - Parts []modelkube.WorkloaPartSchema - Steps map[int][]modelkube.WorloadStepSchema - Schema *matrixSchema.SchemaConfig - ProductName string - ServiceName string - Namespace string - Store *model.ImageStore -} - -func New() *workloadv1beta1.WorkLoad { - return &workloadv1beta1.WorkLoad{} -} - -func (g *Builder) Build() (*workloadv1beta1.WorkLoad, error) { - parts, err := g.buildParts() - if err != nil { - return nil, err - } - workload := &workloadv1beta1.WorkLoad{ - Spec: workloadv1beta1.WorkLoadSpec{ - WorkLoadParts: parts, - }, - } - if err = g.FieldSet(workload); err != nil { - return nil, err - } - if workload.Annotations == nil { - workload.Annotations = map[string]string{} - } - workload.Annotations["type"] = g.Def.Name - workload.Annotations["version"] = g.Def.Version - return workload, nil - -} - -func (g *Builder) buildParts() ([]workloadv1beta1.WorkLoadPart, error) { - - parts := make([]workloadv1beta1.WorkLoadPart, 0, len(g.Parts)) - - for _, part := range g.Parts { - steps, err := g.buildSteps(part.Id, part.Name) - if err != nil { - return nil, err - } - m := map[string]interface{}{} - if err = json.Unmarshal([]byte(part.Parameters), &m); err != nil { - log.Errorf("[workload] unmashal part parameters %s to map[string]interface{} fail", part.Parameters) - return nil, err - } - g.parse(m, part.Name, g.WorkloadName()) - - //处理往容器中添加自定义host映射 - podSpec := map[string]interface{}{} - - hostAlias := g.Schema.Service[g.ServiceName].Instance.HostAlias - if hostAlias != nil { - hostAliases := []map[string]interface{}{} - - //["ip:hostname","ip:hostname"] - ipAndhostname := strings.Split(*hostAlias, ",") - - for _, alias := range ipAndhostname { - tmpalias := map[string]interface{}{} - ipHost := strings.Split(alias, ":") - - tmpalias["ip"] = ipHost[0] - tmpalias["hostnames"] = []string{ipHost[1]} - hostAliases = append(hostAliases, tmpalias) - } - - imagePullSecret := map[string]interface{}{ - "spec": map[string]interface{}{ - "template": map[string]interface{}{ - "spec": map[string]interface{}{ - "imagePullSecrets": []map[string]string{ - {"name": g.Store.Alias}, - }, - "hostAliases": hostAliases, - }, - }, - }, - } - - podSpec = imagePullSecret - } else { - //set imagepullsecret - imagePullSecret := map[string]interface{}{ - "spec": map[string]interface{}{ - "template": map[string]interface{}{ - "spec": map[string]interface{}{ - "imagePullSecrets": []map[string]string{ - {"name": g.Store.Alias}, - }, - }, - }, - }, - } - - podSpec = imagePullSecret - } - - util.DeepCopy(podSpec, m) - p := workloadv1beta1.WorkLoadPart{ - BaseWorkLoad: workloadv1beta1.BaseWorkLoad{ - Type: part.Type, - Name: part.Name, - Parameters: workloadv1beta1.Object{Object: m}, - }, - Steps: steps, - } - parts = append(parts, p) - } - return parts, nil -} - -func (g *Builder) buildSteps(partId int, partName string) ([]workloadv1beta1.WorkLoadPartStep, error) { - steps := g.Steps[partId] - workloadSteps := make([]workloadv1beta1.WorkLoadPartStep, 0, len(steps)) - for _, step := range steps { - m := map[string]interface{}{} - if err := json.Unmarshal([]byte(step.Object), &m); err != nil { - log.Errorf("[workload] unmashal step Object %s to map[string]interface{} fail", step.Object) - return nil, err - } - //parse @xxx - m = g.parse(m, partName, g.WorkloadName()).(map[string]interface{}) - st := workloadv1beta1.WorkLoadPartStep{ - Name: step.Name, - Type: step.Type, - Action: workloadv1beta1.ComponentAction(step.Action), - Object: workloadv1beta1.Object{Object: m}, - } - workloadSteps = append(workloadSteps, st) - } - return workloadSteps, nil -} - -func (g *Builder) FieldSet(workload *workloadv1beta1.WorkLoad) error { - instance := g.Schema.Service[g.ServiceName].Instance - if instance == nil { - return nil - } - instanceMap, err := util.ToMap(instance) - if err != nil { - log.Errorf("[workload] ServiceConfig to map fail, error %v", err) - return err - } - workloadMap, err := util.ToMap(workload) - if err != nil { - log.Errorf("[workload] WorkLoad to map fail,error %v", err) - return err - } - //deal schema's config_path - if err = g.Schema.ParseServiceVariable(g.ServiceName); err != nil { - log.Errorf("parse servie %s fail, error: %v", g.ServiceName, err) - return err - } - if len(instance.ConfigPaths) > 0 { - configmap := map[string]string{} - baseDir := filepath.Join(base.WebRoot, g.Schema.ProductName, g.Schema.ProductVersion) - contents, err := g.Schema.ParseServiceConfigFiles(baseDir, g.ServiceName) - if err != nil { - log.Errorf("parse %s config variables to config file fail,error:%v", g.ServiceName, err) - return err - } - for index, content := range contents { - fileName := instance.ConfigPaths[index] - - fileName = fileName[strings.LastIndex(fileName, "/")+1:] - configmap[fileName] = string(content[:]) - } - instanceMap["ConfigPaths"] = configmap - } - - params := g.Def.Params.ToStruct() - for _, param := range params { - v, err := FieldGet(instanceMap, param.Key) - if err != nil { - return err - } - if v == nil { - continue - } - if err = FieldSet(workloadMap, param.Ref, v); err != nil { - return err - } - } - if err = util.ToObject(workloadMap, workload); err != nil { - return err - } - return nil -} - -func (g *Builder) WorkloadName() string { - return util.BuildWorkloadName(g.ProductName, g.ServiceName) -} - -func FieldGet(data interface{}, key string) (interface{}, error) { - v := data - for _, field := range strings.Split(key, ".") { - switch v.(type) { - case map[string]interface{}: - m := v.(map[string]interface{}) - v = m[field] - case []interface{}: - sl := v.([]interface{}) - index, err := strconv.Atoi(field) - if err != nil { - log.Errorf("[resource/workload]: field get convert field to int err, field %s, error %v", field, err) - return nil, err - } - v = sl[index] - } - } - return v, nil -} - -func FieldSet(data interface{}, key string, value interface{}) error { - v := data - fields := strings.Split(key, ".") - l := len(fields) - - for i, field := range strings.Split(key, ".") { - switch v.(type) { - case map[string]interface{}: - m := v.(map[string]interface{}) - if i == l-1 { - m[field] = value - continue - } - v = m[field] - case []interface{}: - sl := v.([]interface{}) - index, err := strconv.Atoi(field) - if err != nil { - log.Errorf("[resource/workload]: field get convert field to int err, field %s, error %v", field, err) - return err - } - if i == l-1 { - sl[index] = value - continue - } - v = sl[index] - } - } - return nil -} - -func (g *Builder) parse(obj interface{}, partName, workloadName string) interface{} { - switch obj.(type) { - case map[string]interface{}: - m := obj.(map[string]interface{}) - for k, v := range m { - if k == "image" { - m[k] = g.Store.Address + "/" + v.(string) - continue - } - m[k] = g.parse(v, partName, workloadName) - } - return m - case []interface{}: - sl := obj.([]interface{}) - for i, v := range sl { - sl[i] = g.parse(v, partName, workloadName) - } - return sl - case string: - s := obj.(string) - if strings.Contains(s, "@") { - if s[1:] == partName { - return util.BuildBaseName(workloadName, partName) - } - return util.BuildStepName(util.BuildBaseName(workloadName, partName), s[1:]) - } - return s - default: - return obj - } -} diff --git a/chengying-server/matrix/k8s/resource/workloadprocess/workloadprocess.go b/chengying-server/matrix/k8s/resource/workloadprocess/workloadprocess.go deleted file mode 100644 index 27f4601..0000000 --- a/chengying-server/matrix/k8s/resource/workloadprocess/workloadprocess.go +++ /dev/null @@ -1,33 +0,0 @@ -// Licensed to Apache Software Foundation(ASF) under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. Apache Software Foundation(ASF) licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -package workloadprocess - -import ( - workloadv1beta1 "dtstack.com/dtstack/easymatrix/addons/operator/pkg/apis/workload/v1beta1" - "k8s.io/apimachinery/pkg/runtime/schema" -) - -var GVK = schema.GroupVersionKind{ - Group: "dtstack.com", - Version: "v1beta1", - Kind: "WorkloadProcess", -} - -func New() *workloadv1beta1.WorkloadProcess{ - return &workloadv1beta1.WorkloadProcess{} -} diff --git a/chengying-server/matrix/k8s/util/util.go b/chengying-server/matrix/k8s/util/util.go deleted file mode 100644 index 8599cd2..0000000 --- a/chengying-server/matrix/k8s/util/util.go +++ /dev/null @@ -1,151 +0,0 @@ -// Licensed to Apache Software Foundation(ASF) under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. Apache Software Foundation(ASF) licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -package util - -import ( - "bytes" - "dtstack.com/dtstack/easymatrix/matrix/k8s/constant" - "fmt" - "os" - "os/exec" - "strconv" - "syscall" -) - -// GetExitCode returns the ExitStatus of the specified error if its type is -// exec.ExitError, returns 0 and an error otherwise. -func GetExitCode(err error) (int, error) { - exitCode := 0 - if exiterr, ok := err.(*exec.ExitError); ok { - if procExit, ok := exiterr.Sys().(syscall.WaitStatus); ok { - return procExit.ExitStatus(), nil - } - } - return exitCode, fmt.Errorf("failed to get exit code") -} - -// ProcessExitCode process the specified error and returns the exit status code -// if the error was of type exec.ExitError, returns nothing otherwise. -func ProcessExitCode(err error) (exitCode int) { - if err != nil { - var exiterr error - if exitCode, exiterr = GetExitCode(err); exiterr != nil { - // TODO: Fix this so we check the error's text. - // we've failed to retrieve exit code, so we set it to 127 - exitCode = 127 - } - } - return -} - -// copy from os/exec/exec.go -// PrefixSuffixSaver is an io.Writer which retains the first N bytes -// and the last N bytes written to it. The Bytes() methods reconstructs -// it with a pretty error message. -type PrefixSuffixSaver struct { - N int // max size of prefix or suffix - prefix []byte - suffix []byte // ring buffer once len(suffix) == N - suffixOff int // offset to write into suffix - skipped int64 - - // TODO(bradfitz): we could keep one large []byte and use part of it for - // the prefix, reserve space for the '... Omitting N bytes ...' message, - // then the ring buffer suffix, and just rearrange the ring buffer - // suffix when Bytes() is called, but it doesn't seem worth it for - // now just for error messages. It's only ~64KB anyway. -} - -func (w *PrefixSuffixSaver) Write(p []byte) (n int, err error) { - lenp := len(p) - p = w.fill(&w.prefix, p) - - // Only keep the last w.N bytes of suffix data. - if overage := len(p) - w.N; overage > 0 { - p = p[overage:] - w.skipped += int64(overage) - } - p = w.fill(&w.suffix, p) - - // w.suffix is full now if p is non-empty. Overwrite it in a circle. - for len(p) > 0 { // 0, 1, or 2 iterations. - n := copy(w.suffix[w.suffixOff:], p) - p = p[n:] - w.skipped += int64(n) - w.suffixOff += n - if w.suffixOff == w.N { - w.suffixOff = 0 - } - } - return lenp, nil -} - -// fill appends up to len(p) bytes of p to *dst, such that *dst does not -// grow larger than w.N. It returns the un-appended suffix of p. -func (w *PrefixSuffixSaver) fill(dst *[]byte, p []byte) (pRemain []byte) { - if remain := w.N - len(*dst); remain > 0 { - add := minInt(len(p), remain) - *dst = append(*dst, p[:add]...) - p = p[add:] - } - return p -} - -func (w *PrefixSuffixSaver) Bytes() []byte { - if w.suffix == nil { - return w.prefix - } - if w.skipped == 0 { - return append(w.prefix, w.suffix...) - } - var buf bytes.Buffer - buf.Grow(len(w.prefix) + len(w.suffix) + 50) - buf.Write(w.prefix) - buf.WriteString("\n... omitting ") - buf.WriteString(strconv.FormatInt(w.skipped, 10)) - buf.WriteString(" bytes ...\n") - buf.Write(w.suffix[w.suffixOff:]) - buf.Write(w.suffix[:w.suffixOff]) - return buf.Bytes() -} - -func minInt(a, b int) int { - if a < b { - return a - } - return b -} - -func Env(environment map[string]string) []string { - if len(environment) == 0 { - return nil - } - env := os.Environ() - for k, v := range environment { - env = append(env, k+"="+v) - } - return env -} - -func BuildClusterLogName(name string, id int) string { - return fmt.Sprintf("%v%v_%v.log", constant.ClusterStoreDir, name, id) -} - -func BuildProductLogName(clusterName, namespace string, clusterId, pid int) string { - return fmt.Sprintf("%v%v_%v_%v_%v.log", constant.ClusterStoreDir, clusterName, namespace, clusterId, pid) -} diff --git a/chengying-server/matrix/k8s/util/util_darwin.go b/chengying-server/matrix/k8s/util/util_darwin.go deleted file mode 100644 index 428b3e5..0000000 --- a/chengying-server/matrix/k8s/util/util_darwin.go +++ /dev/null @@ -1,87 +0,0 @@ -// Licensed to Apache Software Foundation(ASF) under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. Apache Software Foundation(ASF) licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -package util - -import ( - "io/ioutil" - "os" - "path/filepath" - "strconv" - "sync" - "time" -) - -var randmu sync.Mutex -var rand uint32 - -func CreateTempScript(content string, prefix string) (path string, err error) { - f, err := ioutil.TempFile("", prefix) - if err != nil { - return "", err - } - - if _, err = f.WriteString(content); err != nil { - f.Close() - os.Remove(f.Name()) - return "", err - } - if err = os.Chmod(f.Name(), 0500); err != nil { - f.Close() - os.Remove(f.Name()) - return "", err - } - - f.Close() - return f.Name(), nil -} -func reseed() uint32 { - return uint32(time.Now().UnixNano() + int64(os.Getpid())) -} -func NewFile(dir, fname string) (f *os.File, err error) { - if dir == "" { - dir = os.TempDir() - } - nconflict := 0 - for i := 0; i < 10000; i++ { - name := filepath.Join(dir, fname) - f, err = os.OpenFile(name, os.O_RDWR|os.O_CREATE|os.O_EXCL, 0600) - if os.IsExist(err) { - os.Rename(name, name+nextRandom()) - if nconflict++; nconflict > 10 { - randmu.Lock() - rand = reseed() - randmu.Unlock() - } - continue - } - break - } - return -} - -func nextRandom() string { - randmu.Lock() - r := rand - if r == 0 { - r = reseed() - } - r = r*1664525 + 1013904223 // constants from Numerical Recipes - rand = r - randmu.Unlock() - return strconv.Itoa(int(1e9 + r%1e9))[1:] -} diff --git a/chengying-server/matrix/k8s/util/util_linux.go b/chengying-server/matrix/k8s/util/util_linux.go deleted file mode 100644 index ef8425c..0000000 --- a/chengying-server/matrix/k8s/util/util_linux.go +++ /dev/null @@ -1,101 +0,0 @@ -// Licensed to Apache Software Foundation(ASF) under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. Apache Software Foundation(ASF) licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -package util - -import ( - "io/ioutil" - "os" - "path/filepath" - "strconv" - "sync" - "time" -) - -// Random number state. -// We generate random temporary file names so that there's a good -// chance the file doesn't exist yet - keeps the number of tries in -// TempFile to a minimum. -var rand uint32 -var randmu sync.Mutex - -func reseed() uint32 { - return uint32(time.Now().UnixNano() + int64(os.Getpid())) -} - -func CreateTempScript(content string, prefix string) (path string, err error) { - f, err := ioutil.TempFile("", prefix) - if err != nil { - return "", err - } - - if _, err = f.WriteString(content); err != nil { - f.Close() - os.Remove(f.Name()) - return "", err - } - if err = os.Chmod(f.Name(), 0500); err != nil { - f.Close() - os.Remove(f.Name()) - return "", err - } - - f.Close() - return f.Name(), nil -} - -func nextRandom() string { - randmu.Lock() - r := rand - if r == 0 { - r = reseed() - } - r = r*1664525 + 1013904223 // constants from Numerical Recipes - rand = r - randmu.Unlock() - return strconv.Itoa(int(1e9 + r%1e9))[1:] -} - -// NewFile creates a new file in the directory dir, -// opens the file for reading and writing, and returns the resulting *os.File. -// The filename is generated by taking pattern -// If dir is the empty string, NewFile uses the default directory -// for temporary files (see os.TempDir). -// The caller can use f.Name() -// to find the pathname of the file. It is the caller's responsibility -// to remove the file when no longer needed. -func NewFile(dir, fname string) (f *os.File, err error) { - if dir == "" { - dir = os.TempDir() - } - nconflict := 0 - for i := 0; i < 10000; i++ { - name := filepath.Join(dir, fname) - f, err = os.OpenFile(name, os.O_RDWR|os.O_CREATE|os.O_EXCL, 0600) - if os.IsExist(err) { - os.Rename(name, name+nextRandom()) - if nconflict++; nconflict > 10 { - randmu.Lock() - rand = reseed() - randmu.Unlock() - } - continue - } - break - } - return -} diff --git a/chengying-server/matrix/k8s/xke-service/driver/rke_driver.go b/chengying-server/matrix/k8s/xke-service/driver/rke_driver.go deleted file mode 100644 index 200c64b..0000000 --- a/chengying-server/matrix/k8s/xke-service/driver/rke_driver.go +++ /dev/null @@ -1,124 +0,0 @@ -// Licensed to Apache Software Foundation(ASF) under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. Apache Software Foundation(ASF) licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -package driver - -import ( - "bytes" - "context" - "dtstack.com/dtstack/easymatrix/matrix/k8s/constant" - "dtstack.com/dtstack/easymatrix/matrix/k8s/util" - kutil "dtstack.com/dtstack/easymatrix/matrix/k8s/util" - "dtstack.com/dtstack/easymatrix/matrix/log" - mutil "dtstack.com/dtstack/easymatrix/matrix/util" - "fmt" - "os" - "os/exec" - "time" -) - -func RkeCreate(clusterName, config string, clusterId int) error { - ctx, cancel := context.WithTimeout(context.Background(), 10*time.Minute) - defer cancel() - - configf, err := createRkeConfig(clusterName, config) - if err != nil { - log.Errorf("%v", err) - return err - } - rkeBin, err := getRunTimeBin("rke") - if err != nil { - return err - } - param := []string{"up", "--config", configf} - cmd := exec.CommandContext(ctx, rkeBin, param...) - - //logf, err := ioutil.TempFile(k8s.ClusterStoreDir, cluster+"*.log") - logf, err := os.OpenFile(kutil.BuildClusterLogName(clusterName, clusterId), os.O_RDWR|os.O_CREATE|os.O_APPEND, 0766) - if err != nil { - return err - } - defer logf.Close() - cmd.Stdout = logf - cmd.Stderr = logf - - if err := cmd.Run(); err != nil { - log.Errorf("%v", err) - return err - } - return nil -} - -func createRkeConfig(clusterName, config string) (string, error) { - f, err := util.NewFile(constant.ClusterStoreDir, clusterName+constant.TEMPLATE_SUFFIX) - if err != nil { - return "", err - } - defer f.Close() - if _, err = f.WriteString(config); err != nil { - return "", err - } - return f.Name(), nil -} - -func getClusterKubeconfigF(clusterName string) (string, error) { - config := constant.ClusterStoreDir + "kube_config_" + clusterName + constant.TEMPLATE_SUFFIX - if !mutil.IsPathExist(config) { - return "", fmt.Errorf("%v not exist!", config) - } - return config, nil -} - -func getRunTimeBin(name string) (string, error) { - bin := constant.RuntimeBinDir + name - if !mutil.IsPathExist(bin) { - return "", fmt.Errorf("%v not exist!", bin) - } - return bin, nil -} - -func DeployWithKubeCtl(clusterName, yaml string) error { - buf := bytes.NewBufferString(yaml) - kubeConfig, err := getClusterKubeconfigF(clusterName) - if err != nil { - return err - } - kubeCtl, err := getRunTimeBin("kubectl") - if err != nil { - return err - } - cmd := exec.Command(kubeCtl, "--kubeconfig", kubeConfig, "apply", "-f", "-") - cmd.Stdin = buf - cmd.Stdout = os.Stdout - cmd.Stderr = os.Stderr - return cmd.Run() -} - -func DeployWithKubeCtlWithFile(clusterName, file string) error { - kubeConfig, err := getClusterKubeconfigF(clusterName) - fmt.Println("-----------------------kubeconfig------------------------",kubeConfig) - fmt.Println("---------------------------file-----------------------------",file) - if err != nil { - return err - } - kubeCtl, err := getRunTimeBin("kubectl") - if err != nil { - return err - } - cmd := exec.Command(kubeCtl, "--kubeconfig", kubeConfig, "apply", "-f", file) - return cmd.Run() -} diff --git a/chengying-server/matrix/k8s/xke-service/driver/types.go b/chengying-server/matrix/k8s/xke-service/driver/types.go deleted file mode 100644 index d6ead61..0000000 --- a/chengying-server/matrix/k8s/xke-service/driver/types.go +++ /dev/null @@ -1,22 +0,0 @@ -// Licensed to Apache Software Foundation(ASF) under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. Apache Software Foundation(ASF) licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -package driver - -// Driver defines the interface that each driver plugin should implement -type Driver interface { -} diff --git a/chengying-server/matrix/k8s/xke-service/rke_config_builder.go b/chengying-server/matrix/k8s/xke-service/rke_config_builder.go deleted file mode 100644 index ba7a733..0000000 --- a/chengying-server/matrix/k8s/xke-service/rke_config_builder.go +++ /dev/null @@ -1,149 +0,0 @@ -// Licensed to Apache Software Foundation(ASF) under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. Apache Software Foundation(ASF) licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -package xke_service - -import ( - "fmt" - rutil "github.com/rancher/kontainer-engine/drivers/util" - v3 "github.com/rancher/types/apis/management.cattle.io/v3" - "gopkg.in/yaml.v2" - "strings" -) - -const ( - SPLIT_SEP_ROLES = "," - DEFALT_CONFIG_RKE_SSH_KEY_PATH = "~/.ssh/id_rsa" - DEFALT_CONFIG_RKE_SSH_PORT = "22" - DEFALT_CONFIG_RKE_SSH_USER = "docker" - DEFALT_CONFIG_RKE_ROLES = "controlplane,etcd,worker" - DEFALT_CONFIG_RKE_VERSION = "v1.16.3" -) - -var ignoreDockerVersion = true - -var rkeConfigTemplate = &v3.RancherKubernetesEngineConfig{ - Version: DEFALT_CONFIG_RKE_VERSION, - Authorization: v3.AuthzConfig{ - Mode: "none", - }, - ClusterName: "dtstack", - Network: v3.NetworkConfig{ - Plugin: "flannel", - }, - IgnoreDockerVersion: &ignoreDockerVersion, - Ingress: v3.IngressConfig{ - Provider: "nginx", - }, - Monitoring: v3.MonitoringConfig{ - Provider: "metrics-server", - }, - Restore: v3.RestoreConfig{ - Restore: false, - }, -} - -func BuildRKEConfigFromRaw(raw string) (*v3.RancherKubernetesEngineConfig, error) { - rkeConfig, err := rutil.ConvertToRkeConfig(raw) - if err != nil { - return &rkeConfig, err - } - return &rkeConfig, nil -} - -func GetDefaultRKEconfig(version, clusterName, networkPlugin string) v3.RancherKubernetesEngineConfig { - tmpConfig := *rkeConfigTemplate - tmpConfig.ClusterName = clusterName - tmpConfig.Network.Plugin = networkPlugin - tmpConfig.Version = version - - return tmpConfig -} - -func GetDefaultRKEconfigRaw(version, clusterName, networkPlugin string) (string, error) { - tmpConfig := *rkeConfigTemplate - tmpConfig.ClusterName = clusterName - tmpConfig.Network.Plugin = networkPlugin - tmpConfig.Version = version - - config, err := yaml.Marshal(tmpConfig) - if err != nil { - return "", err - } - return string(config), nil -} - -func AddNodeToRawConfig(raw string, nodeIp, port, roles, sshKeyPath, user string) error { - config, err := BuildRKEConfigFromRaw(raw) - if err != nil { - return err - } - for _, node := range config.Nodes { - if node.Address == nodeIp { - return fmt.Errorf("error add, node exist %v", nodeIp) - } - } - config.Nodes = append(config.Nodes, v3.RKEConfigNode{ - Address: nodeIp, - User: user, - SSHKeyPath: sshKeyPath, - Port: port, - Role: strings.Split(roles, SPLIT_SEP_ROLES), - }) - return nil -} - -func AddNodeToConfig(config *v3.RancherKubernetesEngineConfig, nodeIp, port, roles, sshKeyPath, user string) error { - for _, node := range config.Nodes { - if node.Address == nodeIp { - return fmt.Errorf("error add, node exist %v", nodeIp) - } - } - config.Nodes = append(config.Nodes, v3.RKEConfigNode{ - Address: nodeIp, - User: user, - SSHKeyPath: sshKeyPath, - Port: port, - Role: strings.Split(roles, SPLIT_SEP_ROLES), - }) - return nil -} - -func AddDefaultNodeToConfig(config *v3.RancherKubernetesEngineConfig, nodeIp string) error { - for _, node := range config.Nodes { - if node.Address == nodeIp { - return fmt.Errorf("error add, node exist %v", nodeIp) - } - } - config.Nodes = append(config.Nodes, v3.RKEConfigNode{ - Address: nodeIp, - User: DEFALT_CONFIG_RKE_SSH_USER, - SSHKeyPath: DEFALT_CONFIG_RKE_SSH_KEY_PATH, - Port: DEFALT_CONFIG_RKE_SSH_PORT, - Role: strings.Split(DEFALT_CONFIG_RKE_ROLES, SPLIT_SEP_ROLES), - }) - return nil -} - -func RemoveNodeFromConfig(config *v3.RancherKubernetesEngineConfig, nodeIp string) { - for index, node := range config.Nodes { - if node.Address == nodeIp { - config.Nodes = append(config.Nodes[:index], config.Nodes[index+1:]...) - break - } - } -} diff --git a/chengying-server/matrix/k8s/xke-service/xke_servicer.go b/chengying-server/matrix/k8s/xke-service/xke_servicer.go deleted file mode 100644 index 6e055e3..0000000 --- a/chengying-server/matrix/k8s/xke-service/xke_servicer.go +++ /dev/null @@ -1,46 +0,0 @@ -// Licensed to Apache Software Foundation(ASF) under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. Apache Software Foundation(ASF) licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -package xke_service - -import "dtstack.com/dtstack/easymatrix/matrix/k8s/xke-service/driver" - -type XkeServicer interface { - Create(name, config string, id int) error - Deploy(name, yaml string) error - DeployWithF(name, file string) error -} - -type xkeService struct { -} - -func NewXkeService() (XkeServicer, error) { - newService := &xkeService{} - return newService, nil -} - -func (this *xkeService) Create(clusterName, config string, clusterId int) error { - return driver.RkeCreate(clusterName, config, clusterId) -} - -func (this *xkeService) Deploy(clusterName, yaml string) error { - return driver.DeployWithKubeCtl(clusterName, yaml) -} - -func (this *xkeService) DeployWithF(clusterName, file string) error { - return driver.DeployWithKubeCtlWithFile(clusterName, file) -} diff --git a/chengying-server/matrix/model/kube/T10_workload_step.go b/chengying-server/matrix/model/kube/T10_workload_step.go deleted file mode 100644 index d28c664..0000000 --- a/chengying-server/matrix/model/kube/T10_workload_step.go +++ /dev/null @@ -1,134 +0,0 @@ -// Licensed to Apache Software Foundation(ASF) under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. Apache Software Foundation(ASF) licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -package kube - -import ( - "database/sql" - "dtstack.com/dtstack/easymatrix/matrix/log" - "dtstack.com/dtstack/easymatrix/matrix/model" - "github.com/jmoiron/sqlx" -) - -var( - getStepSql = "select * from workload_step where workloadpart_id = :workloadpart_id order by id asc" - getStepByTypeSql = "select * from workload_step where workloadpart_id = :workloadpart_id and type = :type" - getStepSts *sqlx.NamedStmt - getStepByTypeSts *sqlx.NamedStmt - WorkloadStep = &workloadStep{ - PrepareFunc: prepareWorkload, - } -) - -func prepareWorkload()error{ - var err error - getStepSts,err = model.USE_MYSQL_DB().PrepareNamed(getStepSql) - if err != nil{ - log.Errorf("[kube workload_step]: init sql: %s , error %v",getStepSql,err) - return err - } - getStepByTypeSts,err = model.USE_MYSQL_DB().PrepareNamed(getStepByTypeSql) - if err != nil{ - log.Errorf("[[kube workload_step]: init sql: %s, error %v]",getStepByTypeSql,err) - } - return nil -} - -type workloadStep struct { - PrepareFunc -} -type WorloadStepSchema struct { - Id int `db:"id""` - Name string `db:"name"` - Type string `db:"type"` - Action string `db:"action"` - Object string `db:"object"` - WorkloadPartId int `db:"workloadpart_id"` -} - -func (w *workloadStep) SelectType(workloadPartId int, typ string) ([]WorloadStepSchema,error){ - arg := &WorloadStepSchema{ - WorkloadPartId: workloadPartId, - Type: typ, - } - rows,err := getStepByTypeSts.Queryx(arg) - if err != nil{ - log.Errorf("[kube workload_step] select sql %s, workloadpartid %d, type %s, error %v",getStepByTypeSql,workloadPartId,typ,err) - return nil,err - } - result := []WorloadStepSchema{} - for rows.Next(){ - tbsc := WorloadStepSchema{} - if err = rows.StructScan(&tbsc);err != nil{ - log.Errorf("[kube workload_step] sql %s result failed struct scan to workload_part error %v",getStepByTypeSql,err) - return nil,err - } - result = append(result,tbsc) - } - if len(result) == 0{ - return nil, nil - } - return result,nil -} - -func (w *workloadStep) Select(workloadPartId int) ([]WorloadStepSchema,error){ - arg := &WorloadStepSchema{ - WorkloadPartId: workloadPartId, - } - rows,err := getStepSts.Queryx(arg) - if err != nil{ - log.Errorf("[kube workload_step] select sql %s, workloadpartid %d, error %v",getStepSql,workloadPartId,err) - return nil,err - } - result := []WorloadStepSchema{} - for rows.Next(){ - tbsc := WorloadStepSchema{} - if err = rows.StructScan(&tbsc);err != nil{ - log.Errorf("[kube workload_step] sql %s result failed struct scan to workload_part error %v",getStepSql,err) - return nil,err - } - result = append(result,tbsc) - } - if len(result) == 0{ - return nil, nil - } - return result,nil -} - -func(w *workloadStep) InsertOrUpdate(db *sqlx.Tx ,name, parttype, action,object string, workloadPartid int64)error{ - - var workloadstep WorloadStepSchema - - query := "select id,name,type,action,workloadpart_id from workload_step where name=? and workloadpart_id=?" - wkstep_insert := "insert into workload_step (name,type,action,object,workloadpart_id) values(?,?,?,?,?)" - wkstep_update := "update workload_step set object=?,type=?,action=? where id=? and workloadpart_id=?" - err:=db.Get(&workloadstep,query,name,workloadPartid) - if err == sql.ErrNoRows { - _,err:=db.Exec(wkstep_insert,name,parttype,action,object,workloadPartid) - if err !=nil { - log.Errorf("Database insert workloadpart error:%v, sql:%v\n",err,wkstep_insert) - return err - } - }else { - _,err:=db.Exec(wkstep_update,object,parttype,action,workloadstep.Id,workloadPartid) - if err !=nil { - log.Errorf("Database update workloadpart error:%v, sql:%v\n",err,wkstep_update) - return err - } - } - return nil -} \ No newline at end of file diff --git a/chengying-server/matrix/model/kube/T11_workload_part.go b/chengying-server/matrix/model/kube/T11_workload_part.go deleted file mode 100644 index c38a1f1..0000000 --- a/chengying-server/matrix/model/kube/T11_workload_part.go +++ /dev/null @@ -1,104 +0,0 @@ -// Licensed to Apache Software Foundation(ASF) under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. Apache Software Foundation(ASF) licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -package kube - -import ( - "database/sql" - "dtstack.com/dtstack/easymatrix/matrix/log" - "dtstack.com/dtstack/easymatrix/matrix/model" - "github.com/jmoiron/sqlx" -) - -var ( - getPartSql = "select * from workload_part where workload_id = :workload_id order by id asc" - getPartSts *sqlx.NamedStmt - WorkloadPart = &worloadPart{ - PrepareFunc: prepareWorkloadPart, - } -) - -func prepareWorkloadPart() error{ - var err error - getPartSts,err = model.USE_MYSQL_DB().PrepareNamed(getPartSql) - if err != nil{ - log.Errorf("[kube workload_part]: init sql: %s , error %v",getPartSql,err) - return err - } - return nil -} -type worloadPart struct { - PrepareFunc -} -type WorkloaPartSchema struct { - Id int `db:"id"` - Name string `db:"name"` - Type string `db:"type"` - Parameters string `db:"parameters"` - WorkloadID int `db:"workload_id"` -} - -func (w *worloadPart) Select(workloadId int) ([]WorkloaPartSchema,error){ - arg := &WorkloaPartSchema{ - WorkloadID: workloadId, - } - rows,err := getPartSts.Queryx(arg) - if err != nil{ - log.Errorf("[kube workload_part] select sql %s, workloadid %d, error %v",getPartSql,workloadId,err) - return nil,err - } - result := []WorkloaPartSchema{} - for rows.Next(){ - tbsc := WorkloaPartSchema{} - if err = rows.StructScan(&tbsc);err != nil{ - log.Errorf("[kube workload_part] sql %s result failed struct scan to workload_part error %v",getPartSql,err) - return nil,err - } - result = append(result,tbsc) - } - if len(result) == 0{ - return nil, nil - } - return result,nil -} - -func (w *worloadPart) InsertOrUpdate(db *sqlx.Tx,name, parttype, parameters string, workloadid int64)(workloadPartId int64, err error){ - - var workloadpart WorkloaPartSchema - var workloadpart_id int64 - - query := "select id,name,type,workload_id from workload_part where workload_id=?" - wkpart_insert := "insert into workload_part (name,type,parameters,workload_id) values(?,?,?,?)" - wkpart_update := "update workload_part set parameters=?,name=?,type=? where id=? and workload_id=?" - err=db.Get(&workloadpart,query,workloadid) - if err == sql.ErrNoRows { - relid,err:=db.Exec(wkpart_insert,name,parttype,parameters,workloadid) - if err !=nil { - log.Errorf("Database insert workloadpart error:%v, sql:%v\n",err,wkpart_insert) - return 0,err - } - workloadpart_id,_ = relid.LastInsertId() - }else { - _,err:=db.Exec(wkpart_update,parameters,name,parttype,workloadpart.Id,workloadid) - if err !=nil { - log.Errorf("Database update workloadpart error:%v, sql:%v\n",err,wkpart_update) - return 0,err - } - workloadpart_id = int64(workloadpart.Id) - } - return workloadpart_id,nil -} \ No newline at end of file diff --git a/chengying-server/matrix/model/kube/T12_workload_definition.go b/chengying-server/matrix/model/kube/T12_workload_definition.go deleted file mode 100644 index 51de189..0000000 --- a/chengying-server/matrix/model/kube/T12_workload_definition.go +++ /dev/null @@ -1,167 +0,0 @@ -// Licensed to Apache Software Foundation(ASF) under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. Apache Software Foundation(ASF) licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -package kube - -import ( - "database/sql" - "dtstack.com/dtstack/easymatrix/matrix/log" - "dtstack.com/dtstack/easymatrix/matrix/model" - "encoding/json" - "github.com/jmoiron/sqlx" -) - -var ( - getDefLatestSql = "select * from workload_definition where name = :name and latest = 1" - getDefSql = "select * from workload_definition where name = :name and version = :version" - getDefLatestSts *sqlx.NamedStmt - getDefSts *sqlx.NamedStmt - WorkloadDefinition = &workloadDefinition{ - PrepareFunc: prepareWorkloadDefinition, - } -) - -func prepareWorkloadDefinition() error { - var err error - getDefLatestSts, err = model.USE_MYSQL_DB().PrepareNamed(getDefLatestSql) - if err != nil { - log.Errorf("[kube workload_definition]: init sql: %s , error %v", getDefLatestSql, err) - return err - } - getDefSts, err = model.USE_MYSQL_DB().PrepareNamed(getDefSql) - if err != nil { - log.Errorf("[kube workload_definition]: init sql: %s , error %v", getDefSql, err) - } - return nil -} - -type workloadDefinition struct { - PrepareFunc -} -type WorkloadDefinitionSchema struct { - Id int `db:"id"` - Name string `db:"name"` - Version string `db:"version"` - Params ParamsTyp `db:"params"` - Latest int `db:"latest"` -} -type ParamsTyp string - -func (p ParamsTyp) ToStruct() []ParamStruct { - - params := []ParamStruct{} - json.Unmarshal([]byte(p), ¶ms) - return params -} - -type ParamStruct struct { - Key string `json:"key"` - Ref string `json:"ref"` -} - -// if the version is not specified, get the latest -func (w *workloadDefinition) Get(name, version string) (*WorkloadDefinitionSchema, error) { - tbsc := &WorkloadDefinitionSchema{ - Name: name, - Version: version, - } - var err error - if len(version) == 0 { - err = getDefLatestSts.Get(tbsc, tbsc) - } else { - err = getDefSts.Get(tbsc, tbsc) - } - if err != nil { - if err == sql.ErrNoRows { - return nil, nil - } - log.Errorf("[workload_definition]: get workload, sql %s, name %s, version %s, err %v", getDefLatestSql, name, version, err) - return nil, err - } - return tbsc, nil -} - -type WorkloadDefinitionYaml struct { - ApiVersion string `yaml:"apiVersion" jason:"apiVersion"` - Kind string `yaml: "kind" json:"kind"` - Metadata Metadata `yaml: "metadata" json:"metadata"` - Spec Spec `yaml: "spec" json:"spec"` -} - -type Metadata struct { - Name string `yaml:"name" json:"name"` -} - -type Spec struct { - Params []Params `yaml: "params" json:"params"` - WorkloadPatrs []WorkloadPatrs `yaml: "workloadpatrs" json:"workloadpatrs"` -} - -type Params struct { - Key string `yaml:"key" json:"key"` - Ref string `yaml:"ref" json:"ref"` -} - -type WorkloadPatrs struct { - Baseworkload Baseworkload `yaml: "baseworkload" json:"baseworkload"` - Steps []Steps `yaml: "steps" json:"steps"` -} - -type Baseworkload struct { - Type string `yaml: "type" json:"type"` - Name string `yaml: "name" json:"name"` - Parameters struct { - Spec struct { - Replicas int `yaml:"replicas" json:"replicas,omitempty"` - ServiceName string `yaml:"serviceName" json:"serviceName,omitempty"` - } `yaml:"spec" json:"spec,omitempty"` - } `yaml: "parameters" json:"parameters"` -} - -type Steps struct { - Name string `yaml: "name" json:"name"` - Type string `yaml: "type" json:"type"` - Action string `yaml: "action" json:"action"` - Object interface{} `yaml: "object" json:"object"` -} - -func (w *workloadDefinition) InsertOrUpdate(db *sqlx.Tx, name, version, params string) (workloadId int64, err error) { - workloaddef := WorkloadDefinitionSchema{} - var workload_id int64 - - query := "select id,name,version from workload_definition where name=? and version=?" - wkdef_insert := "insert into workload_definition (name,version,params,latest) values(?,?,?,1)" - wkdef_update := "update workload_definition set params=? where name=? and version=?" - err = db.Get(&workloaddef, query, name, version) - if err == sql.ErrNoRows { - relid, err := db.Exec(wkdef_insert, name, version, params) - if err != nil { - log.Errorf("Database insert workloaddefination error:%v, sql:%v\n", err, wkdef_insert) - return 0, err - } - workload_id, _ = relid.LastInsertId() - - } else { - _, err := db.Exec(wkdef_update, params, name, version) - if err != nil { - log.Errorf("Database update workloaddefination error:%v, sql:%v\n", err, wkdef_update) - return 0, err - } - workload_id = int64(workloaddef.Id) - } - return workload_id, nil -} diff --git a/chengying-server/matrix/model/kube/T1_deploy_cluster_image_store.go b/chengying-server/matrix/model/kube/T1_deploy_cluster_image_store.go deleted file mode 100644 index 07fc5b3..0000000 --- a/chengying-server/matrix/model/kube/T1_deploy_cluster_image_store.go +++ /dev/null @@ -1,105 +0,0 @@ -// Licensed to Apache Software Foundation(ASF) under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. Apache Software Foundation(ASF) licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -package kube - -import ( - "database/sql" - "dtstack.com/dtstack/easymatrix/matrix/log" - "dtstack.com/dtstack/easymatrix/matrix/model" - "github.com/jmoiron/sqlx" -) -var ( - getImageStoreByIdSql = "select * from deploy_cluster_image_store where id = :id and is_deleted = 0" - getImageStoreByIdSts *sqlx.NamedStmt - getImageStoreByClusterIdSql = "select * from deploy_cluster_image_store where clusterid = :clusterId and is_deleted = 0" - getImageStoreByClusterIdSts *sqlx.NamedStmt - DeployClusterImageStore = &deployClusterImageStore{ - PrepareFunc: prepareDeployClusterImageStore, - } -) -type deployClusterImageStore struct { - PrepareFunc -} - -func prepareDeployClusterImageStore() error{ - var err error - getImageStoreByIdSts,err = model.USE_MYSQL_DB().PrepareNamed(getImageStoreByIdSql) - if err != nil{ - log.Errorf("[kube deploy_cluster_image_store]: init sql: %s , error %v",getImageStoreByIdSql,err) - return err - } - getImageStoreByClusterIdSts,err = model.USE_MYSQL_DB().PrepareNamed(getImageStoreByClusterIdSql) - if err != nil { - log.Errorf("[kube deploy_cluster_image_store]: init sql: %s , error %v",getImageStoreByClusterIdSql,err) - return err - } - return nil -} - -type DeployClusterImageStoreSchema struct { - Id int `db:"id"` - ClusterId int `db:"clusterId"` - IsDefault int `db:"is_default"` - Name string `db:"name"` - Alias string `db:"alias"` - Address string `db:"address"` - Username string `db:"username"` - Password string `db:"password"` - Email string `db:"email"` - UpdateTime sql.NullTime `db:"update_time"` - CreateTime sql.NullTime `db:"create_time"` - IsDeleted int `db:"is_deleted"` -} - -func (s *deployClusterImageStore)GetById(id int) (*DeployClusterImageStoreSchema,error){ - sc := &DeployClusterImageStoreSchema{ - Id: id, - } - if err := getImageStoreByIdSts.Get(sc,sc);err!=nil{ - if err == sql.ErrNoRows{ - return nil,nil - } - log.Errorf("[kube deploy_cluster_image_store]: get imagestore %s by id %d error: %v",getImageStoreByIdSql,id,err) - return nil,err - } - return sc,nil -} - -func (s *deployClusterImageStore)GetByClusterId(cid int) (*[]DeployClusterImageStoreSchema,error){ - - arg := &DeployClusterImageStoreSchema{ - ClusterId: cid, - } - - rows, err := getImageStoreByClusterIdSts.Queryx(arg) - if err != nil { - log.Errorf("[kube deploy_cluster_image_store]: init sql: %s, value %+v , error %v",getImageStoreByClusterIdSql,*arg,err) - return nil,err - } - result := []DeployClusterImageStoreSchema{} - for rows.Next(){ - imageStore:= DeployClusterImageStoreSchema{} - if err = rows.StructScan(&imageStore);err != nil{ - log.Errorf("[kube deploy_cluster_image_store]: init sql: %s, error %v",getImageStoreByClusterIdSql,err) - return nil,err - } - result = append(result,imageStore) - } - - return &result,nil -} \ No newline at end of file diff --git a/chengying-server/matrix/model/kube/T2_deploy_cluster_k8s_available.go b/chengying-server/matrix/model/kube/T2_deploy_cluster_k8s_available.go deleted file mode 100644 index 1567e68..0000000 --- a/chengying-server/matrix/model/kube/T2_deploy_cluster_k8s_available.go +++ /dev/null @@ -1,99 +0,0 @@ -// Licensed to Apache Software Foundation(ASF) under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. Apache Software Foundation(ASF) licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -package kube - -import ( - dbhelper "dtstack.com/dtstack/easymatrix/go-common/db-helper" - "dtstack.com/dtstack/easymatrix/matrix/log" - "dtstack.com/dtstack/easymatrix/matrix/model" - "github.com/jmoiron/sqlx" -) - -type deployClusterK8sAvailable struct { - PrepareFunc -} -var ( - getAvailableSql = "select * from deploy_cluster_k8s_available where mode = :mode and is_deleted = 0" - getAvailableVersionSql = "select version from deploy_cluster_k8s_available where version like :version and is_deleted=0" - getAvailableSts *sqlx.NamedStmt - getAvailableVersionSts *sqlx.NamedStmt - DeployClusterK8sAvailable = &deployClusterK8sAvailable{ - PrepareFunc: prepareDeployClusterK8sAvailable, - } -) - -func prepareDeployClusterK8sAvailable() error{ - var err error - getAvailableSts,err = model.USE_MYSQL_DB().PrepareNamed(getAvailableSql) - if err != nil{ - log.Errorf("[kube cluster_k8s_availbale]: init sql: %s , error %v",getAvailableSql,err) - return err - } - getAvailableVersionSts,err = model.USE_MYSQL_DB().PrepareNamed(getAvailableVersionSql) - if err != nil{ - log.Errorf("[kube cluster_k8s_availbale]: init sql: %s, error %v",getAvailableVersionSql,err) - } - return nil -} - -type ClusterK8sAvailable struct { - Id int `db:"id"` - Mode int `db:"mode"` - Version string `db:"version"` - Properties string `db:"properties"` - UpdateTime dbhelper.NullTime `db:"update_time"` - CreateTime dbhelper.NullTime `db:"create_time"` - IsDeleted int `db:"is_deleted"` -} - -func (l *deployClusterK8sAvailable) GetClusterK8sAvailableByMode(mode int) ([]ClusterK8sAvailable, error) { - info := []ClusterK8sAvailable{} - arg := &ClusterK8sAvailable{ - Mode: mode, - } - rows,err := getAvailableSts.Queryx(arg) - if err != nil{ - log.Errorf("[kube cluster_k8s_availbale] getk8sAvailable by mode sql: %s, value: %d, error: %v",getAvailableSql,mode,err) - return nil,err - } - for rows.Next(){ - tbsc := ClusterK8sAvailable{} - if err = rows.StructScan(&tbsc); err != nil{ - log.Errorf("[kube cluster_k8s_availbale]: struct scan to ClusterK8sAvailable error :%v",err) - return nil, err - } - info = append(info, tbsc) - } - return info, nil -} - -func (l *deployClusterK8sAvailable) GetRealVersion(version string) (string, error) { - if len(version) == 0{ - return "",nil - } - version = version + "%" - available := &ClusterK8sAvailable{ - Version: version, - } - if err := getAvailableVersionSts.Get(&version,available);err != nil{ - log.Errorf("[kube cluster_k8s_available] getRealVersion sql: %s, value: %s, error: %v",getAvailableVersionSql,version,err) - return "",err - } - - return version, nil -} diff --git a/chengying-server/matrix/model/kube/T3_deploy_cluster_list.go b/chengying-server/matrix/model/kube/T3_deploy_cluster_list.go deleted file mode 100644 index 72df346..0000000 --- a/chengying-server/matrix/model/kube/T3_deploy_cluster_list.go +++ /dev/null @@ -1,118 +0,0 @@ -// Licensed to Apache Software Foundation(ASF) under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. Apache Software Foundation(ASF) licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -package kube - -import ( - "database/sql" - "dtstack.com/dtstack/easymatrix/matrix/log" - "github.com/jmoiron/sqlx" - - //apibase "dtstack.com/dtstack/easymatrix/go-common/api-base" - dbhelper "dtstack.com/dtstack/easymatrix/go-common/db-helper" - "dtstack.com/dtstack/easymatrix/matrix/model" - "fmt" -) - -var ( - getClusterSql string = "select * from deploy_cluster_list where name = :name and type = 'kubernetes' and is_deleted = :is_deleted" - insertClusterSql string = "insert into deploy_cluster_list (name,`desc`,tags,mode,configs,yaml,version,type) values (:name, :desc, :tags, :mode, :configs, :yaml, :version, 'kubernetes')" - getClusterByIdSql string = "select * from deploy_cluster_list where id = :id and is_deleted = 0" - getClusterSts *sqlx.NamedStmt - insertClusterSts *sqlx.NamedStmt - getClusterByIdSts *sqlx.NamedStmt - DeployClusterList = &deployClusterList{ - PrepareFunc: prepareDeployClusterList, - } -) -type deployClusterList struct { - PrepareFunc -} - -func prepareDeployClusterList() error{ - var err error - getClusterSts,err = model.USE_MYSQL_DB().PrepareNamed(getClusterSql) - if err != nil{ - log.Errorf("[kube cluster_list] init sql: %s , error %v",getClusterSql,err) - return err - } - insertClusterSts,err = model.USE_MYSQL_DB().PrepareNamed(insertClusterSql) - if err != nil{ - log.Errorf("[kube cluster_list] init sql: %s , error %v",insertClusterSql,err) - return err - } - getClusterByIdSts,err = model.USE_MYSQL_DB().PrepareNamed(getClusterByIdSql) - if err != nil{ - log.Errorf("[kube cluster_list] init sql: %s, error %v",getClusterByIdSql,err) - return err - } - return nil -} - - -type ClusterInfo struct { - Id int `db:"id" json:"id"` - Name string `db:"name" json:"name"` - Type string `db:"type" json:"type"` - Mode int `db:"mode" json:"mode"` - Version string `db:"version" json:"version"` - Desc string `db:"desc" json:"desc"` - Tags string `db:"tags" json:"tags"` - Configs sql.NullString `db:"configs" json:"configs"` - Yaml sql.NullString `db:"yaml" json:"yaml"` - Status int `db:"status" json:"status"` - ErrorMsg string `db:"errorMsg" json:"errorMsg"` - CreateUser string `db:"create_user" json:"create_user"` - UpdateUser string `db:"update_user" json:"update_user"` - UpdateTime dbhelper.NullTime `db:"update_time" json:"update_time"` - CreateTime dbhelper.NullTime `db:"create_time" json:"create_time"` - IsDeleted int `db:"is_deleted" json:"is_deleted"` -} - -func (l *deployClusterList) InsertK8sCluster(cluster *ClusterInfo) (int, error) { - err := getClusterSts.Get(cluster,cluster) - if err != nil && err == sql.ErrNoRows { - result,err := insertClusterSts.Exec(cluster) - if err != nil { - log.Errorf("[kube cluster_list] exec sql: %s, value: %+v, error: %v:",insertClusterSts.QueryString,*cluster,err) - return -1, err - } - id, err := result.LastInsertId() - if err != nil{ - log.Errorf("[kube cluster_list] get lastInsertId error :%v",err) - } - return int(id), err - } else if err == nil { - return cluster.Id, fmt.Errorf("k8s集群:%v 已存在", cluster.Name) - } else { - log.Errorf("[kube cluster_list] query sql: %s, value: %+v, error: %v",getClusterSts.QueryString,*cluster,err) - return -1, err - } -} - -func (l *deployClusterList) GetClusterById(id int) (*ClusterInfo,error){ - info := ClusterInfo{} - info.Id = id - err := getClusterByIdSts.Get(&info,info) - if err == nil{ - return &info,nil - } - if err == sql.ErrNoRows{ - return nil, nil - } - return nil, fmt.Errorf("[kube cluster_list] query sql: %s, id: %d, error: %v",getClusterByIdSql,id,err) -} diff --git a/chengying-server/matrix/model/kube/T4_deploy_cluster_product_rel.go b/chengying-server/matrix/model/kube/T4_deploy_cluster_product_rel.go deleted file mode 100644 index 5988c35..0000000 --- a/chengying-server/matrix/model/kube/T4_deploy_cluster_product_rel.go +++ /dev/null @@ -1,85 +0,0 @@ -// Licensed to Apache Software Foundation(ASF) under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. Apache Software Foundation(ASF) licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -package kube - -import ( - "database/sql" - "dtstack.com/dtstack/easymatrix/matrix/log" - "dtstack.com/dtstack/easymatrix/matrix/model" - "github.com/jmoiron/sqlx" -) - -var ( - selectNamespacedDeployedProductSql = "select * from deploy_cluster_product_rel where clusterId = :clusterId and namespace = :namespace and status = 'deployed'" - selectNamespecedDeployedProductsts *sqlx.NamedStmt - DeployClusterProductRel = deployClusterProductRel{ - PrepareFunc: prepareDeplyClusterProductRel, - } -) - -type deployClusterProductRel struct { - PrepareFunc -} - -func prepareDeplyClusterProductRel() error{ - var err error - selectNamespecedDeployedProductsts,err = model.USE_MYSQL_DB().PrepareNamed(selectNamespacedDeployedProductSql) - if err != nil{ - log.Errorf("[deploy_cluster_product_rel]: init sql: %s , error %v",selectNamespacedDeployedProductSql,err) - return err - } - return nil -} - -type DeployClusterProductRelSchema struct { - Id int `db:"id"` - Pid int `db:"pid"` - ClusterId int `db:"clusterId"` - Namespace string `db:"namespace"` - ProductParsed []byte `db:"product_parsed"` - Status string `db:"status"` - DeployUUID string `db:"deploy_uuid"` - AlertRecover int `db:"alert_recover"` - UserId int `db:"user_id"` - IsDeleted int `db:"is_deleted"` - UpdateTime sql.NullTime `db:"update_time"` - DeployTime sql.NullTime `db:"deploy_time"` - CreateTime sql.NullTime `db:"create_time"` -} - -func (d *deployClusterProductRel) SelectNamespacedDeployed(clusterid int, namespace string) ([]DeployClusterProductRelSchema,error){ - list := []DeployClusterProductRelSchema{} - arg := &DeployClusterProductRelSchema{ - ClusterId: clusterid, - Namespace: namespace, - } - rows,err := selectNamespecedDeployedProductsts.Queryx(arg) - if err != nil && err != sql.ErrNoRows{ - log.Errorf("[deploy_cluster_product_rel]: sql %s, err %v",selectNamespacedDeployedProductSql,err) - return nil,err - } - for rows.Next(){ - tbsc := DeployClusterProductRelSchema{} - if err = rows.StructScan(&tbsc); err != nil{ - log.Errorf("[deploy_cluster_product_rel]: struct scan to DeployClusterProductRelSchema error: %v",err) - return nil,err - } - list = append(list,tbsc) - } - return list,nil -} diff --git a/chengying-server/matrix/model/kube/T5_deploy_namespace_client.go b/chengying-server/matrix/model/kube/T5_deploy_namespace_client.go deleted file mode 100644 index 80524e4..0000000 --- a/chengying-server/matrix/model/kube/T5_deploy_namespace_client.go +++ /dev/null @@ -1,99 +0,0 @@ -// Licensed to Apache Software Foundation(ASF) under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. Apache Software Foundation(ASF) licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -package kube - -import ( - "database/sql" - "dtstack.com/dtstack/easymatrix/matrix/log" - "dtstack.com/dtstack/easymatrix/matrix/model" - "github.com/jmoiron/sqlx" -) - -var ( - insertNamespaceClientSql = "insert into deploy_namespace_client (yaml, namespace_id, file_name) values (:yaml, :namespace_id, :file_name)" - updateNamespaceClientSql = "update deploy_namespace_client set yaml = :yaml, file_name = :file_name where namespace_id = :namespace_id" - selectNamespaceClientSql = "select * from deploy_namespace_client where namespace_id = :namespace_id" - insertNamespaceClientSts *sqlx.NamedStmt - updateNamespaceClientSts *sqlx.NamedStmt - selectNamespaceClientSts *sqlx.NamedStmt - DeployNamespaceClient = &deployNamespaceClient{ - PrepareFunc: prepareDeployNamespaceClinet, - } -) -type deployNamespaceClient struct { - PrepareFunc -} - -type DeployNamespaceClientSchema struct { - Id int `db:"id"` - Yaml string `db:"yaml"` - NamespaceId int `db:"namespace_id"` - Filename string `db:"file_name"` -} - -func prepareDeployNamespaceClinet() error{ - var err error - insertNamespaceClientSts,err = model.USE_MYSQL_DB().PrepareNamed(insertNamespaceClientSql) - if err != nil{ - log.Errorf("[kube deploy_namespace_client]: init sql: %s , error %v",insertNamespaceClientSql,err) - return err - } - updateNamespaceClientSts,err = model.USE_MYSQL_DB().PrepareNamed(updateNamespaceClientSql) - if err !=nil{ - log.Errorf("[kube deploy_namespace_client]: init sql: %s , error %v",updateNamespaceClientSql,err) - return err - } - selectNamespaceClientSts,err = model.USE_MYSQL_DB().PrepareNamed(selectNamespaceClientSql) - if err != nil{ - log.Errorf("[kube deploy_namespace_client]: init sql: %s , error %v",selectNamespaceClientSql,err) - return err - } - return nil -} - -func (c *deployNamespaceClient)Insert(tbsc *DeployNamespaceClientSchema) error{ - _,err := insertNamespaceClientSts.Exec(tbsc) - if err != nil{ - log.Errorf("[deploy_namespace_client]: insert sql exec error %v",err) - return err - } - return nil -} - -func (c *deployNamespaceClient)Update(tbsc *DeployNamespaceClientSchema) error{ - _,err := updateNamespaceClientSts.Exec(tbsc) - if err != nil{ - log.Errorf("[deploy_namespace_client]: update sql exec error %v",err) - return err - } - return nil -} - -func (c *deployNamespaceClient)Get(namespaceId int) (*DeployNamespaceClientSchema,error){ - tbsc := &DeployNamespaceClientSchema{ - NamespaceId: namespaceId, - } - err := selectNamespaceClientSts.Get(tbsc,tbsc) - if err != nil{ - if err == sql.ErrNoRows{ - return nil,nil - } - return nil,err - } - return tbsc,nil -} diff --git a/chengying-server/matrix/model/kube/T6_deploy_namespace_list.go b/chengying-server/matrix/model/kube/T6_deploy_namespace_list.go deleted file mode 100644 index 5354fb8..0000000 --- a/chengying-server/matrix/model/kube/T6_deploy_namespace_list.go +++ /dev/null @@ -1,304 +0,0 @@ -// Licensed to Apache Software Foundation(ASF) under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. Apache Software Foundation(ASF) licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -package kube - -import ( - "database/sql" - "dtstack.com/dtstack/easymatrix/matrix/api/k8s/view" - "dtstack.com/dtstack/easymatrix/matrix/log" - "dtstack.com/dtstack/easymatrix/matrix/model" - "fmt" - "github.com/jmoiron/sqlx" - "strings" - "time" -) - -var ( - insertNamespaceSql = "insert into deploy_namespace_list (namespace,type,registry_id,ip,port,cluster_id,is_deleted,status,user) values (:namespace,:type,:registry_id,:ip,:port,:cluster_id,:is_deleted,:status,:user)" - selectNamespaceSql = "select * from deploy_namespace_list where namespace = :namespace and cluster_id = :cluster_id and is_deleted=0" - updateNamespaceStatusSql = "update deploy_namespace_list set status = :status where namespace = :namespace and cluster_id = :cluster_id and is_deleted=0" - updateNamespaceSql = "update deploy_namespace_list set namespace=:namespace,type=:type,registry_id=:registry_id,ip=:ip,port=:port,user =:user,`status`=:status,update_time=:update_time where id=:id" - deleteNamespaceSql = "update deploy_namespace_list set is_deleted=1, update_time=:update_time where namespace = :namespace and cluster_id = :cluster_id and is_deleted=0" - selectLikedNamespaceDescSql = "select * from deploy_namespace_list where cluster_id = :cluster_id and namespace like :namespace and is_deleted=0 and `status` =:status order by update_time desc" - selectLikedNamespaceAscSql = "select * from deploy_namespace_list where cluster_id = :cluster_id and namespace like :namespace and is_deleted=0 and `status` =:status order by update_time asc" - selectAllSql = "select * from deploy_namespace_list where is_deleted=0" - updateIpAndPortSql = "update deploy_namespace_list set ip=:ip,port=:port where namespace=:namespace and cluster_id=:cluster_id and is_deleted=0" - //selectNamespacesByClusterSql = "select * from deploy_namespace_list where cluster_id = :cluster_id and is_deleted=0 order by update_time desc" - updateNamespaceStatusSts *sqlx.NamedStmt - insertNamespaceSts *sqlx.NamedStmt - selectNamespaceSts *sqlx.NamedStmt - updateNamespaceSts *sqlx.NamedStmt - deleteNamespaceSts *sqlx.NamedStmt - selectLikedNamespaceDescSts *sqlx.NamedStmt - selectLIkedNamespaceAscSts *sqlx.NamedStmt - updateIpAndPortSts *sqlx.NamedStmt - selectAllSts *sqlx.Stmt - //selectNamespacesByClusterSts *sqlx.NamedStmt - DeployNamespaceList = &deployNamespaceList{ - PrepareFunc: prepareDeployNamespaceList, - } -) -type deployNamespaceList struct { - PrepareFunc -} -type DeployNamespaceListSchema struct { - ClusterId int `db:"cluster_id"` - Status string `db:"status"` - IsDeleted int `db:"is_deleted"` - User string `db:"user"` - CreateTime time.Time `db:"create_time"` - UpdateTime time.Time `db:"update_time"` - view.NamespaceSaveReq -} - -func prepareDeployNamespaceList() error{ - var err error - insertNamespaceSts,err = model.USE_MYSQL_DB().PrepareNamed(insertNamespaceSql) - if err != nil{ - log.Errorf("[kube deploy_namespace_list]: init sql: %s , error %v",insertNamespaceSql,err) - return err - } - selectNamespaceSts,err = model.USE_MYSQL_DB().PrepareNamed(selectNamespaceSql) - if err != nil{ - log.Errorf("[kube deploy_namespace_list]: init sql: %s, error %v",selectNamespaceSql,err) - return err - } - updateNamespaceStatusSts,err = model.USE_MYSQL_DB().PrepareNamed(updateNamespaceStatusSql) - if err != nil{ - log.Errorf("[kube deploy_namespace_list]: init sql: %s, error %v",updateNamespaceStatusSql,err) - return err - } - updateNamespaceSts,err = model.USE_MYSQL_DB().PrepareNamed(updateNamespaceSql) - if err != nil{ - log.Errorf("[kube deploy_namespace_list]: init sql: %s, error %v",updateNamespaceSql,err) - return err - } - deleteNamespaceSts,err = model.USE_MYSQL_DB().PrepareNamed(deleteNamespaceSql) - if err != nil{ - log.Errorf("[kube deploy_namespace_list]: init sql: %s, error %v",deleteNamespaceSql,err) - return err - } - selectLikedNamespaceDescSts,err = model.USE_MYSQL_DB().PrepareNamed(selectLikedNamespaceDescSql) - if err != nil{ - log.Errorf("[kube deploy_namespace_list]: init sql %s, error %v",selectLikedNamespaceDescSql,err) - return err - } - selectLIkedNamespaceAscSts,err = model.USE_MYSQL_DB().PrepareNamed(selectLikedNamespaceAscSql) - if err != nil{ - log.Errorf("[kube deploy_namespace_list]: init sql %s, error %v",selectLikedNamespaceAscSql,err) - return err - } - selectAllSts,err = model.USE_MYSQL_DB().Preparex(selectAllSql) - if err != nil{ - log.Errorf("[kube deploy_namespace_list]: init sql %s, error %v",selectAllSql,err) - return err - } - updateIpAndPortSts,err = model.USE_MYSQL_DB().PrepareNamed(updateIpAndPortSql) - if err != nil{ - log.Errorf("[kube deploy_namespace_list]: init sql %s, error %v",updateIpAndPortSql,err) - return err - } - //selectNamespacesByClusterSts,err = model.USE_MYSQL_DB().PrepareNamed(selectNamespacesByClusterSql) - //if err != nil{ - // log.Errorf("[kube deploy_namespace_list]: init sql: %s, error %v",updateNamespaceSql,err) - // return err - //} - return nil -} - -func (l *deployNamespaceList) Insert(s *DeployNamespaceListSchema) (int,error){ - err := selectNamespaceSts.Get(s,s) - if err != nil && err == sql.ErrNoRows{ - rs,err := insertNamespaceSts.Exec(s) - if err != nil{ - log.Errorf("[deploy_namespace_list]: insert sql exec error: %v",err) - return -1,err - } - id,err := rs.LastInsertId() - if err!= nil{ - log.Errorf("[deploy_namespace_list] get last insert id error :%v",err) - return -1,err - } - return int(id),nil - }else if err == nil{ - return -1,fmt.Errorf("namespace %s is exist",s.Namespace) - }else { - log.Errorf("[deploy_namespace_list]: query sql: %s, value: %+v, error: %v",selectNamespaceSql,*s,err) - return -1,err - } -} - -func (l *deployNamespaceList) SelectAll() ([]DeployNamespaceListSchema,error){ - rows,err := selectAllSts.Queryx() - if err != nil{ - log.Errorf("[deploy_namespace_list]: select all sql: %s, error: %v",selectAllSql,err) - return nil,err - } - tbscs := []DeployNamespaceListSchema{} - for rows.Next(){ - tbsc := DeployNamespaceListSchema{} - if err := rows.StructScan(&tbsc);err != nil{ - log.Errorf("[deploy_namespace_list]: sql %s result struct scan to deploy_namespace_list error %v",selectAllSql,err) - return nil,err - } - tbscs = append(tbscs,tbsc) - } - return tbscs,nil -} - -func (l *deployNamespaceList) Update(s *DeployNamespaceListSchema) error{ - s.UpdateTime = time.Now() - if _,err := updateNamespaceSts.Exec(s);err != nil{ - log.Errorf("[deploy_namespace_list]: update sql: %s, error: %v",updateNamespaceSql,err) - return err - } - return nil -} - -func (l *deployNamespaceList) UpdateStatus(s *DeployNamespaceListSchema) error{ - _,err := updateNamespaceStatusSts.Exec(s) - if err != nil{ - log.Errorf("[deploy_namespace_list]: update sql: %s, error: %v",updateNamespaceStatusSql,err) - return err - } - return nil -} - -func (l *deployNamespaceList) GetLike(namespace string, clusterid int, status string, desc bool)([]DeployNamespaceListSchema,error){ - namespace = "%"+namespace+"%" - arg := &DeployNamespaceListSchema{ - ClusterId: clusterid, - Status: status, - NamespaceSaveReq:view.NamespaceSaveReq{ - Namespace: namespace, - }, - } - var rows *sqlx.Rows - var err error - if desc{ - rows,err = selectLikedNamespaceDescSts.Queryx(arg) - }else{ - rows,err = selectLikedNamespaceDescSts.Queryx(arg) - } - if err != nil{ - log.Errorf("[kube deploy_namespace_list]: query liked namespace sql %s, value %+v, error %v",selectNamespaceSql,*arg,err) - return nil,err - } - result := []DeployNamespaceListSchema{} - for rows.Next(){ - tbsc := DeployNamespaceListSchema{} - if err = rows.StructScan(&tbsc);err != nil{ - log.Errorf("[kube deploy_namespace_list]: sql %s result struct scan to deplyonamespacelist error %v",selectNamespaceSql,err) - return nil,err - } - result = append(result,tbsc) - } - if len(result) == 0{ - return nil,nil - } - return result,nil -} -func (l *deployNamespaceList) Get(namespace string, clusterid int) (*DeployNamespaceListSchema,error){ - tbsc := &DeployNamespaceListSchema{ - ClusterId: clusterid, - NamespaceSaveReq: view.NamespaceSaveReq{ - Namespace: namespace, - }, - } - err := selectNamespaceSts.Get(tbsc,tbsc) - if err != nil{ - if err == sql.ErrNoRows{ - return nil,nil - } - log.Errorf("[deploy_namespace_list]: get namespace info, sql %s, value %+v, error %v",selectNamespaceSql,*tbsc,err) - return nil ,err - } - return tbsc,nil -} - - -func (l *deployNamespaceList) Select(clsuterid,status,desc,namespace,typ string) ([]DeployNamespaceListSchema,error){ - s := "select * from deploy_namespace_list where is_deleted = 0 and cluster_id = "+clsuterid - if len(status) != 0{ - statusList := strings.Split(status,",") - statusQuery := "" - for i,item := range statusList{ - if i == len(statusList) -1 { - statusQuery = statusQuery + " `status` = '"+item+"'" - }else{ - statusQuery = statusQuery + " `status` = '"+item+"' or" - } - } - s = s + " and ("+statusQuery+")" - } - if len(typ) !=0{ - typList := strings.Split(typ,",") - typQuery := "" - for i,item := range typList{ - if i == len(typList) - 1{ - typQuery = typQuery + " type = '"+item+"'" - }else{ - typQuery = typQuery + " type = '"+item+"' or" - } - } - s = s + " and ("+typQuery+")" - } - if len(namespace) !=0 { - s = s + " and namespace like '%"+namespace+"%'" - } - - if len(desc) != 0 && desc == "false"{ - s = s + " order by update_time asc" - }else{ - s = s + " order by update_time desc" - } - rows,err := model.USE_MYSQL_DB().Queryx(s) - if err != nil{ - if err == sql.ErrNoRows{ - return nil, nil - } - log.Errorf("[deploy_namespace_list]: get namespaces info, sql %s, error %v",s,err) - return nil,err - } - tbscs := []DeployNamespaceListSchema{} - for rows.Next(){ - tbsc := DeployNamespaceListSchema{} - if err := rows.StructScan(&tbsc); err != nil{ - log.Errorf("[deploy_namespace_list]: struct scan to DeployNamespaceListSchema error :%v",err) - return nil, err - } - tbscs = append(tbscs,tbsc) - } - return tbscs,nil -} - -func (l *deployNamespaceList) Delete(namespace string, clusterid int) error{ - tbsc := &DeployNamespaceListSchema{ - ClusterId: clusterid, - UpdateTime: time.Now(), - NamespaceSaveReq: view.NamespaceSaveReq{ - Namespace: namespace, - }, - } - _,err := deleteNamespaceSts.Exec(tbsc) - if err != nil{ - log.Errorf("[deploy_namespace_list]: sql %s, value %+v, error %v",deleteNamespaceSql,tbsc,err) - return err - } - return nil -} diff --git a/chengying-server/matrix/model/kube/T7_deploy_product_list.go b/chengying-server/matrix/model/kube/T7_deploy_product_list.go deleted file mode 100644 index 09713ce..0000000 --- a/chengying-server/matrix/model/kube/T7_deploy_product_list.go +++ /dev/null @@ -1,41 +0,0 @@ -// Licensed to Apache Software Foundation(ASF) under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. Apache Software Foundation(ASF) licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -package kube - -import ( - "database/sql" -) - -type DeployProductListSchema struct { - ID int `db:"id"` - ParentProductName string `db:"parent_product_name"` - ProductName string `db:"product_name"` - ProductNameDisplay string `db:"product_name_display"` - ProductVersion string `db:"product_version"` - Product []byte `db:"product"` - ProductParsed []byte `db:"product_parsed"` - IsCurrentVersion int `db:"is_current_version"` - Status string `db:"status"` - DeployUUID string `db:"deploy_uuid"` - AlertRecover int `db:"alert_recover"` - DeployTime sql.NullTime `db:"deploy_time"` - CreateTime sql.NullTime `db:"create_time"` - UserId int `db:"user_id"` - Schema []byte `db:"schema"` - ProductType int `db:"product_type"` -} diff --git a/chengying-server/matrix/model/kube/T8_import_init_moudle.go b/chengying-server/matrix/model/kube/T8_import_init_moudle.go deleted file mode 100644 index a8e0808..0000000 --- a/chengying-server/matrix/model/kube/T8_import_init_moudle.go +++ /dev/null @@ -1,63 +0,0 @@ -// Licensed to Apache Software Foundation(ASF) under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. Apache Software Foundation(ASF) licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -package kube - -import ( - "dtstack.com/dtstack/easymatrix/matrix/log" - "dtstack.com/dtstack/easymatrix/matrix/model" - "github.com/jmoiron/sqlx" -) - -var ( - getMoudleSql = "select * from import_init_moudle where is_deleted = 0" - getMoudleSts *sqlx.Stmt - ImportInitMoudle = &importInitMoudle{ - PrepareFunc: prepareImportInitMoudle, - } -) -type importInitMoudle struct { - PrepareFunc -} - -func prepareImportInitMoudle() error{ - var err error - getMoudleSts,err = model.USE_MYSQL_DB().Preparex(getMoudleSql) - if err != nil{ - log.Errorf("[kube import_init_moudle]: init sql: %s , error %v",getMoudleSql,err) - return err - } - return nil -} -type ImportInitMoudleSchema struct { - Id int `db:"id"` - ServiceAccount string `db:"service_account"` - Role string `db:"role"` - RoleBinding string `db:"role_binding"` - Operator string `db:"operator"` - LogConfig string `db:"log_config"` - IsDeleted int `db:"is_deleted"` -} - -func (i *importInitMoudle) GetInitMoudle() (*ImportInitMoudleSchema,error){ - sc := &ImportInitMoudleSchema{} - if err := getMoudleSts.Get(sc);err!=nil{ - log.Errorf("[kube import_init_moudle]: get init moudle error %v",err) - return nil ,err - } - return sc,nil -} diff --git a/chengying-server/matrix/model/kube/T9_deploy_namespace_event.go b/chengying-server/matrix/model/kube/T9_deploy_namespace_event.go deleted file mode 100644 index 38383ef..0000000 --- a/chengying-server/matrix/model/kube/T9_deploy_namespace_event.go +++ /dev/null @@ -1,126 +0,0 @@ -// Licensed to Apache Software Foundation(ASF) under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. Apache Software Foundation(ASF) licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -package kube - -import ( - "database/sql" - "dtstack.com/dtstack/easymatrix/matrix/log" - "dtstack.com/dtstack/easymatrix/matrix/model" - "github.com/jmoiron/sqlx" - "time" -) - -var ( - insertEventSql = "insert into deploy_namespace_event (type,reason,resource,message,namespace_id,time) values (:type, :reason, :resource, :message, :namespace_id,:time)" - pageEventSql = "select * from deploy_namespace_event where namespace_id = ? order by time desc, id desc limit?,?" - selectCountSql = "select count(*) from deploy_namespace_event where namespace_id = :namespace_id" - cleanEventsSql = "delete from deploy_namespace_event where DATE_SUB(CURDATE(),INTERVAL ? DAY) >= DATE(time)" - insertEventSts *sqlx.NamedStmt - selectCountSts *sqlx.NamedStmt - cleanEventsSts *sqlx.Stmt - DeployNamespaceEvent = &deployNamespaceEvent{ - PrepareFunc: prepareDeloyNamespaceEvent, - } -) - -type deployNamespaceEvent struct { - PrepareFunc -} - -type DeployNamespaceEventSchema struct { - Id int `db:"id"` - Type string `db:"type"` - Reason string `db:"reason"` - Resource string `db:"resource"` - Message string `db:"message"` - NamespaceId int `db:"namespace_id"` - Time time.Time `db:"time"` -} - -func prepareDeloyNamespaceEvent() error{ - var err error - insertEventSts,err = model.USE_MYSQL_DB().PrepareNamed(insertEventSql) - if err != nil{ - log.Errorf("[kube deploy_namespace_event]: init sql: %s , error %v",insertEventSql,err) - return err - } - selectCountSts,err = model.USE_MYSQL_DB().PrepareNamed(selectCountSql) - if err != nil{ - log.Errorf("[kube deploy_namespace_event]: init sql %s, error %v",selectCountSql,err) - return err - } - cleanEventsSts,err = model.USE_MYSQL_DB().Preparex(cleanEventsSql) - if err != nil{ - log.Errorf("[kube deploy_namespace_event]: init sql %s,err %v",deleteNamespaceSql,err) - } - return nil -} - -func (e *deployNamespaceEvent) Insert(tbsc *DeployNamespaceEventSchema) error{ - _,err := insertEventSts.Exec(tbsc) - if err != nil{ - log.Errorf("[deploy_namespace_event]: insert sql exec error %v",err) - return err - } - return nil -} - -func (e *deployNamespaceEvent) PageSelect(namespaceId, start, limit int)([]DeployNamespaceEventSchema,error){ - rows,err := model.USE_MYSQL_DB().Queryx(pageEventSql,namespaceId,start,limit) - if err != nil{ - log.Errorf("[deploy_namespace_event]: pageselect sql %s, namespaceid %d, start %d, limit %d error %v", - pageEventSql,namespaceId,start,limit,err) - return nil,err - } - tbscs := []DeployNamespaceEventSchema{} - for rows.Next(){ - tbsc := &DeployNamespaceEventSchema{} - if err = rows.StructScan(tbsc);err != nil{ - log.Errorf("[deploy_namespace_event]: convert to DeployNamespaceEventSchema error %v",err) - return nil,err - } - tbscs = append(tbscs,*tbsc) - } - return tbscs,nil -} - -func (e *deployNamespaceEvent) SelectCount(namespaceid int) (int,error){ - var count int - tbsc := &DeployNamespaceEventSchema{ - NamespaceId: namespaceid, - } - err := selectCountSts.Get(&count,tbsc) - if err != nil{ - if err == sql.ErrNoRows{ - return 0,nil - } - log.Errorf("[deploy_namespace_event]: select count error: %v",err) - return 0,err - } - return count,nil -} - -func (e *deployNamespaceEvent) CleanHistory(day int) error{ - - _,err := cleanEventsSts.Exec(day) - if err != nil{ - log.Errorf("[deploy_namespace_event]: clean history error: %v",err) - return err - } - return nil -} diff --git a/chengying-server/matrix/model/kube/alias.go b/chengying-server/matrix/model/kube/alias.go deleted file mode 100644 index b5b5ea7..0000000 --- a/chengying-server/matrix/model/kube/alias.go +++ /dev/null @@ -1,31 +0,0 @@ -// Licensed to Apache Software Foundation(ASF) under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. Apache Software Foundation(ASF) licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -package kube - -type T1 DeployClusterImageStoreSchema -type T2 ClusterK8sAvailable -type T3 ClusterInfo -type T4 DeployClusterProductRelSchema -type T5 DeployNamespaceClientSchema -type T6 DeployNamespaceListSchema -type T7 DeployProductListSchema -type T8 ImportInitMoudleSchema -type T9 DeployNamespaceEventSchema -type T10 WorloadStepSchema -type T11 WorkloaPartSchema -type T12 WorkloadDefinitionSchema diff --git a/chengying-server/matrix/model/kube/db_test.go b/chengying-server/matrix/model/kube/db_test.go deleted file mode 100644 index 9deaa94..0000000 --- a/chengying-server/matrix/model/kube/db_test.go +++ /dev/null @@ -1,200 +0,0 @@ -// Licensed to Apache Software Foundation(ASF) under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. Apache Software Foundation(ASF) licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -package kube - -import ( - "dtstack.com/dtstack/easymatrix/matrix/log" - "dtstack.com/dtstack/easymatrix/matrix/model" - "encoding/json" - "fmt" - "github.com/jmoiron/sqlx" - "testing" -) - - -func getConn(){ - user := "root" - password := "dtstack" - host:= "172.16.10.37" - port := 3306 - dbname := "dtagent" - log.ConfigureLogger("/tmp/matrix",100,3,1) - db,_ := sqlx.Connect("mysql", fmt.Sprintf("%s:%s@tcp(%s:%d)/%s?charset=utf8&loc=Local&parseTime=true", user, password, host, port, dbname)) - model.MYSQLDB = db - err := Build() - if err != nil{ - fmt.Printf("err: %v \n",err) - } -} -func TestGetClusterSts(t *testing.T) { - getConn() - info := &ClusterInfo{ - Name: "ccaqdwa", - IsDeleted: 0, - } - if err := getClusterSts.Get(info,info);err!=nil{ - fmt.Println(err.Error()) - } - bts,_:=json.Marshal(info) - fmt.Println(string(bts)) -} - -func TestInsertClusterSts(t *testing.T) { - getConn() - info := &ClusterInfo{ - Name: "cccccc", - Type: "kubernetes", - Mode: 0, - Version: "1.11.1", - IsDeleted: 0, - //NetworkPlugin: "flannel", - } - i,err := DeployClusterList.InsertK8sCluster(info) - if err != nil{ - fmt.Println(err.Error()) - } - fmt.Println("------",i) -} - -func TestGetClusterK8sAvailableByMode(t *testing.T) { - getConn() - as,err := DeployClusterK8sAvailable.GetClusterK8sAvailableByMode(1) - if err != nil{ - fmt.Println(err.Error()) - } - for _,a := range as{ - bts,_:=json.Marshal(a) - fmt.Println(string(bts)) - } -} - -func TestGetRealVersion(t *testing.T) { - getConn() - s,err := DeployClusterK8sAvailable.GetRealVersion("") - if err != nil{ - fmt.Println("err ",err.Error()) - } - fmt.Println(s) -} - -func TestInitmoudle(t *testing.T) { - getConn() - s,err := ImportInitMoudle.GetInitMoudle() - if err != nil{ - fmt.Println(err.Error()) - } - - fmt.Println(s) -} -//func TestInserNamspaceList(t *testing.T) { -// getConn() -// ss,err := DeployNamespaceList.GetByCluster(1) -// if err != nil{ -// fmt.Println("err",err.Error()) -// -// } -// for _,s := range ss{ -// fmt.Printf("s %+v \n",s) -// } -// //err := DeployNamespaceList.UpdateStatus(&s) -// //if err != nil{ -// // fmt.Println("err5",err.Error()) -// //} -//} - -var kubeconfig = `apiVersion: v1 -clusters: -- cluster: - certificate-authority-data: LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSUZWRENDQXp3Q0NRQ3ZTQlZyUVQ1ZGpEQU5CZ2txaGtpRzl3MEJBUXNGQURCc01Rc3dDUVlEVlFRR0V3SkQKVGpFUk1BOEdBMVVFQ0F3SVdtaGxhbWxoYm1jeEVUQVBCZ05WQkFjTUNFaGhibWQ2YUc5MU1SQXdEZ1lEVlFRSwpEQWQ0WkdWMmIzQnpNUkF3RGdZRFZRUUxEQWQ0WkdWMmIzQnpNUk13RVFZRFZRUUREQXBrZEhOMFlXTnJMbU51Ck1CNFhEVEl3TVRFd01USXhNVGd5TmxvWERUTXdNVEF6TURJeE1UZ3lObG93YkRFTE1Ba0dBMVVFQmhNQ1EwNHgKRVRBUEJnTlZCQWdNQ0Zwb1pXcHBZVzVuTVJFd0R3WURWUVFIREFoSVlXNW5lbWh2ZFRFUU1BNEdBMVVFQ2d3SAplR1JsZG05d2N6RVFNQTRHQTFVRUN3d0hlR1JsZG05d2N6RVRNQkVHQTFVRUF3d0taSFJ6ZEdGamF5NWpiakNDCkFpSXdEUVlKS29aSWh2Y05BUUVCQlFBRGdnSVBBRENDQWdvQ2dnSUJBTHh3MWgzcXptTXE4YUErY01vWFQvM0UKRVVBdzRQNUhCZGZYa2VVa1J1ZjV3VHUvdTBvRHFyUnVRNlcwMFJWS09BUFFQVDZpRVhCQkdyKzdTRGhISi8yTAo4VzBnNDRnaDB5N2lWREE1UmErV2dFS2Y4YmRvT3grUkMzME4wb3JyRmtZbDRCR3p2UWtDQXlOV1lZU1lheGxDCkFEeDdoQldhMzFQb0FaT3MxN0pBM3Y0a1lUVzhzTVBHQzFtdnhCSHJ4cGswK3NxeFFLQjl2TzlaZ05zbXpQcXAKdUNsT0xQbkxjdkFrSjFMSXNIS3c4bXo3TlFnVnpVV3hzWEFTMVFnaTdXWlNwRUVINGsySmtQRTRLNU5Mc2g2Mgo0d3hPS0lRRS83TFFsaVlCRlpIZnFYTHZpU0F5MW94SklTbnp4UmdmOFZVSmUrMUxKbGE0UHp6UDZuVUI2cGxUCnlKODQ2Z0QxQStxTmM1endlN2RtMytHSFVJNVVRNXhZejNZRDdQclRIWlJJd3p3SzVzeXNTM28rTEFOL1duYjgKSnlVK2haNG5hcEZUUzh0SVlLWGQ5V0pWUldYNWNzdkd2MXZSY1daK0tySGRtVi9Mc1oxbG04RFd1ODFLV0EyZQpKSmdvMlMrZ3R0RFBEenZqMHVnbUNEVFVRZGpsYjVQWnhFdWI4cVYvUXViMTBCQ3JJSkNZenJHMm91dld6TVJLCmJIUEE0OWtIVVYrR3BSdW8vNDZZYUw2T3haVjRQcnJjWFU1MVlQTVNZRnJiWU1iT2g1b1NxTnkyY1lrdjRhTkUKMDNzQUllclJHMzYvaktnelYzNFFkZGJvTEI5Yk1sZThEaGJQZ3JEV2VGcTdJRlpBVlYwOUcwdGx6R1hNaDE5YQpLZm8yVnNMRDZMT1dLTGwvOUNVRkFnTUJBQUV3RFFZSktvWklodmNOQVFFTEJRQURnZ0lCQUNvM3ZYcHBJTk9TCkxkSEpTRXRYT3haSi9kMEw4aXZQaEUwZzlRb0h0NUNNUUZWMGlKcVpzZzVLQURDckJSUG42ZnBVZDFhaDROZWoKWW5lUWxzbEpUOFFJN1RIQ1ZiTzBuOUtsbEVxWEJ5c2gxeDdkTGVXdFVaczRxLzB2QVlxbTc3aWYyaVpWTEFzNgprMk81NmhpelNwN2svZC90SXd3a1k3dTN4UkF2b2RWWEM3cnA1ZmViSTRWcDZLUFMwbjF4Yk8wSXBqUzd3KzhPClkxMjFXdmtxUUQyckhCMkUySFJSSWdGTEF2eVFqY01hak9KMzRSUnh4VDljUzFIWEUzVUdDVVl2bHc1NnMySmMKMWYvMXNXYTJNaHFiUUdzVDZJS3dVOXZ2SlArQktoWnBsWnpicUlnZHZyZHVHNWFCbEpnNlNCQTZsUThSTDhnNQp6MmpscGFaTE5jUmYySkdTUm5TTzlDZzJTcU5va2wwaDRRZVRCZEFNeGhPVnk0MmxOc1grLzVOWVhuM0RXRWo1CmoybTV0SFpRU3ptY3BZZmNlY0ZpRXdud3BwOVdMbWlsb0N3SHVON2FNYU9ZakpSVnVPcWJoTXZMUjFLTnpWVm0KUFdVblZJa3FBY2p0TXVKVFh6clZGV081VXEvazF0WkIzdGhNNEd4c1JZcElDbEJmS3c3emFIaGxsZmNvNE53eQprbWVDeENWMnVLZ3AxYkJlZ0hReTVEc3E4OFI5Qkh1b0g0aWpEbzlUTGRpU2NXT0o1TkFEOUJ5K2F3VGpsUk1qCmtrVHgyMFRZdm1VdEF6T2N5R0xCOENEWERwS1B4b1ZBdVREMGFKMy9na3p0aHZQQ1dDamxINGI2cXVMS3lwVHgKOU85OVRZWGw3Y2VNSXZIc2I3L3l4L01KUG9RbUZjcUgKLS0tLS1FTkQgQ0VSVElGSUNBVEUtLS0tLQ== - server: https://172.16.8.88/k8s/clusters/c-vckqj - name: dtstack -- cluster: - certificate-authority-data: LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSUN3akNDQWFxZ0F3SUJBZ0lCQURBTkJna3Foa2lHOXcwQkFRc0ZBREFTTVJBd0RnWURWUVFERXdkcmRXSmwKTFdOaE1CNFhEVEl3TVRFd05UQXlNekF3T0ZvWERUTXdNVEV3TXpBeU16QXdPRm93RWpFUU1BNEdBMVVFQXhNSAphM1ZpWlMxallUQ0NBU0l3RFFZSktvWklodmNOQVFFQkJRQURnZ0VQQURDQ0FRb0NnZ0VCQUsyQmpTMEdYVmo5ClNZQWpjTFhYWUR2bXo2OStHdWkvbHQ4WHp0aC9ZdG4rU1NxR2NXSms4NzhLaHI5RGdRQ1hNR3VtZXZtbUhFemIKYVVsY29oQXU0Q0NaS0VmYmxncFY2ZzFqNGtreVFxS2hTSG84VDBhU2VLOW53dDZZMzQ4MXVxTG9UWHhubFhPKwpZblJOWjVsQnlVTWRXb2JmSGhzRGJQM2lLcXdkU3NYckhxYWJlNmFDdk5tMlpIelNJbnc1eG0wakZHWXJvS0M5Cll3a3FVYmpWMDEzRXV1bzV1dzdKZ2l1eFdFcDhoSjJ1WEFKNkp3OGZEeml5aUxIay9qTGVyTFM2UnN5dWNtYXEKWUJPclIvS2pmTllGV1hlTWlqNzF3NXZqRTJFcG1DUnRLMFdtRjFpU3gyUFo2ZlBtYmVSd2lpRUVScXFFZGhYbQpqeGZNRnRWSzUzY0NBd0VBQWFNak1DRXdEZ1lEVlIwUEFRSC9CQVFEQWdLa01BOEdBMVVkRXdFQi93UUZNQU1CCkFmOHdEUVlKS29aSWh2Y05BUUVMQlFBRGdnRUJBSTRxcUxnVFRJa1VQbGtJUWRGdjlNNmRseHpJTlZmU0xXU2QKdEJuZGV6NUVmelBRaVBOdHQzbDlHNklrZmpYSGJUcU1rN0NsTWkvUnZtVDlDcjMwc093NHY4WVNOQTFyYjBHYwp2VURJdEl0ZGoyVW8wSUtzQ2dsN0psalhMcVNvd01jczMwQy9IQXJGdU9pSTlsS2VBdlVIeFhFTG5ST1hxaGozCjhoTG5kS0dTak8rYXRFVSs1b0ZFa0pydS9hcDdjTGxWSWVQVmh3eHpuM2pSS2dmRDVXTmI4aHRpRzg1YjMrNVIKMGt4eGFjNlRyaDBKQkh5cVpRSlVWMUg2djk3NXdqNnZJNU5NcDNvbnlVZjJxaGJzSjVIWEJJRDh2NEtUQms3MQoxVnliMzFwY3NjZEVibGNPTFlveTFyR1VDT1QxMzNmbFlyTldwc2VXcFJ6Y2NPUE1WYVE9Ci0tLS0tRU5EIENFUlRJRklDQVRFLS0tLS0K - server: https://172.16.8.160:6443 - name: dtstack-172-16-8-160 -- cluster: - certificate-authority-data: LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSUN3akNDQWFxZ0F3SUJBZ0lCQURBTkJna3Foa2lHOXcwQkFRc0ZBREFTTVJBd0RnWURWUVFERXdkcmRXSmwKTFdOaE1CNFhEVEl3TVRFd05UQXlNekF3T0ZvWERUTXdNVEV3TXpBeU16QXdPRm93RWpFUU1BNEdBMVVFQXhNSAphM1ZpWlMxallUQ0NBU0l3RFFZSktvWklodmNOQVFFQkJRQURnZ0VQQURDQ0FRb0NnZ0VCQUsyQmpTMEdYVmo5ClNZQWpjTFhYWUR2bXo2OStHdWkvbHQ4WHp0aC9ZdG4rU1NxR2NXSms4NzhLaHI5RGdRQ1hNR3VtZXZtbUhFemIKYVVsY29oQXU0Q0NaS0VmYmxncFY2ZzFqNGtreVFxS2hTSG84VDBhU2VLOW53dDZZMzQ4MXVxTG9UWHhubFhPKwpZblJOWjVsQnlVTWRXb2JmSGhzRGJQM2lLcXdkU3NYckhxYWJlNmFDdk5tMlpIelNJbnc1eG0wakZHWXJvS0M5Cll3a3FVYmpWMDEzRXV1bzV1dzdKZ2l1eFdFcDhoSjJ1WEFKNkp3OGZEeml5aUxIay9qTGVyTFM2UnN5dWNtYXEKWUJPclIvS2pmTllGV1hlTWlqNzF3NXZqRTJFcG1DUnRLMFdtRjFpU3gyUFo2ZlBtYmVSd2lpRUVScXFFZGhYbQpqeGZNRnRWSzUzY0NBd0VBQWFNak1DRXdEZ1lEVlIwUEFRSC9CQVFEQWdLa01BOEdBMVVkRXdFQi93UUZNQU1CCkFmOHdEUVlKS29aSWh2Y05BUUVMQlFBRGdnRUJBSTRxcUxnVFRJa1VQbGtJUWRGdjlNNmRseHpJTlZmU0xXU2QKdEJuZGV6NUVmelBRaVBOdHQzbDlHNklrZmpYSGJUcU1rN0NsTWkvUnZtVDlDcjMwc093NHY4WVNOQTFyYjBHYwp2VURJdEl0ZGoyVW8wSUtzQ2dsN0psalhMcVNvd01jczMwQy9IQXJGdU9pSTlsS2VBdlVIeFhFTG5ST1hxaGozCjhoTG5kS0dTak8rYXRFVSs1b0ZFa0pydS9hcDdjTGxWSWVQVmh3eHpuM2pSS2dmRDVXTmI4aHRpRzg1YjMrNVIKMGt4eGFjNlRyaDBKQkh5cVpRSlVWMUg2djk3NXdqNnZJNU5NcDNvbnlVZjJxaGJzSjVIWEJJRDh2NEtUQms3MQoxVnliMzFwY3NjZEVibGNPTFlveTFyR1VDT1QxMzNmbFlyTldwc2VXcFJ6Y2NPUE1WYVE9Ci0tLS0tRU5EIENFUlRJRklDQVRFLS0tLS0K - server: https://172.16.8.166:6443 - name: dtstack-172-16-8-166 -- cluster: - certificate-authority-data: LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSUN3akNDQWFxZ0F3SUJBZ0lCQURBTkJna3Foa2lHOXcwQkFRc0ZBREFTTVJBd0RnWURWUVFERXdkcmRXSmwKTFdOaE1CNFhEVEl3TVRFd05UQXlNekF3T0ZvWERUTXdNVEV3TXpBeU16QXdPRm93RWpFUU1BNEdBMVVFQXhNSAphM1ZpWlMxallUQ0NBU0l3RFFZSktvWklodmNOQVFFQkJRQURnZ0VQQURDQ0FRb0NnZ0VCQUsyQmpTMEdYVmo5ClNZQWpjTFhYWUR2bXo2OStHdWkvbHQ4WHp0aC9ZdG4rU1NxR2NXSms4NzhLaHI5RGdRQ1hNR3VtZXZtbUhFemIKYVVsY29oQXU0Q0NaS0VmYmxncFY2ZzFqNGtreVFxS2hTSG84VDBhU2VLOW53dDZZMzQ4MXVxTG9UWHhubFhPKwpZblJOWjVsQnlVTWRXb2JmSGhzRGJQM2lLcXdkU3NYckhxYWJlNmFDdk5tMlpIelNJbnc1eG0wakZHWXJvS0M5Cll3a3FVYmpWMDEzRXV1bzV1dzdKZ2l1eFdFcDhoSjJ1WEFKNkp3OGZEeml5aUxIay9qTGVyTFM2UnN5dWNtYXEKWUJPclIvS2pmTllGV1hlTWlqNzF3NXZqRTJFcG1DUnRLMFdtRjFpU3gyUFo2ZlBtYmVSd2lpRUVScXFFZGhYbQpqeGZNRnRWSzUzY0NBd0VBQWFNak1DRXdEZ1lEVlIwUEFRSC9CQVFEQWdLa01BOEdBMVVkRXdFQi93UUZNQU1CCkFmOHdEUVlKS29aSWh2Y05BUUVMQlFBRGdnRUJBSTRxcUxnVFRJa1VQbGtJUWRGdjlNNmRseHpJTlZmU0xXU2QKdEJuZGV6NUVmelBRaVBOdHQzbDlHNklrZmpYSGJUcU1rN0NsTWkvUnZtVDlDcjMwc093NHY4WVNOQTFyYjBHYwp2VURJdEl0ZGoyVW8wSUtzQ2dsN0psalhMcVNvd01jczMwQy9IQXJGdU9pSTlsS2VBdlVIeFhFTG5ST1hxaGozCjhoTG5kS0dTak8rYXRFVSs1b0ZFa0pydS9hcDdjTGxWSWVQVmh3eHpuM2pSS2dmRDVXTmI4aHRpRzg1YjMrNVIKMGt4eGFjNlRyaDBKQkh5cVpRSlVWMUg2djk3NXdqNnZJNU5NcDNvbnlVZjJxaGJzSjVIWEJJRDh2NEtUQms3MQoxVnliMzFwY3NjZEVibGNPTFlveTFyR1VDT1QxMzNmbFlyTldwc2VXcFJ6Y2NPUE1WYVE9Ci0tLS0tRU5EIENFUlRJRklDQVRFLS0tLS0K - server: https://172.16.8.169:6443 - name: dtstack-172-16-8-169 -contexts: -- context: - cluster: dtstack - user: dtstack - name: dtstack -- context: - cluster: dtstack-172-16-8-160 - user: dtstack - name: dtstack-172-16-8-160 -- context: - cluster: dtstack-172-16-8-166 - user: dtstack - name: dtstack-172-16-8-166 -- context: - cluster: dtstack-172-16-8-169 - user: dtstack - name: dtstack-172-16-8-169 -- context: - cluster: dtstack-172-16-8-160 - user: test - name: test -current-context: dtstack -kind: Config -preferences: {} -users: -- name: dtstack - user: - token: kubeconfig-user-mtrk8.c-vckqj:jk8k6n72dpxtllmtd4p99kwkkxthxsqg6562b9r2t2v7bdkf2jft9n -- name: test - user: - token: eyJhbGciOiJSUzI1NiIsImtpZCI6IjNhTjhlRFZNQl9ld2xGRDhpQ1F3czJDamtHUGNMTVlua2JBVW0yYUhDT1EifQ.eyJpc3MiOiJrdWJlcm5ldGVzL3NlcnZpY2VhY2NvdW50Iiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9uYW1lc3BhY2UiOiJkZXYiLCJrdWJlcm5ldGVzLmlvL3NlcnZpY2VhY2NvdW50L3NlY3JldC5uYW1lIjoiZGVmYXVsdC10b2tlbi1kajl0NiIsImt1YmVybmV0ZXMuaW8vc2VydmljZWFjY291bnQvc2VydmljZS1hY2NvdW50Lm5hbWUiOiJkZWZhdWx0Iiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9zZXJ2aWNlLWFjY291bnQudWlkIjoiOGM4ZTVhZGQtOGYwZi00NDdkLTg3YjAtMTc1ZmQxYTJmYWQ1Iiwic3ViIjoic3lzdGVtOnNlcnZpY2VhY2NvdW50OmRldjpkZWZhdWx0In0.bxqYVW0HOklhEZxNXECMQy1MqmdGzW4D2MLJ6fnXeAAXolkYPVIgf69eOO0P9JDxtX0HALQz9P982CqnuP0U7M3_OkJUptr55ixQXnkYbPn8L18ZxGdQ0R8tqymoqdfZAmUzzNf1lk9BIRaX_DAJwJmwKWUdrSGdJaS2lPcsXILP0GcC0tbwK6PP3GL2ZKKKlQsDy8Hbw2DdgXkMnx6NyU2BlsW2CWfEDc0__XUfY-0TSA4Evy7DnrD-US06992BF63zirhp8Y_kNd-8VQY83oNCo9vrKwOJYU0s0UP_3BgZpaKUSyrn4alKoj69hz4sXnnARwhbgJxKF_qBYqy47Q` -func TestInsertConnectInfo(t *testing.T) { - getConn() - config := kubeconfig - tbsc := DeployNamespaceClientSchema{ - Yaml: config, - NamespaceId: 1, - Filename: "ffff", - } - DeployNamespaceClient.Insert(&tbsc) -} - -func TestGetEventCount(t *testing.T) { - getConn() - count,err := DeployNamespaceEvent.SelectCount(7) - if err != nil{ - fmt.Println("err1",err.Error()) - return - } - fmt.Println(count) -} -// -//func TestGetnamespacelist(t *testing.T) { -// getConn() -// scs,err := DeployNamespaceList.Select("85","valid","desc") -// if err != nil{ -// fmt.Println("err1",err.Error()) -// return -// } -// bts,_ := yaml.Marshal(scs) -// fmt.Println("bts",string(bts)) -// -//} diff --git a/chengying-server/matrix/model/kube/init.go b/chengying-server/matrix/model/kube/init.go deleted file mode 100644 index 90e86b3..0000000 --- a/chengying-server/matrix/model/kube/init.go +++ /dev/null @@ -1,42 +0,0 @@ -// Licensed to Apache Software Foundation(ASF) under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. Apache Software Foundation(ASF) licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -package kube - -var localtbs = []KubeTable{ - DeployClusterList, - DeployClusterK8sAvailable, - DeployNamespaceList, - DeployClusterImageStore, - DeployNamespaceClient, - ImportInitMoudle, - DeployClusterProductRel, - DeployNamespaceEvent, - WorkloadDefinition, - WorkloadPart, - WorkloadStep, -} -//prepare sql -func Build() error{ - for _,tb := range localtbs{ - if err := tb.Prepare();err!= nil{ - return err - } - } - return nil -} - diff --git a/chengying-server/matrix/model/kube/interface.go b/chengying-server/matrix/model/kube/interface.go deleted file mode 100644 index fcd8e09..0000000 --- a/chengying-server/matrix/model/kube/interface.go +++ /dev/null @@ -1,29 +0,0 @@ -// Licensed to Apache Software Foundation(ASF) under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. Apache Software Foundation(ASF) licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -package kube - -// db table related to k8s -type KubeTable interface { - Prepare() error -} - -type PrepareFunc func() error - -func (p PrepareFunc) Prepare() error{ - return p() -} diff --git a/chengying-server/matrix/model/kube/union/db_test.go b/chengying-server/matrix/model/kube/union/db_test.go deleted file mode 100644 index 6b6a692..0000000 --- a/chengying-server/matrix/model/kube/union/db_test.go +++ /dev/null @@ -1,51 +0,0 @@ -// Licensed to Apache Software Foundation(ASF) under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. Apache Software Foundation(ASF) licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -package union - -import ( - "dtstack.com/dtstack/easymatrix/matrix/log" - "dtstack.com/dtstack/easymatrix/matrix/model" - "fmt" - "github.com/jmoiron/sqlx" -) - -func getConn(){ - user := "root" - password := "dtstack" - host:= "172.16.10.37" - port := 3306 - dbname := "dtagent_test" - log.ConfigureLogger("/tmp/matrix",100,3,1) - db,_ := sqlx.Connect("mysql", fmt.Sprintf("%s:%s@tcp(%s:%d)/%s?charset=utf8&loc=Local&parseTime=true", user, password, host, port, dbname)) - model.MYSQLDB = db - err := Build() - if err != nil{ - fmt.Printf("err: %v \n",err) - } -} -//func Test1(t *testing.T) { -// getConn() -// tbscs,err := UnionT4T7.Select(58,"dtstack-system") -// if err != nil{ -// fmt.Println("err",err.Error()) -// return -// } -// for _, sc := range tbscs{ -// fmt.Printf("sc %+v \n",sc) -// } -//} diff --git a/chengying-server/matrix/model/kube/union/init.go b/chengying-server/matrix/model/kube/union/init.go deleted file mode 100644 index e762b42..0000000 --- a/chengying-server/matrix/model/kube/union/init.go +++ /dev/null @@ -1,32 +0,0 @@ -// Licensed to Apache Software Foundation(ASF) under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. Apache Software Foundation(ASF) licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -package union - -import modelkube "dtstack.com/dtstack/easymatrix/matrix/model/kube" - -var localtbs = []modelkube.KubeTable{ - UnionT4T7, -} -func Build() error{ - for _,tb := range localtbs{ - if err := tb.Prepare();err!= nil{ - return err - } - } - return nil -} diff --git a/chengying-server/matrix/model/kube/union/union_T4_T7.go b/chengying-server/matrix/model/kube/union/union_T4_T7.go deleted file mode 100644 index c7a2170..0000000 --- a/chengying-server/matrix/model/kube/union/union_T4_T7.go +++ /dev/null @@ -1,148 +0,0 @@ -// Licensed to Apache Software Foundation(ASF) under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. Apache Software Foundation(ASF) licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -package union - -import ( - "database/sql" - "dtstack.com/dtstack/easymatrix/matrix/log" - "dtstack.com/dtstack/easymatrix/matrix/model" - modelkube "dtstack.com/dtstack/easymatrix/matrix/model/kube" - "github.com/jmoiron/sqlx" -) - -var ( - _getProductInfoSql = "select p.parent_product_name, p.product_name, p.product_version, p.product from deploy_product_list as p LEFT JOIN deploy_cluster_product_rel as r on p.id = r.pid where r.`status` = 'deployed'" - //r.clusterId = :clusterId and r.namespace = :namespace and - getparentProductsSql = _getProductInfoSql + " and r.clusterId = :clusterId and r.namespace = :namespace" - getProductsSql = getparentProductsSql + " and p.parent_product_name = :parent_product_name" - getServciesSql = getProductsSql + " and p.product_name = :product_name" - getInstalledProductSql = "select p.product from deploy_product_list as p LEFT JOIN deploy_cluster_product_rel as r on p.id = r.pid where r.`status` = 'deployed' and r.clusterId = :clusterId and r.namespace = :namespace and p.product_name = :product_name" - getparentProductsSts *sqlx.NamedStmt - getProductsSts *sqlx.NamedStmt - getServciesSts *sqlx.NamedStmt - getInstalledProductSts *sqlx.NamedStmt - UnionT4T7 = unionT4T7{ - PrepareFunc: prepareUnionT4T7, - } -) - -type unionT4T7 struct { - modelkube.PrepareFunc -} - -func prepareUnionT4T7() error{ - var err error - getparentProductsSts,err = model.USE_MYSQL_DB().PrepareNamed(getparentProductsSql) - if err != nil{ - log.Errorf("[union_T4_T7]: init sql: %s , error %v",getparentProductsSql,err) - return err - } - getProductsSts,err = model.USE_MYSQL_DB().PrepareNamed(getProductsSql) - if err != nil{ - log.Errorf("[union_T4_T7]: init sql %s, error %v",getProductsSql,err) - return err - } - getServciesSts,err = model.USE_MYSQL_DB().PrepareNamed(getServciesSql) - if err != nil{ - log.Errorf("[union_T4_T7]: init sql %s, error %v",getServciesSql,err) - return err - } - getInstalledProductSts,err = model.USE_MYSQL_DB().PrepareNamed(getInstalledProductSql) - if err != nil{ - log.Errorf("[union_T4_T7]: init sql %s, error %v",getInstalledProductSql,err) - return err - } - return nil -} - -type UnionT4T7Schema struct { - modelkube.T4 - modelkube.T7 -} - -func (u *unionT4T7)SelectParentProduct(clusterid int, namespace string) ([]UnionT4T7Schema,error){ - unionSc := &UnionT4T7Schema{ - T4: modelkube.T4{ - ClusterId: clusterid, - Namespace: namespace, - }, - } - unionscs := []UnionT4T7Schema{} - rows,err := getparentProductsSts.Queryx(unionSc) - if err != nil && err != sql.ErrNoRows{ - log.Errorf("[union_T4_T7]: sql %s, value %+v, error %v",getparentProductsSql,unionSc,err) - return nil,err - } - for rows.Next(){ - err := rows.StructScan(unionSc) - if err != nil{ - log.Errorf("[union_T4_T7]: struct scan to deploy_cluster_product_rel and deploy_product_list error :%v",err) - return nil,err - } - unionscs = append(unionscs,*unionSc) - } - return unionscs,nil -} - -func (u *unionT4T7)SelectProducts(clusterid int, namespace string, parentProduct string) ([]UnionT4T7Schema,error){ - unionSc := &UnionT4T7Schema{ - T7: modelkube.T7{ - ParentProductName: parentProduct, - }, - T4: modelkube.T4{ - ClusterId: clusterid, - Namespace: namespace, - }, - } - unionscs := []UnionT4T7Schema{} - rows,err := getparentProductsSts.Queryx(unionSc) - if err != nil && err != sql.ErrNoRows{ - log.Errorf("[union_T4_T7]: sql %s, value %+v, error %v",getparentProductsSql,unionSc,err) - return nil,err - } - for rows.Next(){ - err := rows.StructScan(unionSc) - if err != nil{ - log.Errorf("[union_T4_T7]: struct scan to deploy_cluster_product_rel and deploy_product_list error :%v",err) - return nil,err - } - unionscs = append(unionscs,*unionSc) - } - return unionscs,nil -} - -func (u *unionT4T7) GetProduct(clusterid int, namespace string,productname string) (*UnionT4T7Schema,error){ - unionSc := &UnionT4T7Schema{ - T7: modelkube.T7{ - ProductName: productname, - }, - T4: modelkube.T4{ - ClusterId: clusterid, - Namespace: namespace, - }, - } - err := getInstalledProductSts.Get(unionSc,unionSc) - if err != nil{ - if err == sql.ErrNoRows{ - return nil,nil - } - log.Errorf("[union_T4_T7]: sql %s exec fail, clusterid %d, productname %s, namespace %s",clusterid,productname,namespace) - return nil, err - } - return unionSc,nil -} diff --git a/chengying-server/matrix/k8s/monitor/cluster_status_monitor.go b/chengying-server/matrix/monitor/cluster_status_monitor.go similarity index 58% rename from chengying-server/matrix/k8s/monitor/cluster_status_monitor.go rename to chengying-server/matrix/monitor/cluster_status_monitor.go index 7db09a5..2115e6c 100644 --- a/chengying-server/matrix/k8s/monitor/cluster_status_monitor.go +++ b/chengying-server/matrix/monitor/cluster_status_monitor.go @@ -1,31 +1,11 @@ -// Licensed to Apache Software Foundation(ASF) under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. Apache Software Foundation(ASF) licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - package monitor import ( "dtstack.com/dtstack/easymatrix/matrix/base" "dtstack.com/dtstack/easymatrix/matrix/host" - "dtstack.com/dtstack/easymatrix/matrix/k8s/constant" "dtstack.com/dtstack/easymatrix/matrix/log" "dtstack.com/dtstack/easymatrix/matrix/model" - modelkube "dtstack.com/dtstack/easymatrix/matrix/model/kube" "fmt" - "strconv" "time" ) @@ -61,13 +41,7 @@ func StartClusterStatusM() { "LEFT JOIN deploy_cluster_list ON deploy_cluster_list.id = deploy_cluster_host_rel.clusterId " + "LEFT JOIN %s as h ON deploy_cluster_host_rel.sid = h.sid " + "WHERE deploy_cluster_host_rel.is_deleted=0 and deploy_cluster_list.id = ? and deploy_cluster_list.is_deleted=0 and h.isDeleted=0 and h.status is not NULL" - if cluster.Type == model.DEPLOY_CLUSTER_TYPE_KUBERNETES && cluster.Mode == model.DEPLOY_CLUSTER_MODE_IMPORT { - clusterStatus := processImportK8sClusterStatus(cluster.Id) - model.DeployClusterList.UpdateClusterStatus(cluster.Id,clusterStatus) - continue - } else { - hostPersist = "deploy_host" - } + hostPersist = "deploy_host" query = fmt.Sprintf(query, hostPersist) hostList := make([]HostStatus, 0) if _ = model.USE_MYSQL_DB().Select(&hostList, query, cluster.Id); len(hostList) == 0 { @@ -125,27 +99,3 @@ func processK8SClusterStaus(cluster model.ClusterInfo, hostList []HostStatus) { } model.DeployClusterList.UpdateClusterStatus(cluster.Id, model.DEPLOY_CLUSTER_STATUS_PENDING) } - - -//it's pretty different with the before. -//one of the cluster's namespaced client is valid. the cluster is running -func processImportK8sClusterStatus(cid int) int{ - validtbscs,err :=modelkube.DeployNamespaceList.Select(strconv.Itoa(cid),constant.NAMESPACE_VALID,"","","") - if err != nil{ - log.Errorf("in the cycle to update cluster status, find valid namespace occurs the error %v",err) - return model.DEPLOY_CLUSTER_STATUS_WAITING - } - invalidtbscs,err := modelkube.DeployNamespaceList.Select(strconv.Itoa(cid),constant.NAMESPACE_INVALID,"","","") - if err != nil{ - log.Errorf("in the cycle to update cluster status, find invalid namespace occurs the error %v",err) - return model.DEPLOY_CLUSTER_STATUS_WAITING - } - if len(validtbscs) == 0{ - if len(invalidtbscs) > 0{ - return model.DEPLOY_CLUSTER_STATUS_ERROR - } - return model.DEPLOY_CLUSTER_STATUS_WAITING - }else{ - return model.DEPLOY_CLUSTER_STATUS_RUNNING - } -} diff --git a/chengying-server/matrix/monitor/monitor.go b/chengying-server/matrix/monitor/monitor.go new file mode 100644 index 0000000..3198aee --- /dev/null +++ b/chengying-server/matrix/monitor/monitor.go @@ -0,0 +1,5 @@ +package monitor + +func StartMonitot() { + go StartClusterStatusM() +} diff --git a/chengying-server/matrix/k8s/monitor/resource_monitor.go b/chengying-server/matrix/monitor/resource_monitor.go similarity index 89% rename from chengying-server/matrix/k8s/monitor/resource_monitor.go rename to chengying-server/matrix/monitor/resource_monitor.go index dbc33f0..f047f3d 100644 --- a/chengying-server/matrix/k8s/monitor/resource_monitor.go +++ b/chengying-server/matrix/monitor/resource_monitor.go @@ -1,20 +1,3 @@ -// Licensed to Apache Software Foundation(ASF) under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. Apache Software Foundation(ASF) licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - package monitor import ( @@ -23,7 +6,6 @@ import ( "dtstack.com/dtstack/easymatrix/go-common/db-helper" "dtstack.com/dtstack/easymatrix/matrix/log" "dtstack.com/dtstack/easymatrix/matrix/model" - modelkube "dtstack.com/dtstack/easymatrix/matrix/model/kube" "dtstack.com/dtstack/easymatrix/matrix/util" "dtstack.com/dtstack/easymatrix/schema" "encoding/json" @@ -34,6 +16,7 @@ import ( "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" "strconv" "strings" + "time" ) var ( @@ -347,6 +330,7 @@ func handlePodE(event *events.Event) error { if len(pod.Status.HostIP) == 0 { return nil } + time.Sleep(3 * time.Second) err = triggerInstanceListUpdate(pod, labels) if err != nil { log.Errorf("%v", err.Error()) @@ -516,50 +500,22 @@ func handleMoleE(event *events.Event) error { } return nil } -func handleEvent(event *events.Event) error{ - bts,err := json.Marshal(event.Object) - if err != nil{ - log.Errorf("[resource_monitor]: mashal obj err %v",err) - return err - } - e := &v1.Event{} - err = json.Unmarshal(bts,e) - if err != nil{ - log.Errorf("[resource_monitor]: unmashal obj to corev1 event error %v",err) - return err - } - resource := e.InvolvedObject.Kind+"/"+e.InvolvedObject.Name - if err != nil{ - log.Errorf("[resouce_monitor]: convert string %s to int error %v",event.Workspaceid,err ) - return err - } - - saveEvent := &modelkube.DeployNamespaceEventSchema{ - Type: e.Type, - Reason: e.Reason, - Resource: resource, - Message: e.Message, - NamespaceId: event.Workspaceid, - Time: e.LastTimestamp.Local(), - } - return modelkube.DeployNamespaceEvent.Insert(saveEvent) -} -func handleWorkload(event *events.Event) error{ +func handleWorkload(event *events.Event) error { obj, err := json.Marshal(event.Object) if err != nil { - log.Errorf("[resource_monitor]: mashal obj err %v",err) + log.Errorf("[resource_monitor]: mashal obj err %v", err) return err } process := &workloadv1beta1.WorkloadProcess{} err = json.Unmarshal(obj, process) if err != nil { - log.Errorf("[resource_monitor]: unmashal obj to workload error %v",err) + log.Errorf("[resource_monitor]: unmashal obj to workload error %v", err) return err } phase := process.Status.Phase - fmt.Println("=====-----+++",phase) + fmt.Println("=====-----+++", phase) switch event.Operation { case events.OPERATION_CREATE_OR_UPDATE: var pid, clusterId int @@ -638,28 +594,3 @@ func handleWorkload(event *events.Event) error{ func hanldeDefaultE(obj interface{}) error { return nil } - -func HandleResourceM(event *events.Event) error { - sigc <- 0 - defer func() { - <-sigc - }() - log.Infof("k8s resourcce monitor get event, key: %v", event.Key) - switch event.Resource { - case "Pod": - return handlePodE(event) - case "Event": - return handleEvent(event) - case "Service": - return handleServiceE(event) - case "Deployment": - return handleDeploymentE(event) - case "Ingress": - return handleIngressE(event) - case "WorkloadProcess": - return handleWorkload(event) - default: - return handleMoleE(event) - } - return nil -} From 428a9a7c3a9f24ed5018f5a4a860c678465c8020 Mon Sep 17 00:00:00 2001 From: wangqi Date: Wed, 30 Nov 2022 17:12:51 +0800 Subject: [PATCH 2/2] fix(command): service stop operator list --- chengying-server/matrix/api/impl/agent.go | 4 ++++ chengying-server/matrix/api/impl/cluster.go | 4 ++-- chengying-server/matrix/instance/instancer.go | 5 ++++- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/chengying-server/matrix/api/impl/agent.go b/chengying-server/matrix/api/impl/agent.go index 31cb1e7..78fb271 100644 --- a/chengying-server/matrix/api/impl/agent.go +++ b/chengying-server/matrix/api/impl/agent.go @@ -19,6 +19,7 @@ package impl import ( "database/sql" + dbhelper "dtstack.com/dtstack/easymatrix/go-common/db-helper" "dtstack.com/dtstack/easymatrix/matrix/encrypt" "encoding/base64" "encoding/json" @@ -902,6 +903,7 @@ func HostInstallStepEnvInit(sid string, aid int) error { log.Errorf("DeployHostList.GetHostInfoBySid error:%v", err) } //生成 operationid 并且落库 + startTime := time.Now() operationId := uuid.NewV4().String() err = model.OperationList.Insert(model.OperationInfo{ ClusterId: clusterHostRel.ClusterId, @@ -922,6 +924,8 @@ func HostInstallStepEnvInit(sid string, aid int) error { if err := host.AgentInstall.EnvironmentInit(sid, execId); err != nil { log.Errorf("\t\tHostInstallStepEnvInit error: %v", err) model.DeployHostList.UpdateStatus(aid, host.InitInitializeShFail, host.ERROR_HOST_INIT+","+err.Error()) + err = model.OperationList.UpdateStatusByOperationId(operationId, enums.ExecStatusType.Failed.Code, dbhelper.NullTime{Time: time.Now(), Valid: true}, + sql.NullFloat64{Float64: time.Now().Sub(startTime).Seconds(), Valid: true}) return err } model.DeployHostList.UpdateStatus(aid, host.InitInitializeShOk, host.SUCCESS_HOST_INIT) diff --git a/chengying-server/matrix/api/impl/cluster.go b/chengying-server/matrix/api/impl/cluster.go index cc96fcc..075f4b5 100644 --- a/chengying-server/matrix/api/impl/cluster.go +++ b/chengying-server/matrix/api/impl/cluster.go @@ -3541,9 +3541,9 @@ func ShellStatusReport(ctx context.Context) apibase.Result { return err } if errors.Is(err, sql.ErrNoRows) || - execShellInfo.ExecStatus != enums.ExecStatusType.Running.Code || + execShellInfo.ExecStatus != enums.ExecStatusType.Running.Code { //如果脚本类型为启动 不允许修改 - execShellInfo.ShellType == enums.ShellType.Start.Code { + //execShellInfo.ShellType == enums.ShellType.Start.Code { return nil } diff --git a/chengying-server/matrix/instance/instancer.go b/chengying-server/matrix/instance/instancer.go index aa6ea60..47e3abd 100644 --- a/chengying-server/matrix/instance/instancer.go +++ b/chengying-server/matrix/instance/instancer.go @@ -703,7 +703,10 @@ func (this *instance) Stop(stopAgentOptionsTypeArr ...int) (ret error) { stopAgentOptionsType = stopAgentOptionsTypeArr[0] } - err, agentServerResp := agent.AgentClient.AgentStop(this.agentId, stopAgentOptionsType, "") + execId := uuid.NewV4().String() + model.ExecShellList.InsertExecShellInfo(this.clusterId, this.operationId, execId, this.schema.ProductName, this.name, this.sid, enums.ShellType.Start.Code) + + err, agentServerResp := agent.AgentClient.AgentStop(this.agentId, stopAgentOptionsType, execId) if err != nil { msg := fmt.Sprintf("exec stop err: %v", err.Error()) return this.handleError(model.INSTANCE_STATUS_STOP_FAIL, msg, this.agentId, "")