Skip to content

Add per-field suppression to extraconfig encoder#8038

Merged
hickeng merged 2 commits intovmware:masterfrom
hickeng:write-only-extraconfig
Jun 26, 2018
Merged

Add per-field suppression to extraconfig encoder#8038
hickeng merged 2 commits intovmware:masterfrom
hickeng:write-only-extraconfig

Conversation

@hickeng
Copy link
Contributor

@hickeng hickeng commented Jun 9, 2018

Turns the annotation string labels for controlling serialization behaviour
into constants with comments. Still requires package level descripton
and examples.

Adds a recursion property to skip encode or decode of a field. If skipping
both the depth=0 should be used.

Splits DefaultGuestInfoPrefix into pieces. The vSphere mandatory guestinfo
prefix should not be user configurations, whereas the key "namespacing"
prefix should have been. For VIC this was the "vice" namespace prefix which
was not applied to the hidden (non-guestinfo) keys. As such this commit
drops the DefaultPrefix from the encode/decode paths for now due to
upgrade constraints.

There is now an explicit separation between those elements that should not
be modified (constants) and those that should be usage configuration (vars).
Future work should extend this with a defined config structure that Encode
and Decode can operate from.

If it turns out that we need initialize once rather than skip-decode for any
field, we can look at making the field a pointer and having explicit logic based
around whether the target is a nil pointer or not. This gives us easy inline
tracking of whether initialization has occurred, although with unfortunate
dependence on the user not having explicitly initialized some pointer paths in
the target structure ahead of time.

[full ci]

Towards #7410

Copy link
Member

@zjs zjs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it turns out that need need

Small typo in the commit message.

svm := simulator.Map.Get(ref).(*simulator.VirtualMachine)

template := config.VirtualContainerHostConfigSpec{}
keys := extraconfig.CalculateKeys(template, "ExecutorConfig.ExecutorConfigCommon.ID", "")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unrelated to this PR, but: It seems like it would be helpful to have a extraconfig.CalculateKey helper that calls extraconfig.CalculateKeys, verifies that a single key is returned, and returns the single value to the caller. This would avoid the need to follow the extraconfig.CalculateKeys call with an unchecked [0] all over the place.

const (
// DefaultTagName value
// GuestInfoPrefix is dictated by vSphere
GuestInfoPrefix = "guestinfo."
Copy link
Member

@zjs zjs Jun 21, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unrelated to this change, but it seems like this prefix is hard-coded elsewhere:

const GuestInfoSecretKey = "guestinfo.ovfEnv"

if containerExecKeyValues["guestinfo.vice./common/id"] == "" {
return nil, fmt.Errorf("Update: change version %s failed assertion extraconfig id != nil", o.Config.ChangeVersion)
}
op.Debugf("Update: for %s, change version %s, extraconfig id: %+v", c, o.Config.ChangeVersion, containerExecKeyValues["guestinfo.vice./common/id"])

ApplianceVersionKey = "guestinfo.vice./init/version/PluginVersion"
ContainerVersionKey = "guestinfo.vice./version/PluginVersion"

Should those be updated to refer to this constant?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The manager should be updated with a test that asserts that the key returned by extraconfig.CalculateKey matches the embedded string so we're alerted if we ever try to change the version location.

For the secrets, yes.

For base.go - this should be using CalculateKey

RecurseTag = "recurse"

// HiddenScope means the key is hidden from the guest and will not have a GuestInfoPrefix
HiddenScope = "hidden"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should any of the instances of this string be updated to use this constant?

return calculateKey(calculateScope([]string{"hidden"}), "", key)

scopes := []string{"hidden"}

scopes := []string{"hidden"}

// HiddenScope means the key is hidden from the guest and will not have a GuestInfoPrefix
HiddenScope = "hidden"
// ReadOnlyScope means the key is read-only from the guest
ReadOnlyScope = "read-only"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As above, keys-test.go contains hard-coded instances of this string (and others, below).

hickeng added 2 commits June 25, 2018 18:08
This adds a recursion property to skip encode or decode of a field. If
skipping both the depth=0 should be used.
This also extractst most string constants used in the package and turns
them into actual constants.

This also splits DefaultGuestInfoPrefix which should have only contained
the vSphere mandatory guestinfo prefix but also contained the default VIC
"vice" namespace prefix. As part of this it move those constants that
should be modifiable to be variables. Future work should extend this to be
a defined config structure that Encode and Decode can operate from.
This updates the extraconfig package to use the constants introduced by
the earlier commit in the PR.

This also updates extraconfig to have a CalculateKey function in addition
to the CalculateKeys function that returns an array. This has been done
because of an observation that by far the most common usage was
CalculateKeys(...)[0], sometimes with length checking of the return,
frequently without. The new method panics if the structure pattern for
the field cannot be found.
@hickeng hickeng force-pushed the write-only-extraconfig branch from 1c9a96b to 4405d0e Compare June 26, 2018 01:09
@hickeng hickeng requested a review from a team as a code owner June 26, 2018 01:09
@hickeng hickeng merged commit 525fbcf into vmware:master Jun 26, 2018
hickeng added a commit to hickeng/vic that referenced this pull request Jun 27, 2018
Adds a recursion property to skip encode or decode of a field. If
skipping both the depth=0 should be used.

Splits DefaultGuestInfoPrefix. It should have only contained the vSphere
mandatory guestinfo prefix but also contained the default VIC "vice"
namespace prefix. As part of this it extracts most string constants used
in the package and turns them into actual constants, and moves those
constants that should be modifiable to be variables. Future work should
extend this to be a defined config structure that Encode and Decode
can operate from.

Updates extraconfig to have a CalculateKey function in addition to the
CalculateKeys function that returns an array. This has been done because
of an observation that by far the most common usage was
CalculateKeys(...)[0], sometimes with length checking of the return but
frequently without. The new method panics if the structure pattern for
the field cannot be found.

(cherry picked from commit 525fbcf)
hickeng added a commit to hickeng/vic that referenced this pull request Jun 27, 2018
…e#8101)

Adds a recursion property to skip encode or decode of a field. If
skipping both the depth=0 should be used.

Splits DefaultGuestInfoPrefix. It should have only contained the vSphere
mandatory guestinfo prefix but also contained the default VIC "vice"
namespace prefix. As part of this it extracts most string constants used
in the package and turns them into actual constants, and moves those
constants that should be modifiable to be variables. Future work should
extend this to be a defined config structure that Encode and Decode
can operate from.

Updates extraconfig to have a CalculateKey function in addition to the
CalculateKeys function that returns an array. This has been done because
of an observation that by far the most common usage was
CalculateKeys(...)[0], sometimes with length checking of the return but
frequently without. The new method panics if the structure pattern for
the field cannot be found.

(cherry picked from commit 525fbcf)
hickeng added a commit that referenced this pull request Jun 28, 2018
Adds a recursion property to skip encode or decode of a field. If
skipping both the depth=0 should be used.

Splits DefaultGuestInfoPrefix. It should have only contained the vSphere
mandatory guestinfo prefix but also contained the default VIC "vice"
namespace prefix. As part of this it extracts most string constants used
in the package and turns them into actual constants, and moves those
constants that should be modifiable to be variables. Future work should
extend this to be a defined config structure that Encode and Decode
can operate from.

Updates extraconfig to have a CalculateKey function in addition to the
CalculateKeys function that returns an array. This has been done because
of an observation that by far the most common usage was
CalculateKeys(...)[0], sometimes with length checking of the return but
frequently without. The new method panics if the structure pattern for
the field cannot be found.

(cherry picked from commit 525fbcf)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants