-
Notifications
You must be signed in to change notification settings - Fork 12
/
model.go
61 lines (56 loc) · 1.79 KB
/
model.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/*
* Copyright 2022 Holoinsight Project Authors. Licensed under Apache-2.0.
*/
package k8ssync
import (
regpb "github.com/traas-stack/holoinsight-agent/pkg/server/registry/pb"
)
type (
Resource struct {
Namespace string `json:"namespace"`
Name string `json:"name"`
App string `json:"app"`
Labels map[string]string `json:"labels"`
Annotations map[string]string `json:"annotations"`
Ip string `json:"ip"`
Hostname string `json:"hostname"`
HostIP string `json:"hostIP"`
Status string `json:"status"`
Spec map[string]string `json:"spec"`
}
FullSyncRequest struct {
Apikey string `json:"apikey"`
Type string `json:"type"`
Workspace string `json:"workspace"`
Cluster string `json:"cluster"`
Resources []*Resource `json:"resources"`
}
DeltaSyncRequest struct {
Apikey string `json:"apikey"`
Type string `json:"type"`
Workspace string `json:"workspace"`
Cluster string `json:"cluster"`
Add []*Resource `json:"add"`
Del []*Resource `json:"del"`
}
)
func convertToPbResource(resource *Resource) *regpb.MetaSync_Resource {
return ®pb.MetaSync_Resource{
Name: resource.Name,
Namespace: resource.Namespace,
Labels: resource.Labels,
Annotations: resource.Annotations,
App: resource.App,
Ip: resource.Ip,
Hostname: resource.Hostname,
HostIP: resource.HostIP,
Spec: resource.Spec,
}
}
func convertToPbResourceSlice(resources []*Resource) []*regpb.MetaSync_Resource {
ret := make([]*regpb.MetaSync_Resource, len(resources))
for i, resource := range resources {
ret[i] = convertToPbResource(resource)
}
return ret
}