From 8afeb5338fb873ab1f6942afc8ce414e809b6864 Mon Sep 17 00:00:00 2001 From: Nurmukhammad Kozubaev <55165651+kozubaeff@users.noreply.github.com> Date: Fri, 28 Jun 2024 11:24:15 +0300 Subject: [PATCH] Add support for directDownload to UI Spec (#257) --- api/v1/ytsaurus_types.go | 4 ++++ api/v1/zz_generated.deepcopy.go | 5 +++++ .../bases/cluster.ytsaurus.tech_ytsaurus.yaml | 4 ++++ docs/api.md | 1 + .../test.canondata | 3 +++ pkg/ytconfig/generator.go | 11 +++++++++++ pkg/ytconfig/generator_test.go | 16 ++++++++++++++++ pkg/ytconfig/ui.go | 7 ++++++- ytop-chart/templates/ytsaurus-crd.yaml | 4 ++++ 9 files changed, 54 insertions(+), 1 deletion(-) create mode 100644 pkg/ytconfig/canondata/TestGetUICustomConfigWithSettings/test.canondata diff --git a/api/v1/ytsaurus_types.go b/api/v1/ytsaurus_types.go index ba368641..c692e4e7 100644 --- a/api/v1/ytsaurus_types.go +++ b/api/v1/ytsaurus_types.go @@ -493,6 +493,10 @@ type UISpec struct { Theme string `json:"theme,omitempty"` Description *string `json:"description,omitempty"` Group *string `json:"group,omitempty"` + // When this is set to false, UI will use backend for downloading instead of proxy. + // If this is set to true or omitted, UI use proxies, which is a default behaviour. + //+optional + DirectDownload *bool `json:"directDownload,omitempty"` } type QueryTrackerSpec struct { diff --git a/api/v1/zz_generated.deepcopy.go b/api/v1/zz_generated.deepcopy.go index 992d2f39..de987ebb 100644 --- a/api/v1/zz_generated.deepcopy.go +++ b/api/v1/zz_generated.deepcopy.go @@ -1497,6 +1497,11 @@ func (in *UISpec) DeepCopyInto(out *UISpec) { *out = new(string) **out = **in } + if in.DirectDownload != nil { + in, out := &in.DirectDownload, &out.DirectDownload + *out = new(bool) + **out = **in + } } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new UISpec. diff --git a/config/crd/bases/cluster.ytsaurus.tech_ytsaurus.yaml b/config/crd/bases/cluster.ytsaurus.tech_ytsaurus.yaml index 20d93d4f..1f995df8 100644 --- a/config/crd/bases/cluster.ytsaurus.tech_ytsaurus.yaml +++ b/config/crd/bases/cluster.ytsaurus.tech_ytsaurus.yaml @@ -34137,6 +34137,10 @@ spec: properties: description: type: string + directDownload: + description: When this is set to false, UI will use backend for + downloading instead of proxy. + type: boolean environment: default: testing type: string diff --git a/docs/api.md b/docs/api.md index f0bceaf2..dabf0bb7 100644 --- a/docs/api.md +++ b/docs/api.md @@ -1534,6 +1534,7 @@ _Appears in:_ | `theme` _string_ | | lavander | | | `description` _string_ | | | | | `group` _string_ | | | | +| `directDownload` _boolean_ | When this is set to false, UI will use backend for downloading instead of proxy.
If this is set to true or omitted, UI use proxies, which is a default behaviour. | | | #### UpdateFlow diff --git a/pkg/ytconfig/canondata/TestGetUICustomConfigWithSettings/test.canondata b/pkg/ytconfig/canondata/TestGetUICustomConfigWithSettings/test.canondata new file mode 100644 index 00000000..51fc34fb --- /dev/null +++ b/pkg/ytconfig/canondata/TestGetUICustomConfigWithSettings/test.canondata @@ -0,0 +1,3 @@ +{ + odinBaseUrl="http://odin-webservice.odin.svc.cluster.local"; +} \ No newline at end of file diff --git a/pkg/ytconfig/generator.go b/pkg/ytconfig/generator.go index 26dcb72e..d61cc83d 100644 --- a/pkg/ytconfig/generator.go +++ b/pkg/ytconfig/generator.go @@ -699,6 +699,16 @@ func (g *Generator) GetUIClustersConfig() ([]byte, error) { }) } +func (g *Generator) GetUICustomSettings() *UICustomSettings { + directDownload := g.ytsaurus.Spec.UI.DirectDownload + if directDownload == nil { + return nil + } + return &UICustomSettings{ + DirectDownload: directDownload, + } +} + func (g *Generator) GetUICustomConfig() ([]byte, error) { if g.ytsaurus.Spec.UI == nil { return []byte{}, nil @@ -706,6 +716,7 @@ func (g *Generator) GetUICustomConfig() ([]byte, error) { c := UICustom{ OdinBaseUrl: g.ytsaurus.Spec.UI.OdinBaseUrl, + Settings: g.GetUICustomSettings(), } return marshallYsonConfig(c) diff --git a/pkg/ytconfig/generator_test.go b/pkg/ytconfig/generator_test.go index aa8093ef..bdf1d5b3 100644 --- a/pkg/ytconfig/generator_test.go +++ b/pkg/ytconfig/generator_test.go @@ -380,6 +380,13 @@ func TestGetUICustomConfig(t *testing.T) { canonize.Assert(t, cfg) } +func TestGetUICustomConfigWithSettings(t *testing.T) { + g := NewGenerator(withUICustomSettings(getYtsaurus()), testClusterDomain) + cfg, err := g.GetUICustomConfig() + require.NoError(t, err) + canonize.Assert(t, cfg) +} + func TestGetYQLAgentConfig(t *testing.T) { ytsaurus := getYtsaurusWithEverything() g := NewGenerator(ytsaurus, testClusterDomain) @@ -615,6 +622,15 @@ func withUICustom(ytsaurus *ytv1.Ytsaurus) *ytv1.Ytsaurus { return ytsaurus } +func withUICustomSettings(ytsaurus *ytv1.Ytsaurus) *ytv1.Ytsaurus { + odinUrl := "http://odin-webservice.odin.svc.cluster.local" + ytsaurus.Spec.UI = &ytv1.UISpec{ + OdinBaseUrl: &odinUrl, + DirectDownload: nil, + } + return ytsaurus +} + func withMasterCaches(ytsaurus *ytv1.Ytsaurus) *ytv1.Ytsaurus { ytsaurus.Spec.MasterCaches = &ytv1.MasterCachesSpec{InstanceSpec: testBasicInstanceSpec} ytsaurus.Spec.MasterCaches.InstanceSpec.MonitoringPort = ptr.Int32(consts.MasterCachesMonitoringPort) diff --git a/pkg/ytconfig/ui.go b/pkg/ytconfig/ui.go index b4c1b83e..8b629d15 100644 --- a/pkg/ytconfig/ui.go +++ b/pkg/ytconfig/ui.go @@ -36,6 +36,11 @@ func getUIClusterCarcass() UICluster { } } +type UICustomSettings struct { + DirectDownload *bool `yson:"directDownload,omitempty"` +} + type UICustom struct { - OdinBaseUrl *string `yson:"odinBaseUrl,omitempty"` + OdinBaseUrl *string `yson:"odinBaseUrl,omitempty"` + Settings *UICustomSettings `yson:"uiSettings,omitempty"` } diff --git a/ytop-chart/templates/ytsaurus-crd.yaml b/ytop-chart/templates/ytsaurus-crd.yaml index 2ebc0db0..3d3f6042 100644 --- a/ytop-chart/templates/ytsaurus-crd.yaml +++ b/ytop-chart/templates/ytsaurus-crd.yaml @@ -33926,6 +33926,10 @@ spec: properties: description: type: string + directDownload: + description: When this is set to false, UI will use backend for + downloading instead of proxy. + type: boolean environment: default: testing type: string