/
configuration.go
executable file
·156 lines (126 loc) · 3.93 KB
/
configuration.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
156
/*
Copyright (c) 2019 VMware, Inc. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/
package configuration
import (
"context"
"path"
"github.com/pkg/errors"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/runtime/schema"
"github.com/kubenext/lissio/internal/api"
"github.com/kubenext/lissio/internal/config"
"github.com/kubenext/lissio/internal/controllers"
"github.com/kubenext/lissio/internal/describer"
"github.com/kubenext/lissio/internal/event"
"github.com/kubenext/lissio/internal/module"
"github.com/kubenext/lissio/pkg/action"
"github.com/kubenext/lissio/pkg/icon"
"github.com/kubenext/lissio/pkg/navigation"
"github.com/kubenext/lissio/pkg/view/component"
)
type Options struct {
DashConfig config.Dash
KubeConfigPath string
}
type Configuration struct {
Options
pathMatcher *describer.PathMatcher
kubeContextGenerator *event.ContextsGenerator
}
var _ module.Module = (*Configuration)(nil)
var _ module.ActionReceiver = (*Configuration)(nil)
func New(ctx context.Context, options Options) *Configuration {
pm := describer.NewPathMatcher("configuration")
for _, pf := range rootDescriber.PathFilters() {
pm.Register(ctx, pf)
}
return &Configuration{
Options: options,
pathMatcher: pm,
kubeContextGenerator: event.NewContextsGenerator(options.DashConfig),
}
}
func (Configuration) Name() string {
return "configuration"
}
func (c Configuration) ClientRequestHandlers() []controllers.ClientRequestHandler {
return nil
}
func (c *Configuration) SetContext(ctx context.Context, contextName string) error {
return nil
}
func (c *Configuration) Content(ctx context.Context, contentPath string, opts module.ContentOptions) (component.ContentResponse, error) {
pf, err := c.pathMatcher.Find(contentPath)
if err != nil {
if err == describer.ErrPathNotFound {
return component.EmptyContentResponse, api.NewNotFoundError(contentPath)
}
return component.EmptyContentResponse, err
}
options := describer.Options{
Fields: pf.Fields(contentPath),
LabelSet: opts.LabelSet,
Dash: c.DashConfig,
}
cResponse, err := pf.Describer.Describe(ctx, "", options)
if err != nil {
return component.EmptyContentResponse, err
}
return cResponse, nil
}
func (c *Configuration) ContentPath() string {
return c.Name()
}
func (c *Configuration) Navigation(ctx context.Context, namespace, root string) ([]navigation.Navigation, error) {
return []navigation.Navigation{
{
Title: "Configuration",
Path: path.Join(c.ContentPath(), "/"),
IconName: icon.Configuration,
Children: []navigation.Navigation{
{
Title: "Plugins",
Path: path.Join(c.ContentPath(), "plugins"),
IconName: icon.ConfigurationPlugin,
},
},
},
}, nil
}
func (Configuration) SetNamespace(namespace string) error {
return nil
}
func (Configuration) Start() error {
return nil
}
func (Configuration) Stop() {
}
func (c Configuration) SupportedGroupVersionKind() []schema.GroupVersionKind {
return []schema.GroupVersionKind{}
}
func (c Configuration) GroupVersionKindPath(namespace, apiVersion, kind, name string) (string, error) {
return "", errors.Errorf("configuration can't create paths for %s %s", apiVersion, kind)
}
func (c Configuration) AddCRD(ctx context.Context, crd *unstructured.Unstructured) error {
return nil
}
func (c Configuration) RemoveCRD(ctx context.Context, crd *unstructured.Unstructured) error {
return nil
}
func (c Configuration) ResetCRDs(ctx context.Context) error {
return nil
}
// Generators allow modules to send events to the frontend.
func (c Configuration) Generators() []controllers.Generator {
return []controllers.Generator{
c.kubeContextGenerator,
}
}
func (c *Configuration) ActionPaths() map[string]action.DispatcherFunc {
objectDeleter := NewObjectDeleter(c.DashConfig.Logger(), c.DashConfig.ObjectStore())
return map[string]action.DispatcherFunc{
objectDeleter.ActionName(): objectDeleter.Handle,
}
}