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

ApplicationSet CRD size reduction, by removing validation (CRD defn) of nested merge/matrix generator #463

Merged
merged 2 commits into from
Jan 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 53 additions & 8 deletions api/v1alpha1/applicationset_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ limitations under the License.
package v1alpha1

import (
"encoding/json"
"fmt"
"sort"

Expand Down Expand Up @@ -90,14 +91,18 @@ type ApplicationSetGenerator struct {
// ApplicationSetNestedGenerator represents a generator nested within a combination-type generator (MatrixGenerator or
// MergeGenerator).
type ApplicationSetNestedGenerator struct {
List *ListGenerator `json:"list,omitempty"`
Clusters *ClusterGenerator `json:"clusters,omitempty"`
Git *GitGenerator `json:"git,omitempty"`
SCMProvider *SCMProviderGenerator `json:"scmProvider,omitempty"`
ClusterDecisionResource *DuckTypeGenerator `json:"clusterDecisionResource,omitempty"`
PullRequest *PullRequestGenerator `json:"pullRequest,omitempty"`
Matrix *NestedMatrixGenerator `json:"matrix,omitempty"`
Merge *NestedMergeGenerator `json:"merge,omitempty"`
List *ListGenerator `json:"list,omitempty"`
Clusters *ClusterGenerator `json:"clusters,omitempty"`
Git *GitGenerator `json:"git,omitempty"`
SCMProvider *SCMProviderGenerator `json:"scmProvider,omitempty"`
ClusterDecisionResource *DuckTypeGenerator `json:"clusterDecisionResource,omitempty"`
PullRequest *PullRequestGenerator `json:"pullRequest,omitempty"`

// Matrix should have the form of NestedMatrixGenerator
Matrix *apiextensionsv1.JSON `json:"matrix,omitempty"`

// Merge should have the form of NestedMergeGenerator
Merge *apiextensionsv1.JSON `json:"merge,omitempty"`
}

type ApplicationSetNestedGenerators []ApplicationSetNestedGenerator
Expand Down Expand Up @@ -151,10 +156,30 @@ type MatrixGenerator struct {
// NestedMatrixGenerator is a MatrixGenerator nested under another combination-type generator (MatrixGenerator or
// MergeGenerator). NestedMatrixGenerator does not have an override template, because template overriding has no meaning
// within the constituent generators of combination-type generators.
//
// NOTE: Nested matrix generator is not included directly in the CRD struct, instead it is included
// as a generic 'apiextensionsv1.JSON' object, and then marshalled into a NestedMatrixGenerator
// when processed.
type NestedMatrixGenerator struct {
Generators ApplicationSetTerminalGenerators `json:"generators"`
}

// ToNestedMatrixGenerator converts a JSON struct (from the K8s resource) to corresponding
// NestedMatrixGenerator object.
func ToNestedMatrixGenerator(j *apiextensionsv1.JSON) (*NestedMatrixGenerator, error) {
if j == nil {
return nil, nil
}

nestedMatrixGenerator := NestedMatrixGenerator{}
err := json.Unmarshal(j.Raw, &nestedMatrixGenerator)
if err != nil {
return nil, err
}

return &nestedMatrixGenerator, nil
}

// ToMatrixGenerator converts a NestedMatrixGenerator to a MatrixGenerator. This conversion is for convenience, allowing
// a NestedMatrixGenerator to be used where a MatrixGenerator is expected (of course, the converted generator will have
// no override template).
Expand Down Expand Up @@ -183,11 +208,31 @@ type MergeGenerator struct {
// NestedMergeGenerator is a MergeGenerator nested under another combination-type generator (MatrixGenerator or
// MergeGenerator). NestedMergeGenerator does not have an override template, because template overriding has no meaning
// within the constituent generators of combination-type generators.
//
// NOTE: Nested merge generator is not included directly in the CRD struct, instead it is included
// as a generic 'apiextensionsv1.JSON' object, and then marshalled into a NestedMergeGenerator
// when processed.
type NestedMergeGenerator struct {
Generators ApplicationSetTerminalGenerators `json:"generators"`
MergeKeys []string `json:"mergeKeys"`
}

// ToNestedMergeGenerator converts a JSON struct (from the K8s resource) to corresponding
// NestedMergeGenerator object.
func ToNestedMergeGenerator(j *apiextensionsv1.JSON) (*NestedMergeGenerator, error) {
if j == nil {
return nil, nil
}

nestedMergeGenerator := NestedMergeGenerator{}
err := json.Unmarshal(j.Raw, &nestedMergeGenerator)
if err != nil {
return nil, err
}

return &nestedMergeGenerator, nil
}

// ToMergeGenerator converts a NestedMergeGenerator to a MergeGenerator. This conversion is for convenience, allowing
// a NestedMergeGenerator to be used where a MergeGenerator is expected (of course, the converted generator will have
// no override template).
Expand Down
6 changes: 2 additions & 4 deletions api/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions hack/boilerplate.go.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
/*


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
Expand Down
Loading