-
Notifications
You must be signed in to change notification settings - Fork 1
/
module.go
155 lines (124 loc) · 3.78 KB
/
module.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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
/*
* Copyright (c) 2019 VMware, Inc. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0
*/
package applications
import (
"context"
"path"
"path/filepath"
"github.com/pkg/errors"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/runtime/schema"
"github.com/vmware/octant/internal/config"
"github.com/vmware/octant/internal/describer"
"github.com/vmware/octant/internal/generator"
"github.com/vmware/octant/internal/module"
"github.com/vmware/octant/internal/octant"
"github.com/vmware/octant/pkg/navigation"
"github.com/vmware/octant/pkg/view/component"
)
// Options are options for configuring Module.
type Options struct {
DashConfig config.Dash
}
// Module is an applications module.
type Module struct {
Options
pathMatcher *describer.PathMatcher
}
var _ module.Module = (*Module)(nil)
// New creates an instance of Module.
func New(ctx context.Context, options Options) *Module {
pm := describer.NewPathMatcher("applications")
for _, pf := range rootDescriber.PathFilters() {
pm.Register(ctx, pf)
}
appDescriber := NewApplicationDescriber(options.DashConfig)
for _, pf := range appDescriber.PathFilters() {
pm.Register(ctx, pf)
}
return &Module{
Options: options,
pathMatcher: pm,
}
}
// Name is the name of the module.
func (m Module) Name() string {
return "applications"
}
// ClientRequestHandlers are client handlers for the module.
func (m Module) ClientRequestHandlers() []octant.ClientRequestHandler {
return nil
}
// Content generates content for a content path.
func (m *Module) Content(ctx context.Context, contentPath string, opts module.ContentOptions) (component.ContentResponse, error) {
g, err := generator.NewGenerator(m.pathMatcher, m.DashConfig)
if err != nil {
return component.EmptyContentResponse, err
}
return g.Generate(ctx, contentPath, generator.Options{})
}
// ContentPath returns the root content path for the module.
func (m *Module) ContentPath() string {
return m.Name()
}
// Navigation generates navigation entries for the module.
func (m *Module) Navigation(ctx context.Context, namespace, root string) ([]navigation.Navigation, error) {
rootPath := filepath.Join(m.ContentPath(), "namespace", namespace)
applications, err := listApplications(ctx, m.DashConfig.ObjectStore(), namespace)
if err != nil {
return nil, err
}
rootNav := navigation.Navigation{
Title: "Applications",
Path: rootPath,
}
for _, application := range applications {
childPath := path.Join(rootPath, application.Name, application.Instance, application.Version)
rootNav.Children = append(rootNav.Children, navigation.Navigation{
Title: application.Title(),
Path: childPath,
})
}
return []navigation.Navigation{rootNav}, nil
}
// SetNamespace sets the module's namespace.
func (m Module) SetNamespace(namespace string) error {
return nil
}
// Start does nothing.
func (m Module) Start() error {
return nil
}
// Stop does nothing.
func (m Module) Stop() {
}
// SetContext does nothing.
func (m Module) SetContext(ctx context.Context, contextName string) error {
return nil
}
// Generators does nothing.
func (m Module) Generators() []octant.Generator {
return nil
}
// SupportedGroupVersionKind does nothing.
func (m Module) SupportedGroupVersionKind() []schema.GroupVersionKind {
return nil
}
// GroupVersionKindPath does nothing.
func (m Module) GroupVersionKindPath(namespace, apiVersion, kind, name string) (string, error) {
return "", errors.Errorf("not supported")
}
// AddCRD does nothing.
func (m Module) AddCRD(ctx context.Context, crd *unstructured.Unstructured) error {
return nil
}
// RemoveCRD does nothing.
func (m Module) RemoveCRD(ctx context.Context, crd *unstructured.Unstructured) error {
return nil
}
// ResetCRDs does nothing.
func (m Module) ResetCRDs(ctx context.Context) error {
return nil
}