From 5f9cbe6f4afa78be51d9af8a3870d1523c0b4245 Mon Sep 17 00:00:00 2001 From: George Jenkins Date: Wed, 21 May 2025 11:06:42 -0700 Subject: [PATCH 1/3] fix: Port pluginCommand & command warning Signed-off-by: George Jenkins --- pkg/plugin/plugin.go | 12 ++++++------ pkg/plugin/plugin_test.go | 4 ++-- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/pkg/plugin/plugin.go b/pkg/plugin/plugin.go index 9d79ab4fc..67676b103 100644 --- a/pkg/plugin/plugin.go +++ b/pkg/plugin/plugin.go @@ -83,7 +83,7 @@ type Metadata struct { PlatformCommand []PlatformCommand `json:"platformCommand"` // Command is the plugin command, as a single string. - // Providing a command will result in an error if PlatformCommand is also set. + // Providing a command will result in an deprecation warning if PlatformCommand is also set. // // The command will be passed through environment expansion, so env vars can // be present in this command. Unless IgnoreFlags is set, this will @@ -92,7 +92,7 @@ type Metadata struct { // Note that command is not executed in a shell. To do so, we suggest // pointing the command to a shell script. // - // DEPRECATED: Use PlatformCommand instead. Remove in Helm 4. + // DEPRECATED: Use PlatformCommand instead Command string `json:"command"` // IgnoreFlags ignores any flags passed in from Helm @@ -119,14 +119,14 @@ type Metadata struct { PlatformHooks PlatformHooks `json:"platformHooks"` // Hooks are commands that will run on plugin events, as a single string. - // Providing a hooks will result in an error if PlatformHooks is also set. + // Providing a command will result in an deprecation warning if PlatformHooks is also set. // // The command will be passed through environment expansion, so env vars can // be present in this command. // // Note that the command is executed in the sh shell. // - // DEPRECATED: Use PlatformHooks instead. Remove in Helm 4. + // DEPRECATED: Use PlatformHooks instead Hooks Hooks // Downloaders field is used if the plugin supply downloader mechanism @@ -265,11 +265,11 @@ func validatePluginData(plug *Plugin, filepath string) error { plug.Metadata.Usage = sanitizeString(plug.Metadata.Usage) if len(plug.Metadata.PlatformCommand) > 0 && len(plug.Metadata.Command) > 0 { - return fmt.Errorf("both platformCommand and command are set in %q", filepath) + fmt.Printf("WARNING: both 'platformCommand' and 'command' are set in %q (this will become an error in a future Helm version)\n", filepath) } if len(plug.Metadata.PlatformHooks) > 0 && len(plug.Metadata.Hooks) > 0 { - return fmt.Errorf("both platformHooks and hooks are set in %q", filepath) + fmt.Printf("WARNING: both 'platformHooks' and 'hooks' are set in %q (this will become an error in a future Helm version)\n", filepath) } // We could also validate SemVer, executable, and other fields should we so choose. diff --git a/pkg/plugin/plugin_test.go b/pkg/plugin/plugin_test.go index b96428f6b..20bd2f737 100644 --- a/pkg/plugin/plugin_test.go +++ b/pkg/plugin/plugin_test.go @@ -496,8 +496,8 @@ func TestValidatePluginData(t *testing.T) { {false, mockMissingMeta}, // Test if the metadata section missing {true, mockNoCommand}, // Test no command metadata works {true, mockLegacyCommand}, // Test legacy command metadata works - {false, mockWithCommand}, // Test platformCommand and command both set fails - {false, mockWithHooks}, // Test platformHooks and hooks both set fails + {true, mockWithCommand}, // Test platformCommand and command both set works + {true, mockWithHooks}, // Test platformHooks and hooks both set works } { err := validatePluginData(item.plug, fmt.Sprintf("test-%d", i)) if item.pass && err != nil { From 62ca98f521a616c1b600405aff00d068303c13e6 Mon Sep 17 00:00:00 2001 From: George Jenkins Date: Tue, 1 Jul 2025 08:29:29 -0700 Subject: [PATCH 2/3] fix up verbiage Signed-off-by: George Jenkins --- pkg/plugin/plugin.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/plugin/plugin.go b/pkg/plugin/plugin.go index 67676b103..a30bd06c4 100644 --- a/pkg/plugin/plugin.go +++ b/pkg/plugin/plugin.go @@ -83,7 +83,7 @@ type Metadata struct { PlatformCommand []PlatformCommand `json:"platformCommand"` // Command is the plugin command, as a single string. - // Providing a command will result in an deprecation warning if PlatformCommand is also set. + // Providing Command and PlatformCommand will result in a warning being emitted (PlatformCommand takes precedence). // // The command will be passed through environment expansion, so env vars can // be present in this command. Unless IgnoreFlags is set, this will @@ -119,7 +119,7 @@ type Metadata struct { PlatformHooks PlatformHooks `json:"platformHooks"` // Hooks are commands that will run on plugin events, as a single string. - // Providing a command will result in an deprecation warning if PlatformHooks is also set. + // Providing Hook and PlatformHooks will result in a warning being emitted (PlatformHooks takes precedence). // // The command will be passed through environment expansion, so env vars can // be present in this command. From de1bdf582035dc4079970e06ccdafd2b1e802263 Mon Sep 17 00:00:00 2001 From: George Jenkins Date: Wed, 2 Jul 2025 17:31:35 -0700 Subject: [PATCH 3/3] switch to slog Signed-off-by: George Jenkins --- pkg/plugin/plugin.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/pkg/plugin/plugin.go b/pkg/plugin/plugin.go index a30bd06c4..2c197f02e 100644 --- a/pkg/plugin/plugin.go +++ b/pkg/plugin/plugin.go @@ -17,6 +17,7 @@ package plugin // import "helm.sh/helm/v4/pkg/plugin" import ( "fmt" + "log/slog" "os" "path/filepath" "regexp" @@ -265,11 +266,11 @@ func validatePluginData(plug *Plugin, filepath string) error { plug.Metadata.Usage = sanitizeString(plug.Metadata.Usage) if len(plug.Metadata.PlatformCommand) > 0 && len(plug.Metadata.Command) > 0 { - fmt.Printf("WARNING: both 'platformCommand' and 'command' are set in %q (this will become an error in a future Helm version)\n", filepath) + slog.Warn("both 'platformCommand' and 'command' are set (this will become an error in a future Helm version)", slog.String("filepath", filepath)) } if len(plug.Metadata.PlatformHooks) > 0 && len(plug.Metadata.Hooks) > 0 { - fmt.Printf("WARNING: both 'platformHooks' and 'hooks' are set in %q (this will become an error in a future Helm version)\n", filepath) + slog.Warn("both 'platformHooks' and 'hooks' are set (this will become an error in a future Helm version)", slog.String("filepath", filepath)) } // We could also validate SemVer, executable, and other fields should we so choose.