From cdeec0cdffcfeffe9e518e4732e1ffc371cd5983 Mon Sep 17 00:00:00 2001 From: Arunesh Pandey Date: Wed, 6 Sep 2023 22:07:06 -0700 Subject: [PATCH] Allow non user-configurable properties in VM deployment Currently, VM operator ignores any vApp properties that are not user configurable when patching with values specified in the bootstrap resources (VM metadata ConfigMap/Secret). There are some valid use-cases where users might want to patch hidden properties defined in an image. This change fixes this behavior. Fixes #181. --- .../providers/vsphere/session/session_util.go | 5 +---- .../vsphere/session/session_util_test.go | 18 +++++------------- 2 files changed, 6 insertions(+), 17 deletions(-) diff --git a/pkg/vmprovider/providers/vsphere/session/session_util.go b/pkg/vmprovider/providers/vsphere/session/session_util.go index c1703b053..5821dde16 100644 --- a/pkg/vmprovider/providers/vsphere/session/session_util.go +++ b/pkg/vmprovider/providers/vsphere/session/session_util.go @@ -49,11 +49,8 @@ func MergeExtraConfig(extraConfig []vimTypes.BaseOptionValue, newMap map[string] func GetMergedvAppConfigSpec(inProps map[string]string, vmProps []vimTypes.VAppPropertyInfo) *vimTypes.VmConfigSpec { outProps := make([]vimTypes.VAppPropertySpec, 0) + // Update any vApp properties if they have been specified in VM metadata. for _, vmProp := range vmProps { - if vmProp.UserConfigurable == nil || !*vmProp.UserConfigurable { - continue - } - inPropValue, found := inProps[vmProp.Id] if !found || vmProp.Value == inPropValue { continue diff --git a/pkg/vmprovider/providers/vsphere/session/session_util_test.go b/pkg/vmprovider/providers/vsphere/session/session_util_test.go index 7563d5422..e7ecac638 100644 --- a/pkg/vmprovider/providers/vsphere/session/session_util_test.go +++ b/pkg/vmprovider/providers/vsphere/session/session_util_test.go @@ -41,26 +41,16 @@ var _ = Describe("Test Session Utils", func() { []vimTypes.VAppPropertyInfo{}, nil, ), - Entry("return nil for non UserConfigurable vm props", - map[string]string{ - "one-id": "one-override-value", - "two-id": "two-override-value", - }, - []vimTypes.VAppPropertyInfo{ - {Key: 1, Id: "one-id", Value: "one-value"}, - {Key: 2, Id: "two-id", Value: "two-value", UserConfigurable: &falseVar}, - }, - nil, - ), - Entry("return nil for UserConfigurable vm props but no input props", + Entry("return nil for vm props but no input props", map[string]string{}, []vimTypes.VAppPropertyInfo{ {Key: 1, Id: "one-id", Value: "one-value"}, {Key: 2, Id: "two-id", Value: "two-value", UserConfigurable: &trueVar}, + {Key: 2, Id: "three-id", Value: "three-value", UserConfigurable: &falseVar}, }, nil, ), - Entry("return valid vAppConfigSpec for setting mixed UserConfigurable props", + Entry("return valid vAppConfigSpec for setting mixed props", map[string]string{ "one-id": "one-override-value", "two-id": "two-override-value", @@ -73,7 +63,9 @@ var _ = Describe("Test Session Utils", func() { }, &vimTypes.VmConfigSpec{ Property: []vimTypes.VAppPropertySpec{ + {Info: &vimTypes.VAppPropertyInfo{Key: 1, Id: "one-id", Value: "one-override-value"}}, {Info: &vimTypes.VAppPropertyInfo{Key: 2, Id: "two-id", Value: "two-override-value"}}, + {Info: &vimTypes.VAppPropertyInfo{Key: 3, Id: "three-id", Value: "three-override-value"}}, }, }, ),