Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support different controller families in strawberry configuration #355

Merged
merged 6 commits into from
Nov 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions api/v1/ytsaurus_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -517,10 +517,17 @@ type QueryTrackerSpec struct {
}

type StrawberryControllerSpec struct {
Resources corev1.ResourceRequirements `json:"resources,omitempty"`
Image *string `json:"image,omitempty"`
Tolerations []corev1.Toleration `json:"tolerations,omitempty"`
NodeSelector map[string]string `json:"nodeSelector,omitempty"`
Resources corev1.ResourceRequirements `json:"resources,omitempty"`
Image *string `json:"image,omitempty"`
Tolerations []corev1.Toleration `json:"tolerations,omitempty"`
NodeSelector map[string]string `json:"nodeSelector,omitempty"`
ExternalProxy *string `json:"externalProxy,omitempty"`
// Supported controller families, for example: "chyt", "jupyt", "livy".
ControllerFamilies []string `json:"controllerFamilies,omitempty"`
// The family that will receive requests for domains that are not explicitly specified in http_controller_mappings.
// For example, "chyt" (with `ControllerFamilies` set to {"chyt", "jupyt"} would mean
// that requests to "foo.<domain>" will be processed by chyt controller.
DefaultRouteFamily *string `json:"defaultRouteFamily,omitempty"`
}

type YQLAgentSpec struct {
Expand Down
15 changes: 15 additions & 0 deletions api/v1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions config/crd/bases/cluster.ytsaurus.tech_ytsaurus.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29432,6 +29432,18 @@ spec:
type: object
strawberry:
properties:
controllerFamilies:
description: 'Supported controller families, for example: "chyt",
"jupyt", "livy".'
items:
type: string
type: array
defaultRouteFamily:
description: The family that will receive requests for domains
that are not explicitly specif
type: string
externalProxy:
type: string
image:
type: string
nodeSelector:
Expand Down
3 changes: 3 additions & 0 deletions docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -1471,6 +1471,9 @@ _Appears in:_
| `image` _string_ | | | |
| `tolerations` _[Toleration](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.28/#toleration-v1-core) array_ | | | |
| `nodeSelector` _object (keys:string, values:string)_ | | | |
| `externalProxy` _string_ | | | |
| `controllerFamilies` _string array_ | Supported controller families, for example: "chyt", "jupyt", "livy". | | |
| `defaultRouteFamily` _string_ | The family that will receive requests for domains that are not explicitly specified in http_controller_mappings.<br />For example, "chyt" (with `ControllerFamilies` set to {"chyt", "jupyt"} would mean<br />that requests to "foo.<domain>" will be processed by chyt controller. | | |


#### StructuredLoggerSpec
Expand Down
4 changes: 3 additions & 1 deletion pkg/canonize/canonize.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"os"
"path/filepath"
"strings"
"testing"

"github.com/pmezard/go-difflib/difflib"
Expand Down Expand Up @@ -35,9 +36,10 @@ func Assert(t *testing.T, data []byte) {
t.FailNow()
return
}
canonDataTrimmed := strings.TrimSpace(string(canonData))

diff := difflib.UnifiedDiff{
A: difflib.SplitLines(string(canonData)),
A: difflib.SplitLines(canonDataTrimmed),
B: difflib.SplitLines(string(data)),
FromFile: "old",
ToFile: "new",
Expand Down
2 changes: 1 addition & 1 deletion pkg/components/strawberry_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func NewStrawberryController(
"cluster",
ChytInitClusterJobConfigFileName,
image,
cfgen.GetChytInitClusterConfig,
cfgen.GetStrawberryInitClusterConfig,
getTolerationsWithDefault(resource.Spec.StrawberryController.Tolerations, resource.Spec.Tolerations),
getNodeSelectorWithDefault(resource.Spec.StrawberryController.NodeSelector, resource.Spec.NodeSelector),
),
Expand Down
6 changes: 6 additions & 0 deletions pkg/consts/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,9 @@ const DefaultName = "default"
const DefaultMedium = "default"

const MaxSlotLocationReserve = 10 << 30 // 10GiB

const DefaultStrawberryControllerFamily = "chyt"

func GetDefaultStrawberryControllerFamilies() []string {
return []string{"chyt", "jupyt"}
}
dmi-feo marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,16 @@
retries=1000;
};
};
jupyt={
};
};
"http_api_endpoint"=":80";
"http_location_aliases"={
"http-proxies-lb-test.fake.svc.fake.zone"=[
test;
];
};
}
"http_controller_mappings"={
"*"=chyt;
};
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"location_proxies"=[
"http-proxies-lb-test.fake.svc.fake.zone";
];
strawberry={
root="//sys/strawberry";
stage=production;
"robot_username"="robot-strawberry-controller";
};
controllers={
superservice1={
};
superservice2={
};
superservice3={
};
};
"http_api_endpoint"=":80";
"http_location_aliases"={
"http-proxies-lb-test.fake.svc.fake.zone"=[
test;
];
};
"http_controller_mappings"={
"*"=superservice2;
"superservice1.some.domain"=superservice1;
"superservice3.some.domain"=superservice3;
};
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"location_proxies"=[
"http-proxies-lb-test.fake.svc.fake.zone";
];
strawberry={
root="//sys/strawberry";
stage=production;
"robot_username"="robot-strawberry-controller";
};
controllers={
chyt={
"address_resolver"={
"enable_ipv4"=%true;
"enable_ipv6"=%false;
retries=1000;
};
};
jupyt={
};
};
"http_api_endpoint"=":80";
"http_location_aliases"={
"http-proxies-lb-test.fake.svc.fake.zone"=[
test;
];
};
"http_controller_mappings"={
"*"=chyt;
"jupyt.some.domain"=jupyt;
};
}
61 changes: 0 additions & 61 deletions pkg/ytconfig/chyt.go

