From 4c678f906765d750ec3df90d0272e620e64c41cd Mon Sep 17 00:00:00 2001 From: Alena Varkockova Date: Wed, 31 Jul 2019 19:51:28 +0200 Subject: [PATCH 1/6] Update command --- pkg/kudoctl/cmd/update.go | 108 +++++++++++++++++++++++++++++ pkg/kudoctl/cmd/update_test.go | 98 ++++++++++++++++++++++++++ pkg/kudoctl/cmd/upgrade.go | 3 +- pkg/kudoctl/util/kudo/kudo.go | 2 +- pkg/kudoctl/util/kudo/kudo_test.go | 23 +++--- 5 files changed, 224 insertions(+), 10 deletions(-) create mode 100644 pkg/kudoctl/cmd/update.go create mode 100644 pkg/kudoctl/cmd/update_test.go diff --git a/pkg/kudoctl/cmd/update.go b/pkg/kudoctl/cmd/update.go new file mode 100644 index 000000000..4178a15fe --- /dev/null +++ b/pkg/kudoctl/cmd/update.go @@ -0,0 +1,108 @@ +package cmd + +import ( + "fmt" + + "github.com/kudobuilder/kudo/pkg/kudoctl/cmd/install" + "github.com/kudobuilder/kudo/pkg/kudoctl/util/kudo" + "github.com/pkg/errors" + "github.com/spf13/cobra" + "github.com/spf13/viper" +) + +var ( + updateExample = ` + The update argument must be a name of the instance. + + # Update dev-flink instance with setting parameter param with value value + kubectl kudo upgrade dev-flink -p param=value + + # Update dev-flink instance in namespace services with setting parameter param with value value + kubectl kudo upgrade dev-flink -n services -p param=value` +) + +type updateOptions struct { + Namespace string + Parameters map[string]string +} + +// defaultOptions initializes the install command options to its defaults +var defaultUpdateOptions = &updateOptions{ + Namespace: "default", +} + +// newUpgradeCmd creates the install command for the CLI +func newUpdateCmd() *cobra.Command { + options := defaultUpdateOptions + var parameters []string + upgradeCmd := &cobra.Command{ + Use: "update ", + Short: "Update installed KUDO operator.", + Long: `Update installed KUDO operator with new parameters.`, + Example: updateExample, + RunE: func(cmd *cobra.Command, args []string) error { + // Prior to command execution we parse and validate passed parameters + var err error + options.Parameters, err = install.GetParameterMap(parameters) + if err != nil { + return errors.WithMessage(err, "could not parse parameters") + } + return runUpdate(args, options) + }, + SilenceUsage: true, + } + + upgradeCmd.Flags().StringArrayVarP(¶meters, "parameter", "p", nil, "The parameter name and value separated by '='") + upgradeCmd.Flags().StringVar(&options.Namespace, "namespace", defaultOptions.Namespace, "The namespace where the instance you want to upgrade is installed in.") + + const usageFmt = "Usage:\n %s\n\nFlags:\n%s" + upgradeCmd.SetUsageFunc(func(cmd *cobra.Command) error { + fmt.Fprintf(upgradeCmd.OutOrStderr(), usageFmt, upgradeCmd.UseLine(), upgradeCmd.Flags().FlagUsages()) + return nil + }) + return upgradeCmd +} + +func validateUpdateCmd(args []string, options *updateOptions) error { + if len(args) != 1 { + return errors.New("expecting exactly one argument - name of the instance installed in your cluster") + } + if len(options.Parameters) == 0 { + return errors.New("Need to specify at least one parameter to override via -p otherwise there is nothing to update") + } + + return nil +} + +func runUpdate(args []string, options *updateOptions) error { + err := validateUpdateCmd(args, options) + if err != nil { + return err + } + instanceToUpdate := args[0] + + kc, err := kudo.NewClient(options.Namespace, viper.GetString("kubeconfig")) + if err != nil { + return errors.Wrap(err, "creating kudo client") + } + + return update(instanceToUpdate, kc, options) +} + +func update(instanceToUpdate string, kc *kudo.Client, options *updateOptions) error { + // Make sure the instance you want to upgrade exists + instance, err := kc.GetInstance(instanceToUpdate, options.Namespace) + if err != nil { + return errors.Wrapf(err, "verifying the instance does not already exist") + } + if instance == nil { + return fmt.Errorf("instance %s in namespace %s does not exist in the cluster", instanceToUpdate, options.Namespace) + } + + // Change instance to point to the new OV and optionally update parameters + err = kc.UpdateInstance(instanceToUpdate, options.Namespace, nil, options.Parameters) + if err != nil { + return errors.Wrapf(err, "updating instance %s", instanceToUpdate) + } + return nil +} diff --git a/pkg/kudoctl/cmd/update_test.go b/pkg/kudoctl/cmd/update_test.go new file mode 100644 index 000000000..449c81dbe --- /dev/null +++ b/pkg/kudoctl/cmd/update_test.go @@ -0,0 +1,98 @@ +package cmd + +import ( + "github.com/kudobuilder/kudo/pkg/apis/kudo/v1alpha1" + util "github.com/kudobuilder/kudo/pkg/util/kudo" + v1 "k8s.io/api/core/v1" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "strings" + "testing" +) + +func TestUpdateCommand_Validation(t *testing.T) { + tests := []struct { + name string + args []string + parameters map[string]string + err string + }{ + {"no argument", []string{}, map[string]string{"param":"value"}, "expecting exactly one argument - name of the instance installed in your cluster"}, + {"too many arguments", []string{"aaa", "bbb"}, map[string]string{"param":"value"}, "expecting exactly one argument - name of the instance installed in your cluster"}, + {"no instance name", []string{"arg"}, map[string]string{}, "Need to specify at least one parameter to override via -p otherwise there is nothing to update"}, + } + + for _, tt := range tests { + cmd := newUpdateCmd() + cmd.SetArgs(tt.args) + for _, v := range tt.parameters { + cmd.Flags().Set("p", v) + } + _, err := cmd.ExecuteC() + if err.Error() != tt.err { + t.Errorf("%s: expecting error %s got %v", tt.name, tt.err, err) + } + } +} + +func Testupdate(t *testing.T) { + testInstance := v1alpha1.Instance{ + TypeMeta: metav1.TypeMeta{ + APIVersion: "kudo.dev/v1alpha1", + Kind: "Instance", + }, + ObjectMeta: metav1.ObjectMeta{ + Labels: map[string]string{ + "controller-tools.k8s.io": "1.0", + util.OperatorLabel: "test", + }, + Name: "test", + }, + Spec: v1alpha1.InstanceSpec{ + OperatorVersion: v1.ObjectReference{ + Name: "test-1.0", + }, + }, + } + + installNamespace := "default" + tests := []struct { + name string + instanceExists bool + parameters map[string]string + errMessageContains string + }{ + {"instance does not exist", false, map[string]string{"param":"value"}, "instance test in namespace default does not exist in the cluster"}, + {"update parameters", true, map[string]string{"param":"value"}, ""}, + } + + for _, tt := range tests { + c := newTestClient() + if tt.instanceExists { + c.InstallInstanceObjToCluster(&testInstance, installNamespace) + } + + err := update(testInstance.Name, c, &updateOptions{ + Namespace: installNamespace, + Parameters: tt.parameters, + }) + if err != nil { + if !strings.Contains(err.Error(), tt.errMessageContains) { + t.Errorf("%s: expected error '%s' but got '%v'", tt.name, tt.errMessageContains, err) + } + } else if tt.errMessageContains != "" { + t.Errorf("%s: expected no error but got %v", tt.name, err) + } else { + // the upgrade should have passed without error + instance, err := c.GetInstance(testInstance.Name, installNamespace) + if err != nil { + t.Errorf("%s: error when getting instance to verify the test: %v", tt.name, err) + } + for k, v := range tt.parameters { + value, ok := instance.Spec.Parameters[k] + if !ok || value != v { + t.Errorf("%s: expected parameter %s to be updated to %s but params are %v", tt.name, k, v, instance.Spec.Parameters) + } + } + } + } +} diff --git a/pkg/kudoctl/cmd/upgrade.go b/pkg/kudoctl/cmd/upgrade.go index f2a6c8f68..b71921d3e 100644 --- a/pkg/kudoctl/cmd/upgrade.go +++ b/pkg/kudoctl/cmd/upgrade.go @@ -8,6 +8,7 @@ import ( "github.com/kudobuilder/kudo/pkg/kudoctl/cmd/install" "github.com/kudobuilder/kudo/pkg/kudoctl/util/kudo" "github.com/kudobuilder/kudo/pkg/kudoctl/util/repo" + util "github.com/kudobuilder/kudo/pkg/util/kudo" "github.com/pkg/errors" "github.com/spf13/cobra" "github.com/spf13/viper" @@ -157,7 +158,7 @@ func upgrade(newOv *v1alpha1.OperatorVersion, kc *kudo.Client, options *options) } // Change instance to point to the new OV and optionally update parameters - err = kc.UpdateInstance(options.InstanceName, options.Namespace, newOv.Name, options.Parameters) + err = kc.UpdateInstance(options.InstanceName, options.Namespace, util.String(ov.Name), options.Parameters) if err != nil { return errors.Wrapf(err, "updating instance to point to new operatorversion %s", newOv.Name) } diff --git a/pkg/kudoctl/util/kudo/kudo.go b/pkg/kudoctl/util/kudo/kudo.go index 48b70eb88..980f806b0 100644 --- a/pkg/kudoctl/util/kudo/kudo.go +++ b/pkg/kudoctl/util/kudo/kudo.go @@ -148,7 +148,7 @@ type patchValue struct { } // UpdateInstance updates operatorversion on instance -func (c *Client) UpdateInstance(instanceName, namespace, operatorVersionName string, parameters map[string]string) error { +func (c *Client) UpdateInstance(instanceName, namespace string, operatorVersionName *string, parameters map[string]string) error { instancePatch := []patchValue{ patchValue{ Op: "replace", diff --git a/pkg/kudoctl/util/kudo/kudo_test.go b/pkg/kudoctl/util/kudo/kudo_test.go index c00ebe732..7f5df0626 100644 --- a/pkg/kudoctl/util/kudo/kudo_test.go +++ b/pkg/kudoctl/util/kudo/kudo_test.go @@ -9,6 +9,7 @@ import ( "github.com/kudobuilder/kudo/pkg/apis/kudo/v1alpha1" "github.com/kudobuilder/kudo/pkg/client/clientset/versioned/fake" + util "github.com/kudobuilder/kudo/pkg/util/kudo" v1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) @@ -517,14 +518,15 @@ func TestKudoClient_UpdateOperatorVersion(t *testing.T) { installNamespace := "default" tests := []struct { name string - patchToVersion string + patchToVersion *string existingParameters map[string]string parametersToPatch map[string]string namespace string }{ - {"patch to version", "1.1.1", nil, nil, installNamespace}, - {"patch adding new parameter", "1.1.1", nil, map[string]string{"param": "value"}, installNamespace}, - {"patch updating parameter", "1.1.1", map[string]string{"param": "value"}, map[string]string{"param": "value2"}, installNamespace}, + {"patch to version", util.String("test-1.1.1"), nil, nil, installNamespace}, + {"patch adding new parameter", util.String("test-1.1.1"), nil, map[string]string{"param": "value"}, installNamespace}, + {"patch updating parameter", util.String("test-1.1.1"), map[string]string{"param": "value"}, map[string]string{"param": "value2"}, installNamespace}, + {"do not patch the version", nil, map[string]string{"param": "value"}, map[string]string{"param": "value2"}, installNamespace}, } for _, tt := range tests { @@ -538,11 +540,16 @@ func TestKudoClient_UpdateOperatorVersion(t *testing.T) { t.Errorf("Error creating operator version in tests setup for %s", tt.name) } - err = k2o.UpdateInstance(testInstance.Name, installNamespace, "test-1.1.1", tt.parametersToPatch) + err = k2o.UpdateInstance(testInstance.Name, installNamespace, tt.patchToVersion, tt.parametersToPatch) instance, _ := k2o.GetInstance(testInstance.Name, installNamespace) - expectedVersion := fmt.Sprintf("test-%s", tt.patchToVersion) - if err != nil || instance.Spec.OperatorVersion.Name != expectedVersion { - t.Errorf("%s:\nexpected version: %v\n got: %v, err: %v", tt.name, expectedVersion, instance.Spec.OperatorVersion.Name, err) + if tt.patchToVersion != nil { + if err != nil || instance.Spec.OperatorVersion.Name != util.StringValue(tt.patchToVersion) { + t.Errorf("%s:\nexpected version: %v\n got: %v, err: %v", tt.name, util.StringValue(tt.patchToVersion), instance.Spec.OperatorVersion.Name, err) + } + } else { + if instance.Spec.OperatorVersion.Name != testInstance.Spec.OperatorVersion.Name { + t.Errorf("%s:\nexpected version to not change from: %v\n err: %v", tt.name, instance.Spec.OperatorVersion.Name, err) + } } for n, v := range tt.parametersToPatch { From 73180a2645d1d1286dcbf9b060962d81b9d2cfe4 Mon Sep 17 00:00:00 2001 From: Alena Varkockova Date: Wed, 31 Jul 2019 20:18:27 +0200 Subject: [PATCH 2/6] Formatting --- pkg/kudoctl/cmd/update_test.go | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/pkg/kudoctl/cmd/update_test.go b/pkg/kudoctl/cmd/update_test.go index 449c81dbe..93058b4f8 100644 --- a/pkg/kudoctl/cmd/update_test.go +++ b/pkg/kudoctl/cmd/update_test.go @@ -1,23 +1,24 @@ package cmd import ( + "strings" + "testing" + "github.com/kudobuilder/kudo/pkg/apis/kudo/v1alpha1" util "github.com/kudobuilder/kudo/pkg/util/kudo" v1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "strings" - "testing" ) func TestUpdateCommand_Validation(t *testing.T) { tests := []struct { - name string - args []string + name string + args []string parameters map[string]string - err string + err string }{ - {"no argument", []string{}, map[string]string{"param":"value"}, "expecting exactly one argument - name of the instance installed in your cluster"}, - {"too many arguments", []string{"aaa", "bbb"}, map[string]string{"param":"value"}, "expecting exactly one argument - name of the instance installed in your cluster"}, + {"no argument", []string{}, map[string]string{"param": "value"}, "expecting exactly one argument - name of the instance installed in your cluster"}, + {"too many arguments", []string{"aaa", "bbb"}, map[string]string{"param": "value"}, "expecting exactly one argument - name of the instance installed in your cluster"}, {"no instance name", []string{"arg"}, map[string]string{}, "Need to specify at least one parameter to override via -p otherwise there is nothing to update"}, } @@ -34,7 +35,7 @@ func TestUpdateCommand_Validation(t *testing.T) { } } -func Testupdate(t *testing.T) { +func TestUpdate(t *testing.T) { testInstance := v1alpha1.Instance{ TypeMeta: metav1.TypeMeta{ APIVersion: "kudo.dev/v1alpha1", @@ -58,11 +59,11 @@ func Testupdate(t *testing.T) { tests := []struct { name string instanceExists bool - parameters map[string]string + parameters map[string]string errMessageContains string }{ - {"instance does not exist", false, map[string]string{"param":"value"}, "instance test in namespace default does not exist in the cluster"}, - {"update parameters", true, map[string]string{"param":"value"}, ""}, + {"instance does not exist", false, map[string]string{"param": "value"}, "instance test in namespace default does not exist in the cluster"}, + {"update parameters", true, map[string]string{"param": "value"}, ""}, } for _, tt := range tests { @@ -72,7 +73,7 @@ func Testupdate(t *testing.T) { } err := update(testInstance.Name, c, &updateOptions{ - Namespace: installNamespace, + Namespace: installNamespace, Parameters: tt.parameters, }) if err != nil { From 497c041cbdf4882c2f0e650337163915edde9547 Mon Sep 17 00:00:00 2001 From: Alena Varkockova Date: Thu, 1 Aug 2019 10:08:40 +0200 Subject: [PATCH 3/6] Actually add the command --- pkg/kudoctl/cmd/root.go | 1 + 1 file changed, 1 insertion(+) diff --git a/pkg/kudoctl/cmd/root.go b/pkg/kudoctl/cmd/root.go index 7aa7617ba..dced0a252 100644 --- a/pkg/kudoctl/cmd/root.go +++ b/pkg/kudoctl/cmd/root.go @@ -46,6 +46,7 @@ and serves as an API aggregation layer. cmd.AddCommand(newInstallCmd()) cmd.AddCommand(newUpgradeCmd()) + cmd.AddCommand(newUpdateCmd()) cmd.AddCommand(newGetCmd()) cmd.AddCommand(newPlanCmd()) cmd.AddCommand(newTestCmd()) From 502d895c4f0e67b2d7be2abb38409f4885003e70 Mon Sep 17 00:00:00 2001 From: Alena Varkockova Date: Thu, 1 Aug 2019 12:18:19 +0200 Subject: [PATCH 4/6] Print out happy message --- pkg/kudoctl/cmd/update.go | 1 + 1 file changed, 1 insertion(+) diff --git a/pkg/kudoctl/cmd/update.go b/pkg/kudoctl/cmd/update.go index 4178a15fe..624589dc3 100644 --- a/pkg/kudoctl/cmd/update.go +++ b/pkg/kudoctl/cmd/update.go @@ -104,5 +104,6 @@ func update(instanceToUpdate string, kc *kudo.Client, options *updateOptions) er if err != nil { return errors.Wrapf(err, "updating instance %s", instanceToUpdate) } + fmt.Printf("Instance %s was updated ヽ(•‿•)ノ") return nil } From c66c38a099f850e14082a033cf01239c791cfa38 Mon Sep 17 00:00:00 2001 From: Alena Varkockova Date: Thu, 1 Aug 2019 13:21:38 +0200 Subject: [PATCH 5/6] PR feedback --- pkg/kudoctl/cmd/update.go | 22 +++++++++++----------- pkg/kudoctl/cmd/upgrade.go | 2 +- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/pkg/kudoctl/cmd/update.go b/pkg/kudoctl/cmd/update.go index 624589dc3..8847c0adb 100644 --- a/pkg/kudoctl/cmd/update.go +++ b/pkg/kudoctl/cmd/update.go @@ -15,10 +15,10 @@ var ( The update argument must be a name of the instance. # Update dev-flink instance with setting parameter param with value value - kubectl kudo upgrade dev-flink -p param=value + kubectl kudo update dev-flink -p param=value # Update dev-flink instance in namespace services with setting parameter param with value value - kubectl kudo upgrade dev-flink -n services -p param=value` + kubectl kudo update dev-flink -n services -p param=value` ) type updateOptions struct { @@ -31,11 +31,11 @@ var defaultUpdateOptions = &updateOptions{ Namespace: "default", } -// newUpgradeCmd creates the install command for the CLI +// newUpdateCmd creates the install command for the CLI func newUpdateCmd() *cobra.Command { options := defaultUpdateOptions var parameters []string - upgradeCmd := &cobra.Command{ + updateCmd := &cobra.Command{ Use: "update ", Short: "Update installed KUDO operator.", Long: `Update installed KUDO operator with new parameters.`, @@ -52,15 +52,15 @@ func newUpdateCmd() *cobra.Command { SilenceUsage: true, } - upgradeCmd.Flags().StringArrayVarP(¶meters, "parameter", "p", nil, "The parameter name and value separated by '='") - upgradeCmd.Flags().StringVar(&options.Namespace, "namespace", defaultOptions.Namespace, "The namespace where the instance you want to upgrade is installed in.") + updateCmd.Flags().StringArrayVarP(¶meters, "parameter", "p", nil, "The parameter name and value separated by '='") + updateCmd.Flags().StringVar(&options.Namespace, "namespace", defaultOptions.Namespace, "The namespace where the instance you want to upgrade is installed in.") const usageFmt = "Usage:\n %s\n\nFlags:\n%s" - upgradeCmd.SetUsageFunc(func(cmd *cobra.Command) error { - fmt.Fprintf(upgradeCmd.OutOrStderr(), usageFmt, upgradeCmd.UseLine(), upgradeCmd.Flags().FlagUsages()) + updateCmd.SetUsageFunc(func(cmd *cobra.Command) error { + fmt.Fprintf(updateCmd.OutOrStderr(), usageFmt, updateCmd.UseLine(), updateCmd.Flags().FlagUsages()) return nil }) - return upgradeCmd + return updateCmd } func validateUpdateCmd(args []string, options *updateOptions) error { @@ -99,11 +99,11 @@ func update(instanceToUpdate string, kc *kudo.Client, options *updateOptions) er return fmt.Errorf("instance %s in namespace %s does not exist in the cluster", instanceToUpdate, options.Namespace) } - // Change instance to point to the new OV and optionally update parameters + // Update parameters err = kc.UpdateInstance(instanceToUpdate, options.Namespace, nil, options.Parameters) if err != nil { return errors.Wrapf(err, "updating instance %s", instanceToUpdate) } - fmt.Printf("Instance %s was updated ヽ(•‿•)ノ") + fmt.Printf("Instance %s was updated ヽ(•‿•)ノ", instanceToUpdate) return nil } diff --git a/pkg/kudoctl/cmd/upgrade.go b/pkg/kudoctl/cmd/upgrade.go index b71921d3e..8003f8b61 100644 --- a/pkg/kudoctl/cmd/upgrade.go +++ b/pkg/kudoctl/cmd/upgrade.go @@ -158,7 +158,7 @@ func upgrade(newOv *v1alpha1.OperatorVersion, kc *kudo.Client, options *options) } // Change instance to point to the new OV and optionally update parameters - err = kc.UpdateInstance(options.InstanceName, options.Namespace, util.String(ov.Name), options.Parameters) + err = kc.UpdateInstance(options.InstanceName, options.Namespace, util.String(newOv.Name), options.Parameters) if err != nil { return errors.Wrapf(err, "updating instance to point to new operatorversion %s", newOv.Name) } From 6f368ac52109dab98d25188d0c9f8be452bf67b8 Mon Sep 17 00:00:00 2001 From: Alena Varkockova Date: Thu, 1 Aug 2019 14:09:30 +0200 Subject: [PATCH 6/6] Use merge patch instead of json patch --- pkg/kudoctl/util/kudo/kudo.go | 26 ++++++++------------------ pkg/kudoctl/util/kudo/kudo_test.go | 14 ++++++++++++++ 2 files changed, 22 insertions(+), 18 deletions(-) diff --git a/pkg/kudoctl/util/kudo/kudo.go b/pkg/kudoctl/util/kudo/kudo.go index 48b70eb88..76a78abe7 100644 --- a/pkg/kudoctl/util/kudo/kudo.go +++ b/pkg/kudoctl/util/kudo/kudo.go @@ -6,6 +6,8 @@ import ( "strings" "time" + v1core "k8s.io/api/core/v1" + "github.com/kudobuilder/kudo/pkg/util/kudo" "k8s.io/apimachinery/pkg/types" @@ -141,33 +143,21 @@ func (c *Client) GetOperatorVersion(name, namespace string) (*v1alpha1.OperatorV return ov, err } -type patchValue struct { - Op string `json:"op"` - Path string `json:"path"` - Value interface{} `json:"value"` -} - // UpdateInstance updates operatorversion on instance func (c *Client) UpdateInstance(instanceName, namespace, operatorVersionName string, parameters map[string]string) error { - instancePatch := []patchValue{ - patchValue{ - Op: "replace", - Path: "/spec/operatorVersion/name", - Value: operatorVersionName, + instanceSpec := v1alpha1.InstanceSpec{ + OperatorVersion: v1core.ObjectReference{ + Name: operatorVersionName, }, } if parameters != nil { - instancePatch = append(instancePatch, patchValue{ - Op: "add", - Path: "/spec/parameters", - Value: parameters, - }) + instanceSpec.Parameters = parameters } - serializedPatch, err := json.Marshal(instancePatch) + serializedPatch, err := json.Marshal(instanceSpec) if err != nil { return err } - _, err = c.clientset.KudoV1alpha1().Instances(namespace).Patch(instanceName, types.JSONPatchType, serializedPatch) + _, err = c.clientset.KudoV1alpha1().Instances(namespace).Patch(instanceName, types.MergePatchType, serializedPatch) return err } diff --git a/pkg/kudoctl/util/kudo/kudo_test.go b/pkg/kudoctl/util/kudo/kudo_test.go index c00ebe732..daadeed15 100644 --- a/pkg/kudoctl/util/kudo/kudo_test.go +++ b/pkg/kudoctl/util/kudo/kudo_test.go @@ -525,6 +525,7 @@ func TestKudoClient_UpdateOperatorVersion(t *testing.T) { {"patch to version", "1.1.1", nil, nil, installNamespace}, {"patch adding new parameter", "1.1.1", nil, map[string]string{"param": "value"}, installNamespace}, {"patch updating parameter", "1.1.1", map[string]string{"param": "value"}, map[string]string{"param": "value2"}, installNamespace}, + {"patch with existing parameter should not override", "1.1.1", map[string]string{"param": "value"}, map[string]string{"other": "value2"}, installNamespace}, } for _, tt := range tests { @@ -545,11 +546,24 @@ func TestKudoClient_UpdateOperatorVersion(t *testing.T) { t.Errorf("%s:\nexpected version: %v\n got: %v, err: %v", tt.name, expectedVersion, instance.Spec.OperatorVersion.Name, err) } + // verify that parameters were updated for n, v := range tt.parametersToPatch { found, ok := instance.Spec.Parameters[n] if !ok || found != v { t.Errorf("%s: Value of parameter %s should have been updated to %s but is %s", tt.name, n, v, found) } } + + // make sure that we did not change parameters that should not have been updated + for n, v := range tt.existingParameters { + if _, ok := tt.parametersToPatch[n]; ok { + continue + } + found, ok := instance.Spec.Parameters[n] + fmt.Println(n) + if !ok || found != v { + t.Errorf("%s: Value of parameter %s should have not been updated from value %s but is %s", tt.name, n, v, found) + } + } } }