diff --git a/api/v1/ytsaurus_types.go b/api/v1/ytsaurus_types.go index 90fd98fb..35b8ac47 100644 --- a/api/v1/ytsaurus_types.go +++ b/api/v1/ytsaurus_types.go @@ -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 diff --git a/config/crd/bases/cluster.ytsaurus.tech_remotedatanodes.yaml b/config/crd/bases/cluster.ytsaurus.tech_remotedatanodes.yaml index 6fa8b407..6eb07416 100644 --- a/config/crd/bases/cluster.ytsaurus.tech_remotedatanodes.yaml +++ b/config/crd/bases/cluster.ytsaurus.tech_remotedatanodes.yaml @@ -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: diff --git a/config/crd/bases/cluster.ytsaurus.tech_remoteexecnodes.yaml b/config/crd/bases/cluster.ytsaurus.tech_remoteexecnodes.yaml index 201f55f2..e58681a0 100644 --- a/config/crd/bases/cluster.ytsaurus.tech_remoteexecnodes.yaml +++ b/config/crd/bases/cluster.ytsaurus.tech_remoteexecnodes.yaml @@ -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: diff --git a/config/crd/bases/cluster.ytsaurus.tech_remotetabletnodes.yaml b/config/crd/bases/cluster.ytsaurus.tech_remotetabletnodes.yaml index e63c2abc..521bdcc5 100644 --- a/config/crd/bases/cluster.ytsaurus.tech_remotetabletnodes.yaml +++ b/config/crd/bases/cluster.ytsaurus.tech_remotetabletnodes.yaml @@ -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: diff --git a/config/crd/bases/cluster.ytsaurus.tech_ytsaurus.yaml b/config/crd/bases/cluster.ytsaurus.tech_ytsaurus.yaml index 10be51dd..98bed971 100644 --- a/config/crd/bases/cluster.ytsaurus.tech_ytsaurus.yaml +++ b/config/crd/bases/cluster.ytsaurus.tech_ytsaurus.yaml @@ -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: diff --git a/controllers/chyt_sync.go b/controllers/chyt_sync.go index a00b9bd1..eed9de56 100644 --- a/controllers/chyt_sync.go +++ b/controllers/chyt_sync.go @@ -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) diff --git a/controllers/component_manager.go b/controllers/component_manager.go index 61ef993e..95acde78 100644 --- a/controllers/component_manager.go +++ b/controllers/component_manager.go @@ -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" ) @@ -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) @@ -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)) @@ -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()) } diff --git a/controllers/remotedatanodes_sync.go b/controllers/remotedatanodes_sync.go index 877a812d..9986c593 100644 --- a/controllers/remotedatanodes_sync.go +++ b/controllers/remotedatanodes_sync.go @@ -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" @@ -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, diff --git a/controllers/remoteexecnodes_sync.go b/controllers/remoteexecnodes_sync.go index 41a70428..8b8ac059 100644 --- a/controllers/remoteexecnodes_sync.go +++ b/controllers/remoteexecnodes_sync.go @@ -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" @@ -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, diff --git a/controllers/remotetabletnodes_sync.go b/controllers/remotetabletnodes_sync.go index 6c5793ce..f0fe6d96 100644 --- a/controllers/remotetabletnodes_sync.go +++ b/controllers/remotetabletnodes_sync.go @@ -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" @@ -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, diff --git a/controllers/spyt_sync.go b/controllers/spyt_sync.go index 33789920..831231c0 100644 --- a/controllers/spyt_sync.go +++ b/controllers/spyt_sync.go @@ -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) diff --git a/docs/api.md b/docs/api.md index c48bb8fb..f7f9e361 100644 --- a/docs/api.md +++ b/docs/api.md @@ -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.
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)_ | | | | @@ -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.
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)_ | | | | @@ -1336,6 +1336,7 @@ _Appears in:_ | Field | Description | Default | Validation | | --- | --- | --- | --- | +| `observedGeneration` _integer_ | Reflects resource generation which was used for updating status. | | | | `releaseStatus` _[RemoteNodeReleaseStatus](#remotenodereleasestatus)_ | | | | @@ -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.
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)_ | | | | @@ -1435,6 +1436,7 @@ _Appears in:_ | Field | Description | Default | Validation | | --- | --- | --- | --- | +| `observedGeneration` _integer_ | Reflects resource generation which was used for updating status. | | | | `releaseStatus` _[RemoteNodeReleaseStatus](#remotenodereleasestatus)_ | | | | @@ -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.
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)_ | | | | @@ -1567,6 +1569,7 @@ _Appears in:_ | Field | Description | Default | Validation | | --- | --- | --- | --- | +| `observedGeneration` _integer_ | Reflects resource generation which was used for updating status. | | | | `releaseStatus` _[RemoteNodeReleaseStatus](#remotenodereleasestatus)_ | | | | @@ -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.
For example, "chyt" (with `ControllerFamilies` set to {"chyt", "jupyt"} would mean
that requests to "foo." 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.
For example, "chyt" (with `ControllerFamilies` set to \{"chyt", "jupyt"\} would mean
that requests to "foo." will be processed by chyt controller. | | | #### StructuredLoggerSpec @@ -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.
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)_ | | | | diff --git a/pkg/components/chyt.go b/pkg/components/chyt.go index b9aa99bd..0e020b88 100644 --- a/pkg/components/chyt.go +++ b/pkg/components/chyt.go @@ -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 @@ -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, @@ -59,7 +49,7 @@ func NewChyt( ytsaurus.Spec.NodeSelector, ), initEnvironment: NewInitJob( - &l, + l, chyt.APIProxy(), chyt, ytsaurus.Spec.ImagePullSecrets, @@ -71,7 +61,7 @@ func NewChyt( ytsaurus.Spec.NodeSelector, ), initChPublicJob: NewInitJob( - &l, + l, chyt.APIProxy(), chyt, ytsaurus.Spec.ImagePullSecrets, @@ -84,7 +74,7 @@ func NewChyt( ), secret: resources.NewStringSecret( l.GetSecretName(), - &l, + l, chyt.APIProxy()), } } @@ -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", diff --git a/pkg/components/component.go b/pkg/components/component.go index 0595ebeb..433717f5 100644 --- a/pkg/components/component.go +++ b/pkg/components/component.go @@ -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. @@ -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 { diff --git a/pkg/components/controller_agent.go b/pkg/components/controller_agent.go index 20216b84..be33a0f7 100644 --- a/pkg/components/controller_agent.go +++ b/pkg/components/controller_agent.go @@ -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" ) @@ -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, @@ -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, } @@ -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) } diff --git a/pkg/components/data_node.go b/pkg/components/data_node.go index 8eb3046f..9cbffb44 100644 --- a/pkg/components/data_node.go +++ b/pkg/components/data_node.go @@ -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" ) @@ -26,26 +25,18 @@ func NewDataNode( master Component, spec ytv1.DataNodesSpec, ) *DataNode { - resource := ytsaurus.GetResource() - l := labeller.Labeller{ - ObjectMeta: &resource.ObjectMeta, - APIProxy: ytsaurus.APIProxy(), - ComponentType: consts.DataNodeType, - ComponentNamePart: spec.Name, - } + l := cfgen.GetComponentLabeller(consts.DataNodeType, spec.Name) if spec.InstanceSpec.MonitoringPort == nil { spec.InstanceSpec.MonitoringPort = ptr.To(int32(consts.DataNodeMonitoringPort)) } srv := newServer( - &l, + l, ytsaurus, &spec.InstanceSpec, "/usr/bin/ytserver-node", "ytserver-data-node.yson", - cfgen.GetDataNodesStatefulSetName(spec.Name), - cfgen.GetDataNodesServiceName(spec.Name), func() ([]byte, error) { return cfgen.GetDataNodeConfig(spec) }, @@ -57,7 +48,7 @@ func NewDataNode( ) return &DataNode{ - localServerComponent: newLocalServerComponent(&l, ytsaurus, srv), + localServerComponent: newLocalServerComponent(l, ytsaurus, srv), cfgen: cfgen, master: master, } @@ -67,8 +58,6 @@ func (n *DataNode) IsUpdatable() bool { return true } -func (n *DataNode) GetType() consts.ComponentType { return consts.DataNodeType } - func (n *DataNode) Fetch(ctx context.Context) error { return resources.Fetch(ctx, n.server) } diff --git a/pkg/components/data_node_remote.go b/pkg/components/data_node_remote.go index f5638df1..9eb0e1e6 100644 --- a/pkg/components/data_node_remote.go +++ b/pkg/components/data_node_remote.go @@ -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" ) @@ -28,26 +27,19 @@ func NewRemoteDataNodes( spec ytv1.DataNodesSpec, commonSpec ytv1.CommonSpec, ) *RemoteDataNode { - l := labeller.Labeller{ - ObjectMeta: &nodes.ObjectMeta, - APIProxy: proxy, - ComponentType: consts.DataNodeType, - ComponentNamePart: spec.Name, - } + l := cfgen.GetComponentLabeller(consts.DataNodeType, spec.Name) if spec.InstanceSpec.MonitoringPort == nil { spec.InstanceSpec.MonitoringPort = ptr.To(int32(consts.DataNodeMonitoringPort)) } srv := newServerConfigured( - &l, + l, proxy, commonSpec, &spec.InstanceSpec, "/usr/bin/ytserver-node", "ytserver-data-node.yson", - cfgen.GetDataNodesStatefulSetName(spec.Name), - cfgen.GetDataNodesServiceName(spec.Name), func() ([]byte, error) { return cfgen.GetDataNodeConfig(spec) }, @@ -58,7 +50,7 @@ func NewRemoteDataNodes( }), ) return &RemoteDataNode{ - baseComponent: baseComponent{labeller: &l}, + baseComponent: baseComponent{labeller: l}, server: srv, cfgen: cfgen, spec: &spec, diff --git a/pkg/components/discovery.go b/pkg/components/discovery.go index 4b113105..86156a09 100644 --- a/pkg/components/discovery.go +++ b/pkg/components/discovery.go @@ -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" ) @@ -20,25 +19,19 @@ type Discovery struct { } func NewDiscovery(cfgen *ytconfig.Generator, ytsaurus *apiproxy.Ytsaurus) *Discovery { + l := cfgen.GetComponentLabeller(consts.DiscoveryType, "") resource := ytsaurus.GetResource() - l := labeller.Labeller{ - ObjectMeta: &resource.ObjectMeta, - APIProxy: ytsaurus.APIProxy(), - ComponentType: consts.DiscoveryType, - } if resource.Spec.Discovery.InstanceSpec.MonitoringPort == nil { resource.Spec.Discovery.InstanceSpec.MonitoringPort = ptr.To(int32(consts.DiscoveryMonitoringPort)) } srv := newServer( - &l, + l, ytsaurus, &resource.Spec.Discovery.InstanceSpec, "/usr/bin/ytserver-discovery", "ytserver-discovery.yson", - cfgen.GetDiscoveryStatefulSetName(), - cfgen.GetDiscoveryServiceName(), func() ([]byte, error) { return cfgen.GetDiscoveryConfig(&resource.Spec.Discovery) }, @@ -50,7 +43,7 @@ func NewDiscovery(cfgen *ytconfig.Generator, ytsaurus *apiproxy.Ytsaurus) *Disco ) return &Discovery{ - localServerComponent: newLocalServerComponent(&l, ytsaurus, srv), + localServerComponent: newLocalServerComponent(l, ytsaurus, srv), cfgen: cfgen, } } @@ -59,8 +52,6 @@ func (d *Discovery) IsUpdatable() bool { return true } -func (d *Discovery) GetType() consts.ComponentType { return consts.DiscoveryType } - func (d *Discovery) Fetch(ctx context.Context) error { return resources.Fetch(ctx, d.server) } diff --git a/pkg/components/exec_node.go b/pkg/components/exec_node.go index df7baf1a..9418c19a 100644 --- a/pkg/components/exec_node.go +++ b/pkg/components/exec_node.go @@ -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/ytconfig" ) @@ -25,26 +24,18 @@ func NewExecNode( master Component, spec ytv1.ExecNodesSpec, ) *ExecNode { - resource := ytsaurus.GetResource() - l := labeller.Labeller{ - ObjectMeta: &resource.ObjectMeta, - APIProxy: ytsaurus.APIProxy(), - ComponentType: consts.ExecNodeType, - ComponentNamePart: spec.Name, - } + l := cfgen.GetComponentLabeller(consts.ExecNodeType, spec.Name) if spec.InstanceSpec.MonitoringPort == nil { spec.InstanceSpec.MonitoringPort = ptr.To(int32(consts.ExecNodeMonitoringPort)) } srv := newServer( - &l, + l, ytsaurus, &spec.InstanceSpec, "/usr/bin/ytserver-node", "ytserver-exec-node.yson", - cfgen.GetExecNodesStatefulSetName(spec.Name), - cfgen.GetExecNodesServiceName(spec.Name), func() ([]byte, error) { return cfgen.GetExecNodeConfig(spec) }, @@ -58,7 +49,7 @@ func NewExecNode( var sidecarConfig *ConfigHelper if spec.JobEnvironment != nil && spec.JobEnvironment.CRI != nil { sidecarConfig = NewConfigHelper( - &l, + l, ytsaurus.APIProxy(), l.GetSidecarConfigMapName(consts.JobsContainerName), ytsaurus.GetResource().Spec.ConfigOverrides, @@ -73,7 +64,7 @@ func NewExecNode( } return &ExecNode{ - localComponent: newLocalComponent(&l, ytsaurus), + localComponent: newLocalComponent(l, ytsaurus), baseExecNode: baseExecNode{ server: srv, cfgen: cfgen, @@ -88,8 +79,6 @@ func (n *ExecNode) IsUpdatable() bool { return true } -func (n *ExecNode) GetType() consts.ComponentType { return consts.ExecNodeType } - func (n *ExecNode) doSync(ctx context.Context, dry bool) (ComponentStatus, error) { var err error diff --git a/pkg/components/exec_node_remote.go b/pkg/components/exec_node_remote.go index 9611cd3e..dc17aebc 100644 --- a/pkg/components/exec_node_remote.go +++ b/pkg/components/exec_node_remote.go @@ -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/ytconfig" ) @@ -25,26 +24,19 @@ func NewRemoteExecNodes( spec ytv1.ExecNodesSpec, commonSpec ytv1.CommonSpec, ) *RemoteExecNode { - l := labeller.Labeller{ - ObjectMeta: &nodes.ObjectMeta, - APIProxy: proxy, - ComponentType: consts.ExecNodeType, - ComponentNamePart: spec.Name, - } + l := cfgen.GetComponentLabeller(consts.ExecNodeType, spec.Name) if spec.InstanceSpec.MonitoringPort == nil { spec.InstanceSpec.MonitoringPort = ptr.To(int32(consts.ExecNodeMonitoringPort)) } srv := newServerConfigured( - &l, + l, proxy, commonSpec, &spec.InstanceSpec, "/usr/bin/ytserver-node", "ytserver-exec-node.yson", - cfgen.GetExecNodesStatefulSetName(spec.Name), - cfgen.GetExecNodesServiceName(spec.Name), func() ([]byte, error) { return cfgen.GetExecNodeConfig(spec) }, @@ -58,7 +50,7 @@ func NewRemoteExecNodes( var sidecarConfig *ConfigHelper if spec.JobEnvironment != nil && spec.JobEnvironment.CRI != nil { sidecarConfig = NewConfigHelper( - &l, + l, proxy, l.GetSidecarConfigMapName(consts.JobsContainerName), commonSpec.ConfigOverrides, @@ -73,7 +65,7 @@ func NewRemoteExecNodes( } return &RemoteExecNode{ - baseComponent: baseComponent{labeller: &l}, + baseComponent: baseComponent{labeller: l}, baseExecNode: baseExecNode{ server: srv, cfgen: cfgen, diff --git a/pkg/components/httpproxy.go b/pkg/components/httpproxy.go index 8e9e1dff..f4d7ff3d 100644 --- a/pkg/components/httpproxy.go +++ b/pkg/components/httpproxy.go @@ -10,7 +10,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" ) @@ -31,27 +30,20 @@ func NewHTTPProxy( cfgen *ytconfig.Generator, ytsaurus *apiproxy.Ytsaurus, masterReconciler Component, - spec ytv1.HTTPProxiesSpec) *HttpProxy { - resource := ytsaurus.GetResource() - l := labeller.Labeller{ - ObjectMeta: &resource.ObjectMeta, - APIProxy: ytsaurus.APIProxy(), - ComponentType: consts.HttpProxyType, - ComponentNamePart: spec.Role, - } + spec ytv1.HTTPProxiesSpec, +) *HttpProxy { + l := cfgen.GetComponentLabeller(consts.HttpProxyType, spec.Role) if spec.InstanceSpec.MonitoringPort == nil { spec.InstanceSpec.MonitoringPort = ptr.To(int32(consts.HTTPProxyMonitoringPort)) } srv := newServer( - &l, + l, ytsaurus, &spec.InstanceSpec, "/usr/bin/ytserver-http-proxy", "ytserver-http-proxy.yson", - cfgen.GetHTTPProxiesStatefulSetName(spec.Role), - cfgen.GetHTTPProxiesHeadlessServiceName(spec.Role), func() ([]byte, error) { return cfgen.GetHTTPProxyConfig(spec) }, @@ -87,14 +79,14 @@ func NewHTTPProxy( balancingService := resources.NewHTTPService( cfgen.GetHTTPProxiesServiceName(spec.Role), &spec.Transport, - &l, + l, ytsaurus.APIProxy()) balancingService.SetHttpNodePort(spec.HttpNodePort) balancingService.SetHttpsNodePort(spec.HttpsNodePort) return &HttpProxy{ - localServerComponent: newLocalServerComponent(&l, ytsaurus, srv), + localServerComponent: newLocalServerComponent(l, ytsaurus, srv), cfgen: cfgen, master: masterReconciler, serviceType: spec.ServiceType, @@ -108,8 +100,6 @@ func (hp *HttpProxy) IsUpdatable() bool { return true } -func (hp *HttpProxy) GetType() consts.ComponentType { return consts.HttpProxyType } - func (hp *HttpProxy) Fetch(ctx context.Context) error { return resources.Fetch(ctx, hp.server, diff --git a/pkg/components/init_job_test.go b/pkg/components/init_job_test.go index 3ec20e55..f0032ba6 100644 --- a/pkg/components/init_job_test.go +++ b/pkg/components/init_job_test.go @@ -10,7 +10,6 @@ import ( batchv1 "k8s.io/api/batch/v1" corev1 "k8s.io/api/core/v1" apierrors "k8s.io/apimachinery/pkg/api/errors" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" utilruntime "k8s.io/apimachinery/pkg/util/runtime" "k8s.io/client-go/tools/record" @@ -73,13 +72,12 @@ func syncJobUntilReady(t *testing.T, job *InitJob) { } func newTestJob(ytsaurus *apiproxy.Ytsaurus) *InitJob { - k8sName := "dummy-name" + resource := ytsaurus.GetResource() return NewInitJob( &labeller.Labeller{ - ObjectMeta: &metav1.ObjectMeta{ - Name: k8sName, - Namespace: ytsaurus.GetResource().Namespace, - }, + Namespace: resource.GetNamespace(), + ResourceName: resource.GetName(), + ClusterName: resource.GetName(), ComponentType: consts.MasterType, }, ytsaurus.APIProxy(), diff --git a/pkg/components/master.go b/pkg/components/master.go index 30d11fee..56dcb534 100644 --- a/pkg/components/master.go +++ b/pkg/components/master.go @@ -15,7 +15,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" ) @@ -34,26 +33,19 @@ type Master struct { } func NewMaster(cfgen *ytconfig.Generator, ytsaurus *apiproxy.Ytsaurus) *Master { - resource := ytsaurus.GetResource() - l := labeller.Labeller{ - ObjectMeta: &resource.ObjectMeta, - APIProxy: ytsaurus.APIProxy(), - ComponentType: consts.MasterType, - Annotations: resource.Spec.ExtraPodAnnotations, - } + l := cfgen.GetComponentLabeller(consts.MasterType, "") + resource := ytsaurus.GetResource() if resource.Spec.PrimaryMasters.InstanceSpec.MonitoringPort == nil { resource.Spec.PrimaryMasters.InstanceSpec.MonitoringPort = ptr.To(int32(consts.MasterMonitoringPort)) } srv := newServer( - &l, + l, ytsaurus, &resource.Spec.PrimaryMasters.InstanceSpec, "/usr/bin/ytserver-master", "ytserver-master.yson", - cfgen.GetMastersStatefulSetName(), - cfgen.GetMastersServiceName(), func() ([]byte, error) { return cfgen.GetMasterConfig(&resource.Spec.PrimaryMasters) }, WithContainerPorts(corev1.ContainerPort{ Name: consts.YTRPCPortName, @@ -63,7 +55,7 @@ func NewMaster(cfgen *ytconfig.Generator, ytsaurus *apiproxy.Ytsaurus) *Master { ) initJob := NewInitJob( - &l, + l, ytsaurus.APIProxy(), ytsaurus, resource.Spec.ImagePullSecrets, @@ -76,7 +68,7 @@ func NewMaster(cfgen *ytconfig.Generator, ytsaurus *apiproxy.Ytsaurus) *Master { ) exitReadOnlyJob := NewInitJob( - &l, + l, ytsaurus.APIProxy(), ytsaurus, resource.Spec.ImagePullSecrets, @@ -89,15 +81,13 @@ func NewMaster(cfgen *ytconfig.Generator, ytsaurus *apiproxy.Ytsaurus) *Master { ) return &Master{ - localServerComponent: newLocalServerComponent(&l, ytsaurus, srv), + localServerComponent: newLocalServerComponent(l, ytsaurus, srv), cfgen: cfgen, initJob: initJob, exitReadOnlyJob: exitReadOnlyJob, } } -func (m *Master) GetType() consts.ComponentType { return consts.MasterType } - func (m *Master) IsUpdatable() bool { return true } diff --git a/pkg/components/master_caches.go b/pkg/components/master_caches.go index 48101b25..e088e1b3 100644 --- a/pkg/components/master_caches.go +++ b/pkg/components/master_caches.go @@ -10,7 +10,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" ) @@ -21,26 +20,19 @@ type MasterCache struct { } func NewMasterCache(cfgen *ytconfig.Generator, ytsaurus *apiproxy.Ytsaurus) *MasterCache { - resource := ytsaurus.GetResource() - l := labeller.Labeller{ - ObjectMeta: &resource.ObjectMeta, - APIProxy: ytsaurus.APIProxy(), - ComponentType: consts.MasterCacheType, - Annotations: resource.Spec.ExtraPodAnnotations, - } + l := cfgen.GetComponentLabeller(consts.MasterCacheType, "") + resource := ytsaurus.GetResource() if resource.Spec.MasterCaches.InstanceSpec.MonitoringPort == nil { resource.Spec.MasterCaches.InstanceSpec.MonitoringPort = ptr.To(int32(consts.MasterCachesMonitoringPort)) } srv := newServer( - &l, + l, ytsaurus, &resource.Spec.MasterCaches.InstanceSpec, "/usr/bin/ytserver-master-cache", "ytserver-master-cache.yson", - cfgen.GetMasterCachesStatefulSetName(), - cfgen.GetMasterCachesServiceName(), func() ([]byte, error) { return cfgen.GetMasterCachesConfig(resource.Spec.MasterCaches) }, WithContainerPorts(corev1.ContainerPort{ Name: consts.YTRPCPortName, @@ -50,7 +42,7 @@ func NewMasterCache(cfgen *ytconfig.Generator, ytsaurus *apiproxy.Ytsaurus) *Mas ) return &MasterCache{ - localServerComponent: newLocalServerComponent(&l, ytsaurus, srv), + localServerComponent: newLocalServerComponent(l, ytsaurus, srv), cfgen: cfgen, } } @@ -59,8 +51,6 @@ func (mc *MasterCache) IsUpdatable() bool { return true } -func (mc *MasterCache) GetType() consts.ComponentType { return consts.MasterCacheType } - func (mc *MasterCache) Fetch(ctx context.Context) error { return resources.Fetch(ctx, mc.server) } diff --git a/pkg/components/pods_manager.go b/pkg/components/pods_manager.go index b1be835d..c13e6c26 100644 --- a/pkg/components/pods_manager.go +++ b/pkg/components/pods_manager.go @@ -4,8 +4,6 @@ import ( "context" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - - "github.com/ytsaurus/ytsaurus-k8s-operator/pkg/labeller" ) // TODO: move to Updatable @@ -49,7 +47,7 @@ func setPodsRemovingStartedCondition(ctx context.Context, c *localComponent) { func setPodsRemovedCondition(ctx context.Context, c *localComponent) { c.ytsaurus.SetUpdateStatusCondition(ctx, metav1.Condition{ - Type: labeller.GetPodsRemovedCondition(c.GetName()), + Type: c.labeller.GetPodsRemovedCondition(), Status: metav1.ConditionTrue, Reason: "Update", Message: "Pods removed", diff --git a/pkg/components/query_tracker.go b/pkg/components/query_tracker.go index dde8f959..7244a648 100644 --- a/pkg/components/query_tracker.go +++ b/pkg/components/query_tracker.go @@ -16,7 +16,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" ) @@ -38,26 +37,19 @@ func NewQueryTracker( yc internalYtsaurusClient, tabletNodes []Component, ) *QueryTracker { + l := cfgen.GetComponentLabeller(consts.QueryTrackerType, "") resource := ytsaurus.GetResource() - l := labeller.Labeller{ - ObjectMeta: &resource.ObjectMeta, - APIProxy: ytsaurus.APIProxy(), - ComponentType: consts.QueryTrackerType, - Annotations: resource.Spec.ExtraPodAnnotations, - } if resource.Spec.QueryTrackers.InstanceSpec.MonitoringPort == nil { resource.Spec.QueryTrackers.InstanceSpec.MonitoringPort = ptr.To(int32(consts.QueryTrackerMonitoringPort)) } srv := newServer( - &l, + l, ytsaurus, &resource.Spec.QueryTrackers.InstanceSpec, "/usr/bin/ytserver-query-tracker", "ytserver-query-tracker.yson", - cfgen.GetQueryTrackerStatefulSetName(), - cfgen.GetQueryTrackerServiceName(), func() ([]byte, error) { return cfgen.GetQueryTrackerConfig(resource.Spec.QueryTrackers) }, WithContainerPorts(corev1.ContainerPort{ Name: consts.YTRPCPortName, @@ -67,13 +59,13 @@ func NewQueryTracker( ) return &QueryTracker{ - localServerComponent: newLocalServerComponent(&l, ytsaurus, srv), + localServerComponent: newLocalServerComponent(l, ytsaurus, srv), cfgen: cfgen, tabletNodes: tabletNodes, initCondition: "queryTrackerInitCompleted", ytsaurusClient: yc, initQTState: NewInitJob( - &l, + l, ytsaurus.APIProxy(), ytsaurus, resource.Spec.ImagePullSecrets, @@ -86,7 +78,7 @@ func NewQueryTracker( ), secret: resources.NewStringSecret( l.GetSecretName(), - &l, + l, ytsaurus.APIProxy()), } } @@ -95,8 +87,6 @@ func (qt *QueryTracker) IsUpdatable() bool { return true } -func (qt *QueryTracker) GetType() consts.ComponentType { return consts.QueryTrackerType } - func (qt *QueryTracker) Fetch(ctx context.Context) error { return resources.Fetch(ctx, qt.server, diff --git a/pkg/components/queue_agent.go b/pkg/components/queue_agent.go index 00cbdfd0..96e4f7c0 100644 --- a/pkg/components/queue_agent.go +++ b/pkg/components/queue_agent.go @@ -16,7 +16,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" ) @@ -40,26 +39,20 @@ func NewQueueAgent( master Component, tabletNodes []Component, ) *QueueAgent { + l := cfgen.GetComponentLabeller(consts.QueueAgentType, "") + resource := ytsaurus.GetResource() - l := labeller.Labeller{ - ObjectMeta: &resource.ObjectMeta, - APIProxy: ytsaurus.APIProxy(), - ComponentType: consts.QueueAgentType, - Annotations: resource.Spec.ExtraPodAnnotations, - } if resource.Spec.QueueAgents.InstanceSpec.MonitoringPort == nil { resource.Spec.QueueAgents.InstanceSpec.MonitoringPort = ptr.To(int32(consts.QueueAgentMonitoringPort)) } srv := newServer( - &l, + l, ytsaurus, &resource.Spec.QueueAgents.InstanceSpec, "/usr/bin/ytserver-queue-agent", "ytserver-queue-agent.yson", - cfgen.GetQueueAgentStatefulSetName(), - cfgen.GetQueueAgentServiceName(), func() ([]byte, error) { return cfgen.GetQueueAgentConfig(resource.Spec.QueueAgents) }, WithContainerPorts(corev1.ContainerPort{ Name: consts.YTRPCPortName, @@ -69,14 +62,14 @@ func NewQueueAgent( ) return &QueueAgent{ - localServerComponent: newLocalServerComponent(&l, ytsaurus, srv), + localServerComponent: newLocalServerComponent(l, ytsaurus, srv), cfgen: cfgen, master: master, tabletNodes: tabletNodes, initCondition: "queueAgentInitCompleted", ytsaurusClient: yc, initQAState: NewInitJob( - &l, + l, ytsaurus.APIProxy(), ytsaurus, resource.Spec.ImagePullSecrets, @@ -89,7 +82,7 @@ func NewQueueAgent( ), secret: resources.NewStringSecret( l.GetSecretName(), - &l, + l, ytsaurus.APIProxy()), } } @@ -106,8 +99,6 @@ func (qa *QueueAgent) Fetch(ctx context.Context) error { ) } -func (qa *QueueAgent) GetType() consts.ComponentType { return consts.QueueAgentType } - func (qa *QueueAgent) doSync(ctx context.Context, dry bool) (ComponentStatus, error) { var err error diff --git a/pkg/components/rpcproxy.go b/pkg/components/rpcproxy.go index b2b35aaf..319d9260 100644 --- a/pkg/components/rpcproxy.go +++ b/pkg/components/rpcproxy.go @@ -10,7 +10,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" ) @@ -30,27 +29,20 @@ func NewRPCProxy( cfgen *ytconfig.Generator, ytsaurus *apiproxy.Ytsaurus, masterReconciler Component, - spec ytv1.RPCProxiesSpec) *RpcProxy { - resource := ytsaurus.GetResource() - l := labeller.Labeller{ - ObjectMeta: &resource.ObjectMeta, - APIProxy: ytsaurus.APIProxy(), - ComponentType: consts.RpcProxyType, - ComponentNamePart: spec.Role, - } + spec ytv1.RPCProxiesSpec, +) *RpcProxy { + l := cfgen.GetComponentLabeller(consts.RpcProxyType, spec.Role) if spec.InstanceSpec.MonitoringPort == nil { spec.InstanceSpec.MonitoringPort = ptr.To(int32(consts.RPCProxyMonitoringPort)) } srv := newServer( - &l, + l, ytsaurus, &spec.InstanceSpec, "/usr/bin/ytserver-proxy", "ytserver-rpc-proxy.yson", - cfgen.GetRPCProxiesStatefulSetName(spec.Role), - cfgen.GetRPCProxiesHeadlessServiceName(spec.Role), func() ([]byte, error) { return cfgen.GetRPCProxyConfig(spec) }, @@ -65,7 +57,7 @@ func NewRPCProxy( if spec.ServiceType != nil { balancingService = resources.NewRPCService( cfgen.GetRPCProxiesServiceName(spec.Role), - &l, + l, ytsaurus.APIProxy()) balancingService.SetNodePort(spec.NodePort) @@ -80,7 +72,7 @@ func NewRPCProxy( } return &RpcProxy{ - localServerComponent: newLocalServerComponent(&l, ytsaurus, srv), + localServerComponent: newLocalServerComponent(l, ytsaurus, srv), cfgen: cfgen, master: masterReconciler, serviceType: spec.ServiceType, @@ -93,8 +85,6 @@ func (rp *RpcProxy) IsUpdatable() bool { return true } -func (rp *RpcProxy) GetType() consts.ComponentType { return consts.RpcProxyType } - func (rp *RpcProxy) Fetch(ctx context.Context) error { fetchable := []resources.Fetchable{ rp.server, diff --git a/pkg/components/scheduler.go b/pkg/components/scheduler.go index 0296ad66..e780b833 100644 --- a/pkg/components/scheduler.go +++ b/pkg/components/scheduler.go @@ -15,7 +15,6 @@ import ( "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" ) @@ -35,27 +34,22 @@ func NewScheduler( cfgen *ytconfig.Generator, ytsaurus *apiproxy.Ytsaurus, master Component, - execNodes, tabletNodes []Component) *Scheduler { + execNodes, tabletNodes []Component, +) *Scheduler { + l := cfgen.GetComponentLabeller(consts.SchedulerType, "") + resource := ytsaurus.GetResource() - l := labeller.Labeller{ - ObjectMeta: &resource.ObjectMeta, - APIProxy: ytsaurus.APIProxy(), - ComponentType: consts.SchedulerType, - Annotations: resource.Spec.ExtraPodAnnotations, - } if resource.Spec.Schedulers.InstanceSpec.MonitoringPort == nil { resource.Spec.Schedulers.InstanceSpec.MonitoringPort = ptr.To(int32(consts.SchedulerMonitoringPort)) } srv := newServer( - &l, + l, ytsaurus, &resource.Spec.Schedulers.InstanceSpec, "/usr/bin/ytserver-scheduler", "ytserver-scheduler.yson", - cfgen.GetSchedulerStatefulSetName(), - cfgen.GetSchedulerServiceName(), func() ([]byte, error) { return cfgen.GetSchedulerConfig(resource.Spec.Schedulers) }, @@ -67,13 +61,13 @@ func NewScheduler( ) return &Scheduler{ - localServerComponent: newLocalServerComponent(&l, ytsaurus, srv), + localServerComponent: newLocalServerComponent(l, ytsaurus, srv), cfgen: cfgen, master: master, execNodes: execNodes, tabletNodes: tabletNodes, initUser: NewInitJob( - &l, + l, ytsaurus.APIProxy(), ytsaurus, resource.Spec.ImagePullSecrets, @@ -85,7 +79,7 @@ func NewScheduler( getNodeSelectorWithDefault(resource.Spec.Schedulers.NodeSelector, resource.Spec.NodeSelector), ), initOpArchive: NewInitJob( - &l, + l, ytsaurus.APIProxy(), ytsaurus, resource.Spec.ImagePullSecrets, @@ -98,7 +92,7 @@ func NewScheduler( ), secret: resources.NewStringSecret( l.GetSecretName(), - &l, + l, ytsaurus.APIProxy()), } } @@ -107,8 +101,6 @@ func (s *Scheduler) IsUpdatable() bool { return true } -func (s *Scheduler) GetType() consts.ComponentType { return consts.SchedulerType } - func (s *Scheduler) Fetch(ctx context.Context) error { return resources.Fetch(ctx, s.server, diff --git a/pkg/components/server.go b/pkg/components/server.go index cb64263a..9b7b282d 100644 --- a/pkg/components/server.go +++ b/pkg/components/server.go @@ -66,7 +66,7 @@ func newServer( l *labeller.Labeller, ytsaurus *apiproxy.Ytsaurus, instanceSpec *ytv1.InstanceSpec, - binaryPath, configFileName, statefulSetName, serviceName string, + binaryPath, configFileName string, generator ytconfig.YsonGeneratorFunc, options ...Option, ) server { @@ -77,7 +77,7 @@ func newServer( proxy, commonSpec, instanceSpec, - binaryPath, configFileName, statefulSetName, serviceName, + binaryPath, configFileName, generator, options..., ) @@ -88,7 +88,7 @@ func newServerConfigured( proxy apiproxy.APIProxy, commonSpec ytv1.CommonSpec, instanceSpec *ytv1.InstanceSpec, - binaryPath, configFileName, statefulSetName, serviceName string, + binaryPath, configFileName string, generator ytconfig.YsonGeneratorFunc, optFuncs ...Option, ) server { @@ -139,13 +139,13 @@ func newServerConfigured( instanceSpec: instanceSpec, binaryPath: binaryPath, statefulSet: resources.NewStatefulSet( - statefulSetName, + l.GetServerStatfulSetName(), l, proxy, commonSpec, ), headlessService: resources.NewHeadlessService( - serviceName, + l.GetHeadlessServiceName(), l, proxy, ), diff --git a/pkg/components/spyt.go b/pkg/components/spyt.go index 8aa8a56b..8e885035 100644 --- a/pkg/components/spyt.go +++ b/pkg/components/spyt.go @@ -18,7 +18,7 @@ import ( type Spyt struct { labeller *labeller.Labeller spyt *apiproxy.Spyt - cfgen *ytconfig.Generator + cfgen *ytconfig.NodeGenerator ytsaurus *ytv1.Ytsaurus secret *resources.StringSecret @@ -27,25 +27,15 @@ type Spyt struct { initEnvironment *InitJob } -func NewSpyt( - cfgen *ytconfig.Generator, - spyt *apiproxy.Spyt, - ytsaurus *ytv1.Ytsaurus) *Spyt { - l := labeller.Labeller{ - ObjectMeta: &spyt.GetResource().ObjectMeta, - APIProxy: spyt.APIProxy(), - ComponentType: consts.SpytType, - ComponentNamePart: spyt.GetResource().Name, - Annotations: ytsaurus.Spec.ExtraPodAnnotations, - } - +func NewSpyt(cfgen *ytconfig.NodeGenerator, spyt *apiproxy.Spyt, ytsaurus *ytv1.Ytsaurus) *Spyt { + l := cfgen.GetComponentLabeller(consts.SpytType, spyt.GetResource().Name) return &Spyt{ - labeller: &l, + labeller: l, spyt: spyt, cfgen: cfgen, ytsaurus: ytsaurus, initUser: NewInitJob( - &l, + l, spyt.APIProxy(), spyt, ytsaurus.Spec.ImagePullSecrets, @@ -57,7 +47,7 @@ func NewSpyt( ytsaurus.Spec.NodeSelector, ), initEnvironment: NewInitJob( - &l, + l, spyt.APIProxy(), spyt, ytsaurus.Spec.ImagePullSecrets, @@ -70,7 +60,7 @@ func NewSpyt( ), secret: resources.NewStringSecret( l.GetSecretName(), - &l, + l, spyt.APIProxy()), } } diff --git a/pkg/components/strawberry_controller.go b/pkg/components/strawberry_controller.go index 923fbec5..b84c0548 100644 --- a/pkg/components/strawberry_controller.go +++ b/pkg/components/strawberry_controller.go @@ -12,7 +12,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" ) @@ -40,7 +39,10 @@ func NewStrawberryController( ytsaurus *apiproxy.Ytsaurus, master Component, scheduler Component, - dataNodes []Component) *StrawberryController { + dataNodes []Component, +) *StrawberryController { + l := cfgen.GetComponentLabeller(consts.StrawberryControllerType, "") + resource := ytsaurus.GetResource() // TODO: strawberry has a different image and can't be nil/fallback on CoreImage. @@ -49,15 +51,8 @@ func NewStrawberryController( image = *resource.Spec.StrawberryController.Image } - l := labeller.Labeller{ - ObjectMeta: &resource.ObjectMeta, - APIProxy: ytsaurus.APIProxy(), - ComponentType: consts.StrawberryControllerType, - Annotations: resource.Spec.ExtraPodAnnotations, - } - microservice := newMicroservice( - &l, + l, ytsaurus, image, 1, @@ -74,11 +69,11 @@ func NewStrawberryController( ) return &StrawberryController{ - localComponent: newLocalComponent(&l, ytsaurus), + localComponent: newLocalComponent(l, ytsaurus), cfgen: cfgen, microservice: microservice, initUserAndUrlJob: NewInitJob( - &l, + l, ytsaurus.APIProxy(), ytsaurus, ytsaurus.GetResource().Spec.ImagePullSecrets, @@ -90,7 +85,7 @@ func NewStrawberryController( getNodeSelectorWithDefault(resource.Spec.StrawberryController.NodeSelector, resource.Spec.NodeSelector), ), initChytClusterJob: NewInitJob( - &l, + l, ytsaurus.APIProxy(), ytsaurus, resource.Spec.ImagePullSecrets, @@ -103,7 +98,7 @@ func NewStrawberryController( ), secret: resources.NewStringSecret( l.GetSecretName(), - &l, + l, ytsaurus.APIProxy()), name: "strawberry", master: master, @@ -116,8 +111,6 @@ func (c *StrawberryController) IsUpdatable() bool { return true } -func (c *StrawberryController) GetType() consts.ComponentType { return consts.StrawberryControllerType } - func (c *StrawberryController) Fetch(ctx context.Context) error { return resources.Fetch(ctx, c.microservice, diff --git a/pkg/components/suite_test.go b/pkg/components/suite_test.go index 7132bc86..739c3243 100644 --- a/pkg/components/suite_test.go +++ b/pkg/components/suite_test.go @@ -15,6 +15,7 @@ import ( "sigs.k8s.io/controller-runtime/pkg/log/zap" "github.com/ytsaurus/ytsaurus-k8s-operator/pkg/consts" + "github.com/ytsaurus/ytsaurus-k8s-operator/pkg/labeller" mock_yt "github.com/ytsaurus/ytsaurus-k8s-operator/pkg/mock" ) @@ -74,6 +75,10 @@ func (fc *FakeComponent) GetType() consts.ComponentType { return fc.compType } +func (fyc *FakeComponent) GetLabeller() *labeller.Labeller { + return nil +} + func (fc *FakeComponent) SetReadyCondition(status ComponentStatus) {} type FakeServer struct { diff --git a/pkg/components/tablet_node.go b/pkg/components/tablet_node.go index 945dadd9..7662183f 100644 --- a/pkg/components/tablet_node.go +++ b/pkg/components/tablet_node.go @@ -15,7 +15,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" ) @@ -43,26 +42,18 @@ func NewTabletNode( spec ytv1.TabletNodesSpec, doInitiailization bool, ) *TabletNode { - resource := ytsaurus.GetResource() - l := labeller.Labeller{ - ObjectMeta: &resource.ObjectMeta, - APIProxy: ytsaurus.APIProxy(), - ComponentType: consts.TabletNodeType, - ComponentNamePart: spec.Name, - } + l := cfgen.GetComponentLabeller(consts.TabletNodeType, spec.Name) if spec.InstanceSpec.MonitoringPort == nil { spec.InstanceSpec.MonitoringPort = ptr.To(int32(consts.TabletNodeMonitoringPort)) } srv := newServer( - &l, + l, ytsaurus, &spec.InstanceSpec, "/usr/bin/ytserver-node", "ytserver-tablet-node.yson", - cfgen.GetTabletNodesStatefulSetName(spec.Name), - cfgen.GetTabletNodesServiceName(spec.Name), func() ([]byte, error) { return cfgen.GetTabletNodeConfig(spec) }, @@ -74,7 +65,7 @@ func NewTabletNode( ) return &TabletNode{ - localServerComponent: newLocalServerComponent(&l, ytsaurus, srv), + localServerComponent: newLocalServerComponent(l, ytsaurus, srv), cfgen: cfgen, initBundlesCondition: "bundlesTabletNodeInitCompleted", ytsaurusClient: ytsaurusClient, @@ -87,8 +78,6 @@ func (tn *TabletNode) IsUpdatable() bool { return true } -func (tn *TabletNode) GetType() consts.ComponentType { return consts.TabletNodeType } - func (tn *TabletNode) doSync(ctx context.Context, dry bool) (ComponentStatus, error) { var err error diff --git a/pkg/components/tablet_node_remote.go b/pkg/components/tablet_node_remote.go index 422bed0c..d4faab39 100644 --- a/pkg/components/tablet_node_remote.go +++ b/pkg/components/tablet_node_remote.go @@ -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" ) @@ -28,26 +27,19 @@ func NewRemoteTabletNodes( spec ytv1.TabletNodesSpec, commonSpec ytv1.CommonSpec, ) *RemoteTabletNode { - l := labeller.Labeller{ - ObjectMeta: &nodes.ObjectMeta, - APIProxy: proxy, - ComponentType: consts.TabletNodeType, - ComponentNamePart: spec.Name, - } + l := cfgen.GetComponentLabeller(consts.TabletNodeType, spec.Name) if spec.InstanceSpec.MonitoringPort == nil { spec.InstanceSpec.MonitoringPort = ptr.To(int32(consts.TabletNodeMonitoringPort)) } srv := newServerConfigured( - &l, + l, proxy, commonSpec, &spec.InstanceSpec, "/usr/bin/ytserver-node", "ytserver-tablet-node.yson", - cfgen.GetTabletNodesStatefulSetName(spec.Name), - cfgen.GetTabletNodesServiceName(spec.Name), func() ([]byte, error) { return cfgen.GetTabletNodeConfig(spec) }, @@ -58,7 +50,7 @@ func NewRemoteTabletNodes( }), ) return &RemoteTabletNode{ - baseComponent: baseComponent{labeller: &l}, + baseComponent: baseComponent{labeller: l}, server: srv, cfgen: cfgen, spec: &spec, diff --git a/pkg/components/tablet_node_test.go b/pkg/components/tablet_node_test.go index 6cae50ce..6af81ade 100644 --- a/pkg/components/tablet_node_test.go +++ b/pkg/components/tablet_node_test.go @@ -165,7 +165,7 @@ var _ = Describe("Tablet node test", func() { }) It("Tablet node Sync; ytclient not ready", func() { - cfgen := ytconfig.NewLocalNodeGenerator(ytsaurusSpec, "cluster_domain") + cfgen := ytconfig.NewLocalNodeGenerator(ytsaurusSpec, ytsaurusSpec.Name, "cluster_domain") ytsaurus := apiproxy.NewYtsaurus(ytsaurusSpec, client, record.NewFakeRecorder(1), scheme) ytsaurusClient := NewFakeYtsaurusClient(mockYtClient) @@ -186,7 +186,7 @@ var _ = Describe("Tablet node test", func() { }) It("Tablet node Sync; pods are not ready", func() { - cfgen := ytconfig.NewLocalNodeGenerator(ytsaurusSpec, "cluster_domain") + cfgen := ytconfig.NewLocalNodeGenerator(ytsaurusSpec, ytsaurusSpec.Name, "cluster_domain") ytsaurus := apiproxy.NewYtsaurus(ytsaurusSpec, client, record.NewFakeRecorder(1), scheme) ytsaurusClient := NewFakeYtsaurusClient(mockYtClient) @@ -216,7 +216,7 @@ var _ = Describe("Tablet node test", func() { getNetError := net.UnknownNetworkError("get: some net error") createCellNetError := net.UnknownNetworkError("create cell: some net error") - nodeCfgen := ytconfig.NewLocalNodeGenerator(ytsaurusSpec, "cluster_domain") + nodeCfgen := ytconfig.NewLocalNodeGenerator(ytsaurusSpec, ytsaurusSpec.Name, "cluster_domain") tabletNode := NewTabletNode(nodeCfgen, ytsaurus, ytsaurusClient, ytsaurusSpec.Spec.TabletNodes[0], true) tabletNode.server = NewFakeServer() @@ -510,7 +510,7 @@ var _ = Describe("Tablet node test", func() { }})).Return(yt.NodeID(guid.New()), nil) } - nodeCfgen := ytconfig.NewLocalNodeGenerator(ytsaurusSpec, "cluster_domain") + nodeCfgen := ytconfig.NewLocalNodeGenerator(ytsaurusSpec, ytsaurusSpec.Name, "cluster_domain") tabletNode := NewTabletNode(nodeCfgen, ytsaurus, ytsaurusClient, ytsaurusSpec.Spec.TabletNodes[0], true) tabletNode.server = NewFakeServer() err := tabletNode.Sync(context.Background()) @@ -526,7 +526,7 @@ var _ = Describe("Tablet node test", func() { ytsaurusClient := NewFakeYtsaurusClient(mockYtClient) - cfgen := ytconfig.NewLocalNodeGenerator(ytsaurusSpec, "cluster_domain") + cfgen := ytconfig.NewLocalNodeGenerator(ytsaurusSpec, ytsaurusSpec.Name, "cluster_domain") tabletNode := NewTabletNode(cfgen, ytsaurus, ytsaurusClient, ytsaurusSpec.Spec.TabletNodes[0], false) tabletNode.server = NewFakeServer() err := tabletNode.Sync(context.Background()) diff --git a/pkg/components/tcpproxy.go b/pkg/components/tcpproxy.go index 32640a92..a9229527 100644 --- a/pkg/components/tcpproxy.go +++ b/pkg/components/tcpproxy.go @@ -10,7 +10,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" ) @@ -25,31 +24,19 @@ type TcpProxy struct { balancingService *resources.TCPService } -func NewTCPProxy( - cfgen *ytconfig.Generator, - ytsaurus *apiproxy.Ytsaurus, - masterReconciler Component, - spec ytv1.TCPProxiesSpec) *TcpProxy { - resource := ytsaurus.GetResource() - l := labeller.Labeller{ - ObjectMeta: &resource.ObjectMeta, - APIProxy: ytsaurus.APIProxy(), - ComponentType: consts.TcpProxyType, - ComponentNamePart: spec.Role, - } +func NewTCPProxy(cfgen *ytconfig.Generator, ytsaurus *apiproxy.Ytsaurus, masterReconciler Component, spec ytv1.TCPProxiesSpec) *TcpProxy { + l := cfgen.GetComponentLabeller(consts.TcpProxyType, spec.Role) if spec.InstanceSpec.MonitoringPort == nil { spec.InstanceSpec.MonitoringPort = ptr.To(int32(consts.TCPProxyMonitoringPort)) } srv := newServer( - &l, + l, ytsaurus, &spec.InstanceSpec, "/usr/bin/ytserver-tcp-proxy", "ytserver-tcp-proxy.yson", - cfgen.GetTCPProxiesStatefulSetName(spec.Role), - cfgen.GetTCPProxiesHeadlessServiceName(spec.Role), func() ([]byte, error) { return cfgen.GetTCPProxyConfig(spec) }, @@ -62,12 +49,12 @@ func NewTCPProxy( *spec.ServiceType, spec.PortCount, spec.MinPort, - &l, + l, ytsaurus.APIProxy()) } return &TcpProxy{ - localServerComponent: newLocalServerComponent(&l, ytsaurus, srv), + localServerComponent: newLocalServerComponent(l, ytsaurus, srv), cfgen: cfgen, master: masterReconciler, serviceType: spec.ServiceType, @@ -79,8 +66,6 @@ func (tp *TcpProxy) IsUpdatable() bool { return true } -func (tp *TcpProxy) GetType() consts.ComponentType { return consts.TcpProxyType } - func (tp *TcpProxy) Fetch(ctx context.Context) error { fetchable := []resources.Fetchable{ tp.server, diff --git a/pkg/components/ui.go b/pkg/components/ui.go index 65b866f1..3b89ae49 100644 --- a/pkg/components/ui.go +++ b/pkg/components/ui.go @@ -13,7 +13,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" ) @@ -32,13 +31,9 @@ const UIClustersConfigFileName = "clusters-config.json" const UICustomConfigFileName = "common.js" func NewUI(cfgen *ytconfig.Generator, ytsaurus *apiproxy.Ytsaurus, master Component) *UI { + l := cfgen.GetComponentLabeller(consts.UIType, "") + resource := ytsaurus.GetResource() - l := labeller.Labeller{ - ObjectMeta: &resource.ObjectMeta, - APIProxy: ytsaurus.APIProxy(), - ComponentType: consts.UIType, - Annotations: resource.Spec.ExtraPodAnnotations, - } image := resource.Spec.UIImage if resource.Spec.UI.Image != nil { image = *resource.Spec.UI.Image @@ -50,7 +45,7 @@ func NewUI(cfgen *ytconfig.Generator, ytsaurus *apiproxy.Ytsaurus, master Compon } microservice := newMicroservice( - &l, + l, ytsaurus, image, resource.Spec.UI.InstanceCount, @@ -73,11 +68,11 @@ func NewUI(cfgen *ytconfig.Generator, ytsaurus *apiproxy.Ytsaurus, master Compon microservice.getHttpService().SetHttpNodePort(resource.Spec.UI.HttpNodePort) return &UI{ - localComponent: newLocalComponent(&l, ytsaurus), + localComponent: newLocalComponent(l, ytsaurus), cfgen: cfgen, microservice: microservice, initJob: NewInitJob( - &l, + l, ytsaurus.APIProxy(), ytsaurus, resource.Spec.ImagePullSecrets, @@ -90,7 +85,7 @@ func NewUI(cfgen *ytconfig.Generator, ytsaurus *apiproxy.Ytsaurus, master Compon ), secret: resources.NewStringSecret( l.GetSecretName(), - &l, + l, ytsaurus.APIProxy()), caBundle: caBundle, master: master, @@ -101,8 +96,6 @@ func (u *UI) IsUpdatable() bool { return true } -func (u *UI) GetType() consts.ComponentType { return consts.UIType } - func (u *UI) Fetch(ctx context.Context) error { return resources.Fetch(ctx, u.microservice, diff --git a/pkg/components/yql_agent.go b/pkg/components/yql_agent.go index cef94751..784d5fcf 100644 --- a/pkg/components/yql_agent.go +++ b/pkg/components/yql_agent.go @@ -13,7 +13,6 @@ import ( "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" ) @@ -27,26 +26,19 @@ type YqlAgent struct { } func NewYQLAgent(cfgen *ytconfig.Generator, ytsaurus *apiproxy.Ytsaurus, master Component) *YqlAgent { - resource := ytsaurus.GetResource() - l := labeller.Labeller{ - ObjectMeta: &resource.ObjectMeta, - APIProxy: ytsaurus.APIProxy(), - ComponentType: consts.YqlAgentType, - Annotations: resource.Spec.ExtraPodAnnotations, - } + l := cfgen.GetComponentLabeller(consts.YqlAgentType, "") + resource := ytsaurus.GetResource() if resource.Spec.YQLAgents.InstanceSpec.MonitoringPort == nil { resource.Spec.YQLAgents.InstanceSpec.MonitoringPort = ptr.To(int32(consts.YQLAgentMonitoringPort)) } srv := newServer( - &l, + l, ytsaurus, &resource.Spec.YQLAgents.InstanceSpec, "/usr/bin/ytserver-yql-agent", "ytserver-yql-agent.yson", - cfgen.GetYQLAgentStatefulSetName(), - cfgen.GetYQLAgentServiceName(), func() ([]byte, error) { return cfgen.GetYQLAgentConfig(resource.Spec.YQLAgents) }, @@ -58,11 +50,11 @@ func NewYQLAgent(cfgen *ytconfig.Generator, ytsaurus *apiproxy.Ytsaurus, master ) return &YqlAgent{ - localServerComponent: newLocalServerComponent(&l, ytsaurus, srv), + localServerComponent: newLocalServerComponent(l, ytsaurus, srv), cfgen: cfgen, master: master, initEnvironment: NewInitJob( - &l, + l, ytsaurus.APIProxy(), ytsaurus, resource.Spec.ImagePullSecrets, @@ -75,7 +67,7 @@ func NewYQLAgent(cfgen *ytconfig.Generator, ytsaurus *apiproxy.Ytsaurus, master ), secret: resources.NewStringSecret( l.GetSecretName(), - &l, + l, ytsaurus.APIProxy()), } } @@ -84,8 +76,6 @@ func (yqla *YqlAgent) IsUpdatable() bool { return true } -func (yqla *YqlAgent) GetType() consts.ComponentType { return consts.YqlAgentType } - func (yqla *YqlAgent) GetName() string { return yqla.labeller.GetFullComponentName() } diff --git a/pkg/components/ytsaurus_client.go b/pkg/components/ytsaurus_client.go index 2fe5c984..a0095623 100644 --- a/pkg/components/ytsaurus_client.go +++ b/pkg/components/ytsaurus_client.go @@ -17,7 +17,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" ) @@ -43,20 +42,14 @@ func NewYtsaurusClient( ytsaurus *apiproxy.Ytsaurus, httpProxy Component, ) *YtsaurusClient { + l := cfgen.GetComponentLabeller(consts.YtsaurusClientType, "") resource := ytsaurus.GetResource() - l := labeller.Labeller{ - ObjectMeta: &resource.ObjectMeta, - APIProxy: ytsaurus.APIProxy(), - ComponentType: consts.YtsaurusClientType, - Annotations: resource.Spec.ExtraPodAnnotations, - } - return &YtsaurusClient{ - localComponent: newLocalComponent(&l, ytsaurus), + localComponent: newLocalComponent(l, ytsaurus), cfgen: cfgen, httpProxy: httpProxy, initUserJob: NewInitJob( - &l, + l, ytsaurus.APIProxy(), ytsaurus, ytsaurus.GetResource().Spec.ImagePullSecrets, @@ -69,7 +62,7 @@ func NewYtsaurusClient( ), secret: resources.NewStringSecret( l.GetSecretName(), - &l, + l, ytsaurus.APIProxy()), } } @@ -78,8 +71,6 @@ func (yc *YtsaurusClient) IsUpdatable() bool { return false } -func (yc *YtsaurusClient) GetType() consts.ComponentType { return consts.YtsaurusClientType } - func (yc *YtsaurusClient) Fetch(ctx context.Context) error { return resources.Fetch(ctx, yc.secret, diff --git a/pkg/consts/labels.go b/pkg/consts/labels.go index 578eb439..cfb57fda 100644 --- a/pkg/consts/labels.go +++ b/pkg/consts/labels.go @@ -54,10 +54,3 @@ func ComponentLabel(component ComponentType) string { panic(fmt.Sprintf("Unknown component type: %s", component)) } - -func FormatComponentStringWithDefault(base string, name string) string { - if name != DefaultName { - return fmt.Sprintf("%s-%s", base, name) - } - return base -} diff --git a/pkg/consts/names.go b/pkg/consts/names.go new file mode 100644 index 00000000..4025582b --- /dev/null +++ b/pkg/consts/names.go @@ -0,0 +1,77 @@ +package consts + +import ( + "fmt" +) + +func ComponentServicePrefix(component ComponentType) string { + switch component { + case ControllerAgentType: + return "controller-agents" + case DataNodeType: + return "data-nodes" + case DiscoveryType: + return "discovery" + case ExecNodeType: + return "exec-nodes" + case HttpProxyType: + return "http-proxies" + case MasterCacheType: + return "master-caches" + case MasterType: + return "masters" + case QueryTrackerType: + return "query-trackers" + case QueueAgentType: + return "queue-agents" + case RpcProxyType: + return "rpc-proxies" + case SchedulerType: + return "schedulers" + case StrawberryControllerType: + return "strawberry" + case TabletNodeType: + return "tablet-nodes" + case TcpProxyType: + return "tcp-proxies" + case YqlAgentType: + return "yql-agents" + } + + panic(fmt.Sprintf("No service is defined for component type: %s", component)) +} + +func ComponentStatefulSetPrefix(component ComponentType) string { + switch component { + case ControllerAgentType: + return "ca" + case DataNodeType: + return "dnd" + case DiscoveryType: + return "ds" + case ExecNodeType: + return "end" + case HttpProxyType: + return "hp" + case MasterCacheType: + return "msc" + case MasterType: + return "ms" + case QueryTrackerType: + return "qt" + case QueueAgentType: + return "qa" + case RpcProxyType: + return "rp" + case SchedulerType: + return "sch" + case TabletNodeType: + return "tnd" + case TcpProxyType: + return "tp" + case YqlAgentType: + return "yqla" + } + + panic(fmt.Sprintf("No stateful set is defined for component type: %s", component)) +} diff --git a/pkg/labeller/labeller.go b/pkg/labeller/labeller.go index 39bc74ab..ba756a56 100644 --- a/pkg/labeller/labeller.go +++ b/pkg/labeller/labeller.go @@ -4,43 +4,120 @@ import ( "fmt" "strings" - "github.com/ytsaurus/ytsaurus-k8s-operator/pkg/apiproxy" - "github.com/ytsaurus/ytsaurus-k8s-operator/pkg/consts" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "sigs.k8s.io/controller-runtime/pkg/client" -) -type FetchableObject struct { - Name string - Object client.Object -} + "github.com/ytsaurus/ytsaurus-k8s-operator/pkg/consts" +) +// Labeller defines component names, labels and addresses. type Labeller struct { - APIProxy apiproxy.APIProxy - ObjectMeta *metav1.ObjectMeta + Namespace string + + // Name of YTsaurus cluster. + ClusterName string + + // Name of resource which defines this component. + ResourceName string + ComponentType consts.ComponentType + // An optional name identifying a group of instances of the type above. // Role for proxies, instance group name for nodes, may be empty. - ComponentNamePart string - Annotations map[string]string + InstanceGroup string + + // K8s cluster domain, usually "cluster.local". + ClusterDomain string + + Annotations map[string]string + + // Do not include resource name into component name. + UseShortNames bool +} + +func (l *Labeller) ForComponent(component consts.ComponentType, instanceGroup string) *Labeller { + cl := *l + cl.ComponentType = component + cl.InstanceGroup = instanceGroup + return &cl +} + +func (l *Labeller) GetNamespace() string { + return l.Namespace } func (l *Labeller) GetClusterName() string { - return l.ObjectMeta.Name + return l.ClusterName } -// GetComponentName Returns CamelCase component type without name part. -func (l *Labeller) GetComponentName() string { - return string(l.ComponentType) +func (l *Labeller) GetClusterDomain() string { + return l.ClusterDomain } -// GetFullComponentName Returns CamelCase component type with name part. -func (l *Labeller) GetFullComponentName() string { - if l.ComponentNamePart != "" { - return consts.FormatComponentStringWithDefault(l.GetComponentName(), l.ComponentNamePart) +// getGroupName converts into [-group] +func (l *Labeller) getGroupName(name string) string { + if l.InstanceGroup != "" && l.InstanceGroup != consts.DefaultName { + name += "-" + l.InstanceGroup } + return name +} - return l.GetComponentName() +// getName converts into [-group][-infix][-resource] +func (l *Labeller) getName(name, infix string) string { + name = l.getGroupName(name) + if infix != "" { + name += "-" + infix + } + if !l.UseShortNames { + // NOTE: It would be better add resource as prefix rather than as suffix ¯\_(ツ)_/¯. + name += "-" + l.ResourceName + } + return name +} + +// GetFullComponentName Returns CamelCase component type with instance group. +func (l *Labeller) GetFullComponentName() string { + // NOTE: Group name is not CamelCase. + return l.getGroupName(string(l.ComponentType)) +} + +func (l *Labeller) GetServerStatfulSetName() string { + return l.getName(consts.ComponentStatefulSetPrefix(l.ComponentType), "") +} + +func (l *Labeller) GetHeadlessServiceName() string { + return l.getName(consts.ComponentServicePrefix(l.ComponentType), "") +} + +func (l *Labeller) GetBalancerServiceName() string { + // NOTE: For non-short names "-lb-" is inside ¯\_(ツ)_/¯. + return l.getName(consts.ComponentServicePrefix(l.ComponentType), "lb") +} + +func (l *Labeller) GetHeadlessServiceAddress() string { + return fmt.Sprintf("%s.%s.svc.%s", + l.GetHeadlessServiceName(), + l.GetNamespace(), + l.ClusterDomain) +} + +func (l *Labeller) GetBalancerServiceAddress() string { + return fmt.Sprintf("%s.%s.svc.%s", + l.GetBalancerServiceName(), + l.GetNamespace(), + l.ClusterDomain) +} + +func (l *Labeller) GetInstanceAddressPort(index, port int) string { + // NOTE: https://kubernetes.io/docs/concepts/services-networking/dns-pod-service/ + return fmt.Sprintf("%s-%d.%s.%s.svc.%s:%d", + l.GetServerStatfulSetName(), + index, + l.GetHeadlessServiceName(), + l.GetNamespace(), + l.ClusterDomain, + port) } // GetComponentLabel Returns lower case hyphenated component type without name part. @@ -50,11 +127,8 @@ func (l *Labeller) GetComponentLabel() string { // GetFullComponentLabel Returns lower case hyphenated component type with name part. func (l *Labeller) GetFullComponentLabel() string { - if l.ComponentNamePart != "" { - return consts.FormatComponentStringWithDefault(l.GetComponentLabel(), l.ComponentNamePart) - } - - return l.GetComponentLabel() + // NOTE: Resulting name does not include resource name, not so full ¯\_(ツ)_/¯. + return l.getGroupName(l.GetComponentLabel()) } func (l *Labeller) GetSecretName() string { @@ -77,10 +151,14 @@ func (l *Labeller) GetPodsRemovingStartedCondition() string { return fmt.Sprintf("%sPodsRemovingStarted", l.GetFullComponentName()) } +func (l *Labeller) GetPodsRemovedCondition() string { + return fmt.Sprintf("%sPodsRemoved", l.GetFullComponentName()) +} + func (l *Labeller) GetObjectMeta(name string) metav1.ObjectMeta { return metav1.ObjectMeta{ Name: name, - Namespace: l.ObjectMeta.Namespace, + Namespace: l.GetNamespace(), Labels: l.GetMetaLabelMap(false), Annotations: l.Annotations, } @@ -89,14 +167,15 @@ func (l *Labeller) GetObjectMeta(name string) metav1.ObjectMeta { func (l *Labeller) GetInitJobObjectMeta() metav1.ObjectMeta { return metav1.ObjectMeta{ Name: "ytsaurus-init", - Namespace: l.ObjectMeta.Namespace, + Namespace: l.GetNamespace(), Labels: l.GetMetaLabelMap(true), Annotations: l.Annotations, } } func (l *Labeller) GetInstanceLabelValue(isInitJob bool) string { - result := fmt.Sprintf("%s-%s", l.GetClusterName(), l.GetFullComponentLabel()) + // NOTE: Prefix is not cluster name as it was documented before ¯\_(ツ)_/¯. + result := fmt.Sprintf("%s-%s", l.ResourceName, l.GetFullComponentLabel()) if isInitJob { result = fmt.Sprintf("%s-%s", result, "init-job") } @@ -123,7 +202,7 @@ func (l *Labeller) GetSelectorLabelMap() map[string]string { func (l *Labeller) GetListOptions() []client.ListOption { return []client.ListOption{ - client.InNamespace(l.ObjectMeta.Namespace), + client.InNamespace(l.GetNamespace()), client.MatchingLabels(l.GetSelectorLabelMap()), } } @@ -145,10 +224,12 @@ func (l *Labeller) GetMetaLabelMap(isInitJob bool) map[string]string { "app.kubernetes.io/managed-by": "ytsaurus-k8s-operator", // It is nice to have the cluster name as a label. // Template: . + // NOTE: Previously this was "" by mistake ¯\_(ツ)_/¯. consts.YTClusterLabelName: l.GetClusterName(), // This label is used to check pods for readiness during updates. // The name isn't quite right, but we keep it for backwards compatibility. - // Template: -yt--[-init-job]. + // Template: -yt--[-init-job]. + // NOTE: Prefix is not cluster name as it was documented before ¯\_(ツ)_/¯. consts.YTComponentLabelName: l.GetInstanceLabelValue(isInitJob), } } @@ -160,7 +241,3 @@ func (l *Labeller) GetMonitoringMetaLabelMap() map[string]string { return labels } - -func GetPodsRemovedCondition(componentName string) string { - return fmt.Sprintf("%sPodsRemoved", componentName) -} diff --git a/pkg/resources/monitoring_service.go b/pkg/resources/monitoring_service.go index 27909419..4c20cc16 100644 --- a/pkg/resources/monitoring_service.go +++ b/pkg/resources/monitoring_service.go @@ -52,7 +52,7 @@ func (s *MonitoringService) Sync(ctx context.Context) error { func (s *MonitoringService) GetServiceMeta(name string) metav1.ObjectMeta { return metav1.ObjectMeta{ Name: name, - Namespace: s.labeller.ObjectMeta.Namespace, + Namespace: s.labeller.GetNamespace(), Labels: s.labeller.GetMonitoringMetaLabelMap(), } } diff --git a/pkg/testutil/spec_builders.go b/pkg/testutil/spec_builders.go index a5228306..d29bef38 100644 --- a/pkg/testutil/spec_builders.go +++ b/pkg/testutil/spec_builders.go @@ -15,7 +15,8 @@ import ( ) const ( - YtsaurusName = "test-ytsaurus" + YtsaurusName = "test-ytsaurus" + MasterPodName = "ms-0" // RemoteResourceName is a name for test remote ytsaurus and nodes. // It is short because of error: // `Failed to create pod sandbox: failed to construct FQDN from pod hostname and cluster domain, FQDN diff --git a/pkg/ytconfig/base_generator.go b/pkg/ytconfig/base_generator.go deleted file mode 100644 index fd298634..00000000 --- a/pkg/ytconfig/base_generator.go +++ /dev/null @@ -1,63 +0,0 @@ -package ytconfig - -import ( - "k8s.io/apimachinery/pkg/types" - - ytv1 "github.com/ytsaurus/ytsaurus-k8s-operator/api/v1" -) - -type BaseGenerator struct { - key types.NamespacedName - clusterDomain string - - commonSpec ytv1.CommonSpec - masterConnectionSpec ytv1.MasterConnectionSpec - masterInstanceCount int32 - discoveryInstanceCount int32 - dataNodesInstanceCount int32 - masterCachesSpec *ytv1.MasterCachesSpec -} - -func NewRemoteBaseGenerator( - key types.NamespacedName, - clusterDomain string, - commonSpec ytv1.CommonSpec, - masterConnectionSpec ytv1.MasterConnectionSpec, - masterCachesSpec *ytv1.MasterCachesSpec, -) *BaseGenerator { - return &BaseGenerator{ - key: key, - clusterDomain: clusterDomain, - commonSpec: commonSpec, - masterConnectionSpec: masterConnectionSpec, - masterCachesSpec: masterCachesSpec, - } -} - -func NewLocalBaseGenerator( - ytsaurus *ytv1.Ytsaurus, - clusterDomain string, -) *BaseGenerator { - var dataNodesInstanceCount int32 - for _, dataNodes := range ytsaurus.Spec.DataNodes { - dataNodesInstanceCount += dataNodes.InstanceCount - } - - return &BaseGenerator{ - key: types.NamespacedName{ - Namespace: ytsaurus.Namespace, - Name: ytsaurus.Name, - }, - clusterDomain: clusterDomain, - commonSpec: ytsaurus.Spec.CommonSpec, - masterConnectionSpec: ytsaurus.Spec.PrimaryMasters.MasterConnectionSpec, - masterInstanceCount: ytsaurus.Spec.PrimaryMasters.InstanceCount, - discoveryInstanceCount: ytsaurus.Spec.Discovery.InstanceCount, - masterCachesSpec: ytsaurus.Spec.MasterCaches, - dataNodesInstanceCount: dataNodesInstanceCount, - } -} - -func (g *BaseGenerator) GetMaxReplicationFactor() int32 { - return g.dataNodesInstanceCount -} diff --git a/pkg/ytconfig/generator.go b/pkg/ytconfig/generator.go index db4c7d12..cced030b 100644 --- a/pkg/ytconfig/generator.go +++ b/pkg/ytconfig/generator.go @@ -4,14 +4,16 @@ import ( "fmt" "path" - corev1 "k8s.io/api/core/v1" - "k8s.io/utils/ptr" "go.ytsaurus.tech/yt/go/yson" + corev1 "k8s.io/api/core/v1" + ytv1 "github.com/ytsaurus/ytsaurus-k8s-operator/api/v1" + "github.com/ytsaurus/ytsaurus-k8s-operator/pkg/consts" + "github.com/ytsaurus/ytsaurus-k8s-operator/pkg/labeller" ) type ConfigFormat string @@ -24,6 +26,7 @@ const ( ) type YsonGeneratorFunc func() ([]byte, error) + type GeneratorDescriptor struct { // F must generate config in YSON. F YsonGeneratorFunc @@ -33,49 +36,110 @@ type GeneratorDescriptor struct { Fmt ConfigFormat } +type NodeGenerator struct { + baseLabeller *labeller.Labeller + + commonSpec *ytv1.CommonSpec + masterConnectionSpec *ytv1.MasterConnectionSpec + masterCachesSpec *ytv1.MasterCachesSpec + + masterInstanceCount int32 + discoveryInstanceCount int32 + dataNodesInstanceCount int32 +} + type Generator struct { - BaseGenerator + NodeGenerator + ytsaurus *ytv1.Ytsaurus } -func NewGenerator( - ytsaurus *ytv1.Ytsaurus, - clusterDomain string, -) *Generator { - baseGenerator := NewLocalBaseGenerator(ytsaurus, clusterDomain) +func NewGenerator(ytsaurus *ytv1.Ytsaurus, clusterDomain string) *Generator { return &Generator{ - BaseGenerator: *baseGenerator, + NodeGenerator: *NewLocalNodeGenerator(ytsaurus, ytsaurus.Name, clusterDomain), ytsaurus: ytsaurus, } } -func (g *BaseGenerator) getMasterPodFqdnSuffix() string { - return fmt.Sprintf("%s.%s.svc.%s", - g.GetMastersServiceName(), - g.key.Namespace, - g.clusterDomain) + +func NewLocalNodeGenerator(ytsaurus *ytv1.Ytsaurus, resourceName string, clusterDomain string) *NodeGenerator { + var dataNodesInstanceCount int32 + for _, dataNodes := range ytsaurus.Spec.DataNodes { + dataNodesInstanceCount += dataNodes.InstanceCount + } + + return &NodeGenerator{ + baseLabeller: &labeller.Labeller{ + Namespace: ytsaurus.GetNamespace(), + ClusterName: ytsaurus.GetName(), + ResourceName: resourceName, + ClusterDomain: clusterDomain, + Annotations: ytsaurus.Spec.ExtraPodAnnotations, + UseShortNames: ytsaurus.Spec.UseShortNames, + }, + commonSpec: &ytsaurus.Spec.CommonSpec, + masterConnectionSpec: &ytsaurus.Spec.PrimaryMasters.MasterConnectionSpec, + masterInstanceCount: ytsaurus.Spec.PrimaryMasters.InstanceCount, + discoveryInstanceCount: ytsaurus.Spec.Discovery.InstanceCount, + masterCachesSpec: ytsaurus.Spec.MasterCaches, + dataNodesInstanceCount: dataNodesInstanceCount, + } +} + +func NewRemoteNodeGenerator(ytsaurus *ytv1.RemoteYtsaurus, resourceName string, clusterDomain string, commonSpec *ytv1.CommonSpec) *NodeGenerator { + return &NodeGenerator{ + baseLabeller: &labeller.Labeller{ + Namespace: ytsaurus.GetNamespace(), + ClusterName: ytsaurus.GetName(), + ResourceName: resourceName, + ClusterDomain: clusterDomain, + Annotations: commonSpec.ExtraPodAnnotations, + UseShortNames: commonSpec.UseShortNames, + }, + commonSpec: commonSpec, + masterConnectionSpec: &ytsaurus.Spec.MasterConnectionSpec, + masterCachesSpec: &ytsaurus.Spec.MasterCachesSpec, + } +} + +func (g *NodeGenerator) GetComponentLabeller(component consts.ComponentType, instanceGroup string) *labeller.Labeller { + return g.baseLabeller.ForComponent(component, instanceGroup) } -func (g *BaseGenerator) getMasterAddresses() []string { - hosts := g.masterConnectionSpec.HostAddresses +func (g *NodeGenerator) getComponentAddresses(ct consts.ComponentType, instanceCount int32, port int) []string { + labeller := g.GetComponentLabeller(ct, "") + addresses := make([]string, instanceCount) + for i := range int(instanceCount) { + addresses[i] = labeller.GetInstanceAddressPort(i, port) + } + return addresses +} - if len(hosts) == 0 { - masterPodSuffix := g.getMasterPodFqdnSuffix() - for _, podName := range g.GetMasterPodNames() { - hosts = append(hosts, fmt.Sprintf("%s.%s", - podName, - masterPodSuffix, - )) +func (g *NodeGenerator) getMasterAddresses() []string { + if hosts := g.masterConnectionSpec.HostAddresses; len(hosts) != 0 { + addresses := make([]string, len(hosts)) + for idx, host := range hosts { + addresses[idx] = fmt.Sprintf("%s:%d", host, consts.MasterRPCPort) } + return addresses } + return g.getComponentAddresses(consts.MasterType, g.masterInstanceCount, consts.MasterRPCPort) +} - addresses := make([]string, len(hosts)) - for idx, host := range hosts { - addresses[idx] = fmt.Sprintf("%s:%d", host, consts.MasterRPCPort) +func (g *NodeGenerator) getMasterCachesAddresses() []string { + if g.masterCachesSpec == nil { + return nil } - return addresses + if hosts := g.masterCachesSpec.HostAddresses; len(hosts) != 0 { + addresses := make([]string, len(hosts)) + for idx, host := range hosts { + addresses[idx] = fmt.Sprintf("%s:%d", host, consts.MasterCachesRPCPort) + } + return addresses + } + return g.getComponentAddresses(consts.MasterCacheType, g.masterCachesSpec.InstanceCount, consts.MasterCachesRPCPort) } -func (g *BaseGenerator) getMasterHydraPeers() []HydraPeer { +func (g *NodeGenerator) getMasterHydraPeers() []HydraPeer { peers := make([]HydraPeer, 0, g.masterInstanceCount) for _, address := range g.getMasterAddresses() { peers = append(peers, HydraPeer{ @@ -86,59 +150,51 @@ func (g *BaseGenerator) getMasterHydraPeers() []HydraPeer { return peers } -func (g *BaseGenerator) getDiscoveryAddresses() []string { - names := make([]string, 0, g.discoveryInstanceCount) - for _, podName := range g.GetDiscoveryPodNames() { - names = append(names, fmt.Sprintf("%s.%s.%s.svc.%s:%d", - podName, - g.GetDiscoveryServiceName(), - g.key.Namespace, - g.clusterDomain, - consts.DiscoveryRPCPort)) - } - return names +func (g *NodeGenerator) getDiscoveryAddresses() []string { + return g.getComponentAddresses(consts.DiscoveryType, g.discoveryInstanceCount, consts.DiscoveryRPCPort) +} + +func (g *NodeGenerator) GetMaxReplicationFactor() int32 { + return g.dataNodesInstanceCount +} + +func (g *Generator) GetHTTPProxiesServiceName(role string) string { + return g.GetComponentLabeller(consts.HttpProxyType, role).GetBalancerServiceName() +} + +func (g *Generator) GetHTTPProxiesServiceAddress(role string) string { + return g.GetComponentLabeller(consts.HttpProxyType, role).GetHeadlessServiceAddress() +} + +func (g *NodeGenerator) GetHTTPProxiesAddress(role string) string { + return g.GetComponentLabeller(consts.HttpProxyType, role).GetBalancerServiceAddress() +} + +func (g *Generator) GetRPCProxiesServiceName(role string) string { + return g.GetComponentLabeller(consts.RpcProxyType, role).GetBalancerServiceName() +} + +func (g *Generator) GetTCPProxiesServiceName(role string) string { + return g.GetComponentLabeller(consts.TcpProxyType, role).GetBalancerServiceName() +} + +func (g *NodeGenerator) GetStrawberryControllerServiceAddress() string { + return g.GetComponentLabeller(consts.StrawberryControllerType, "").GetHeadlessServiceAddress() } func (g *Generator) GetYQLAgentAddresses() []string { - names := make([]string, 0, g.ytsaurus.Spec.YQLAgents.InstanceCount) - for _, podName := range g.GetYQLAgentPodNames() { - names = append(names, fmt.Sprintf("%s.%s.%s.svc.%s:%d", - podName, - g.GetYQLAgentServiceName(), - g.ytsaurus.Namespace, - g.clusterDomain, - consts.YQLAgentRPCPort)) - } - return names + return g.getComponentAddresses(consts.YqlAgentType, g.ytsaurus.Spec.YQLAgents.InstanceCount, consts.YQLAgentRPCPort) } func (g *Generator) GetQueryTrackerAddresses() []string { - names := make([]string, 0, g.ytsaurus.Spec.QueryTrackers.InstanceCount) - for _, podName := range g.GetQueryTrackerPodNames() { - names = append(names, fmt.Sprintf("%s.%s.%s.svc.%s:%d", - podName, - g.GetQueryTrackerServiceName(), - g.ytsaurus.Namespace, - g.clusterDomain, - consts.QueryTrackerRPCPort)) - } - return names + return g.getComponentAddresses(consts.QueryTrackerType, g.ytsaurus.Spec.QueryTrackers.InstanceCount, consts.QueryTrackerRPCPort) } func (g *Generator) GetQueueAgentAddresses() []string { - names := make([]string, 0, g.ytsaurus.Spec.QueueAgents.InstanceCount) - for _, podName := range g.GetQueueAgentPodNames() { - names = append(names, fmt.Sprintf("%s.%s.%s.svc.%s:%d", - podName, - g.GetQueueAgentServiceName(), - g.ytsaurus.Namespace, - g.clusterDomain, - consts.QueueAgentRPCPort)) - } - return names + return g.getComponentAddresses(consts.QueueAgentType, g.ytsaurus.Spec.QueueAgents.InstanceCount, consts.QueueAgentRPCPort) } -func (g *BaseGenerator) fillIOEngine(ioEngine **IOEngine) { +func (g *NodeGenerator) fillIOEngine(ioEngine **IOEngine) { if g.commonSpec.EphemeralCluster { if *ioEngine == nil { *ioEngine = &IOEngine{} @@ -147,15 +203,15 @@ func (g *BaseGenerator) fillIOEngine(ioEngine **IOEngine) { } } -func (g *Generator) fillDriver(c *Driver) { +func (g *NodeGenerator) fillDriver(c *Driver) { c.TimestampProviders.Addresses = g.getMasterAddresses() c.PrimaryMaster.Addresses = g.getMasterAddresses() - c.PrimaryMaster.CellID = generateCellID(g.ytsaurus.Spec.PrimaryMasters.CellTag) + c.PrimaryMaster.CellID = generateCellID(g.masterConnectionSpec.CellTag) g.fillPrimaryMaster(&c.PrimaryMaster) } -func (g *BaseGenerator) fillAddressResolver(c *AddressResolver) { +func (g *NodeGenerator) fillAddressResolver(c *AddressResolver) { var retries = 1000 c.EnableIPv4 = g.commonSpec.UseIPv4 c.EnableIPv6 = g.commonSpec.UseIPv6 @@ -169,33 +225,32 @@ func (g *BaseGenerator) fillAddressResolver(c *AddressResolver) { c.Retries = &retries } -func (g *BaseGenerator) fillSolomonExporter(c *SolomonExporter) { +func (g *NodeGenerator) fillSolomonExporter(c *SolomonExporter) { c.Host = ptr.To("{POD_SHORT_HOSTNAME}") c.InstanceTags = map[string]string{ "pod": "{K8S_POD_NAME}", } } -func (g *BaseGenerator) fillPrimaryMaster(c *MasterCell) { +func (g *NodeGenerator) fillPrimaryMaster(c *MasterCell) { c.Addresses = g.getMasterAddresses() c.Peers = g.getMasterHydraPeers() c.CellID = generateCellID(g.masterConnectionSpec.CellTag) } -func (g *BaseGenerator) fillClusterConnection(c *ClusterConnection, s *ytv1.RPCTransportSpec) { +func (g *NodeGenerator) fillClusterConnection(c *ClusterConnection, s *ytv1.RPCTransportSpec) { g.fillPrimaryMaster(&c.PrimaryMaster) - c.ClusterName = g.key.Name + c.ClusterName = g.baseLabeller.GetClusterName() c.DiscoveryConnection.Addresses = g.getDiscoveryAddresses() g.fillClusterConnectionEncryption(c, s) - if len(g.getMasterCachesAddresses()) == 0 { - c.MasterCache.Addresses = g.getMasterAddresses() - } else { - c.MasterCache.Addresses = g.getMasterCachesAddresses() + c.MasterCache.Addresses = g.getMasterCachesAddresses() + if len(c.MasterCache.Addresses) == 0 { + c.MasterCache.Addresses = c.PrimaryMaster.Addresses } c.MasterCache.CellID = generateCellID(g.masterConnectionSpec.CellTag) } -func (g *BaseGenerator) fillCypressAnnotations(c *CommonServer) { +func (g *NodeGenerator) fillCypressAnnotations(c *CommonServer) { c.CypressAnnotations = map[string]any{ "k8s_pod_name": "{K8S_POD_NAME}", "k8s_pod_namespace": "{K8S_POD_NAMESPACE}", @@ -205,7 +260,7 @@ func (g *BaseGenerator) fillCypressAnnotations(c *CommonServer) { } } -func (g *BaseGenerator) fillCommonService(c *CommonServer, s *ytv1.InstanceSpec) { +func (g *NodeGenerator) fillCommonService(c *CommonServer, s *ytv1.InstanceSpec) { // ToDo(psushin): enable porto resource tracker? g.fillAddressResolver(&c.AddressResolver) g.fillSolomonExporter(&c.SolomonExporter) @@ -229,7 +284,7 @@ func (g *Generator) fillBusEncryption(b *Bus, s *ytv1.RPCTransportSpec) { } } -func (g *BaseGenerator) fillBusServer(c *CommonServer, s *ytv1.RPCTransportSpec) { +func (g *NodeGenerator) fillBusServer(c *CommonServer, s *ytv1.RPCTransportSpec) { if s == nil { // Use common bus transport config s = g.commonSpec.NativeTransport @@ -257,7 +312,7 @@ func (g *BaseGenerator) fillBusServer(c *CommonServer, s *ytv1.RPCTransportSpec) } } -func (g *BaseGenerator) fillClusterConnectionEncryption(c *ClusterConnection, s *ytv1.RPCTransportSpec) { +func (g *NodeGenerator) fillClusterConnectionEncryption(c *ClusterConnection, s *ytv1.RPCTransportSpec) { if s == nil { // Use common bus transport config s = g.commonSpec.NativeTransport @@ -372,8 +427,13 @@ func (g *Generator) getMasterConfigImpl(spec *ytv1.MastersSpec) (MasterServer, e // POD_NAME is set to pod name through downward API env var and substituted during // config postprocessing. + l := g.GetComponentLabeller(consts.MasterType, "") c.AddressResolver.LocalhostNameOverride = ptr.To( - fmt.Sprintf("%v.%v", "{K8S_POD_NAME}", g.getMasterPodFqdnSuffix())) + fmt.Sprintf("%s.%s.%s.svc.%s", + "{K8S_POD_NAME}", + l.GetHeadlessServiceName(), + l.GetNamespace(), + l.GetClusterDomain())) } return c, nil @@ -387,7 +447,7 @@ func (g *Generator) GetMasterConfig(spec *ytv1.MastersSpec) ([]byte, error) { return marshallYsonConfig(c) } -func (g *Generator) GetNativeClientConfig() ([]byte, error) { +func (g *NodeGenerator) GetNativeClientConfig() ([]byte, error) { c, err := getNativeClientCarcass() if err != nil { return nil, err @@ -549,7 +609,7 @@ func (g *NodeGenerator) GetDataNodeConfig(spec ytv1.DataNodesSpec) ([]byte, erro } func (g *NodeGenerator) getExecNodeConfigImpl(spec *ytv1.ExecNodesSpec) (ExecNodeServer, error) { - c, err := getExecNodeServerCarcass(spec, &g.commonSpec) + c, err := getExecNodeServerCarcass(spec, g.commonSpec) if err != nil { return c, err } @@ -796,31 +856,3 @@ func (g *Generator) GetMasterCachesConfig(spec *ytv1.MasterCachesSpec) ([]byte, } return marshallYsonConfig(c) } - -func (g *BaseGenerator) getMasterCachesPodFqdnSuffix() string { - return fmt.Sprintf("%s.%s.svc.%s", - g.GetMasterCachesServiceName(), - g.key.Namespace, - g.clusterDomain) -} - -func (g *BaseGenerator) getMasterCachesAddresses() []string { - if g.masterCachesSpec != nil { - hosts := g.masterCachesSpec.HostAddresses - if len(hosts) == 0 { - masterCachesPodSuffix := g.getMasterCachesPodFqdnSuffix() - for _, podName := range g.GetMasterCachesPodNames() { - hosts = append(hosts, fmt.Sprintf("%s.%s", - podName, - masterCachesPodSuffix, - )) - } - } - addresses := make([]string, len(hosts)) - for idx, host := range hosts { - addresses[idx] = fmt.Sprintf("%s:%d", host, consts.MasterCachesRPCPort) - } - return addresses - } - return make([]string, 0) -} diff --git a/pkg/ytconfig/generator_test.go b/pkg/ytconfig/generator_test.go index a9e31d7f..177b725d 100644 --- a/pkg/ytconfig/generator_test.go +++ b/pkg/ytconfig/generator_test.go @@ -5,7 +5,6 @@ import ( "github.com/stretchr/testify/require" "github.com/ytsaurus/ytsaurus-k8s-operator/pkg/consts" - "k8s.io/apimachinery/pkg/types" "k8s.io/utils/ptr" @@ -18,10 +17,10 @@ import ( ) var ( - testClusterDomain = "fake.zone" - testNamespace = "fake" - testYtsaurusName = "test" - testNamespacedName = types.NamespacedName{ + testClusterDomain = "fake.zone" + testNamespace = "fake" + testYtsaurusName = "test" + testObjectMeta = metav1.ObjectMeta{ Namespace: testNamespace, Name: testYtsaurusName, } @@ -148,7 +147,8 @@ func TestGetDataNodeConfig(t *testing.T) { for name, test := range cases { t.Run(name, func(t *testing.T) { - g := NewLocalNodeGenerator(getYtsaurusWithEverything(), testClusterDomain) + ytsaurus := getYtsaurusWithEverything() + g := NewLocalNodeGenerator(ytsaurus, ytsaurus.Name, testClusterDomain) cfg, err := g.GetDataNodeConfig(getDataNodeSpec(test.Location)) require.NoError(t, err) canonize.Assert(t, cfg) @@ -158,11 +158,10 @@ func TestGetDataNodeConfig(t *testing.T) { func TestGetDataNodeWithoutYtsaurusConfig(t *testing.T) { g := NewRemoteNodeGenerator( - testNamespacedName, + getRemoteYtsaurus(), + testYtsaurusName, testClusterDomain, getCommonSpec(), - getMasterConnectionSpecWithFixedMasterHosts(), - getMasterCachesSpecWithFixedHosts(), ) cfg, err := g.GetDataNodeConfig(getDataNodeSpec(testLocationChunkStore)) require.NoError(t, err) @@ -191,7 +190,8 @@ func TestGetExecNodeConfig(t *testing.T) { for name, test := range cases { t.Run(name, func(t *testing.T) { - g := NewLocalNodeGenerator(getYtsaurusWithEverything(), testClusterDomain) + ytsaurus := getYtsaurusWithEverything() + g := NewLocalNodeGenerator(ytsaurus, ytsaurus.Name, testClusterDomain) cfg, err := g.GetExecNodeConfig(getExecNodeSpec(test.JobResources)) require.NoError(t, err) canonize.Assert(t, cfg) @@ -200,7 +200,8 @@ func TestGetExecNodeConfig(t *testing.T) { } func TestGetExecNodeConfigWithCri(t *testing.T) { - g := NewLocalNodeGenerator(getYtsaurusWithEverything(), testClusterDomain) + ytsaurus := getYtsaurusWithEverything() + g := NewLocalNodeGenerator(ytsaurus, ytsaurus.Name, testClusterDomain) cases := map[string]struct { JobResources *corev1.ResourceRequirements @@ -235,7 +236,8 @@ func TestGetExecNodeConfigWithCri(t *testing.T) { } func TestGetContainerdConfig(t *testing.T) { - g := NewLocalNodeGenerator(getYtsaurusWithEverything(), testClusterDomain) + ytsaurus := getYtsaurusWithEverything() + g := NewLocalNodeGenerator(ytsaurus, ytsaurus.Name, testClusterDomain) spec := withCri(getExecNodeSpec(nil), nil, false) cfg, err := g.GetContainerdConfig(&spec) @@ -245,11 +247,10 @@ func TestGetContainerdConfig(t *testing.T) { func TestGetExecNodeWithoutYtsaurusConfig(t *testing.T) { g := NewRemoteNodeGenerator( - testNamespacedName, + getRemoteYtsaurus(), + testYtsaurusName, testClusterDomain, getCommonSpec(), - getMasterConnectionSpecWithFixedMasterHosts(), - getMasterCachesSpecWithFixedHosts(), ) cfg, err := g.GetExecNodeConfig(getExecNodeSpec(nil)) require.NoError(t, err) @@ -364,7 +365,8 @@ func TestGetStrawberryControllerConfigWithCustomFamilies(t *testing.T) { } func TestGetTabletNodeConfig(t *testing.T) { - g := NewLocalNodeGenerator(getYtsaurusWithEverything(), testClusterDomain) + ytsaurus := getYtsaurusWithEverything() + g := NewLocalNodeGenerator(ytsaurus, ytsaurus.Name, testClusterDomain) cfg, err := g.GetTabletNodeConfig(getTabletNodeSpec()) require.NoError(t, err) canonize.Assert(t, cfg) @@ -372,11 +374,10 @@ func TestGetTabletNodeConfig(t *testing.T) { func TestGetTabletNodeWithoutYtsaurusConfig(t *testing.T) { g := NewRemoteNodeGenerator( - testNamespacedName, + getRemoteYtsaurus(), + testYtsaurusName, testClusterDomain, getCommonSpec(), - getMasterConnectionSpecWithFixedMasterHosts(), - getMasterCachesSpecWithFixedHosts(), ) cfg, err := g.GetTabletNodeConfig(getTabletNodeSpec()) require.NoError(t, err) @@ -454,12 +455,9 @@ func TestGetMasterCachesConfig(t *testing.T) { func getYtsaurus() *ytv1.Ytsaurus { return &ytv1.Ytsaurus{ - ObjectMeta: metav1.ObjectMeta{ - Namespace: testNamespace, - Name: testYtsaurusName, - }, + ObjectMeta: testObjectMeta, Spec: ytv1.YtsaurusSpec{ - CommonSpec: getCommonSpec(), + CommonSpec: *getCommonSpec(), PrimaryMasters: ytv1.MastersSpec{ MasterConnectionSpec: getMasterConnectionSpec(), @@ -550,6 +548,16 @@ func getYtsaurus() *ytv1.Ytsaurus { } } +func getRemoteYtsaurus() *ytv1.RemoteYtsaurus { + return &ytv1.RemoteYtsaurus{ + ObjectMeta: testObjectMeta, + Spec: ytv1.RemoteYtsaurusSpec{ + MasterConnectionSpec: getMasterConnectionSpecWithFixedMasterHosts(), + MasterCachesSpec: getMasterCachesSpecWithFixedHosts(), + }, + } +} + func getYtsaurusWithEverything() *ytv1.Ytsaurus { ytsaurus := getYtsaurus() ytsaurus = withControllerAgents(ytsaurus) @@ -821,8 +829,8 @@ func getTCPProxySpec() ytv1.TCPProxiesSpec { } } -func getCommonSpec() ytv1.CommonSpec { - return ytv1.CommonSpec{ +func getCommonSpec() *ytv1.CommonSpec { + return &ytv1.CommonSpec{ UseIPv6: true, } } @@ -850,8 +858,8 @@ func getMasterCachesSpec() ytv1.MasterCachesSpec { } } -func getMasterCachesSpecWithFixedHosts() *ytv1.MasterCachesSpec { +func getMasterCachesSpecWithFixedHosts() ytv1.MasterCachesSpec { spec := getMasterCachesSpec() spec.MasterCachesConnectionSpec.HostAddresses = testMasterCachesExternalHosts - return &spec + return spec } diff --git a/pkg/ytconfig/names.go b/pkg/ytconfig/names.go deleted file mode 100644 index c6a000e1..00000000 --- a/pkg/ytconfig/names.go +++ /dev/null @@ -1,210 +0,0 @@ -package ytconfig - -import ( - "fmt" - - "github.com/ytsaurus/ytsaurus-k8s-operator/pkg/consts" -) - -func (g *BaseGenerator) getName(shortName string) string { - if g.commonSpec.UseShortNames { - return shortName - } else { - return fmt.Sprintf("%s-%s", shortName, g.key.Name) - } -} - -func (g *BaseGenerator) GetMastersStatefulSetName() string { - return g.getName("ms") -} - -func (g *BaseGenerator) GetDiscoveryStatefulSetName() string { - return g.getName("ds") -} - -func (g *Generator) GetYQLAgentStatefulSetName() string { - return g.getName("yqla") -} - -func (g *BaseGenerator) GetMastersServiceName() string { - return g.getName("masters") -} - -func (g *BaseGenerator) GetDiscoveryServiceName() string { - return g.getName("discovery") -} - -func (g *Generator) GetYQLAgentServiceName() string { - return g.getName("yql-agents") -} - -func (g *BaseGenerator) GetMasterPodNames() []string { - podNames := make([]string, 0, g.masterInstanceCount) - for i := 0; i < int(g.masterInstanceCount); i++ { - podNames = append(podNames, fmt.Sprintf("%s-%d", g.GetMastersStatefulSetName(), i)) - } - - return podNames -} - -func (g *BaseGenerator) GetDiscoveryPodNames() []string { - podNames := make([]string, 0, g.discoveryInstanceCount) - for i := 0; i < int(g.discoveryInstanceCount); i++ { - podNames = append(podNames, fmt.Sprintf("%s-%d", g.GetDiscoveryStatefulSetName(), i)) - } - - return podNames -} - -func (g *Generator) GetQueryTrackerPodNames() []string { - podNames := make([]string, 0, g.ytsaurus.Spec.QueryTrackers.InstanceSpec.InstanceCount) - for i := 0; i < int(g.ytsaurus.Spec.QueryTrackers.InstanceSpec.InstanceCount); i++ { - podNames = append(podNames, fmt.Sprintf("%s-%d", g.GetQueryTrackerStatefulSetName(), i)) - } - - return podNames -} - -func (g *Generator) GetYQLAgentPodNames() []string { - podNames := make([]string, 0, g.ytsaurus.Spec.YQLAgents.InstanceSpec.InstanceCount) - for i := 0; i < int(g.ytsaurus.Spec.YQLAgents.InstanceSpec.InstanceCount); i++ { - podNames = append(podNames, fmt.Sprintf("%s-%d", g.GetYQLAgentStatefulSetName(), i)) - } - - return podNames -} - -func (g *Generator) GetQueueAgentPodNames() []string { - podNames := make([]string, 0, g.ytsaurus.Spec.QueueAgents.InstanceSpec.InstanceCount) - for i := 0; i < int(g.ytsaurus.Spec.QueueAgents.InstanceSpec.InstanceCount); i++ { - podNames = append(podNames, fmt.Sprintf("%s-%d", g.GetQueueAgentStatefulSetName(), i)) - } - - return podNames -} - -func (g *Generator) GetHTTPProxiesServiceAddress(role string) string { - return fmt.Sprintf("%s.%s.svc.%s", - g.GetHTTPProxiesHeadlessServiceName(role), - g.ytsaurus.Namespace, - g.clusterDomain) -} - -func (g *Generator) GetStrawberryControllerServiceAddress() string { - return fmt.Sprintf("%s.%s.svc.%s", - g.GetStrawberryControllerHeadlessServiceName(), - g.ytsaurus.Namespace, - g.clusterDomain) -} - -func (g *Generator) GetStrawberryControllerHeadlessServiceName() string { - return g.getName("strawberry") -} - -func (g *Generator) GetHTTPProxiesServiceName(role string) string { - return g.getName(fmt.Sprintf("%s-lb", consts.FormatComponentStringWithDefault("http-proxies", role))) -} - -func (g *Generator) GetHTTPProxiesHeadlessServiceName(role string) string { - return g.getName(consts.FormatComponentStringWithDefault("http-proxies", role)) -} - -func (g *Generator) GetHTTPProxiesStatefulSetName(role string) string { - return g.getName(consts.FormatComponentStringWithDefault("hp", role)) -} - -func (g *Generator) GetHTTPProxiesAddress(role string) string { - return fmt.Sprintf("%s.%s.svc.%s", - g.GetHTTPProxiesServiceName(role), - g.ytsaurus.Namespace, - g.clusterDomain) -} - -func (g *Generator) GetSchedulerStatefulSetName() string { - return g.getName("sch") -} - -func (g *Generator) GetSchedulerServiceName() string { - return g.getName("schedulers") -} - -func (g *Generator) GetRPCProxiesStatefulSetName(role string) string { - return g.getName(consts.FormatComponentStringWithDefault("rp", role)) -} - -func (g *Generator) GetRPCProxiesServiceName(role string) string { - return g.getName(fmt.Sprintf("%s-lb", consts.FormatComponentStringWithDefault("rpc-proxies", role))) -} - -func (g *Generator) GetRPCProxiesHeadlessServiceName(role string) string { - return g.getName(consts.FormatComponentStringWithDefault("rpc-proxies", role)) -} - -func (g *Generator) GetTCPProxiesStatefulSetName(role string) string { - return g.getName(consts.FormatComponentStringWithDefault("tp", role)) -} - -func (g *Generator) GetTCPProxiesServiceName(role string) string { - return g.getName(fmt.Sprintf("%s-lb", consts.FormatComponentStringWithDefault("tcp-proxies", role))) -} - -func (g *Generator) GetTCPProxiesHeadlessServiceName(role string) string { - return g.getName(consts.FormatComponentStringWithDefault("tcp-proxies", role)) -} - -func (g *Generator) GetQueryTrackerStatefulSetName() string { - return g.getName("qt") -} - -func (g *Generator) GetQueryTrackerServiceName() string { - return g.getName("query-trackers") -} - -func (g *Generator) GetQueueAgentStatefulSetName() string { - return g.getName("qa") -} - -func (g *Generator) GetQueueAgentServiceName() string { - return g.getName("queue-agents") -} - -func (g *NodeGenerator) GetDataNodesStatefulSetName(name string) string { - return g.getName(consts.FormatComponentStringWithDefault("dnd", name)) -} - -func (g *NodeGenerator) GetDataNodesServiceName(name string) string { - return g.getName(consts.FormatComponentStringWithDefault("data-nodes", name)) -} - -func (g *NodeGenerator) GetExecNodesStatefulSetName(name string) string { - return g.getName(consts.FormatComponentStringWithDefault("end", name)) -} - -func (g *NodeGenerator) GetExecNodesServiceName(name string) string { - return g.getName(consts.FormatComponentStringWithDefault("exec-nodes", name)) -} - -func (g *NodeGenerator) GetTabletNodesStatefulSetName(name string) string { - return g.getName(consts.FormatComponentStringWithDefault("tnd", name)) -} - -func (g *NodeGenerator) GetTabletNodesServiceName(name string) string { - return g.getName(consts.FormatComponentStringWithDefault("tablet-nodes", name)) -} - -func (g *BaseGenerator) GetMasterCachesStatefulSetName() string { - return g.getName("msc") -} - -func (g *BaseGenerator) GetMasterCachesServiceName() string { - return g.getName("master-caches") -} - -func (g *BaseGenerator) GetMasterCachesPodNames() []string { - podNames := make([]string, 0, g.masterCachesSpec.InstanceSpec.InstanceCount) - for i := 0; i < int(g.masterCachesSpec.InstanceSpec.InstanceCount); i++ { - podNames = append(podNames, fmt.Sprintf("%s-%d", g.GetMasterCachesStatefulSetName(), i)) - } - - return podNames -} diff --git a/pkg/ytconfig/node_generator.go b/pkg/ytconfig/node_generator.go deleted file mode 100644 index a796695f..00000000 --- a/pkg/ytconfig/node_generator.go +++ /dev/null @@ -1,40 +0,0 @@ -package ytconfig - -import ( - "k8s.io/apimachinery/pkg/types" - - ytv1 "github.com/ytsaurus/ytsaurus-k8s-operator/api/v1" -) - -type NodeGenerator struct { - BaseGenerator -} - -func NewRemoteNodeGenerator( - key types.NamespacedName, - clusterDomain string, - commonSpec ytv1.CommonSpec, - masterConnectionSpec ytv1.MasterConnectionSpec, - masterCachesSpec *ytv1.MasterCachesSpec, -) *NodeGenerator { - baseGenerator := NewRemoteBaseGenerator( - key, - clusterDomain, - commonSpec, - masterConnectionSpec, - masterCachesSpec, - ) - return &NodeGenerator{ - BaseGenerator: *baseGenerator, - } -} - -func NewLocalNodeGenerator( - ytsaurus *ytv1.Ytsaurus, - clusterDomain string, -) *NodeGenerator { - baseGenerator := NewLocalBaseGenerator(ytsaurus, clusterDomain) - return &NodeGenerator{ - BaseGenerator: *baseGenerator, - } -} diff --git a/test/e2e/ytsaurus_controller_test.go b/test/e2e/ytsaurus_controller_test.go index 75346526..352bf76e 100644 --- a/test/e2e/ytsaurus_controller_test.go +++ b/test/e2e/ytsaurus_controller_test.go @@ -468,7 +468,7 @@ var _ = Describe("Basic e2e test for Ytsaurus controller", Label("e2e"), func() It("Master shouldn't be recreated before WaitingForPodsCreation state if config changes", func(ctx context.Context) { By("Store master pod creation time") - msPod := getMasterPod(g.GetMasterPodNames()[0], namespace) + msPod := getMasterPod(testutil.MasterPodName, namespace) msPodCreationFirstTimestamp := msPod.CreationTimestamp By("Setting artificial conditions for deploy to stuck in PossibilityCheck") @@ -497,7 +497,7 @@ var _ = Describe("Basic e2e test for Ytsaurus controller", Label("e2e"), func() By("Check that master pod was NOT recreated at the PossibilityCheck stage") time.Sleep(1 * time.Second) - msPod = getMasterPod(g.GetMasterPodNames()[0], namespace) + msPod = getMasterPod(testutil.MasterPodName, namespace) msPodCreationSecondTimestamp := msPod.CreationTimestamp log.Info("ms pods ts", "first", msPodCreationFirstTimestamp, "second", msPodCreationSecondTimestamp) Expect(msPodCreationFirstTimestamp.Equal(&msPodCreationSecondTimestamp)).Should(BeTrue()) @@ -954,7 +954,7 @@ var _ = Describe("Basic e2e test for Ytsaurus controller", Label("e2e"), func() monitoringPort := 0 Expect(ytClient.GetNode(ctx, ypath.Path(fmt.Sprintf("//sys/primary_masters/%v/orchid/config/monitoring_port", masterAddress)), &monitoringPort, nil)).Should(Succeed()) - msPod := getMasterPod(g.GetMasterPodNames()[0], namespace) + msPod := getMasterPod(testutil.MasterPodName, namespace) log.Info("Pod", "ip", msPod.Status.PodIP) rsp, err := http.Get(fmt.Sprintf( diff --git a/ytop-chart/templates/crds/remotedatanodes.cluster.ytsaurus.tech.yaml b/ytop-chart/templates/crds/remotedatanodes.cluster.ytsaurus.tech.yaml index 0b84548e..4d83098d 100644 --- a/ytop-chart/templates/crds/remotedatanodes.cluster.ytsaurus.tech.yaml +++ b/ytop-chart/templates/crds/remotedatanodes.cluster.ytsaurus.tech.yaml @@ -1079,6 +1079,8 @@ spec: type: boolean useShortNames: default: true + description: Do not add resource name into names of resources under + control. type: boolean volumeClaimTemplates: items: diff --git a/ytop-chart/templates/crds/remoteexecnodes.cluster.ytsaurus.tech.yaml b/ytop-chart/templates/crds/remoteexecnodes.cluster.ytsaurus.tech.yaml index 9ed0c401..5f642dfe 100644 --- a/ytop-chart/templates/crds/remoteexecnodes.cluster.ytsaurus.tech.yaml +++ b/ytop-chart/templates/crds/remoteexecnodes.cluster.ytsaurus.tech.yaml @@ -1272,6 +1272,8 @@ spec: type: boolean useShortNames: default: true + description: Do not add resource name into names of resources under + control. type: boolean volumeClaimTemplates: items: diff --git a/ytop-chart/templates/crds/remotetabletnodes.cluster.ytsaurus.tech.yaml b/ytop-chart/templates/crds/remotetabletnodes.cluster.ytsaurus.tech.yaml index 7a3531cb..e1efccf7 100644 --- a/ytop-chart/templates/crds/remotetabletnodes.cluster.ytsaurus.tech.yaml +++ b/ytop-chart/templates/crds/remotetabletnodes.cluster.ytsaurus.tech.yaml @@ -1079,6 +1079,8 @@ spec: type: boolean useShortNames: default: true + description: Do not add resource name into names of resources under + control. type: boolean volumeClaimTemplates: items: diff --git a/ytop-chart/templates/crds/ytsaurus.cluster.ytsaurus.tech.yaml b/ytop-chart/templates/crds/ytsaurus.cluster.ytsaurus.tech.yaml index aa0f3110..86ef9fd4 100644 --- a/ytop-chart/templates/crds/ytsaurus.cluster.ytsaurus.tech.yaml +++ b/ytop-chart/templates/crds/ytsaurus.cluster.ytsaurus.tech.yaml @@ -34678,6 +34678,8 @@ spec: type: boolean useShortNames: default: true + description: Do not add resource name into names of resources under + control. type: boolean yqlAgents: properties: