From ea428eb722a384ea8e5d02ea03ee7ccdda872229 Mon Sep 17 00:00:00 2001 From: Jesse Suen Date: Thu, 17 Jan 2019 19:38:35 -0800 Subject: [PATCH] Fix ability to unset ApplicationSource specific parameters (#1041) --- cmd/argocd/commands/app.go | 11 +++++++++++ pkg/apis/application/v1alpha1/types.go | 12 ++++++++++++ 2 files changed, 23 insertions(+) diff --git a/cmd/argocd/commands/app.go b/cmd/argocd/commands/app.go index 20abc2fdcd..30d3403e03 100644 --- a/cmd/argocd/commands/app.go +++ b/cmd/argocd/commands/app.go @@ -421,6 +421,10 @@ func setKsonnetOpt(src *argoappv1.ApplicationSource, env *string) { } if env != nil { src.Ksonnet.Environment = *env + src.Environment = *env + } + if src.Ksonnet.IsZero() { + src.Ksonnet = nil } } @@ -431,6 +435,9 @@ func setKustomizeOpt(src *argoappv1.ApplicationSource, namePrefix *string) { if namePrefix != nil { src.Kustomize.NamePrefix = *namePrefix } + if src.Kustomize.IsZero() { + src.Kustomize = nil + } } func setHelmOpt(src *argoappv1.ApplicationSource, valueFiles []string) { @@ -439,6 +446,10 @@ func setHelmOpt(src *argoappv1.ApplicationSource, valueFiles []string) { } if valueFiles != nil { src.Helm.ValueFiles = valueFiles + src.ValuesFiles = valueFiles + } + if src.Helm.IsZero() { + src.Helm = nil } } diff --git a/pkg/apis/application/v1alpha1/types.go b/pkg/apis/application/v1alpha1/types.go index 0c96ed7b33..c973fc0998 100644 --- a/pkg/apis/application/v1alpha1/types.go +++ b/pkg/apis/application/v1alpha1/types.go @@ -91,18 +91,30 @@ type ApplicationSourceHelm struct { ValueFiles []string `json:"valueFiles,omitempty" protobuf:"bytes,1,opt,name=valueFiles"` } +func (h *ApplicationSourceHelm) IsZero() bool { + return len(h.ValueFiles) == 0 +} + // ApplicationSourceKustomize holds kustomize specific options type ApplicationSourceKustomize struct { // NamePrefix is a prefix appended to resources for kustomize apps NamePrefix string `json:"namePrefix" protobuf:"bytes,1,opt,name=namePrefix"` } +func (k *ApplicationSourceKustomize) IsZero() bool { + return k.NamePrefix == "" +} + // ApplicationSourceKsonnet holds ksonnet specific options type ApplicationSourceKsonnet struct { // Environment is a ksonnet application environment name Environment string `json:"environment,omitempty" protobuf:"bytes,1,opt,name=environment"` } +func (k *ApplicationSourceKsonnet) IsZero() bool { + return k.Environment == "" +} + // ApplicationDestination contains deployment destination information type ApplicationDestination struct { // Server overrides the environment server value in the ksonnet app.yaml