Skip to content

Commit

Permalink
fix: spec.source.helm.valuesObject should use replace patch strategy
Browse files Browse the repository at this point in the history
Signed-off-by: Alexander Matyushentsev <[email protected]>
  • Loading branch information
alexmt committed May 2, 2024
1 parent 220dee0 commit 5c9f939
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pkg/apis/application/v1alpha1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ type ApplicationSourceHelm struct {
SkipCrds bool `json:"skipCrds,omitempty" protobuf:"bytes,9,opt,name=skipCrds"`
// ValuesObject specifies Helm values to be passed to helm template, defined as a map. This takes precedence over Values.
// +kubebuilder:pruning:PreserveUnknownFields
ValuesObject *runtime.RawExtension `json:"valuesObject,omitempty" protobuf:"bytes,10,opt,name=valuesObject"`
ValuesObject *runtime.RawExtension `patchStrategy:"replace" json:"valuesObject,omitempty" protobuf:"bytes,10,opt,name=valuesObject"`
}

// HelmParameter is a parameter that's passed to helm template during manifest generation
Expand Down
35 changes: 35 additions & 0 deletions pkg/apis/application/v1alpha1/types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ import (
"testing"
"time"

"github.com/argoproj/gitops-engine/pkg/diff"
"github.com/stretchr/testify/require"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/utils/pointer"

argocdcommon "github.com/argoproj/argo-cd/v2/common"
Expand Down Expand Up @@ -3730,3 +3733,35 @@ func TestApplicationSpec_GetSourcePtrByIndex(t *testing.T) {
})
}
}

func TestHelmValuesObjectHasReplaceStrategy(t *testing.T) {
app := Application{
Spec: ApplicationSpec{
Source: &ApplicationSource{
Helm: &ApplicationSourceHelm{
ValuesObject: &runtime.RawExtension{
Object: &unstructured.Unstructured{Object: map[string]interface{}{"key": []string{"value"}}},
},
},
},
},
}

appModified := Application{
Spec: ApplicationSpec{
Source: &ApplicationSource{
Helm: &ApplicationSourceHelm{
ValuesObject: &runtime.RawExtension{
Object: &unstructured.Unstructured{Object: map[string]interface{}{"key": []string{"value-modified1"}}},
},
},
},
},
}

patch, _, err := diff.CreateTwoWayMergePatch(
app,
appModified, Application{})
require.NoError(t, err)
assert.Equal(t, `{"spec":{"source":{"helm":{"valuesObject":{"key":["value-modified1"]}}}}}`, string(patch))
}

0 comments on commit 5c9f939

Please sign in to comment.