-
Notifications
You must be signed in to change notification settings - Fork 873
/
envbinding_types.go
175 lines (137 loc) · 5.93 KB
/
envbinding_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
167
168
169
170
171
172
173
174
175
/*
Copyright 2021. The KubeVela Authors.
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 (
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"github.com/oam-dev/kubevela/apis/core.oam.dev/common"
"github.com/oam-dev/kubevela/apis/core.oam.dev/condition"
)
// ClusterManagementEngine represents a multi-cluster management solution
type ClusterManagementEngine string
const (
// OCMEngine represents Open-Cluster-Management multi-cluster management solution
OCMEngine ClusterManagementEngine = "ocm"
// SingleClusterEngine represents single cluster ClusterManagerEngine
SingleClusterEngine ClusterManagementEngine = "single-cluster"
// ClusterGatewayEngine represents multi-cluster management solution with cluster-gateway
ClusterGatewayEngine ClusterManagementEngine = "cluster-gateway"
)
// EnvBindingPhase is a label for the condition of a EnvBinding at the current time
type EnvBindingPhase string
const (
// EnvBindingPrepare means EnvBinding is preparing the pre-work for cluster scheduling
EnvBindingPrepare EnvBindingPhase = "preparing"
// EnvBindingRendering means EnvBinding is rendering the apps in different envs
EnvBindingRendering EnvBindingPhase = "rendering"
// EnvBindingScheduling means EnvBinding is deciding which cluster the apps is scheduled to.
EnvBindingScheduling EnvBindingPhase = "scheduling"
// EnvBindingFinished means EnvBinding finished env binding
EnvBindingFinished EnvBindingPhase = "finished"
)
// EnvPatch specify the parameter configuration for different environments
type EnvPatch struct {
Components []common.ApplicationComponent `json:"components"`
}
// NamespaceSelector defines the rules to select a Namespace resource.
// Either name or labels is needed.
type NamespaceSelector struct {
// Name is the name of the namespace.
Name string `json:"name,omitempty"`
// Labels defines the label selector to select the namespace.
Labels map[string]string `json:"labels,omitempty"`
}
// EnvPlacement defines the placement rules for an app.
type EnvPlacement struct {
ClusterSelector *common.ClusterSelector `json:"clusterSelector,omitempty"`
NamespaceSelector *NamespaceSelector `json:"namespaceSelector,omitempty"`
}
// EnvSelector defines which components should this env contains
type EnvSelector struct {
Components []string `json:"components,omitempty"`
}
// EnvConfig is the configuration for different environments.
type EnvConfig struct {
Name string `json:"name"`
Placement EnvPlacement `json:"placement,omitempty"`
Selector *EnvSelector `json:"selector,omitempty"`
Patch EnvPatch `json:"patch"`
}
// AppTemplate represents a application to be configured.
type AppTemplate struct {
// +kubebuilder:validation:EmbeddedResource
// +kubebuilder:pruning:PreserveUnknownFields
runtime.RawExtension `json:",inline"`
}
// ClusterDecision recorded the mapping of environment and cluster
type ClusterDecision struct {
Env string `json:"env"`
Cluster string `json:"cluster,omitempty"`
Namespace string `json:"namespace,omitempty"`
}
// A ConfigMapReference is a reference to a configMap in an arbitrary namespace.
type ConfigMapReference struct {
// Name of the secret.
Name string `json:"name"`
// Namespace of the secret.
Namespace string `json:"namespace,omitempty"`
}
// A EnvBindingSpec defines the desired state of a EnvBinding.
type EnvBindingSpec struct {
Engine ClusterManagementEngine `json:"engine,omitempty"`
// AppTemplate indicates the application template.
AppTemplate AppTemplate `json:"appTemplate"`
Envs []EnvConfig `json:"envs"`
// OutputResourcesTo specifies the namespace and name of a ConfigMap
// which store the resources rendered after differentiated configuration
// +optional
OutputResourcesTo *ConfigMapReference `json:"outputResourcesTo,omitempty"`
}
// A EnvBindingStatus is the status of EnvBinding
type EnvBindingStatus struct {
// ConditionedStatus reflects the observed status of a resource
condition.ConditionedStatus `json:",inline"`
Phase EnvBindingPhase `json:"phase,omitempty"`
ClusterDecisions []ClusterDecision `json:"clusterDecisions,omitempty"`
// ResourceTracker record the status of the ResourceTracker
ResourceTracker *corev1.ObjectReference `json:"resourceTracker,omitempty"`
}
// EnvBinding is the Schema for the EnvBinding API
// +kubebuilder:object:root=true
// +kubebuilder:subresource:status
// +kubebuilder:resource:scope=Namespaced,categories={oam},shortName=envbind
// +kubebuilder:printcolumn:name="ENGINE",type=string,JSONPath=`.spec.engine`
// +kubebuilder:printcolumn:name="PHASE",type=string,JSONPath=`.status.phase`
// +kubebuilder:printcolumn:name="AGE",type=date,JSONPath=".metadata.creationTimestamp"
type EnvBinding struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
Spec EnvBindingSpec `json:"spec,omitempty"`
Status EnvBindingStatus `json:"status,omitempty"`
}
// +kubebuilder:object:root=true
// EnvBindingList contains a list of EnvBinding.
type EnvBindingList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []EnvBinding `json:"items"`
}
// SetConditions set condition for EnvBinding
func (e *EnvBinding) SetConditions(c ...condition.Condition) {
e.Status.SetConditions(c...)
}
// GetCondition gets condition from EnvBinding
func (e *EnvBinding) GetCondition(conditionType condition.ConditionType) condition.Condition {
return e.Status.GetCondition(conditionType)
}