From cae334dfe3a14f35815e1b55e9be4374c257d47d Mon Sep 17 00:00:00 2001 From: Eduardo Apolinario Date: Mon, 29 Jan 2024 15:54:16 -0800 Subject: [PATCH 1/2] Bring Scheme back for backwards compatibility Signed-off-by: Eduardo Apolinario --- .../tasks/pluginmachinery/tasklog/plugin.go | 15 +++- .../tasklog/templatescheme_enumer.go | 84 +++++++++++++++++++ .../go/tasks/plugins/k8s/ray/config.go | 2 +- 3 files changed, 98 insertions(+), 3 deletions(-) create mode 100644 flyteplugins/go/tasks/pluginmachinery/tasklog/templatescheme_enumer.go diff --git a/flyteplugins/go/tasks/pluginmachinery/tasklog/plugin.go b/flyteplugins/go/tasks/pluginmachinery/tasklog/plugin.go index 1caf8a2bac..6b748db37a 100644 --- a/flyteplugins/go/tasks/pluginmachinery/tasklog/plugin.go +++ b/flyteplugins/go/tasks/pluginmachinery/tasklog/plugin.go @@ -7,6 +7,15 @@ import ( pluginsCore "github.com/flyteorg/flyte/flyteplugins/go/tasks/pluginmachinery/core" ) +//go:generate enumer --type=TemplateScheme --trimprefix=TemplateScheme -json -yaml + +type TemplateScheme int + +const ( + TemplateSchemePod TemplateScheme = iota + TemplateSchemeTaskExecution +) + // TemplateURI is a URI that accepts templates. See: go/tasks/pluginmachinery/tasklog/template.go for available templates. type TemplateURI = string @@ -49,6 +58,8 @@ type TemplateLogPlugin struct { Name string `json:"name" pflag:",Name of the plugin."` DisplayName string `json:"displayName" pflag:",Display name for the generated log when displayed in the console."` TemplateURIs []TemplateURI `json:"templateUris" pflag:",URI Templates for generating task log links."` - DynamicTemplateURIs []TemplateURI `json:"dynamictemplateUris" pflag:",URI Templates for generating dynamic task log links."` - MessageFormat core.TaskLog_MessageFormat `json:"messageFormat" pflag:",Log Message Format."` + DynamicTemplateURIs []TemplateURI `json:"dynamicTemplateUris" pflag:",URI Templates for generating dynamic task log links."` + MessageFormat core.TaskLog_MessageFormat `json:"messageFormat" pflag:"-,Log Message Format."` + // Deprecated: Please, do not use + Scheme TemplateScheme `json:"scheme" pflag:",Templating scheme to use. Supported values are Pod and TaskExecution."` } diff --git a/flyteplugins/go/tasks/pluginmachinery/tasklog/templatescheme_enumer.go b/flyteplugins/go/tasks/pluginmachinery/tasklog/templatescheme_enumer.go new file mode 100644 index 0000000000..70f15faf01 --- /dev/null +++ b/flyteplugins/go/tasks/pluginmachinery/tasklog/templatescheme_enumer.go @@ -0,0 +1,84 @@ +// Code generated by "enumer --type=TemplateScheme --trimprefix=TemplateScheme -json -yaml"; DO NOT EDIT. + +package tasklog + +import ( + "encoding/json" + "fmt" +) + +const _TemplateSchemeName = "PodTaskExecution" + +var _TemplateSchemeIndex = [...]uint8{0, 3, 16} + +func (i TemplateScheme) String() string { + if i < 0 || i >= TemplateScheme(len(_TemplateSchemeIndex)-1) { + return fmt.Sprintf("TemplateScheme(%d)", i) + } + return _TemplateSchemeName[_TemplateSchemeIndex[i]:_TemplateSchemeIndex[i+1]] +} + +var _TemplateSchemeValues = []TemplateScheme{0, 1} + +var _TemplateSchemeNameToValueMap = map[string]TemplateScheme{ + _TemplateSchemeName[0:3]: 0, + _TemplateSchemeName[3:16]: 1, +} + +// TemplateSchemeString retrieves an enum value from the enum constants string name. +// Throws an error if the param is not part of the enum. +func TemplateSchemeString(s string) (TemplateScheme, error) { + if val, ok := _TemplateSchemeNameToValueMap[s]; ok { + return val, nil + } + return 0, fmt.Errorf("%s does not belong to TemplateScheme values", s) +} + +// TemplateSchemeValues returns all values of the enum +func TemplateSchemeValues() []TemplateScheme { + return _TemplateSchemeValues +} + +// IsATemplateScheme returns "true" if the value is listed in the enum definition. "false" otherwise +func (i TemplateScheme) IsATemplateScheme() bool { + for _, v := range _TemplateSchemeValues { + if i == v { + return true + } + } + return false +} + +// MarshalJSON implements the json.Marshaler interface for TemplateScheme +func (i TemplateScheme) MarshalJSON() ([]byte, error) { + return json.Marshal(i.String()) +} + +// UnmarshalJSON implements the json.Unmarshaler interface for TemplateScheme +func (i *TemplateScheme) UnmarshalJSON(data []byte) error { + var s string + if err := json.Unmarshal(data, &s); err != nil { + return fmt.Errorf("TemplateScheme should be a string, got %s", data) + } + + var err error + *i, err = TemplateSchemeString(s) + return err +} + +// MarshalYAML implements a YAML Marshaler for TemplateScheme +func (i TemplateScheme) MarshalYAML() (interface{}, error) { + return i.String(), nil +} + +// UnmarshalYAML implements a YAML Unmarshaler for TemplateScheme +func (i *TemplateScheme) UnmarshalYAML(unmarshal func(interface{}) error) error { + var s string + if err := unmarshal(&s); err != nil { + return err + } + + var err error + *i, err = TemplateSchemeString(s) + return err +} diff --git a/flyteplugins/go/tasks/plugins/k8s/ray/config.go b/flyteplugins/go/tasks/plugins/k8s/ray/config.go index 8601264edf..67ea4d2aeb 100644 --- a/flyteplugins/go/tasks/plugins/k8s/ray/config.go +++ b/flyteplugins/go/tasks/plugins/k8s/ray/config.go @@ -82,7 +82,7 @@ type Config struct { RemoteClusterConfig pluginmachinery.ClusterConfig `json:"remoteClusterConfig" pflag:"Configuration of remote K8s cluster for ray jobs"` Logs logs.LogConfig `json:"logs" pflag:"-,Log configuration for ray jobs"` LogsSidecar *v1.Container `json:"logsSidecar" pflag:"-,Sidecar to inject into head pods for capturing ray job logs"` - DashboardURLTemplate *tasklog.TemplateLogPlugin `json:"dashboardURLTemplate" pflag:",Template for URL of Ray dashboard running on a head node."` + DashboardURLTemplate *tasklog.TemplateLogPlugin `json:"dashboardURLTemplate" pflag:"-,Template for URL of Ray dashboard running on a head node."` Defaults DefaultConfig `json:"defaults" pflag:"-,Default configuration for ray jobs"` EnableUsageStats bool `json:"enableUsageStats" pflag:",Enable usage stats for ray jobs. These stats are submitted to usage-stats.ray.io per https://docs.ray.io/en/latest/cluster/usage-stats.html"` } From 7a8aee4cda48c5edfedef6f399bdbeea8a8835e6 Mon Sep 17 00:00:00 2001 From: Eduardo Apolinario Date: Tue, 30 Jan 2024 10:41:55 -0800 Subject: [PATCH 2/2] Rename deprecated field to `DeprecatedScheme` Signed-off-by: Eduardo Apolinario --- flyteplugins/go/tasks/pluginmachinery/tasklog/plugin.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flyteplugins/go/tasks/pluginmachinery/tasklog/plugin.go b/flyteplugins/go/tasks/pluginmachinery/tasklog/plugin.go index 6b748db37a..fa47fa4729 100644 --- a/flyteplugins/go/tasks/pluginmachinery/tasklog/plugin.go +++ b/flyteplugins/go/tasks/pluginmachinery/tasklog/plugin.go @@ -61,5 +61,5 @@ type TemplateLogPlugin struct { DynamicTemplateURIs []TemplateURI `json:"dynamicTemplateUris" pflag:",URI Templates for generating dynamic task log links."` MessageFormat core.TaskLog_MessageFormat `json:"messageFormat" pflag:"-,Log Message Format."` // Deprecated: Please, do not use - Scheme TemplateScheme `json:"scheme" pflag:",Templating scheme to use. Supported values are Pod and TaskExecution."` + DeprecatedScheme TemplateScheme `json:"scheme" pflag:",Templating scheme to use. Supported values are Pod and TaskExecution."` }