This file was deleted.

6 changes: 6 additions & 0 deletions pkg/ytconfig/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@ type AddressResolver struct {
LocalhostNameOverride *string `yson:"localhost_name_override,omitempty"`
}

type StrawberryControllerFamiliesConfig struct {
ControllerFamilies []string `yson:"controller_families,omitempty"`
DefaultRouteFamily string `yson:"default_route_family,omitempty"`
ExternalProxy *string `yson:"external_proxy,omitempty"`
}

type SolomonExporter struct {
Host *string `yson:"host,omitempty"`
InstanceTags map[string]string `yson:"instance_tags,omitempty"`
Expand Down
26 changes: 23 additions & 3 deletions pkg/ytconfig/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -311,10 +311,28 @@ func (g *Generator) GetClusterConnection() ([]byte, error) {
return marshallYsonConfig(c)
}

func (g *Generator) fillStrawberryControllerFamiliesConfig(c *StrawberryControllerFamiliesConfig, s *ytv1.StrawberryControllerSpec) {
if s.ControllerFamilies != nil {
c.ControllerFamilies = s.ControllerFamilies
} else {
c.ControllerFamilies = consts.GetDefaultStrawberryControllerFamilies()
}
if s.DefaultRouteFamily != nil {
c.DefaultRouteFamily = *s.DefaultRouteFamily
} else {
c.DefaultRouteFamily = consts.DefaultStrawberryControllerFamily
}
c.ExternalProxy = s.ExternalProxy
}

func (g *Generator) GetStrawberryControllerConfig() ([]byte, error) {
var resolver AddressResolver
g.fillAddressResolver(&resolver)
c, err := getStrawberryController(resolver)

var conFamConfig StrawberryControllerFamiliesConfig
g.fillStrawberryControllerFamiliesConfig(&conFamConfig, g.ytsaurus.Spec.StrawberryController)

c, err := getStrawberryController(conFamConfig, resolver)
if err != nil {
return nil, err
}
Expand All @@ -326,8 +344,10 @@ func (g *Generator) GetStrawberryControllerConfig() ([]byte, error) {
return marshallYsonConfig(c)
}

func (g *Generator) GetChytInitClusterConfig() ([]byte, error) {
c := getChytInitCluster()
func (g *Generator) GetStrawberryInitClusterConfig() ([]byte, error) {
var conFamConfig StrawberryControllerFamiliesConfig
g.fillStrawberryControllerFamiliesConfig(&conFamConfig, g.ytsaurus.Spec.StrawberryController)
c := getStrawberryInitCluster(conFamConfig)
c.Proxy = g.GetHTTPProxiesAddress(consts.DefaultHTTPProxyRole)
return marshallYsonConfig(c)
}
Expand Down
28 changes: 26 additions & 2 deletions pkg/ytconfig/generator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,9 @@ var (
}
)

func TestGetChytInitClusterConfig(t *testing.T) {
func TestGetStrawberryInitClusterConfig(t *testing.T) {
g := NewGenerator(getYtsaurusWithEverything(), testClusterDomain)
cfg, err := g.GetChytInitClusterConfig()
cfg, err := g.GetStrawberryInitClusterConfig()
require.NoError(t, err)
canonize.Assert(t, cfg)
}
Expand Down Expand Up @@ -339,6 +339,30 @@ func TestGetStrawberryControllerConfig(t *testing.T) {
canonize.Assert(t, cfg)
}

func TestGetStrawberryControllerConfigWithExtendedHTTPMapping(t *testing.T) {
g := NewGenerator(getYtsaurusWithEverything(), testClusterDomain)
externalProxy := "some.domain"
g.ytsaurus.Spec.StrawberryController.ExternalProxy = &externalProxy
cfg, err := g.GetStrawberryControllerConfig()
require.NoError(t, err)
canonize.Assert(t, cfg)
}

func TestGetStrawberryControllerConfigWithCustomFamilies(t *testing.T) {
g := NewGenerator(getYtsaurusWithEverything(), testClusterDomain)
externalProxy := "some.domain"
g.ytsaurus.Spec.StrawberryController.ExternalProxy = &externalProxy
g.ytsaurus.Spec.StrawberryController.ControllerFamilies = append(
g.ytsaurus.Spec.StrawberryController.ControllerFamilies,
"superservice1", "superservice2", "superservice3",
)
defaultRouteFamily := "superservice2"
g.ytsaurus.Spec.StrawberryController.DefaultRouteFamily = &defaultRouteFamily
cfg, err := g.GetStrawberryControllerConfig()
require.NoError(t, err)
canonize.Assert(t, cfg)
}

func TestGetTabletNodeConfig(t *testing.T) {
g := NewLocalNodeGenerator(getYtsaurusWithEverything(), testClusterDomain)
cfg, err := g.GetTabletNodeConfig(getTabletNodeSpec())
Expand Down
Loading
Loading