-
Notifications
You must be signed in to change notification settings - Fork 5
/
bean.go
186 lines (161 loc) · 10.6 KB
/
bean.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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
package commonBean
import (
"k8s.io/apimachinery/pkg/api/meta"
"k8s.io/apimachinery/pkg/runtime/schema"
)
const (
SecretKind = "Secret"
ServiceKind = "Service"
ServiceAccountKind = "ServiceAccount"
EndpointsKind = "Endpoints"
EndPointsSlice = "EndpointSlice"
DeploymentKind = "Deployment"
ReplicaSetKind = "ReplicaSet"
StatefulSetKind = "StatefulSet"
DaemonSetKind = "DaemonSet"
IngressKind = "Ingress"
JobKind = "Job"
PersistentVolumeClaimKind = "PersistentVolumeClaim"
CustomResourceDefinitionKind = "CustomResourceDefinition"
PodKind = "Pod"
APIServiceKind = "APIService"
NamespaceKind = "Namespace"
HorizontalPodAutoscalerKind = "HorizontalPodAutoscaler"
Spec = "spec"
Template = "template"
JobTemplate = "jobTemplate"
Ports = "ports"
Port = "port"
Subsets = "subsets"
Nodes = "nodes"
Containers = "containers"
InitContainers = "initContainers"
EphemeralContainers = "ephemeralContainers"
Image = "image"
)
var defaultContainerPath = []string{Spec, Template, Spec}
var cronJobContainerPath = []string{Spec, JobTemplate, Spec, Template, Spec}
var podContainerPath = []string{Spec}
var kindToPath = map[string][]string{
PodKind: podContainerPath,
K8sClusterResourceCronJobKind: cronJobContainerPath,
}
func GetContainerSubPathForKind(kind string) []string {
if path, ok := kindToPath[kind]; ok {
return path
}
return defaultContainerPath
}
const (
PersistentVolumeClaimsResourceType = "persistentvolumeclaims"
StatefulSetsResourceType = "statefulsets"
)
const (
Group = "group"
Version = "version"
Kind = "kind"
)
type HookType string
const (
HookTypePreSync HookType = "PreSync"
HookTypeSync HookType = "Sync"
HookTypePostSync HookType = "PostSync"
HookTypeSkip HookType = "Skip"
HookTypeSyncFail HookType = "SyncFail"
)
type OperationPhase string
const (
OperationRunning OperationPhase = "Running"
OperationTerminating OperationPhase = "Terminating"
OperationFailed OperationPhase = "Failed"
OperationError OperationPhase = "Error"
OperationSucceeded OperationPhase = "Succeeded"
)
const K8sClusterResourceNameKey = "name"
const K8sClusterResourcePriorityKey = "priority"
const K8sClusterResourceNamespaceKey = "namespace"
const K8sClusterResourceMetadataKey = "metadata"
const K8sClusterResourceMetadataNameKey = "name"
const K8sClusterResourceOwnerReferenceKey = "ownerReferences"
const K8sClusterResourceCreationTimestampKey = "creationTimestamp"
const K8sClusterResourceRowsKey = "rows"
const K8sClusterResourceCellKey = "cells"
const K8sClusterResourceColumnDefinitionKey = "columnDefinitions"
const K8sClusterResourceObjectKey = "object"
const K8sClusterResourceGroupKey = "group"
const K8sClusterResourceKindKey = "kind"
const K8sClusterResourceVersionKey = "version"
const K8sClusterResourceApiVersionKey = "apiVersion"
const K8sClusterResourceReplicationControllerKind = "ReplicationController"
const K8sClusterResourceRolloutKind = "Rollout"
const K8sClusterResourceRolloutGroup = "argoproj.io"
const K8sClusterResourceCronJobKind = "CronJob"
const V1VERSION = "v1"
const BatchGroup = "batch"
const AppsGroup = "apps"
const (
K8sResourceColumnDefinitionName = "Name"
K8sResourceColumnDefinitionSyncStatus = "Sync Status"
K8sResourceColumnDefinitionHealthStatus = "Health Status"
K8sClusterResourceStatusKey = "status"
K8sClusterResourceHealthKey = "health"
K8sClusterResourceResourcesKey = "resources"
K8sClusterResourceSyncKey = "sync"
)
var KindVsChildrenGvk = map[string][]schema.GroupVersionKind{
DeploymentKind: append(make([]schema.GroupVersionKind, 0), schema.GroupVersionKind{Group: AppsGroup, Version: V1VERSION, Kind: ReplicaSetKind}, schema.GroupVersionKind{Version: V1VERSION, Kind: PodKind}),
K8sClusterResourceRolloutKind: append(make([]schema.GroupVersionKind, 0), schema.GroupVersionKind{Group: AppsGroup, Version: V1VERSION, Kind: ReplicaSetKind}, schema.GroupVersionKind{Version: V1VERSION, Kind: PodKind}),
K8sClusterResourceCronJobKind: append(make([]schema.GroupVersionKind, 0), schema.GroupVersionKind{Group: BatchGroup, Version: V1VERSION, Kind: JobKind}, schema.GroupVersionKind{Version: V1VERSION, Kind: PodKind}),
JobKind: append(make([]schema.GroupVersionKind, 0), schema.GroupVersionKind{Version: V1VERSION, Kind: PodKind}),
ReplicaSetKind: append(make([]schema.GroupVersionKind, 0), schema.GroupVersionKind{Version: V1VERSION, Kind: PodKind}),
DaemonSetKind: append(make([]schema.GroupVersionKind, 0), schema.GroupVersionKind{Version: V1VERSION, Kind: PodKind}),
StatefulSetKind: append(make([]schema.GroupVersionKind, 0), schema.GroupVersionKind{Version: V1VERSION, Kind: PodKind}),
K8sClusterResourceReplicationControllerKind: append(make([]schema.GroupVersionKind, 0), schema.GroupVersionKind{Version: V1VERSION, Kind: PodKind}),
}
const (
// EvictionKind represents the kind of evictions object
EvictionKind = "Eviction"
// EvictionSubresource represents the kind of evictions object as pod's subresource
EvictionSubresource = "pods/eviction"
)
// constants starts
var podsGvrAndScope = &GvrAndScope{Gvr: schema.GroupVersionResource{Group: "", Version: "v1", Resource: "pods"}, Scope: meta.RESTScopeNameNamespace}
var replicaSetGvrAndScope = &GvrAndScope{Gvr: schema.GroupVersionResource{Group: "apps", Version: "v1", Resource: "replicasets"}, Scope: meta.RESTScopeNameNamespace}
var jobGvrAndScope = &GvrAndScope{Gvr: schema.GroupVersionResource{Group: "batch", Version: "v1", Resource: "jobs"}, Scope: meta.RESTScopeNameNamespace}
var endpointsGvrAndScope = &GvrAndScope{Gvr: schema.GroupVersionResource{Group: "", Version: "v1", Resource: "endpoints"}, Scope: meta.RESTScopeNameNamespace}
var endpointSliceV1Beta1GvrAndScope = &GvrAndScope{Gvr: schema.GroupVersionResource{Group: "discovery.k8s.io", Version: "v1beta1", Resource: "endpointslices"}, Scope: meta.RESTScopeNameNamespace}
var endpointSliceV1GvrAndScope = &GvrAndScope{Gvr: schema.GroupVersionResource{Group: "discovery.k8s.io", Version: "v1", Resource: "endpointslices"}, Scope: meta.RESTScopeNameNamespace}
var pvGvrAndScope = &GvrAndScope{Gvr: schema.GroupVersionResource{Group: "", Version: "v1", Resource: "persistentvolumes"}, Scope: meta.RESTScopeNameRoot}
var pvcGvrAndScope = &GvrAndScope{Gvr: schema.GroupVersionResource{Group: "", Version: "v1", Resource: "persistentvolumeclaims"}, Scope: meta.RESTScopeNameNamespace}
var stsGvrAndScope = &GvrAndScope{Gvr: schema.GroupVersionResource{Group: "apps", Version: "v1", Resource: "statefulsets"}, Scope: meta.RESTScopeNameNamespace}
var configGvrAndScope = &GvrAndScope{Gvr: schema.GroupVersionResource{Group: "", Version: "v1", Resource: "configmaps"}, Scope: meta.RESTScopeNameNamespace}
var hpaGvrAndScope = &GvrAndScope{Gvr: schema.GroupVersionResource{Group: "autoscaling", Version: "v2", Resource: "horizontalpodautoscalers"}, Scope: meta.RESTScopeNameNamespace}
var deployGvrAndScope = &GvrAndScope{Gvr: schema.GroupVersionResource{Group: "apps", Version: "v1", Resource: "deployments"}, Scope: meta.RESTScopeNameNamespace}
var serviceGvrAndScope = &GvrAndScope{Gvr: schema.GroupVersionResource{Group: "", Version: "v1", Resource: "services"}, Scope: meta.RESTScopeNameNamespace}
var daemonGvrAndScope = &GvrAndScope{Gvr: schema.GroupVersionResource{Group: "apps", Version: "v1", Resource: "daemonsets"}, Scope: meta.RESTScopeNameNamespace}
var gvkVsChildGvrAndScope = map[schema.GroupVersionKind][]*GvrAndScope{
schema.GroupVersionKind{Group: "apps", Version: "v1", Kind: "Deployment"}: append(make([]*GvrAndScope, 0), replicaSetGvrAndScope),
schema.GroupVersionKind{Group: "argoproj.io", Version: "v1alpha1", Kind: "Rollout"}: append(make([]*GvrAndScope, 0), replicaSetGvrAndScope),
schema.GroupVersionKind{Group: "apps", Version: "v1", Kind: "ReplicaSet"}: append(make([]*GvrAndScope, 0), podsGvrAndScope),
schema.GroupVersionKind{Group: "batch", Version: "v1", Kind: "CronJob"}: append(make([]*GvrAndScope, 0), jobGvrAndScope),
schema.GroupVersionKind{Group: "batch", Version: "v1", Kind: "Job"}: append(make([]*GvrAndScope, 0), podsGvrAndScope),
schema.GroupVersionKind{Group: "apps", Version: "v1", Kind: "StatefulSet"}: append(make([]*GvrAndScope, 0), podsGvrAndScope, pvcGvrAndScope, stsGvrAndScope),
schema.GroupVersionKind{Group: "apps", Version: "v1", Kind: "DaemonSet"}: append(make([]*GvrAndScope, 0), podsGvrAndScope),
schema.GroupVersionKind{Group: "", Version: "v1", Kind: "Service"}: append(make([]*GvrAndScope, 0), endpointsGvrAndScope, endpointSliceV1Beta1GvrAndScope, endpointSliceV1GvrAndScope),
schema.GroupVersionKind{Group: "monitoring.coreos.com", Version: "v1", Kind: "Prometheus"}: append(make([]*GvrAndScope, 0), stsGvrAndScope, configGvrAndScope),
schema.GroupVersionKind{Group: "monitoring.coreos.com", Version: "v1", Kind: "Alertmanager"}: append(make([]*GvrAndScope, 0), stsGvrAndScope, configGvrAndScope),
schema.GroupVersionKind{Group: "keda.sh", Version: "v1alpha1", Kind: "ScaledObject"}: append(make([]*GvrAndScope, 0), hpaGvrAndScope),
schema.GroupVersionKind{Group: "autoscaling", Version: "v2", Kind: "HorizontalPodAutoscaler"}: append(make([]*GvrAndScope, 0), podsGvrAndScope),
schema.GroupVersionKind{Group: "flagger.app", Version: "v1beta1", Kind: "Canary"}: append(make([]*GvrAndScope, 0), deployGvrAndScope, serviceGvrAndScope, daemonGvrAndScope),
}
// constants end
type GvrAndScope struct {
Gvr schema.GroupVersionResource
Scope meta.RESTScopeName
}
//var K8sNativeGroups = []string{"", "admissionregistration.k8s.io", "apiextensions.k8s.io", "apiregistration.k8s.io", "apps", "authentication.k8s.io", "authorization.k8s.io",
// "autoscaling", "batch", "certificates.k8s.io", "coordination.k8s.io", "core", "discovery.k8s.io", "events.k8s.io", "flowcontrol.apiserver.k8s.io", "argoproj.io",
// "internal.apiserver.k8s.io", "networking.k8s.io", "node.k8s.io", "policy", "rbac.authorization.k8s.io", "resource.k8s.io", "scheduling.k8s.io", "storage.k8s.io"}
func GetGvkVsChildGvrAndScope() map[schema.GroupVersionKind][]*GvrAndScope {
return gvkVsChildGvrAndScope
}