Skip to content
This repository was archived by the owner on Jul 15, 2024. It is now read-only.

Commit 5787c33

Browse files
authored
ApplicationSet CRD size reduction, by removing validation (CRD defn) of nested merge/matrix generator (#463)
Signed-off-by: Jonathan West <[email protected]>
1 parent c8fb714 commit 5787c33

File tree

11 files changed

+5595
-27294
lines changed

11 files changed

+5595
-27294
lines changed

api/v1alpha1/applicationset_types.go

Lines changed: 53 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ limitations under the License.
1717
package v1alpha1
1818

1919
import (
20+
"encoding/json"
2021
"fmt"
2122
"sort"
2223

@@ -90,14 +91,18 @@ type ApplicationSetGenerator struct {
9091
// ApplicationSetNestedGenerator represents a generator nested within a combination-type generator (MatrixGenerator or
9192
// MergeGenerator).
9293
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"`
101106
}
102107

103108
type ApplicationSetNestedGenerators []ApplicationSetNestedGenerator
@@ -151,10 +156,30 @@ type MatrixGenerator struct {
151156
// NestedMatrixGenerator is a MatrixGenerator nested under another combination-type generator (MatrixGenerator or
152157
// MergeGenerator). NestedMatrixGenerator does not have an override template, because template overriding has no meaning
153158
// 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.
154163
type NestedMatrixGenerator struct {
155164
Generators ApplicationSetTerminalGenerators `json:"generators"`
156165
}
157166

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+
158183
// ToMatrixGenerator converts a NestedMatrixGenerator to a MatrixGenerator. This conversion is for convenience, allowing
159184
// a NestedMatrixGenerator to be used where a MatrixGenerator is expected (of course, the converted generator will have
160185
// no override template).
@@ -183,11 +208,31 @@ type MergeGenerator struct {
183208
// NestedMergeGenerator is a MergeGenerator nested under another combination-type generator (MatrixGenerator or
184209
// MergeGenerator). NestedMergeGenerator does not have an override template, because template overriding has no meaning
185210
// 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.
186215
type NestedMergeGenerator struct {
187216
Generators ApplicationSetTerminalGenerators `json:"generators"`
188217
MergeKeys []string `json:"mergeKeys"`
189218
}
190219

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+
191236
// ToMergeGenerator converts a NestedMergeGenerator to a MergeGenerator. This conversion is for convenience, allowing
192237
// a NestedMergeGenerator to be used where a MergeGenerator is expected (of course, the converted generator will have
193238
// no override template).

api/v1alpha1/zz_generated.deepcopy.go

Lines changed: 2 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

hack/boilerplate.go.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
/*
2-
3-
42
Licensed under the Apache License, Version 2.0 (the "License");
53
you may not use this file except in compliance with the License.
64
You may obtain a copy of the License at

0 commit comments

Comments
 (0)