@@ -17,6 +17,7 @@ limitations under the License.
17
17
package v1alpha1
18
18
19
19
import (
20
+ "encoding/json"
20
21
"fmt"
21
22
"sort"
22
23
@@ -90,14 +91,18 @@ type ApplicationSetGenerator struct {
90
91
// ApplicationSetNestedGenerator represents a generator nested within a combination-type generator (MatrixGenerator or
91
92
// MergeGenerator).
92
93
type ApplicationSetNestedGenerator struct {
93
- List * ListGenerator `json:"list,omitempty"`
94
- Clusters * ClusterGenerator `json:"clusters,omitempty"`
95
- Git * GitGenerator `json:"git,omitempty"`
96
- SCMProvider * SCMProviderGenerator `json:"scmProvider,omitempty"`
97
- ClusterDecisionResource * DuckTypeGenerator `json:"clusterDecisionResource,omitempty"`
98
- PullRequest * PullRequestGenerator `json:"pullRequest,omitempty"`
99
- Matrix * NestedMatrixGenerator `json:"matrix,omitempty"`
100
- Merge * NestedMergeGenerator `json:"merge,omitempty"`
94
+ List * ListGenerator `json:"list,omitempty"`
95
+ Clusters * ClusterGenerator `json:"clusters,omitempty"`
96
+ Git * GitGenerator `json:"git,omitempty"`
97
+ SCMProvider * SCMProviderGenerator `json:"scmProvider,omitempty"`
98
+ ClusterDecisionResource * DuckTypeGenerator `json:"clusterDecisionResource,omitempty"`
99
+ PullRequest * PullRequestGenerator `json:"pullRequest,omitempty"`
100
+
101
+ // Matrix should have the form of NestedMatrixGenerator
102
+ Matrix * apiextensionsv1.JSON `json:"matrix,omitempty"`
103
+
104
+ // Merge should have the form of NestedMergeGenerator
105
+ Merge * apiextensionsv1.JSON `json:"merge,omitempty"`
101
106
}
102
107
103
108
type ApplicationSetNestedGenerators []ApplicationSetNestedGenerator
@@ -151,10 +156,30 @@ type MatrixGenerator struct {
151
156
// NestedMatrixGenerator is a MatrixGenerator nested under another combination-type generator (MatrixGenerator or
152
157
// MergeGenerator). NestedMatrixGenerator does not have an override template, because template overriding has no meaning
153
158
// within the constituent generators of combination-type generators.
159
+ //
160
+ // NOTE: Nested matrix generator is not included directly in the CRD struct, instead it is included
161
+ // as a generic 'apiextensionsv1.JSON' object, and then marshalled into a NestedMatrixGenerator
162
+ // when processed.
154
163
type NestedMatrixGenerator struct {
155
164
Generators ApplicationSetTerminalGenerators `json:"generators"`
156
165
}
157
166
167
+ // ToNestedMatrixGenerator converts a JSON struct (from the K8s resource) to corresponding
168
+ // NestedMatrixGenerator object.
169
+ func ToNestedMatrixGenerator (j * apiextensionsv1.JSON ) (* NestedMatrixGenerator , error ) {
170
+ if j == nil {
171
+ return nil , nil
172
+ }
173
+
174
+ nestedMatrixGenerator := NestedMatrixGenerator {}
175
+ err := json .Unmarshal (j .Raw , & nestedMatrixGenerator )
176
+ if err != nil {
177
+ return nil , err
178
+ }
179
+
180
+ return & nestedMatrixGenerator , nil
181
+ }
182
+
158
183
// ToMatrixGenerator converts a NestedMatrixGenerator to a MatrixGenerator. This conversion is for convenience, allowing
159
184
// a NestedMatrixGenerator to be used where a MatrixGenerator is expected (of course, the converted generator will have
160
185
// no override template).
@@ -183,11 +208,31 @@ type MergeGenerator struct {
183
208
// NestedMergeGenerator is a MergeGenerator nested under another combination-type generator (MatrixGenerator or
184
209
// MergeGenerator). NestedMergeGenerator does not have an override template, because template overriding has no meaning
185
210
// within the constituent generators of combination-type generators.
211
+ //
212
+ // NOTE: Nested merge generator is not included directly in the CRD struct, instead it is included
213
+ // as a generic 'apiextensionsv1.JSON' object, and then marshalled into a NestedMergeGenerator
214
+ // when processed.
186
215
type NestedMergeGenerator struct {
187
216
Generators ApplicationSetTerminalGenerators `json:"generators"`
188
217
MergeKeys []string `json:"mergeKeys"`
189
218
}
190
219
220
+ // ToNestedMergeGenerator converts a JSON struct (from the K8s resource) to corresponding
221
+ // NestedMergeGenerator object.
222
+ func ToNestedMergeGenerator (j * apiextensionsv1.JSON ) (* NestedMergeGenerator , error ) {
223
+ if j == nil {
224
+ return nil , nil
225
+ }
226
+
227
+ nestedMergeGenerator := NestedMergeGenerator {}
228
+ err := json .Unmarshal (j .Raw , & nestedMergeGenerator )
229
+ if err != nil {
230
+ return nil , err
231
+ }
232
+
233
+ return & nestedMergeGenerator , nil
234
+ }
235
+
191
236
// ToMergeGenerator converts a NestedMergeGenerator to a MergeGenerator. This conversion is for convenience, allowing
192
237
// a NestedMergeGenerator to be used where a MergeGenerator is expected (of course, the converted generator will have
193
238
// no override template).
0 commit comments