From caf2e2c413820668cc32ec3edf93c771db044b71 Mon Sep 17 00:00:00 2001 From: Lucas Bajolet Date: Thu, 6 Jun 2024 14:14:14 -0400 Subject: [PATCH] plugin/set: add protocol_version to Description When a plugin describes its capabilities, it needs to advertise whether or not protobuf can be used in order for Packer to know which serialisation protocol to use for communicating with the plugin. To do so, we add a protocol_version attribute to the returned structure, which is now set to v2, in order for Packer to know that the plugin can use that. --- plugin/set.go | 38 ++++++++++++++++++++++++-------------- plugin/set_test.go | 15 ++++++++------- 2 files changed, 32 insertions(+), 21 deletions(-) diff --git a/plugin/set.go b/plugin/set.go index 9211e7ea5..68e6650bc 100644 --- a/plugin/set.go +++ b/plugin/set.go @@ -39,15 +39,24 @@ type Set struct { Datasources map[string]packersdk.Datasource } +// ProtocolVersion2 serves as a compatibility argument to the SetDescription +// so plugins can report whether or not they support protobuf/msgpack for +// serialising some of their entities (typically ObjectSpec) to protobuf. +// +// If absent from the SetDescription, it means only gob is supported, and both +// Packer and the plugins should use that for communication. +const ProtocolVersion2 = "v2" + // SetDescription describes a Set. type SetDescription struct { - Version string `json:"version"` - SDKVersion string `json:"sdk_version"` - APIVersion string `json:"api_version"` - Builders []string `json:"builders"` - PostProcessors []string `json:"post_processors"` - Provisioners []string `json:"provisioners"` - Datasources []string `json:"datasources"` + Version string `json:"version"` + SDKVersion string `json:"sdk_version"` + APIVersion string `json:"api_version"` + Builders []string `json:"builders"` + PostProcessors []string `json:"post_processors"` + Provisioners []string `json:"provisioners"` + Datasources []string `json:"datasources"` + ProtocolVersion string `json:"protocol_version"` } //// @@ -158,13 +167,14 @@ func (i *Set) start(kind, name string) error { func (i *Set) description() SetDescription { return SetDescription{ - Version: i.version, - SDKVersion: i.sdkVersion, - APIVersion: i.apiVersion, - Builders: i.buildersDescription(), - PostProcessors: i.postProcessorsDescription(), - Provisioners: i.provisionersDescription(), - Datasources: i.datasourceDescription(), + Version: i.version, + SDKVersion: i.sdkVersion, + APIVersion: i.apiVersion, + Builders: i.buildersDescription(), + PostProcessors: i.postProcessorsDescription(), + Provisioners: i.provisionersDescription(), + Datasources: i.datasourceDescription(), + ProtocolVersion: ProtocolVersion2, } } diff --git a/plugin/set_test.go b/plugin/set_test.go index f29ecc8f4..02d65e115 100644 --- a/plugin/set_test.go +++ b/plugin/set_test.go @@ -52,13 +52,14 @@ func TestSet(t *testing.T) { sdkVersion := pluginVersion.NewPluginVersion(pluginVersion.Version, pluginVersion.VersionPrerelease, "") if diff := cmp.Diff(SetDescription{ - Version: "1.1.1", - SDKVersion: sdkVersion.String(), - APIVersion: "x" + APIVersionMajor + "." + APIVersionMinor, - Builders: []string{"example", "example-2"}, - PostProcessors: []string{"example", "example-2"}, - Provisioners: []string{"example", "example-2"}, - Datasources: []string{"example", "example-2"}, + Version: "1.1.1", + SDKVersion: sdkVersion.String(), + APIVersion: "x" + APIVersionMajor + "." + APIVersionMinor, + Builders: []string{"example", "example-2"}, + PostProcessors: []string{"example", "example-2"}, + Provisioners: []string{"example", "example-2"}, + Datasources: []string{"example", "example-2"}, + ProtocolVersion: ProtocolVersion2, }, outputDesc); diff != "" { t.Fatalf("Unexpected description: %s", diff) }