This repository has been archived by the owner on Jan 19, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 489
/
dash.go
111 lines (80 loc) · 2.41 KB
/
dash.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
/*
Copyright (c) 2021 the Octant contributors. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/
package config
import (
"context"
apiextv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"github.com/vmware-tanzu/octant/internal/kubeconfig"
"github.com/vmware-tanzu/octant/internal/module"
"github.com/vmware-tanzu/octant/internal/octant"
"github.com/vmware-tanzu/octant/internal/portforward"
"github.com/vmware-tanzu/octant/pkg/cluster"
"github.com/vmware-tanzu/octant/pkg/errors"
"github.com/vmware-tanzu/octant/pkg/log"
"github.com/vmware-tanzu/octant/pkg/plugin"
)
// ObjectHandler is a function that is run when a new object is available.
type ObjectHandler func(ctx context.Context, object *unstructured.Unstructured)
// CRDWatcher watches for CRDs.
type CRDWatcher interface {
Watch(ctx context.Context) error
AddConfig(config *CRDWatchConfig) error
}
// CRDWatchConfig is configuration for CRDWatcher.
type CRDWatchConfig struct {
Add ObjectHandler
Delete ObjectHandler
IsNamespaced bool
}
type BuildInfo struct {
Version string
Commit string
Time string
}
type Context struct {
Name string
DefaultNamespace string
}
// CanPerform returns true if config can perform actions on an object.
func (c *CRDWatchConfig) CanPerform(u *unstructured.Unstructured) bool {
spec, ok := u.Object["spec"].(map[string]interface{})
if !ok {
return false
}
scope, ok := spec["scope"].(string)
if !ok {
return false
}
if c.IsNamespaced && scope != string(apiextv1.NamespaceScoped) {
return false
}
if !c.IsNamespaced && scope != string(apiextv1.ClusterScoped) {
return false
}
return true
}
// Config is configuration for dash. It has knowledge of the all the major sections of
// dash.
type Dash interface {
octant.LinkGenerator
octant.Storage
ClusterClient() cluster.ClientInterface
CRDWatcher() CRDWatcher
ErrorStore() errors.ErrorStore
Logger() log.Logger
PluginManager() plugin.ManagerInterface
PortForwarder() portforward.PortForwarder
SetContextChosenInUI(contextChosen bool)
UseFSContext(ctx context.Context) error
UseContext(ctx context.Context, contextName string) error
CurrentContext() string
Contexts() []kubeconfig.Context
DefaultNamespace() string
Validate() error
ModuleManager() module.ManagerInterface
BuildInfo() (string, string, string)
KubeConfigPath() string
}