-
Notifications
You must be signed in to change notification settings - Fork 6
/
common_types.go
166 lines (129 loc) · 5.57 KB
/
common_types.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
/*
Copyright 2023. projectsveltos.io. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package v1alpha1
import (
"errors"
corev1 "k8s.io/api/core/v1"
)
const (
// PolicyTemplateAnnotation is the annotation that must be set on a policy when the
// policy is a template and needs variable sustitution.
PolicyTemplateAnnotation = "projectsveltos.io/template"
)
const (
// DeployedBySveltosAnnotation is an annotation Sveltos adds to
// EventSource/HealthCheck/Classifier/ResourceSummary instances deployed
// by sveltos in managed clusters. Those resources, once deployed in a
// managed cluster, are evaluated by sveltos services (sveltos-agent and
// drift-detection-manager) running in the managed cluster
DeployedBySveltosAnnotation = "projectsveltos.io/deployed-by-sveltos"
)
const (
// ServiceAccountNameLabel can be set on various Sveltos resources (ClusterProfile/EventSource/...)
// to indicate which admin (represented by a ServiceAccount) is creating it (service account name).
// ServiceAccountNameLabel used along with RoleRequest is Sveltos solution for multi tenancy.
ServiceAccountNameLabel = "projectsveltos.io/serviceaccount-name"
// ServiceAccountNamespaceLabel can be set on various Sveltos resources (ClusterProfile/EventSource/...)
// to indicate which admin (represented by a ServiceAccount) is creating it (service account namespace).
// ServiceAccountNamespaceLabel used along with RoleRequest is Sveltos solution for multi tenancy.
ServiceAccountNamespaceLabel = "projectsveltos.io/serviceaccount-namespace"
)
// ReferencedResourceKind is a string representation of allowed kind of resources
// that can be referenced in a ClusterProfile
type ReferencedResourceKind string
// Define the ReferencedResourceKind constants.
const (
SecretReferencedResourceKind ReferencedResourceKind = "Secret"
ConfigMapReferencedResourceKind ReferencedResourceKind = "ConfigMap"
)
const (
// ClusterProfileSecretType is the only accepted type of secret in resources.
ClusterProfileSecretType corev1.SecretType = "addons.projectsveltos.io/cluster-profile"
)
var (
// ErrSecretTypeNotSupported signals that a Secret is not supported.
ErrSecretTypeNotSupported = errors.New("unsupported secret type")
)
type Selector string
// +kubebuilder:validation:Enum:=Provisioning;Provisioned;Failed;Removing;Removed
type SveltosFeatureStatus string
const (
// SveltosStatusProvisioning indicates that sveltos feature is being
// provisioned in the workload cluster
SveltosStatusProvisioning = SveltosFeatureStatus("Provisioning")
// SveltosStatusProvisioned indicates that sveltos has been
// provisioned in the workload cluster
SveltosStatusProvisioned = SveltosFeatureStatus("Provisioned")
// SveltosStatusFailed indicates that configuring sveltos feature
// in the workload cluster failed
SveltosStatusFailed = SveltosFeatureStatus("Failed")
// SveltosStatusRemoving indicates that sveltos feature is being
// removed
SveltosStatusRemoving = SveltosFeatureStatus("Removing")
// SveltosStatusRemoved indicates that sveltos feature is removed
SveltosStatusRemoved = SveltosFeatureStatus("Removed")
)
type ClusterInfo struct {
// Cluster references the Cluster
Cluster corev1.ObjectReference `json:"cluster"`
// Hash represents the hash of the Classifier currently deployed
// in the Cluster
Hash []byte `json:"hash"`
// Status represents the state of the feature in the workload cluster
// +optional
Status SveltosFeatureStatus `json:"status,omitempty"`
// FailureMessage provides more information about the error.
// +optional
FailureMessage *string `json:"failureMessage,omitempty"`
}
// Operation specifies
// +kubebuilder:validation:Enum:=Equal;Different
type Operation string
const (
// OperationEqual will verify equality. Corresponds to ==
OperationEqual = Operation("Equal")
// OperationDifferent will verify difference. Corresponds to !=
OperationDifferent = Operation("Different")
)
type LabelFilter struct {
// Key is the label key
Key string `json:"key"`
// Operation is the comparison operation
Operation Operation `json:"operation"`
// Value is the label value
Value string `json:"value"`
}
// ResourceSelector defines what resources are a match
type ResourceSelector struct {
// Group of the resource deployed in the Cluster.
Group string `json:"group"`
// Version of the resource deployed in the Cluster.
Version string `json:"version"`
// Kind of the resource deployed in the Cluster.
// +kubebuilder:validation:MinLength=1
Kind string `json:"kind"`
// LabelFilters allows to filter resources based on current labels.
// +optional
LabelFilters []LabelFilter `json:"labelFilters,omitempty"`
// Namespace of the resource deployed in the Cluster.
// Empty for resources scoped at cluster level.
// +optional
Namespace string `json:"namespace,omitempty"`
// Evaluate contains a function "evaluate" in lua language.
// The function will be passed one of the object selected based on
// above criteria.
// Must return struct with field "matching" representing whether
// object is a match and an optional "message" field.
// +optional
Evaluate string `json:"evaluate,omitempty"`
}