-
Notifications
You must be signed in to change notification settings - Fork 198
/
localization.go
136 lines (109 loc) · 4.31 KB
/
localization.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
/*
Copyright 2021 The Clusternet 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 (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
// Important: Run "make generated" to regenerate code after modifying this file
// +genclient
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// +kubebuilder:resource:scope="Namespaced",shortName=loc;local,categories=clusternet
// +kubebuilder:printcolumn:name="AGE",type="date",JSONPath=".metadata.creationTimestamp"
// Localization represents the override config for a group of resources.
type Localization struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
Spec LocalizationSpec `json:"spec"`
}
// LocalizationSpec defines the desired state of Localization
type LocalizationSpec struct {
// OverridePolicy specifies the override policy for this Localization.
//
// +optional
// +kubebuilder:validation:Type=string
// +kubebuilder:validation:Enum=ApplyNow;ApplyLater
// +kubebuilder:default=ApplyLater
OverridePolicy OverridePolicy `json:"overridePolicy,omitempty"`
// Overrides holds all the OverrideConfig.
//
// +optional
Overrides []OverrideConfig `json:"overrides,omitempty"`
// Priority is an integer defining the relative importance of this Localization compared to others.
// Lower numbers are considered lower priority.
// And these Localization(s) will be applied by order from lower priority to higher.
// That means override values in lower Localization will be overridden by those in higher Localization.
//
// +optional
// +kubebuilder:validation:Maximum=1000
// +kubebuilder:validation:Minimum=0
// +kubebuilder:default=500
Priority int32 `json:"priority,omitempty"`
// Feed holds references to the objects the Localization applies to.
//
// +optional
Feed `json:"feed,omitempty"`
}
type OverridePolicy string
const (
// Apply overrides for all matched objects immediately, including those already populated
ApplyNow OverridePolicy = "ApplyNow"
// Apply overrides for all matched objects on next updates (including updates on Subscription,
// Manifest, HelmChart, etc) or new created objects.
ApplyLater OverridePolicy = "ApplyLater"
)
type OverrideType string
const (
// HelmType applies Helm values for all matched HelmCharts.
// Note: HelmType only works with HelmChart(s).
HelmType OverrideType = "Helm"
// JSONPatchType applies a json patch for all matched objects.
// Note: JSONPatchType does not work with HelmChart(s).
JSONPatchType OverrideType = "JSONPatch"
// MergePatchType applies a json merge patch for all matched objects.
// Note: MergePatchType does not work with HelmChart(s).
MergePatchType OverrideType = "MergePatch"
// StrategicMergePatchType won't be supported, since `patchStrategy`
// and `patchMergeKey` can not be retrieved.
)
// OverrideConfig holds information that describes a override config.
type OverrideConfig struct {
// Name indicate the OverrideConfig name.
//
// +optional
Name string `json:"name,omitempty"`
// Value represents override value.
//
// +required
// +kubebuilder:validation:Required
// +kubebuilder:validation:Type=string
Value string `json:"value"`
// Type specifies the override type for override value.
//
// +required
// +kubebuilder:validation:Required
// +kubebuilder:validation:Type=string
// +kubebuilder:validation:Enum=Helm;JSONPatch;MergePatch
Type OverrideType `json:"type"`
// OverrideChart indicates whether the override value for the HelmChart CR.
//
// +optional
OverrideChart bool `json:"overrideChart,omitempty"`
}
// +kubebuilder:object:root=true
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// LocalizationList contains a list of Localization
type LocalizationList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []Localization `json:"items"`
}