/
node-system-info-resolver.go
113 lines (96 loc) · 4.48 KB
/
node-system-info-resolver.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
// Package edgecluster implements different edge cluster GraphQL query resovlers required by the GraphQL transport layer
package edgecluster
import (
"context"
"github.com/decentralized-cloud/api-gateway/services/graphql/types/edgecluster"
edgeclusterGrpcContract "github.com/decentralized-cloud/edge-cluster/contract/grpc/go"
commonErrors "github.com/micro-business/go-core/system/errors"
"go.uber.org/zap"
)
type nodeSystemInfoResolver struct {
logger *zap.Logger
nodeInfo *edgeclusterGrpcContract.NodeSystemInfo
}
// NewNodeSystemInfoResolver creates new instance of the nodeSystemInfoResolver, setting up all dependencies and returns the instance
// ctx: Mandatory. Reference to the context
// logger: Mandatory. Reference to the logger service
// nodeInfo: Mandatory. Contains a set of ids/uuids to uniquely identify the node.
// Returns the new instance or error if something goes wrong
func NewNodeSystemInfoResolver(
ctx context.Context,
logger *zap.Logger,
nodeInfo *edgeclusterGrpcContract.NodeSystemInfo) (edgecluster.NodeSystemInfoResolverContract, error) {
if ctx == nil {
return nil, commonErrors.NewArgumentNilError("ctx", "ctx is required")
}
if logger == nil {
return nil, commonErrors.NewArgumentNilError("logger", "logger is required")
}
if nodeInfo == nil {
return nil, commonErrors.NewArgumentNilError("nodeInfo", "nodeInfo is required")
}
return &nodeSystemInfoResolver{
logger: logger,
nodeInfo: nodeInfo,
}, nil
}
// MachineID reported by the node. For unique machine identification in the cluster this field is preferred.
// ctx: Mandatory. Reference to the context
// Returns the MachineID reported by the node. For unique machine identification in the cluster this field is preferred.
func (r *nodeSystemInfoResolver) MachineID(ctx context.Context) string {
return r.nodeInfo.MachineID
}
// SystemUUID reported by the node. For unique machine identification MachineID is preferred. This field is specific to Red Hat hosts
// ctx: Mandatory. Reference to the context
// Returns the SystemUUID reported by the node. For unique machine identification MachineID is preferred. This field is specific to Red Hat hosts
func (r *nodeSystemInfoResolver) SystemUUID(ctx context.Context) string {
return r.nodeInfo.SystemUUID
}
// BootID reported by the node.
// ctx: Mandatory. Reference to the context
// Returns the Boot ID reported by the node.
func (r *nodeSystemInfoResolver) BootID(ctx context.Context) string {
return r.nodeInfo.BootID
}
// KernelVersion reported by the node from 'uname -r' (e.g. 3.16.0-0.bpo.4-amd64).
// ctx: Mandatory. Reference to the context
// Returns the Kernel Version reported by the node from 'uname -r' (e.g. 3.16.0-0.bpo.4-amd64).
func (r *nodeSystemInfoResolver) KernelVersion(ctx context.Context) string {
return r.nodeInfo.KernelVersion
}
// OSImage reported by the node from /etc/os-release (e.g. Debian GNU/Linux 7 (wheezy)).
// ctx: Mandatory. Reference to the context
// Returns the OS Image reported by the node from /etc/os-release (e.g. Debian GNU/Linux 7 (wheezy)).
func (r *nodeSystemInfoResolver) OSImage(ctx context.Context) string {
return r.nodeInfo.OsImage
}
// ContainerRuntimeVersion reported by the node through runtime remote API (e.g. docker://1.5.0).
// ctx: Mandatory. Reference to the context
// Returns the ContainerRuntime Version reported by the node through runtime remote API (e.g. docker://1.5.0).
func (r *nodeSystemInfoResolver) ContainerRuntimeVersion(ctx context.Context) string {
return r.nodeInfo.ContainerRuntimeVersion
}
// KubeletVersion reported by the node.
// ctx: Mandatory. Reference to the context
// Returns the Kubelet Version reported by the node.
func (r *nodeSystemInfoResolver) KubeletVersion(ctx context.Context) string {
return r.nodeInfo.KubeletVersion
}
// KubeProxyVersion reported by the node.
// ctx: Mandatory. Reference to the context
// Returns the KubeProxy Version reported by the node.
func (r *nodeSystemInfoResolver) KubeProxyVersion(ctx context.Context) string {
return r.nodeInfo.KubeProxyVersion
}
// OperatingSystem System reported by the node
// ctx: Mandatory. Reference to the context
// Returns the Operating System reported by the node
func (r *nodeSystemInfoResolver) OperatingSystem(ctx context.Context) string {
return r.nodeInfo.OperatingSystem
}
// The Architecture reported by the node
// ctx: Mandatory. Reference to the context
// Returns the Architecture reported by the node
func (r *nodeSystemInfoResolver) Architecture(ctx context.Context) string {
return r.nodeInfo.Architecture
}