-
Notifications
You must be signed in to change notification settings - Fork 505
/
v1alpha1_inspect.go
67 lines (53 loc) · 2.04 KB
/
v1alpha1_inspect.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
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
package runtime
import (
"context"
"fmt"
"github.com/cosi-project/runtime/pkg/controller"
"google.golang.org/protobuf/types/known/emptypb"
inspectapi "github.com/talos-systems/talos/pkg/machinery/api/inspect"
)
// InspectServer implements InspectService API.
type InspectServer struct {
inspectapi.UnimplementedInspectServiceServer
server *Server
}
// ControllerRuntimeDependencies implements inspect.InspectService interface.
func (s *InspectServer) ControllerRuntimeDependencies(ctx context.Context, in *emptypb.Empty) (*inspectapi.ControllerRuntimeDependenciesResponse, error) {
graph, err := s.server.Controller.V1Alpha2().DependencyGraph()
if err != nil {
return nil, fmt.Errorf("error fetching dependency graph: %w", err)
}
edges := make([]*inspectapi.ControllerDependencyEdge, 0, len(graph.Edges))
for i := range graph.Edges {
var edgeType inspectapi.DependencyEdgeType
switch graph.Edges[i].EdgeType {
case controller.EdgeOutputExclusive:
edgeType = inspectapi.DependencyEdgeType_OUTPUT_EXCLUSIVE
case controller.EdgeOutputShared:
edgeType = inspectapi.DependencyEdgeType_OUTPUT_SHARED
case controller.EdgeInputStrong:
edgeType = inspectapi.DependencyEdgeType_INPUT_STRONG
case controller.EdgeInputWeak:
edgeType = inspectapi.DependencyEdgeType_INPUT_WEAK
case controller.EdgeInputDestroyReady:
edgeType = inspectapi.DependencyEdgeType_INPUT_DESTROY_READY
}
edges = append(edges, &inspectapi.ControllerDependencyEdge{
ControllerName: graph.Edges[i].ControllerName,
EdgeType: edgeType,
ResourceNamespace: graph.Edges[i].ResourceNamespace,
ResourceType: graph.Edges[i].ResourceType,
ResourceId: graph.Edges[i].ResourceID,
})
}
return &inspectapi.ControllerRuntimeDependenciesResponse{
Messages: []*inspectapi.ControllerRuntimeDependency{
{
Edges: edges,
},
},
}, nil
}