github.com/argoproj/argo-cd@v1.8.7/util/argo/normalizer.go (about)

     1  package argo
     2  
     3  import (
     4  	"github.com/argoproj/argo-cd/pkg/apis/application/v1alpha1"
     5  	"github.com/argoproj/argo-cd/util/argo/normalizers"
     6  
     7  	"github.com/argoproj/gitops-engine/pkg/diff"
     8  	"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
     9  )
    10  
    11  // NewDiffNormalizer creates normalizer that uses Argo CD and application settings to normalize the resource prior to diffing.
    12  func NewDiffNormalizer(ignore []v1alpha1.ResourceIgnoreDifferences, overrides map[string]v1alpha1.ResourceOverride) (diff.Normalizer, error) {
    13  	ignoreNormalizer, err := normalizers.NewIgnoreNormalizer(ignore, overrides)
    14  	if err != nil {
    15  		return nil, err
    16  	}
    17  	knownTypesNorm, err := normalizers.NewKnownTypesNormalizer(overrides)
    18  	if err != nil {
    19  		return nil, err
    20  	}
    21  
    22  	return &composableNormalizer{normalizers: []diff.Normalizer{ignoreNormalizer, knownTypesNorm}}, nil
    23  }
    24  
    25  type composableNormalizer struct {
    26  	normalizers []diff.Normalizer
    27  }
    28  
    29  // Normalize performs resource normalization.
    30  func (n *composableNormalizer) Normalize(un *unstructured.Unstructured) error {
    31  	for i := range n.normalizers {
    32  		if err := n.normalizers[i].Normalize(un); err != nil {
    33  			return err
    34  		}
    35  	}
    36  	return nil
    37  }