Skip to content

Commit

Permalink
Refactor labeller
Browse files Browse the repository at this point in the history
Highlight some mess with "ClusterName" and "ResourceName".
They might be different for for chyt, spyt, and remote nodes.
  • Loading branch information
koct9i committed Nov 20, 2024
1 parent e126e5a commit ab00aee
Show file tree
Hide file tree
Showing 55 changed files with 559 additions and 881 deletions.
3 changes: 3 additions & 0 deletions api/v1/ytsaurus_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -584,9 +584,12 @@ type CommonSpec struct {
//+optional
ForceTCP *bool `json:"forceTcp,omitempty"`

// Do not add resource name into names of resources under control.
// When enabled resource should not share namespace with other Ytsaurus.
//+kubebuilder:default:=true
//+optional
UseShortNames bool `json:"useShortNames"`

// Use the host's network namespace for all components.
//+kubebuilder:default:=false
//+optional
Expand Down
2 changes: 2 additions & 0 deletions config/crd/bases/cluster.ytsaurus.tech_remotedatanodes.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1068,6 +1068,8 @@ spec:
type: boolean
useShortNames:
default: true
description: Do not add resource name into names of resources under
control.
type: boolean
volumeClaimTemplates:
items:
Expand Down
2 changes: 2 additions & 0 deletions config/crd/bases/cluster.ytsaurus.tech_remoteexecnodes.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1261,6 +1261,8 @@ spec:
type: boolean
useShortNames:
default: true
description: Do not add resource name into names of resources under
control.
type: boolean
volumeClaimTemplates:
items:
Expand Down
2 changes: 2 additions & 0 deletions config/crd/bases/cluster.ytsaurus.tech_remotetabletnodes.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1068,6 +1068,8 @@ spec:
type: boolean
useShortNames:
default: true
description: Do not add resource name into names of resources under
control.
type: boolean
volumeClaimTemplates:
items:
Expand Down
2 changes: 2 additions & 0 deletions config/crd/bases/cluster.ytsaurus.tech_ytsaurus.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34667,6 +34667,8 @@ spec:
type: boolean
useShortNames:
default: true
description: Do not add resource name into names of resources under
control.
type: boolean
yqlAgents:
properties:
Expand Down
2 changes: 1 addition & 1 deletion controllers/chyt_sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func (r *ChytReconciler) Sync(ctx context.Context, resource *ytv1.Chyt, ytsaurus

chyt := apiproxy.NewChyt(resource, r.Client, r.Recorder, r.Scheme)

cfgen := ytconfig.NewGenerator(ytsaurus, getClusterDomain(chyt.APIProxy().Client()))
cfgen := ytconfig.NewLocalNodeGenerator(ytsaurus, resource.Name, getClusterDomain(chyt.APIProxy().Client()))

component := components.NewChyt(cfgen, chyt, ytsaurus)

Expand Down
5 changes: 2 additions & 3 deletions controllers/component_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (

apiProxy "github.com/ytsaurus/ytsaurus-k8s-operator/pkg/apiproxy"
"github.com/ytsaurus/ytsaurus-k8s-operator/pkg/components"
"github.com/ytsaurus/ytsaurus-k8s-operator/pkg/labeller"
"github.com/ytsaurus/ytsaurus-k8s-operator/pkg/ytconfig"
)

Expand Down Expand Up @@ -38,6 +37,7 @@ func NewComponentManager(

clusterDomain := getClusterDomain(ytsaurus.APIProxy().Client())
cfgen := ytconfig.NewGenerator(resource, clusterDomain)
nodeCfgGen := &cfgen.NodeGenerator

d := components.NewDiscovery(cfgen, ytsaurus)
m := components.NewMaster(cfgen, ytsaurus)
Expand All @@ -48,7 +48,6 @@ func NewComponentManager(
yc := components.NewYtsaurusClient(cfgen, ytsaurus, hps[0])

var dnds []components.Component
nodeCfgGen := ytconfig.NewLocalNodeGenerator(ytsaurus.GetResource(), clusterDomain)
if len(resource.Spec.DataNodes) > 0 {
for _, dndSpec := range ytsaurus.GetResource().Spec.DataNodes {
dnds = append(dnds, components.NewDataNode(nodeCfgGen, ytsaurus, m, dndSpec))
Expand Down Expand Up @@ -265,5 +264,5 @@ func (cm *ComponentManager) arePodsRemoved() bool {
}

func (cm *ComponentManager) areComponentPodsRemoved(component components.Component) bool {
return cm.ytsaurus.IsUpdateStatusConditionTrue(labeller.GetPodsRemovedCondition(component.GetName()))
return cm.ytsaurus.IsUpdateStatusConditionTrue(component.GetLabeller().GetPodsRemovedCondition())
}
9 changes: 1 addition & 8 deletions controllers/remotedatanodes_sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package controllers
import (
"context"

"k8s.io/apimachinery/pkg/types"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/log"

Expand All @@ -21,13 +20,7 @@ func (r *RemoteDataNodesReconciler) Sync(
logger := log.FromContext(ctx).WithValues("component", "remoteDatanodes")
apiProxy := apiproxy.NewAPIProxy(resource, r.Client, r.Recorder, r.Scheme)

cfgen := ytconfig.NewRemoteNodeGenerator(
types.NamespacedName{Name: resource.Name, Namespace: resource.Namespace},
getClusterDomain(r.Client),
resource.Spec.CommonSpec,
remoteYtsaurus.Spec.MasterConnectionSpec,
&remoteYtsaurus.Spec.MasterCachesSpec,
)
cfgen := ytconfig.NewRemoteNodeGenerator(remoteYtsaurus, resource.GetName(), getClusterDomain(r.Client), &resource.Spec.CommonSpec)

component := components.NewRemoteDataNodes(
cfgen,
Expand Down
9 changes: 1 addition & 8 deletions controllers/remoteexecnodes_sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package controllers
import (
"context"

"k8s.io/apimachinery/pkg/types"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/log"

Expand All @@ -21,13 +20,7 @@ func (r *RemoteExecNodesReconciler) Sync(
logger := log.FromContext(ctx).WithValues("component", "remoteexecnodes")
apiProxy := apiproxy.NewAPIProxy(resource, r.Client, r.Recorder, r.Scheme)

cfgen := ytconfig.NewRemoteNodeGenerator(
types.NamespacedName{Name: resource.Name, Namespace: resource.Namespace},
getClusterDomain(r.Client),
resource.Spec.CommonSpec,
remoteYtsaurus.Spec.MasterConnectionSpec,
&remoteYtsaurus.Spec.MasterCachesSpec,
)
cfgen := ytconfig.NewRemoteNodeGenerator(remoteYtsaurus, resource.GetName(), getClusterDomain(r.Client), &resource.Spec.CommonSpec)

component := components.NewRemoteExecNodes(
cfgen,
Expand Down
9 changes: 1 addition & 8 deletions controllers/remotetabletnodes_sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package controllers
import (
"context"

"k8s.io/apimachinery/pkg/types"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/log"

Expand All @@ -21,13 +20,7 @@ func (r *RemoteTabletNodesReconciler) Sync(
logger := log.FromContext(ctx).WithValues("component", "remoteTabletNodes")
apiProxy := apiproxy.NewAPIProxy(resource, r.Client, r.Recorder, r.Scheme)

cfgen := ytconfig.NewRemoteNodeGenerator(
types.NamespacedName{Name: resource.Name, Namespace: resource.Namespace},
getClusterDomain(r.Client),
resource.Spec.CommonSpec,
remoteYtsaurus.Spec.MasterConnectionSpec,
&remoteYtsaurus.Spec.MasterCachesSpec,
)
cfgen := ytconfig.NewRemoteNodeGenerator(remoteYtsaurus, resource.GetName(), getClusterDomain(r.Client), &resource.Spec.CommonSpec)

component := components.NewRemoteTabletNodes(
cfgen,
Expand Down
2 changes: 1 addition & 1 deletion controllers/spyt_sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func (r *SpytReconciler) Sync(ctx context.Context, resource *ytv1.Spyt, ytsaurus

spyt := apiproxy.NewSpyt(resource, r.Client, r.Recorder, r.Scheme)

cfgen := ytconfig.NewGenerator(ytsaurus, getClusterDomain(spyt.APIProxy().Client()))
cfgen := ytconfig.NewLocalNodeGenerator(ytsaurus, resource.Name, getClusterDomain(spyt.APIProxy().Client()))

component := components.NewSpyt(cfgen, spyt, ytsaurus)

Expand Down
15 changes: 9 additions & 6 deletions docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ _Appears in:_
| `useIpv4` _boolean_ | | false | |
| `keepSocket` _boolean_ | | | |
| `forceTcp` _boolean_ | | | |
| `useShortNames` _boolean_ | | true | |
| `useShortNames` _boolean_ | Do not add resource name into names of resources under control.<br />When enabled resource should not share namespace with other Ytsaurus. | true | |
| `hostNetwork` _boolean_ | Use the host's network namespace for all components. | false | |
| `usePorto` _boolean_ | | false | |
| `extraPodAnnotations` _object (keys:string, values:string)_ | | | |
Expand Down Expand Up @@ -1288,7 +1288,7 @@ _Appears in:_
| `useIpv4` _boolean_ | | false | |
| `keepSocket` _boolean_ | | | |
| `forceTcp` _boolean_ | | | |
| `useShortNames` _boolean_ | | true | |
| `useShortNames` _boolean_ | Do not add resource name into names of resources under control.<br />When enabled resource should not share namespace with other Ytsaurus. | true | |
| `hostNetwork` _boolean_ | Use the host's network namespace for all components. | false | |
| `usePorto` _boolean_ | | false | |
| `extraPodAnnotations` _object (keys:string, values:string)_ | | | |
Expand Down Expand Up @@ -1336,6 +1336,7 @@ _Appears in:_

| Field | Description | Default | Validation |
| --- | --- | --- | --- |
| `observedGeneration` _integer_ | Reflects resource generation which was used for updating status. | | |
| `releaseStatus` _[RemoteNodeReleaseStatus](#remotenodereleasestatus)_ | | | |


Expand Down Expand Up @@ -1381,7 +1382,7 @@ _Appears in:_
| `useIpv4` _boolean_ | | false | |
| `keepSocket` _boolean_ | | | |
| `forceTcp` _boolean_ | | | |
| `useShortNames` _boolean_ | | true | |
| `useShortNames` _boolean_ | Do not add resource name into names of resources under control.<br />When enabled resource should not share namespace with other Ytsaurus. | true | |
| `hostNetwork` _boolean_ | Use the host's network namespace for all components. | false | |
| `usePorto` _boolean_ | | false | |
| `extraPodAnnotations` _object (keys:string, values:string)_ | | | |
Expand Down Expand Up @@ -1435,6 +1436,7 @@ _Appears in:_

| Field | Description | Default | Validation |
| --- | --- | --- | --- |
| `observedGeneration` _integer_ | Reflects resource generation which was used for updating status. | | |
| `releaseStatus` _[RemoteNodeReleaseStatus](#remotenodereleasestatus)_ | | | |


Expand Down Expand Up @@ -1519,7 +1521,7 @@ _Appears in:_
| `useIpv4` _boolean_ | | false | |
| `keepSocket` _boolean_ | | | |
| `forceTcp` _boolean_ | | | |
| `useShortNames` _boolean_ | | true | |
| `useShortNames` _boolean_ | Do not add resource name into names of resources under control.<br />When enabled resource should not share namespace with other Ytsaurus. | true | |
| `hostNetwork` _boolean_ | Use the host's network namespace for all components. | false | |
| `usePorto` _boolean_ | | false | |
| `extraPodAnnotations` _object (keys:string, values:string)_ | | | |
Expand Down Expand Up @@ -1567,6 +1569,7 @@ _Appears in:_

| Field | Description | Default | Validation |
| --- | --- | --- | --- |
| `observedGeneration` _integer_ | Reflects resource generation which was used for updating status. | | |
| `releaseStatus` _[RemoteNodeReleaseStatus](#remotenodereleasestatus)_ | | | |


Expand Down Expand Up @@ -1777,7 +1780,7 @@ _Appears in:_
| `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. | | |
| `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 Expand Up @@ -2172,7 +2175,7 @@ _Appears in:_
| `useIpv4` _boolean_ | | false | |
| `keepSocket` _boolean_ | | | |
| `forceTcp` _boolean_ | | | |
| `useShortNames` _boolean_ | | true | |
| `useShortNames` _boolean_ | Do not add resource name into names of resources under control.<br />When enabled resource should not share namespace with other Ytsaurus. | true | |
| `hostNetwork` _boolean_ | Use the host's network namespace for all components. | false | |
| `usePorto` _boolean_ | | false | |
| `extraPodAnnotations` _object (keys:string, values:string)_ | | | |
Expand Down
30 changes: 11 additions & 19 deletions pkg/components/chyt.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
type Chyt struct {
labeller *labeller.Labeller
chyt *apiproxy.Chyt
cfgen *ytconfig.Generator
cfgen *ytconfig.NodeGenerator
ytsaurus *ytv1.Ytsaurus

secret *resources.StringSecret
Expand All @@ -29,25 +29,15 @@ type Chyt struct {
initChPublicJob *InitJob
}

func NewChyt(
cfgen *ytconfig.Generator,
chyt *apiproxy.Chyt,
ytsaurus *ytv1.Ytsaurus) *Chyt {
l := labeller.Labeller{
ObjectMeta: &chyt.GetResource().ObjectMeta,
APIProxy: chyt.APIProxy(),
ComponentType: consts.ChytType,
ComponentNamePart: chyt.GetResource().Name,
Annotations: ytsaurus.Spec.ExtraPodAnnotations,
}

func NewChyt(cfgen *ytconfig.NodeGenerator, chyt *apiproxy.Chyt, ytsaurus *ytv1.Ytsaurus) *Chyt {
l := cfgen.GetComponentLabeller(consts.ChytType, chyt.GetResource().Name)
return &Chyt{
labeller: &l,
labeller: l,
chyt: chyt,
cfgen: cfgen,
ytsaurus: ytsaurus,
initUser: NewInitJob(
&l,
l,
chyt.APIProxy(),
chyt,
ytsaurus.Spec.ImagePullSecrets,
Expand All @@ -59,7 +49,7 @@ func NewChyt(
ytsaurus.Spec.NodeSelector,
),
initEnvironment: NewInitJob(
&l,
l,
chyt.APIProxy(),
chyt,
ytsaurus.Spec.ImagePullSecrets,
Expand All @@ -71,7 +61,7 @@ func NewChyt(
ytsaurus.Spec.NodeSelector,
),
initChPublicJob: NewInitJob(
&l,
l,
chyt.APIProxy(),
chyt,
ytsaurus.Spec.ImagePullSecrets,
Expand All @@ -84,7 +74,7 @@ func NewChyt(
),
secret: resources.NewStringSecret(
l.GetSecretName(),
&l,
l,
chyt.APIProxy()),
}
}
Expand Down Expand Up @@ -113,7 +103,9 @@ func (c *Chyt) createInitScript() string {
func (c *Chyt) createInitChPublicScript() string {
script := []string{
initJobPrologue,
fmt.Sprintf("export YT_PROXY=%v CHYT_CTL_ADDRESS=%v YT_LOG_LEVEL=debug", c.cfgen.GetHTTPProxiesAddress(consts.DefaultHTTPProxyRole), c.cfgen.GetStrawberryControllerServiceAddress()),
fmt.Sprintf("export YT_PROXY=%v CHYT_CTL_ADDRESS=%v YT_LOG_LEVEL=debug",
c.cfgen.GetHTTPProxiesAddress(consts.DefaultHTTPProxyRole),
c.cfgen.GetStrawberryControllerServiceAddress()),
"yt create scheduler_pool --attributes '{name=chyt; pool_tree=default}' --ignore-existing",
"yt clickhouse ctl create ch_public || true",
"yt clickhouse ctl set-option --alias ch_public pool chyt",
Expand Down
10 changes: 10 additions & 0 deletions pkg/components/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ type Component interface {

// TODO(nadya73): refactor it
IsUpdatable() bool

GetLabeller() *labeller.Labeller
}

// Following structs are used as a base for implementing YTsaurus components objects.
Expand All @@ -69,6 +71,14 @@ func (c *baseComponent) GetName() string {
return c.labeller.GetFullComponentName()
}

func (c *baseComponent) GetType() consts.ComponentType {
return c.labeller.ComponentType
}

func (c *baseComponent) GetLabeller() *labeller.Labeller {
return c.labeller
}

// localComponent is a base structs for components which have access to ytsaurus resource,
// but don't depend on server. Example: UI, Strawberry.
type localComponent struct {
Expand Down
15 changes: 3 additions & 12 deletions pkg/components/controller_agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
ytv1 "github.com/ytsaurus/ytsaurus-k8s-operator/api/v1"
"github.com/ytsaurus/ytsaurus-k8s-operator/pkg/apiproxy"
"github.com/ytsaurus/ytsaurus-k8s-operator/pkg/consts"
"github.com/ytsaurus/ytsaurus-k8s-operator/pkg/labeller"
"github.com/ytsaurus/ytsaurus-k8s-operator/pkg/resources"
"github.com/ytsaurus/ytsaurus-k8s-operator/pkg/ytconfig"
)
Expand All @@ -21,25 +20,19 @@ type ControllerAgent struct {
}

func NewControllerAgent(cfgen *ytconfig.Generator, ytsaurus *apiproxy.Ytsaurus, master Component) *ControllerAgent {
l := cfgen.GetComponentLabeller(consts.ControllerAgentType, "")
resource := ytsaurus.GetResource()
l := labeller.Labeller{
ObjectMeta: &resource.ObjectMeta,
APIProxy: ytsaurus.APIProxy(),
ComponentType: consts.ControllerAgentType,
}

if resource.Spec.ControllerAgents.InstanceSpec.MonitoringPort == nil {
resource.Spec.ControllerAgents.InstanceSpec.MonitoringPort = ptr.To(int32(consts.ControllerAgentMonitoringPort))
}

srv := newServer(
&l,
l,
ytsaurus,
&resource.Spec.ControllerAgents.InstanceSpec,
"/usr/bin/ytserver-controller-agent",
"ytserver-controller-agent.yson",
"ca",
"controller-agents",
func() ([]byte, error) { return cfgen.GetControllerAgentConfig(resource.Spec.ControllerAgents) },
WithContainerPorts(corev1.ContainerPort{
Name: consts.YTRPCPortName,
Expand All @@ -49,7 +42,7 @@ func NewControllerAgent(cfgen *ytconfig.Generator, ytsaurus *apiproxy.Ytsaurus,
)

return &ControllerAgent{
localServerComponent: newLocalServerComponent(&l, ytsaurus, srv),
localServerComponent: newLocalServerComponent(l, ytsaurus, srv),
cfgen: cfgen,
master: master,
}
Expand All @@ -59,8 +52,6 @@ func (ca *ControllerAgent) IsUpdatable() bool {
return true
}

func (ca *ControllerAgent) GetType() consts.ComponentType { return consts.ControllerAgentType }

func (ca *ControllerAgent) Fetch(ctx context.Context) error {
return resources.Fetch(ctx, ca.server)
}
Expand Down
Loading

0 comments on commit ab00aee

Please sign in to comment.