Skip to content

Commit

Permalink
do better
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com>
  • Loading branch information
crenshaw-dev committed Jul 27, 2023
1 parent c49c652 commit d15dd13
Show file tree
Hide file tree
Showing 13 changed files with 1,335 additions and 1,191 deletions.
9 changes: 4 additions & 5 deletions applicationset/controllers/applicationset_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -645,8 +645,8 @@ func (r *ApplicationSetReconciler) createOrUpdateInCluster(ctx context.Context,
found.ObjectMeta.Finalizers = generatedApp.Finalizers
found.ObjectMeta.Labels = generatedApp.Labels

if found != nil && found.Spec.IgnoreDifferences != nil {
err := applyIgnoreDifferences(*applicationSet.Spec.IgnoreDifferences, found, generatedApp)
if found != nil && len(found.Spec.IgnoreDifferences) > 0 {
err := applyIgnoreDifferences(applicationSet.Spec.IgnoreApplicationDifferences, found, generatedApp)
if err != nil {
return fmt.Errorf("failed to apply ignore differences: %w", err)
}
Expand All @@ -669,11 +669,10 @@ func (r *ApplicationSetReconciler) createOrUpdateInCluster(ctx context.Context,
return firstError
}

// applyIgnoreDifferences applies the ignore differences to the found application. It modifies the found application in place.
// applyIgnoreDifferences applies the ignore differences rules to the found application. It modifies the found application in place.
func applyIgnoreDifferences(applicationSetIgnoreDifferences argov1alpha1.ApplicationSetIgnoreDifferences, found *argov1alpha1.Application, generatedApp argov1alpha1.Application) error {
ignoreDifferences := []argov1alpha1.ResourceIgnoreDifferences{applicationSetIgnoreDifferences.ToApplicationIgnoreDifferences()}
diffConfig, err := argodiff.NewDiffConfigBuilder().
WithDiffSettings(ignoreDifferences, nil, false).
WithDiffSettings(applicationSetIgnoreDifferences.ToApplicationIgnoreDifferences(), nil, false).
WithNoCache().
Build()
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions applicationset/controllers/applicationset_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5720,7 +5720,7 @@ func Test_applyIgnoreDifferences(t *testing.T) {
{
name: "ignore target revision with jq",
ignoreDifferences: v1alpha1.ApplicationSetIgnoreDifferences{
JQPathExpressions: []string{".spec.source.targetRevision"},
{JQPathExpressions: []string{".spec.source.targetRevision"}},
},
foundApp: v1alpha1.Application{
TypeMeta: appMeta,
Expand Down Expand Up @@ -5750,7 +5750,7 @@ func Test_applyIgnoreDifferences(t *testing.T) {
{
name: "ignore helm parameter with jq",
ignoreDifferences: v1alpha1.ApplicationSetIgnoreDifferences{
JQPathExpressions: []string{".spec.source.helm.parameters[0].value"},
{JQPathExpressions: []string{".spec.source.helm.parameters[0].value"}},
},
foundApp: v1alpha1.Application{
TypeMeta: appMeta,
Expand Down
48 changes: 29 additions & 19 deletions assets/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -6009,23 +6009,6 @@
}
}
},
"v1alpha1ApplicationSetIgnoreDifferences": {
"type": "object",
"properties": {
"jqPathExpressions": {
"type": "array",
"items": {
"type": "string"
}
},
"jsonPointers": {
"type": "array",
"items": {
"type": "string"
}
}
}
},
"v1alpha1ApplicationSetList": {
"type": "object",
"title": "ApplicationSetList contains a list of ApplicationSet\n+k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object\n+kubebuilder:object:root=true",
Expand Down Expand Up @@ -6077,6 +6060,30 @@
}
}
},
"v1alpha1ApplicationSetResourceIgnoreDifferences": {
"description": "ApplicationSetResourceIgnoreDifferences configures how the ApplicationSet controller will ignore differences in live\napplications when applying changes from generated applications.",
"type": "object",
"properties": {
"jqPathExpressions": {
"description": "JQPathExpressions is a list of JQ path expressions to fields to ignore differences for.",
"type": "array",
"items": {
"type": "string"
}
},
"jsonPointers": {
"description": "JSONPointers is a list of JSON pointers to fields to ignore differences for.",
"type": "array",
"items": {
"type": "string"
}
},
"name": {
"description": "Name is the name of the application to ignore differences for. If not specified, the rule applies to all applications.",
"type": "string"
}
}
},
"v1alpha1ApplicationSetRolloutStep": {
"type": "object",
"properties": {
Expand Down Expand Up @@ -6125,8 +6132,11 @@
"type": "string"
}
},
"ignoreDifferences": {
"$ref": "#/definitions/v1alpha1ApplicationSetIgnoreDifferences"
"ignoreApplicationDifferences": {
"type": "array",
"items": {
"$ref": "#/definitions/v1alpha1ApplicationSetResourceIgnoreDifferences"
}
},
"preservedFields": {
"$ref": "#/definitions/v1alpha1ApplicationPreservedFields"
Expand Down
24 changes: 14 additions & 10 deletions manifests/core-install.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17470,17 +17470,21 @@ spec:
items:
type: string
type: array
ignoreDifferences:
properties:
jqPathExpressions:
items:
type: string
type: array
jsonPointers:
items:
ignoreApplicationDifferences:
items:
properties:
jqPathExpressions:
items:
type: string
type: array
jsonPointers:
items:
type: string
type: array
name:
type: string
type: array
type: object
type: object
type: array
preservedFields:
properties:
annotations:
Expand Down
24 changes: 14 additions & 10 deletions manifests/crds/applicationset-crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12983,17 +12983,21 @@ spec:
items:
type: string
type: array
ignoreDifferences:
properties:
jqPathExpressions:
items:
type: string
type: array
jsonPointers:
items:
ignoreApplicationDifferences:
items:
properties:
jqPathExpressions:
items:
type: string
type: array
jsonPointers:
items:
type: string
type: array
name:
type: string
type: array
type: object
type: object
type: array
preservedFields:
properties:
annotations:
Expand Down
24 changes: 14 additions & 10 deletions manifests/ha/install.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17470,17 +17470,21 @@ spec:
items:
type: string
type: array
ignoreDifferences:
properties:
jqPathExpressions:
items:
type: string
type: array
jsonPointers:
items:
ignoreApplicationDifferences:
items:
properties:
jqPathExpressions:
items:
type: string
type: array
jsonPointers:
items:
type: string
type: array
name:
type: string
type: array
type: object
type: object
type: array
preservedFields:
properties:
annotations:
Expand Down
24 changes: 14 additions & 10 deletions manifests/install.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17470,17 +17470,21 @@ spec:
items:
type: string
type: array
ignoreDifferences:
properties:
jqPathExpressions:
items:
type: string
type: array
jsonPointers:
items:
ignoreApplicationDifferences:
items:
properties:
jqPathExpressions:
items:
type: string
type: array
jsonPointers:
items:
type: string
type: array
name:
type: string
type: array
type: object
type: object
type: array
preservedFields:
properties:
annotations:
Expand Down
4 changes: 2 additions & 2 deletions pkg/apis/api-rules/violation_exceptions.list
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ API rule violation: list_type_missing,github.com/argoproj/argo-cd/v2/pkg/apis/ap
API rule violation: list_type_missing,github.com/argoproj/argo-cd/v2/pkg/apis/application/v1alpha1,AppProjectSpec,SourceRepos
API rule violation: list_type_missing,github.com/argoproj/argo-cd/v2/pkg/apis/application/v1alpha1,ApplicationMatchExpression,Values
API rule violation: list_type_missing,github.com/argoproj/argo-cd/v2/pkg/apis/application/v1alpha1,ApplicationPreservedFields,Annotations
API rule violation: list_type_missing,github.com/argoproj/argo-cd/v2/pkg/apis/application/v1alpha1,ApplicationSetIgnoreDifferences,JQPathExpressions
API rule violation: list_type_missing,github.com/argoproj/argo-cd/v2/pkg/apis/application/v1alpha1,ApplicationSetIgnoreDifferences,JSONPointers
API rule violation: list_type_missing,github.com/argoproj/argo-cd/v2/pkg/apis/application/v1alpha1,ApplicationSetResourceIgnoreDifferences,JQPathExpressions
API rule violation: list_type_missing,github.com/argoproj/argo-cd/v2/pkg/apis/application/v1alpha1,ApplicationSetResourceIgnoreDifferences,JSONPointers
API rule violation: list_type_missing,github.com/argoproj/argo-cd/v2/pkg/apis/application/v1alpha1,ApplicationSetRolloutStep,MatchExpressions
API rule violation: list_type_missing,github.com/argoproj/argo-cd/v2/pkg/apis/application/v1alpha1,ApplicationSetRolloutStrategy,Steps
API rule violation: list_type_missing,github.com/argoproj/argo-cd/v2/pkg/apis/application/v1alpha1,ApplicationSetSpec,Generators
Expand Down
31 changes: 25 additions & 6 deletions pkg/apis/application/v1alpha1/applicationset_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ type ApplicationSetSpec struct {
PreservedFields *ApplicationPreservedFields `json:"preservedFields,omitempty" protobuf:"bytes,6,opt,name=preservedFields"`
GoTemplateOptions []string `json:"goTemplateOptions,omitempty" protobuf:"bytes,7,opt,name=goTemplateOptions"`
// ApplyNestedSelectors enables selectors defined within the generators of two level-nested matrix or merge generators
ApplyNestedSelectors bool `json:"applyNestedSelectors,omitempty" protobuf:"bytes,8,name=applyNestedSelectors"`
IgnoreDifferences *ApplicationSetIgnoreDifferences `json:"ignoreDifferences,omitempty" protobuf:"bytes,9,name=ignoreDifferences"`
ApplyNestedSelectors bool `json:"applyNestedSelectors,omitempty" protobuf:"bytes,8,name=applyNestedSelectors"`
IgnoreApplicationDifferences ApplicationSetIgnoreDifferences `json:"ignoreApplicationDifferences,omitempty" protobuf:"bytes,9,name=ignoreApplicationDifferences"`
}

type ApplicationPreservedFields struct {
Expand Down Expand Up @@ -127,15 +127,34 @@ type ApplicationSetSyncPolicy struct {
ApplicationsSync *ApplicationsSyncPolicy `json:"applicationsSync,omitempty" protobuf:"bytes,2,opt,name=applicationsSync,casttype=ApplicationsSyncPolicy"`
}

type ApplicationSetIgnoreDifferences struct {
JSONPointers []string `json:"jsonPointers,omitempty" protobuf:"bytes,1,name=jsonPointers"`
JQPathExpressions []string `json:"jqPathExpressions,omitempty" protobuf:"bytes,2,name=jqExpressions"`
// ApplicationSetIgnoreDifferences configures how the ApplicationSet controller will ignore differences in live
// applications when applying changes from generated applications.
type ApplicationSetIgnoreDifferences []ApplicationSetResourceIgnoreDifferences

func (a ApplicationSetIgnoreDifferences) ToApplicationIgnoreDifferences() []ResourceIgnoreDifferences {
var result []ResourceIgnoreDifferences
for _, item := range a {
result = append(result, item.ToApplicationResourceIgnoreDifferences())
}
return result
}

// ApplicationSetResourceIgnoreDifferences configures how the ApplicationSet controller will ignore differences in live
// applications when applying changes from generated applications.
type ApplicationSetResourceIgnoreDifferences struct {
// Name is the name of the application to ignore differences for. If not specified, the rule applies to all applications.
Name string `json:"name,omitempty" protobuf:"bytes,1,name=name"`
// JSONPointers is a list of JSON pointers to fields to ignore differences for.
JSONPointers []string `json:"jsonPointers,omitempty" protobuf:"bytes,2,name=jsonPointers"`
// JQPathExpressions is a list of JQ path expressions to fields to ignore differences for.
JQPathExpressions []string `json:"jqPathExpressions,omitempty" protobuf:"bytes,3,name=jqExpressions"`
}

func (a *ApplicationSetIgnoreDifferences) ToApplicationIgnoreDifferences() ResourceIgnoreDifferences {
func (a *ApplicationSetResourceIgnoreDifferences) ToApplicationResourceIgnoreDifferences() ResourceIgnoreDifferences {
return ResourceIgnoreDifferences{
Kind: ApplicationSchemaGroupVersionKind.Kind,
Group: ApplicationSchemaGroupVersionKind.Group,
Name: a.Name,
JSONPointers: a.JSONPointers,
JQPathExpressions: a.JQPathExpressions,
}
Expand Down
Loading

0 comments on commit d15dd13

Please sign in to comment.