fix import cycle
Former-commit-id: b82aeac93877cebca429e9855978f20ee0f16ee1
This commit is contained in:
parent
f071a81be6
commit
e2d6bd4d4d
|
@ -1,12 +1,18 @@
|
||||||
package kq
|
package kq
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"github.com/zeromicro/go-zero/core/logx"
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
"gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/svc"
|
"gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/svc"
|
||||||
"gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/types"
|
"gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/types"
|
||||||
"gitlink.org.cn/jcce-pcm/utils/tool"
|
"gitlink.org.cn/jcce-pcm/pcm-coordinator/model"
|
||||||
|
"io"
|
||||||
|
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
|
||||||
|
"k8s.io/apimachinery/pkg/runtime"
|
||||||
|
syaml "k8s.io/apimachinery/pkg/runtime/serializer/yaml"
|
||||||
|
kyaml "k8s.io/apimachinery/pkg/util/yaml"
|
||||||
)
|
)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -25,6 +31,41 @@ func NewScheduleCloudMq(ctx context.Context, svcCtx *svc.ServiceContext) *Schedu
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func UnMarshalK8sStruct(yamlString string, taskId int64) model.Cloud {
|
||||||
|
var cloud model.Cloud
|
||||||
|
d := kyaml.NewYAMLOrJSONDecoder(bytes.NewBufferString(yamlString), 4096)
|
||||||
|
var err error
|
||||||
|
for {
|
||||||
|
var rawObj runtime.RawExtension
|
||||||
|
err = d.Decode(&rawObj)
|
||||||
|
if err == io.EOF {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
}
|
||||||
|
obj := &unstructured.Unstructured{}
|
||||||
|
syaml.NewDecodingSerializer(unstructured.UnstructuredJSONScheme).Decode(rawObj.Raw, nil, obj)
|
||||||
|
if err != nil {
|
||||||
|
}
|
||||||
|
|
||||||
|
unstructuredMap, err := runtime.DefaultUnstructuredConverter.ToUnstructured(obj)
|
||||||
|
if err != nil {
|
||||||
|
}
|
||||||
|
|
||||||
|
unstructureObj := &unstructured.Unstructured{Object: unstructuredMap}
|
||||||
|
cloud = model.Cloud{
|
||||||
|
TaskId: taskId,
|
||||||
|
ApiVersion: unstructureObj.GetAPIVersion(),
|
||||||
|
Name: unstructureObj.GetName(),
|
||||||
|
Kind: unstructureObj.GetKind(),
|
||||||
|
Namespace: unstructureObj.GetNamespace(),
|
||||||
|
Status: "Saved",
|
||||||
|
ServiceName: "kubeNative",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return cloud
|
||||||
|
}
|
||||||
|
|
||||||
func (l *ScheduleCloudMq) Consume(_, val string) error {
|
func (l *ScheduleCloudMq) Consume(_, val string) error {
|
||||||
var task *types.TaskInfo
|
var task *types.TaskInfo
|
||||||
json.Unmarshal([]byte(val), &task)
|
json.Unmarshal([]byte(val), &task)
|
||||||
|
@ -33,7 +74,7 @@ func (l *ScheduleCloudMq) Consume(_, val string) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
cloud := tool.UnMarshalK8sStruct(string(bytes), task.TaskId)
|
cloud := UnMarshalK8sStruct(string(bytes), task.TaskId)
|
||||||
cloud.YamlString = string(bytes)
|
cloud.YamlString = string(bytes)
|
||||||
// 存储数据
|
// 存储数据
|
||||||
tx := l.svcCtx.DbEngin.Create(&cloud)
|
tx := l.svcCtx.DbEngin.Create(&cloud)
|
||||||
|
|
1
go.mod
1
go.mod
|
@ -6,6 +6,7 @@ require (
|
||||||
github.com/Masterminds/squirrel v1.5.4
|
github.com/Masterminds/squirrel v1.5.4
|
||||||
github.com/aws/aws-sdk-go v1.44.300
|
github.com/aws/aws-sdk-go v1.44.300
|
||||||
github.com/docker/docker v24.0.4+incompatible
|
github.com/docker/docker v24.0.4+incompatible
|
||||||
|
github.com/go-redis/redis v6.15.9+incompatible
|
||||||
github.com/go-sql-driver/mysql v1.7.1
|
github.com/go-sql-driver/mysql v1.7.1
|
||||||
github.com/jinzhu/copier v0.3.5
|
github.com/jinzhu/copier v0.3.5
|
||||||
github.com/pkg/errors v0.9.1
|
github.com/pkg/errors v0.9.1
|
||||||
|
|
Loading…
Reference in New Issue