From ae1d2c9797c9681994e0d2b377385f8c18eb24f4 Mon Sep 17 00:00:00 2001 From: Andrey Chulkov Date: Tue, 3 Sep 2024 17:32:42 +0200 Subject: [PATCH] refactor based on comments --- api/v1/ytsaurus_types.go | 11 ++- api/v1/zz_generated.deepcopy.go | 5 -- .../bases/cluster.ytsaurus.tech_ytsaurus.yaml | 77 ------------------ controllers/component_manager.go | 2 +- controllers/remoteexecnodes_test.go | 2 +- docs/api.md | 1 - pkg/components/chyt.go | 11 ++- pkg/components/component.go | 4 +- pkg/components/controller_agent.go | 7 +- pkg/components/data_node.go | 9 +-- pkg/components/discovery.go | 7 +- pkg/components/exec_node.go | 9 +-- pkg/components/exec_node_remote.go | 9 +-- pkg/components/httpproxy.go | 9 +-- pkg/components/init_job.go | 6 +- pkg/components/init_job_test.go | 3 +- pkg/components/master.go | 9 +-- pkg/components/master_caches.go | 9 +-- pkg/components/query_tracker.go | 9 +-- pkg/components/queue_agent.go | 9 +-- pkg/components/rpcproxy.go | 9 +-- pkg/components/scheduler.go | 9 +-- pkg/components/spyt.go | 11 ++- pkg/components/strawberry_controller.go | 41 +++------- pkg/components/tablet_node.go | 9 +-- pkg/components/tcpproxy.go | 9 +-- pkg/components/ui.go | 9 +-- pkg/components/yql_agent.go | 11 ++- pkg/components/ytsaurus_client.go | 9 +-- pkg/consts/labels.go | 80 +++++++++++++------ pkg/labeller/labeller.go | 60 +++++++++----- pkg/resources/monitoring_service.go | 2 +- pkg/resources/statefulset.go | 6 +- pkg/testutil/spec_builders.go | 18 +++-- pkg/ytconfig/names.go | 37 ++++----- test/e2e/helpers_test.go | 8 +- test/e2e/ytsaurus_controller_test.go | 71 +++++++++++++++- 37 files changed, 305 insertions(+), 302 deletions(-) diff --git a/api/v1/ytsaurus_types.go b/api/v1/ytsaurus_types.go index 402bdaac..ef61aa64 100644 --- a/api/v1/ytsaurus_types.go +++ b/api/v1/ytsaurus_types.go @@ -635,12 +635,11 @@ type YtsaurusSpec struct { ControllerAgents *ControllerAgentsSpec `json:"controllerAgents,omitempty"` TabletNodes []TabletNodesSpec `json:"tabletNodes,omitempty"` - StrawberryController *StrawberryControllerSpec `json:"strawberry,omitempty"` - DeprecatedChytController *StrawberryControllerSpec `json:"chyt,omitempty"` - QueryTrackers *QueryTrackerSpec `json:"queryTrackers,omitempty"` - Spyt *DeprecatedSpytSpec `json:"spyt,omitempty"` - YQLAgents *YQLAgentSpec `json:"yqlAgents,omitempty"` - QueueAgents *QueueAgentSpec `json:"queueAgents,omitempty"` + StrawberryController *StrawberryControllerSpec `json:"strawberry,omitempty"` + QueryTrackers *QueryTrackerSpec `json:"queryTrackers,omitempty"` + Spyt *DeprecatedSpytSpec `json:"spyt,omitempty"` + YQLAgents *YQLAgentSpec `json:"yqlAgents,omitempty"` + QueueAgents *QueueAgentSpec `json:"queueAgents,omitempty"` UI *UISpec `json:"ui,omitempty"` } diff --git a/api/v1/zz_generated.deepcopy.go b/api/v1/zz_generated.deepcopy.go index b62b75b1..00e8e1c2 100644 --- a/api/v1/zz_generated.deepcopy.go +++ b/api/v1/zz_generated.deepcopy.go @@ -1750,11 +1750,6 @@ func (in *YtsaurusSpec) DeepCopyInto(out *YtsaurusSpec) { *out = new(StrawberryControllerSpec) (*in).DeepCopyInto(*out) } - if in.DeprecatedChytController != nil { - in, out := &in.DeprecatedChytController, &out.DeprecatedChytController - *out = new(StrawberryControllerSpec) - (*in).DeepCopyInto(*out) - } if in.QueryTrackers != nil { in, out := &in.QueryTrackers, &out.QueryTrackers *out = new(QueryTrackerSpec) diff --git a/config/crd/bases/cluster.ytsaurus.tech_ytsaurus.yaml b/config/crd/bases/cluster.ytsaurus.tech_ytsaurus.yaml index a208558e..f149e426 100644 --- a/config/crd/bases/cluster.ytsaurus.tech_ytsaurus.yaml +++ b/config/crd/bases/cluster.ytsaurus.tech_ytsaurus.yaml @@ -98,83 +98,6 @@ spec: type: string type: object x-kubernetes-map-type: atomic - chyt: - properties: - image: - type: string - resources: - description: ResourceRequirements describes the compute resource - requirements. - properties: - claims: - description: Claims lists the names of resources, defined - in spec. - items: - description: ResourceClaim references one entry in PodSpec.ResourceClaims. - properties: - name: - description: Name must match the name of one entry in - pod.spec. - type: string - required: - - name - type: object - type: array - x-kubernetes-list-map-keys: - - name - x-kubernetes-list-type: map - limits: - additionalProperties: - anyOf: - - type: integer - - type: string - pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$ - x-kubernetes-int-or-string: true - description: Limits describes the maximum amount of compute - resources allowed. - type: object - requests: - additionalProperties: - anyOf: - - type: integer - - type: string - pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$ - x-kubernetes-int-or-string: true - description: Requests describes the minimum amount of compute - resources required. - type: object - type: object - tolerations: - items: - description: |- - The pod this Toleration is attached to tolerates any taint that matches - the trip - properties: - effect: - description: Effect indicates the taint effect to match. - Empty means match all taint effects. - type: string - key: - description: Key is the taint key that the toleration applies - to. - type: string - operator: - description: Operator represents a key's relationship to - the value. - type: string - tolerationSeconds: - description: |- - TolerationSeconds represents the period of time the toleration (which must be - of - format: int64 - type: integer - value: - description: Value is the taint value the toleration matches - to. - type: string - type: object - type: array - type: object configOverrides: description: |- LocalObjectReference contains enough information to let you locate the diff --git a/controllers/component_manager.go b/controllers/component_manager.go index ef7dccb4..5f565fb4 100644 --- a/controllers/component_manager.go +++ b/controllers/component_manager.go @@ -126,7 +126,7 @@ func NewComponentManager( allComponents = append(allComponents, yqla) } - if (resource.Spec.DeprecatedChytController != nil || resource.Spec.StrawberryController != nil) && resource.Spec.Schedulers != nil { + if resource.Spec.StrawberryController != nil && resource.Spec.Schedulers != nil { strawberry := components.NewStrawberryController(cfgen, ytsaurus, m, s, dnds) allComponents = append(allComponents, strawberry) } diff --git a/controllers/remoteexecnodes_test.go b/controllers/remoteexecnodes_test.go index bfd7b3de..8b714c57 100644 --- a/controllers/remoteexecnodes_test.go +++ b/controllers/remoteexecnodes_test.go @@ -282,7 +282,7 @@ func buildExecNodePod(h *testutil.TestHelper) corev1.Pod { consts.YTComponentLabelName: strings.Join( []string{ remoteExecNodesName, - consts.YTComponentLabelExecNode, + consts.ComponentLabel(consts.ExecNodeType), }, "-", ), diff --git a/docs/api.md b/docs/api.md index b132869d..38a52acb 100644 --- a/docs/api.md +++ b/docs/api.md @@ -1726,7 +1726,6 @@ _Appears in:_ | `controllerAgents` _[ControllerAgentsSpec](#controlleragentsspec)_ | | | | | `tabletNodes` _[TabletNodesSpec](#tabletnodesspec) array_ | | | | | `strawberry` _[StrawberryControllerSpec](#strawberrycontrollerspec)_ | | | | -| `chyt` _[StrawberryControllerSpec](#strawberrycontrollerspec)_ | | | | | `queryTrackers` _[QueryTrackerSpec](#querytrackerspec)_ | | | | | `spyt` _[DeprecatedSpytSpec](#deprecatedspytspec)_ | | | | | `yqlAgents` _[YQLAgentSpec](#yqlagentspec)_ | | | | diff --git a/pkg/components/chyt.go b/pkg/components/chyt.go index 8695a95d..f527cd3e 100644 --- a/pkg/components/chyt.go +++ b/pkg/components/chyt.go @@ -34,12 +34,11 @@ func NewChyt( chyt *apiproxy.Chyt, ytsaurus *ytv1.Ytsaurus) *Chyt { l := labeller.Labeller{ - ObjectMeta: &chyt.GetResource().ObjectMeta, - APIProxy: chyt.APIProxy(), - ComponentType: consts.YTComponentLabelChyt, - ComponentLabel: cfgen.FormatComponentStringWithDefault(consts.YTComponentLabelChyt, chyt.GetResource().Name), - ComponentName: cfgen.FormatComponentStringWithDefault(string(consts.ChytType), chyt.GetResource().Name), - Annotations: ytsaurus.Spec.ExtraPodAnnotations, + ObjectMeta: &chyt.GetResource().ObjectMeta, + APIProxy: chyt.APIProxy(), + ComponentType: consts.ChytType, + ComponentNamePart: chyt.GetResource().Name, + Annotations: ytsaurus.Spec.ExtraPodAnnotations, } return &Chyt{ diff --git a/pkg/components/component.go b/pkg/components/component.go index d6cecb48..c8dca94d 100644 --- a/pkg/components/component.go +++ b/pkg/components/component.go @@ -66,7 +66,7 @@ type baseComponent struct { // For example for master component name is "Master", // For data node name looks like "DataNode". func (c *baseComponent) GetName() string { - return c.labeller.ComponentName + return c.labeller.GetFullComponentName() } // localComponent is a base structs for components which have access to ytsaurus resource, @@ -99,7 +99,7 @@ func (c *localComponent) SetReadyCondition(status ComponentStatus) { ready = metav1.ConditionTrue } c.ytsaurus.SetStatusCondition(metav1.Condition{ - Type: fmt.Sprintf("%sReady", c.labeller.ComponentName), + Type: fmt.Sprintf("%sReady", c.labeller.GetFullComponentName()), Status: ready, Reason: string(status.SyncStatus), Message: status.Message, diff --git a/pkg/components/controller_agent.go b/pkg/components/controller_agent.go index ba102254..20216b84 100644 --- a/pkg/components/controller_agent.go +++ b/pkg/components/controller_agent.go @@ -23,10 +23,9 @@ type ControllerAgent struct { func NewControllerAgent(cfgen *ytconfig.Generator, ytsaurus *apiproxy.Ytsaurus, master Component) *ControllerAgent { resource := ytsaurus.GetResource() l := labeller.Labeller{ - ObjectMeta: &resource.ObjectMeta, - APIProxy: ytsaurus.APIProxy(), - ComponentLabel: consts.YTComponentLabelControllerAgent, - ComponentName: string(consts.ControllerAgentType), + ObjectMeta: &resource.ObjectMeta, + APIProxy: ytsaurus.APIProxy(), + ComponentType: consts.ControllerAgentType, } if resource.Spec.ControllerAgents.InstanceSpec.MonitoringPort == nil { diff --git a/pkg/components/data_node.go b/pkg/components/data_node.go index 26d468d2..8eb3046f 100644 --- a/pkg/components/data_node.go +++ b/pkg/components/data_node.go @@ -28,11 +28,10 @@ func NewDataNode( ) *DataNode { resource := ytsaurus.GetResource() l := labeller.Labeller{ - ObjectMeta: &resource.ObjectMeta, - APIProxy: ytsaurus.APIProxy(), - ComponentType: consts.YTComponentLabelDataNode, - ComponentLabel: cfgen.FormatComponentStringWithDefault(consts.YTComponentLabelDataNode, spec.Name), - ComponentName: cfgen.FormatComponentStringWithDefault(string(consts.DataNodeType), spec.Name), + ObjectMeta: &resource.ObjectMeta, + APIProxy: ytsaurus.APIProxy(), + ComponentType: consts.DataNodeType, + ComponentNamePart: spec.Name, } if spec.InstanceSpec.MonitoringPort == nil { diff --git a/pkg/components/discovery.go b/pkg/components/discovery.go index e4415e2a..4b113105 100644 --- a/pkg/components/discovery.go +++ b/pkg/components/discovery.go @@ -22,10 +22,9 @@ type Discovery struct { func NewDiscovery(cfgen *ytconfig.Generator, ytsaurus *apiproxy.Ytsaurus) *Discovery { resource := ytsaurus.GetResource() l := labeller.Labeller{ - ObjectMeta: &resource.ObjectMeta, - APIProxy: ytsaurus.APIProxy(), - ComponentLabel: consts.YTComponentLabelDiscovery, - ComponentName: string(consts.DiscoveryType), + ObjectMeta: &resource.ObjectMeta, + APIProxy: ytsaurus.APIProxy(), + ComponentType: consts.DiscoveryType, } if resource.Spec.Discovery.InstanceSpec.MonitoringPort == nil { diff --git a/pkg/components/exec_node.go b/pkg/components/exec_node.go index db968c12..df7baf1a 100644 --- a/pkg/components/exec_node.go +++ b/pkg/components/exec_node.go @@ -27,11 +27,10 @@ func NewExecNode( ) *ExecNode { resource := ytsaurus.GetResource() l := labeller.Labeller{ - ObjectMeta: &resource.ObjectMeta, - APIProxy: ytsaurus.APIProxy(), - ComponentType: consts.YTComponentLabelExecNode, - ComponentLabel: cfgen.FormatComponentStringWithDefault(consts.YTComponentLabelExecNode, spec.Name), - ComponentName: cfgen.FormatComponentStringWithDefault(string(consts.ExecNodeType), spec.Name), + ObjectMeta: &resource.ObjectMeta, + APIProxy: ytsaurus.APIProxy(), + ComponentType: consts.ExecNodeType, + ComponentNamePart: spec.Name, } if spec.InstanceSpec.MonitoringPort == nil { diff --git a/pkg/components/exec_node_remote.go b/pkg/components/exec_node_remote.go index f878a0ea..9611cd3e 100644 --- a/pkg/components/exec_node_remote.go +++ b/pkg/components/exec_node_remote.go @@ -26,11 +26,10 @@ func NewRemoteExecNodes( commonSpec ytv1.CommonSpec, ) *RemoteExecNode { l := labeller.Labeller{ - ObjectMeta: &nodes.ObjectMeta, - APIProxy: proxy, - ComponentType: consts.YTComponentLabelExecNode, - ComponentLabel: cfgen.FormatComponentStringWithDefault(consts.YTComponentLabelExecNode, spec.Name), - ComponentName: cfgen.FormatComponentStringWithDefault(string(consts.ExecNodeType), spec.Name), + ObjectMeta: &nodes.ObjectMeta, + APIProxy: proxy, + ComponentType: consts.ExecNodeType, + ComponentNamePart: spec.Name, } if spec.InstanceSpec.MonitoringPort == nil { diff --git a/pkg/components/httpproxy.go b/pkg/components/httpproxy.go index 5373bf24..8e9e1dff 100644 --- a/pkg/components/httpproxy.go +++ b/pkg/components/httpproxy.go @@ -34,11 +34,10 @@ func NewHTTPProxy( spec ytv1.HTTPProxiesSpec) *HttpProxy { resource := ytsaurus.GetResource() l := labeller.Labeller{ - ObjectMeta: &resource.ObjectMeta, - APIProxy: ytsaurus.APIProxy(), - ComponentType: consts.YTComponentLabelHTTPProxy, - ComponentLabel: cfgen.FormatComponentStringWithDefault(consts.YTComponentLabelHTTPProxy, spec.Role), - ComponentName: cfgen.FormatComponentStringWithDefault(string(consts.HttpProxyType), spec.Role), + ObjectMeta: &resource.ObjectMeta, + APIProxy: ytsaurus.APIProxy(), + ComponentType: consts.HttpProxyType, + ComponentNamePart: spec.Role, } if spec.InstanceSpec.MonitoringPort == nil { diff --git a/pkg/components/init_job.go b/pkg/components/init_job.go index 7f26cd0e..46d82176 100644 --- a/pkg/components/init_job.go +++ b/pkg/components/init_job.go @@ -64,7 +64,7 @@ func NewInitJob( apiProxy: apiProxy, conditionsManager: conditionsManager, imagePullSecrets: imagePullSecrets, - initCompletedCondition: fmt.Sprintf("%s%sInitJobCompleted", name, labeller.ComponentName), + initCompletedCondition: fmt.Sprintf("%s%sInitJobCompleted", name, labeller.GetFullComponentName()), image: image, initJob: resources.NewJob( labeller.GetInitJobName(name), @@ -76,7 +76,7 @@ func NewInitJob( fmt.Sprintf( "%s-%s-init-job-config", strings.ToLower(name), - labeller.ComponentLabel), + labeller.GetFullComponentLabel()), nil, map[string]ytconfig.GeneratorDescriptor{ configFileName: { @@ -158,7 +158,7 @@ func (j *InitJob) Sync(ctx context.Context, dry bool) (ComponentStatus, error) { } if !j.initJob.Completed() { - logger.Info("Init job is not completed for " + j.labeller.ComponentName) + logger.Info("Init job is not completed for " + j.labeller.GetFullComponentName()) return WaitingStatus(SyncStatusBlocked, fmt.Sprintf("%s completion", j.initJob.Name())), err } diff --git a/pkg/components/init_job_test.go b/pkg/components/init_job_test.go index f6ff99e2..46b85796 100644 --- a/pkg/components/init_job_test.go +++ b/pkg/components/init_job_test.go @@ -80,8 +80,7 @@ func newTestJob(ytsaurus *apiproxy.Ytsaurus) *InitJob { Name: k8sName, Namespace: ytsaurus.GetResource().Namespace, }, - ComponentLabel: "ms", - ComponentName: k8sName, + ComponentType: consts.MasterCacheType, }, ytsaurus.APIProxy(), ytsaurus, diff --git a/pkg/components/master.go b/pkg/components/master.go index acbba0ac..a4ebea4e 100644 --- a/pkg/components/master.go +++ b/pkg/components/master.go @@ -36,11 +36,10 @@ type Master struct { func NewMaster(cfgen *ytconfig.Generator, ytsaurus *apiproxy.Ytsaurus) *Master { resource := ytsaurus.GetResource() l := labeller.Labeller{ - ObjectMeta: &resource.ObjectMeta, - APIProxy: ytsaurus.APIProxy(), - ComponentLabel: consts.YTComponentLabelMaster, - ComponentName: string(consts.MasterType), - Annotations: resource.Spec.ExtraPodAnnotations, + ObjectMeta: &resource.ObjectMeta, + APIProxy: ytsaurus.APIProxy(), + ComponentType: consts.MasterType, + Annotations: resource.Spec.ExtraPodAnnotations, } if resource.Spec.PrimaryMasters.InstanceSpec.MonitoringPort == nil { diff --git a/pkg/components/master_caches.go b/pkg/components/master_caches.go index 2e041589..48101b25 100644 --- a/pkg/components/master_caches.go +++ b/pkg/components/master_caches.go @@ -23,11 +23,10 @@ type MasterCache struct { func NewMasterCache(cfgen *ytconfig.Generator, ytsaurus *apiproxy.Ytsaurus) *MasterCache { resource := ytsaurus.GetResource() l := labeller.Labeller{ - ObjectMeta: &resource.ObjectMeta, - APIProxy: ytsaurus.APIProxy(), - ComponentLabel: consts.YTComponentLabelMasterCache, - ComponentName: string(consts.MasterCacheType), - Annotations: resource.Spec.ExtraPodAnnotations, + ObjectMeta: &resource.ObjectMeta, + APIProxy: ytsaurus.APIProxy(), + ComponentType: consts.MasterCacheType, + Annotations: resource.Spec.ExtraPodAnnotations, } if resource.Spec.MasterCaches.InstanceSpec.MonitoringPort == nil { diff --git a/pkg/components/query_tracker.go b/pkg/components/query_tracker.go index cfe2b4bb..7b5247fe 100644 --- a/pkg/components/query_tracker.go +++ b/pkg/components/query_tracker.go @@ -40,11 +40,10 @@ func NewQueryTracker( ) *QueryTracker { resource := ytsaurus.GetResource() l := labeller.Labeller{ - ObjectMeta: &resource.ObjectMeta, - APIProxy: ytsaurus.APIProxy(), - ComponentLabel: consts.YTComponentLabelQueryTracker, - ComponentName: string(consts.QueryTrackerType), - Annotations: resource.Spec.ExtraPodAnnotations, + ObjectMeta: &resource.ObjectMeta, + APIProxy: ytsaurus.APIProxy(), + ComponentType: consts.QueryTrackerType, + Annotations: resource.Spec.ExtraPodAnnotations, } if resource.Spec.QueryTrackers.InstanceSpec.MonitoringPort == nil { diff --git a/pkg/components/queue_agent.go b/pkg/components/queue_agent.go index 4eb5033a..9fffe130 100644 --- a/pkg/components/queue_agent.go +++ b/pkg/components/queue_agent.go @@ -42,11 +42,10 @@ func NewQueueAgent( ) *QueueAgent { resource := ytsaurus.GetResource() l := labeller.Labeller{ - ObjectMeta: &resource.ObjectMeta, - APIProxy: ytsaurus.APIProxy(), - ComponentLabel: consts.YTComponentLabelQueueAgent, - ComponentName: string(consts.QueueAgentType), - Annotations: resource.Spec.ExtraPodAnnotations, + ObjectMeta: &resource.ObjectMeta, + APIProxy: ytsaurus.APIProxy(), + ComponentType: consts.QueueAgentType, + Annotations: resource.Spec.ExtraPodAnnotations, } if resource.Spec.QueueAgents.InstanceSpec.MonitoringPort == nil { diff --git a/pkg/components/rpcproxy.go b/pkg/components/rpcproxy.go index 71e847e9..b2b35aaf 100644 --- a/pkg/components/rpcproxy.go +++ b/pkg/components/rpcproxy.go @@ -33,11 +33,10 @@ func NewRPCProxy( spec ytv1.RPCProxiesSpec) *RpcProxy { resource := ytsaurus.GetResource() l := labeller.Labeller{ - ObjectMeta: &resource.ObjectMeta, - APIProxy: ytsaurus.APIProxy(), - ComponentType: consts.YTComponentLabelRPCProxy, - ComponentLabel: cfgen.FormatComponentStringWithDefault(consts.YTComponentLabelRPCProxy, spec.Role), - ComponentName: cfgen.FormatComponentStringWithDefault(string(consts.RpcProxyType), spec.Role), + ObjectMeta: &resource.ObjectMeta, + APIProxy: ytsaurus.APIProxy(), + ComponentType: consts.RpcProxyType, + ComponentNamePart: spec.Role, } if spec.InstanceSpec.MonitoringPort == nil { diff --git a/pkg/components/scheduler.go b/pkg/components/scheduler.go index 55d9c9a1..18f0f092 100644 --- a/pkg/components/scheduler.go +++ b/pkg/components/scheduler.go @@ -38,11 +38,10 @@ func NewScheduler( execNodes, tabletNodes []Component) *Scheduler { resource := ytsaurus.GetResource() l := labeller.Labeller{ - ObjectMeta: &resource.ObjectMeta, - APIProxy: ytsaurus.APIProxy(), - ComponentLabel: consts.YTComponentLabelScheduler, - ComponentName: string(consts.SchedulerType), - Annotations: resource.Spec.ExtraPodAnnotations, + ObjectMeta: &resource.ObjectMeta, + APIProxy: ytsaurus.APIProxy(), + ComponentType: consts.SchedulerType, + Annotations: resource.Spec.ExtraPodAnnotations, } if resource.Spec.Schedulers.InstanceSpec.MonitoringPort == nil { diff --git a/pkg/components/spyt.go b/pkg/components/spyt.go index a7c8e3a8..ebcbecf9 100644 --- a/pkg/components/spyt.go +++ b/pkg/components/spyt.go @@ -32,12 +32,11 @@ func NewSpyt( spyt *apiproxy.Spyt, ytsaurus *ytv1.Ytsaurus) *Spyt { l := labeller.Labeller{ - ObjectMeta: &spyt.GetResource().ObjectMeta, - APIProxy: spyt.APIProxy(), - ComponentType: consts.YTComponentLabelSpyt, - ComponentLabel: cfgen.FormatComponentStringWithDefault(consts.YTComponentLabelSpyt, spyt.GetResource().Name), - ComponentName: cfgen.FormatComponentStringWithDefault(string(consts.SpytType), spyt.GetResource().Name), - Annotations: ytsaurus.Spec.ExtraPodAnnotations, + ObjectMeta: &spyt.GetResource().ObjectMeta, + APIProxy: spyt.APIProxy(), + ComponentType: consts.SpytType, + ComponentNamePart: spyt.GetResource().Name, + Annotations: ytsaurus.Spec.ExtraPodAnnotations, } return &Spyt{ diff --git a/pkg/components/strawberry_controller.go b/pkg/components/strawberry_controller.go index 555d30aa..df5cdf88 100644 --- a/pkg/components/strawberry_controller.go +++ b/pkg/components/strawberry_controller.go @@ -32,14 +32,7 @@ type StrawberryController struct { name string } -func getControllerConfigFileName(name string) string { - if name == "chyt" { - return "chyt-controller.yson" - } else { - return "strawberry-controller.yson" - } -} - +const ControllerConfigFileName = "strawberry-controller.yson" const ChytInitClusterJobConfigFileName = "chyt-init-cluster.yson" func NewStrawberryController( @@ -51,29 +44,15 @@ func NewStrawberryController( resource := ytsaurus.GetResource() image := resource.Spec.CoreImage - name := "chyt" - componentName := "ChytController" - if resource.Spec.DeprecatedChytController != nil { - if resource.Spec.DeprecatedChytController.Image != nil { - image = *resource.Spec.DeprecatedChytController.Image - } - } - if resource.Spec.StrawberryController != nil { - name = "strawberry" - componentName = string(consts.StrawberryControllerType) - if resource.Spec.StrawberryController.Image != nil { - image = *resource.Spec.StrawberryController.Image - } + if resource.Spec.StrawberryController.Image != nil { + image = *resource.Spec.StrawberryController.Image } l := labeller.Labeller{ ObjectMeta: &resource.ObjectMeta, APIProxy: ytsaurus.APIProxy(), - ComponentType: consts.YTComponentLabelStrawberry, - // TODO(achulkov2): Pass the value above here instead after DeprecatedChytController is removed. - ComponentLabel: fmt.Sprintf("yt-%s-controller", name), - ComponentName: componentName, - Annotations: resource.Spec.ExtraPodAnnotations, + ComponentType: consts.StrawberryControllerType, + Annotations: resource.Spec.ExtraPodAnnotations, } microservice := newMicroservice( @@ -82,13 +61,13 @@ func NewStrawberryController( image, 1, map[string]ytconfig.GeneratorDescriptor{ - getControllerConfigFileName(name): { + ControllerConfigFileName: { F: cfgen.GetStrawberryControllerConfig, Fmt: ytconfig.ConfigFormatYson, }, }, - fmt.Sprintf("%s-controller", name), - name, + "strawberry-controller", + "strawberry", resource.Spec.StrawberryController.Tolerations) return &StrawberryController{ @@ -117,7 +96,7 @@ func NewStrawberryController( l.GetSecretName(), &l, ytsaurus.APIProxy()), - name: name, + name: "strawberry", master: master, scheduler: scheduler, dataNodes: dataNodes, @@ -204,7 +183,7 @@ func (c *StrawberryController) syncComponents(ctx context.Context) (err error) { Command: []string{ "/usr/bin/chyt-controller", "--config-path", - path.Join(consts.ConfigMountPoint, getControllerConfigFileName(c.name)), + path.Join(consts.ConfigMountPoint, ControllerConfigFileName), "run", }, Ports: []corev1.ContainerPort{ diff --git a/pkg/components/tablet_node.go b/pkg/components/tablet_node.go index 5d268017..f0931f68 100644 --- a/pkg/components/tablet_node.go +++ b/pkg/components/tablet_node.go @@ -43,11 +43,10 @@ func NewTabletNode( ) *TabletNode { resource := ytsaurus.GetResource() l := labeller.Labeller{ - ObjectMeta: &resource.ObjectMeta, - APIProxy: ytsaurus.APIProxy(), - ComponentType: consts.YTComponentLabelTabletNode, - ComponentLabel: cfgen.FormatComponentStringWithDefault(consts.YTComponentLabelTabletNode, spec.Name), - ComponentName: cfgen.FormatComponentStringWithDefault(string(consts.TabletNodeType), spec.Name), + ObjectMeta: &resource.ObjectMeta, + APIProxy: ytsaurus.APIProxy(), + ComponentType: consts.TabletNodeType, + ComponentNamePart: spec.Name, } if spec.InstanceSpec.MonitoringPort == nil { diff --git a/pkg/components/tcpproxy.go b/pkg/components/tcpproxy.go index f30031b2..32640a92 100644 --- a/pkg/components/tcpproxy.go +++ b/pkg/components/tcpproxy.go @@ -32,11 +32,10 @@ func NewTCPProxy( spec ytv1.TCPProxiesSpec) *TcpProxy { resource := ytsaurus.GetResource() l := labeller.Labeller{ - ObjectMeta: &resource.ObjectMeta, - APIProxy: ytsaurus.APIProxy(), - ComponentType: consts.YTComponentLabelTCPProxy, - ComponentLabel: cfgen.FormatComponentStringWithDefault(consts.YTComponentLabelTCPProxy, spec.Role), - ComponentName: cfgen.FormatComponentStringWithDefault(string(consts.TcpProxyType), spec.Role), + ObjectMeta: &resource.ObjectMeta, + APIProxy: ytsaurus.APIProxy(), + ComponentType: consts.TcpProxyType, + ComponentNamePart: spec.Role, } if spec.InstanceSpec.MonitoringPort == nil { diff --git a/pkg/components/ui.go b/pkg/components/ui.go index 0784f02c..d3809070 100644 --- a/pkg/components/ui.go +++ b/pkg/components/ui.go @@ -34,11 +34,10 @@ const UICustomConfigFileName = "common.js" func NewUI(cfgen *ytconfig.Generator, ytsaurus *apiproxy.Ytsaurus, master Component) *UI { resource := ytsaurus.GetResource() l := labeller.Labeller{ - ObjectMeta: &resource.ObjectMeta, - APIProxy: ytsaurus.APIProxy(), - ComponentLabel: consts.YTComponentLabelUI, - ComponentName: string(consts.UIType), - Annotations: resource.Spec.ExtraPodAnnotations, + ObjectMeta: &resource.ObjectMeta, + APIProxy: ytsaurus.APIProxy(), + ComponentType: consts.UIType, + Annotations: resource.Spec.ExtraPodAnnotations, } image := resource.Spec.UIImage if resource.Spec.UI.Image != nil { diff --git a/pkg/components/yql_agent.go b/pkg/components/yql_agent.go index 6b96653b..e88d65fd 100644 --- a/pkg/components/yql_agent.go +++ b/pkg/components/yql_agent.go @@ -29,11 +29,10 @@ 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(), - ComponentLabel: consts.YTComponentLabelYqlAgent, - ComponentName: string(consts.YqlAgentType), - Annotations: resource.Spec.ExtraPodAnnotations, + ObjectMeta: &resource.ObjectMeta, + APIProxy: ytsaurus.APIProxy(), + ComponentType: consts.YqlAgentType, + Annotations: resource.Spec.ExtraPodAnnotations, } if resource.Spec.YQLAgents.InstanceSpec.MonitoringPort == nil { @@ -85,7 +84,7 @@ func (yqla *YqlAgent) IsUpdatable() bool { func (yqla *YqlAgent) GetType() consts.ComponentType { return consts.YqlAgentType } func (yqla *YqlAgent) GetName() string { - return yqla.labeller.ComponentName + return yqla.labeller.GetFullComponentName() } func (yqla *YqlAgent) Fetch(ctx context.Context) error { diff --git a/pkg/components/ytsaurus_client.go b/pkg/components/ytsaurus_client.go index 30f8c5b3..ebc7309a 100644 --- a/pkg/components/ytsaurus_client.go +++ b/pkg/components/ytsaurus_client.go @@ -45,11 +45,10 @@ func NewYtsaurusClient( ) *YtsaurusClient { resource := ytsaurus.GetResource() l := labeller.Labeller{ - ObjectMeta: &resource.ObjectMeta, - APIProxy: ytsaurus.APIProxy(), - ComponentLabel: consts.YTComponentLabelClient, - ComponentName: string(consts.YtsaurusClientType), - Annotations: resource.Spec.ExtraPodAnnotations, + ObjectMeta: &resource.ObjectMeta, + APIProxy: ytsaurus.APIProxy(), + ComponentType: consts.YtsaurusClientType, + Annotations: resource.Spec.ExtraPodAnnotations, } return &YtsaurusClient{ diff --git a/pkg/consts/labels.go b/pkg/consts/labels.go index a6d2c2ef..578eb439 100644 --- a/pkg/consts/labels.go +++ b/pkg/consts/labels.go @@ -1,29 +1,63 @@ package consts +import ( + "fmt" +) + const YTClusterLabelName = "ytsaurus.tech/cluster-name" const YTComponentLabelName = "yt_component" const YTMetricsLabelName = "yt_metrics" -// TODO(achulkov2): We should probably use `ytsaurus` instead of `yt` everywhere, but -// it will be an inconvenient change that requires all statefulsets to be recreated. -const ( - YTComponentLabelDiscovery string = "yt-discovery" - YTComponentLabelMaster string = "yt-master" - YTComponentLabelScheduler string = "yt-scheduler" - YTComponentLabelControllerAgent string = "yt-controller-agent" - YTComponentLabelDataNode string = "yt-data-node" - YTComponentLabelExecNode string = "yt-exec-node" - YTComponentLabelTabletNode string = "yt-tablet-node" - YTComponentLabelHTTPProxy string = "yt-http-proxy" - YTComponentLabelRPCProxy string = "yt-rpc-proxy" - YTComponentLabelTCPProxy string = "yt-tcp-proxy" - YTComponentLabelUI string = "yt-ui" - YTComponentLabelYqlAgent string = "yt-yql-agent" - YTComponentLabelClient string = "yt-client" - YTComponentLabelMasterCache string = "yt-master-cache" - YTComponentLabelQueueAgent string = "yt-queue-agent" - YTComponentLabelQueryTracker string = "yt-query-tracker" - YTComponentLabelChyt string = "yt-chyt" - YTComponentLabelSpyt string = "yt-spyt" - YTComponentLabelStrawberry string = "yt-strawberry-controller" -) +func ComponentLabel(component ComponentType) string { + // TODO(achulkov2): We should probably use `ytsaurus` instead of `yt` everywhere, but + // it will be an inconvenient change that requires all statefulsets to be recreated. + switch component { + case MasterType: + return "yt-master" + case MasterCacheType: + return "yt-master-cache" + case DiscoveryType: + return "yt-discovery" + case SchedulerType: + return "yt-scheduler" + case ControllerAgentType: + return "yt-controller-agent" + case DataNodeType: + return "yt-data-node" + case ExecNodeType: + return "yt-exec-node" + case TabletNodeType: + return "yt-tablet-node" + case HttpProxyType: + return "yt-http-proxy" + case RpcProxyType: + return "yt-rpc-proxy" + case TcpProxyType: + return "yt-tcp-proxy" + case QueueAgentType: + return "yt-queue-agent" + case QueryTrackerType: + return "yt-query-tracker" + case YqlAgentType: + return "yt-yql-agent" + case StrawberryControllerType: + return "yt-strawberry-controller" + case ChytType: + return "yt-chyt" + case SpytType: + return "yt-spyt" + case YtsaurusClientType: + return "yt-client" + case UIType: + return "yt-ui" + } + + 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/labeller/labeller.go b/pkg/labeller/labeller.go index 35777a89..39bc74ab 100644 --- a/pkg/labeller/labeller.go +++ b/pkg/labeller/labeller.go @@ -16,43 +16,65 @@ type FetchableObject struct { } type Labeller struct { - APIProxy apiproxy.APIProxy - ObjectMeta *metav1.ObjectMeta - ComponentType string - ComponentLabel string - ComponentName string - Annotations map[string]string + APIProxy apiproxy.APIProxy + ObjectMeta *metav1.ObjectMeta + 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 } func (l *Labeller) GetClusterName() string { return l.ObjectMeta.Name } -func (l *Labeller) GetComponentType() string { - if l.ComponentType != "" { - return l.ComponentType +// GetComponentName Returns CamelCase component type without name part. +func (l *Labeller) GetComponentName() string { + return string(l.ComponentType) +} + +// GetFullComponentName Returns CamelCase component type with name part. +func (l *Labeller) GetFullComponentName() string { + if l.ComponentNamePart != "" { + return consts.FormatComponentStringWithDefault(l.GetComponentName(), l.ComponentNamePart) } - return l.ComponentLabel + + return l.GetComponentName() +} + +// GetComponentLabel Returns lower case hyphenated component type without name part. +func (l *Labeller) GetComponentLabel() string { + return consts.ComponentLabel(l.ComponentType) +} + +// 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() } func (l *Labeller) GetSecretName() string { - return fmt.Sprintf("%s-secret", l.ComponentLabel) + return fmt.Sprintf("%s-secret", l.GetFullComponentLabel()) } func (l *Labeller) GetMainConfigMapName() string { - return fmt.Sprintf("%s-config", l.ComponentLabel) + return fmt.Sprintf("%s-config", l.GetFullComponentLabel()) } func (l *Labeller) GetSidecarConfigMapName(name string) string { - return fmt.Sprintf("%s-%s-config", l.ComponentLabel, name) + return fmt.Sprintf("%s-%s-config", l.GetFullComponentLabel(), name) } func (l *Labeller) GetInitJobName(name string) string { - return fmt.Sprintf("%s-init-job-%s", l.ComponentLabel, strings.ToLower(name)) + return fmt.Sprintf("%s-init-job-%s", l.GetFullComponentLabel(), strings.ToLower(name)) } func (l *Labeller) GetPodsRemovingStartedCondition() string { - return fmt.Sprintf("%sPodsRemovingStarted", l.ComponentName) + return fmt.Sprintf("%sPodsRemovingStarted", l.GetFullComponentName()) } func (l *Labeller) GetObjectMeta(name string) metav1.ObjectMeta { @@ -74,7 +96,7 @@ func (l *Labeller) GetInitJobObjectMeta() metav1.ObjectMeta { } func (l *Labeller) GetInstanceLabelValue(isInitJob bool) string { - result := fmt.Sprintf("%s-%s", l.GetClusterName(), l.ComponentLabel) + result := fmt.Sprintf("%s-%s", l.GetClusterName(), l.GetFullComponentLabel()) if isInitJob { result = fmt.Sprintf("%s-%s", result, "init-job") } @@ -83,9 +105,9 @@ func (l *Labeller) GetInstanceLabelValue(isInitJob bool) string { func (l *Labeller) GetComponentTypeLabelValue(isInitJob bool) string { if isInitJob { - return fmt.Sprintf("%s-%s", l.GetComponentType(), "init-job") + return fmt.Sprintf("%s-%s", l.GetComponentLabel(), "init-job") } - return l.GetComponentType() + return l.GetComponentLabel() } func (l *Labeller) GetPartOfLabelValue() string { @@ -115,7 +137,7 @@ func (l *Labeller) GetMetaLabelMap(isInitJob bool) map[string]string { // Template: yt-[-init-job]. "app.kubernetes.io/name": l.GetComponentTypeLabelValue(isInitJob), // Template: yt--. - "app.kubernetes.io/component": l.ComponentLabel, + "app.kubernetes.io/component": l.GetFullComponentLabel(), // This is supposed to be the name of a higher level application // that this app is part of: yt-. "app.kubernetes.io/part-of": l.GetPartOfLabelValue(), diff --git a/pkg/resources/monitoring_service.go b/pkg/resources/monitoring_service.go index 3592a4d6..27909419 100644 --- a/pkg/resources/monitoring_service.go +++ b/pkg/resources/monitoring_service.go @@ -26,7 +26,7 @@ type MonitoringService struct { func NewMonitoringService(monitoringTargetPort int32, labeller *labeller2.Labeller, apiProxy apiproxy.APIProxy) *MonitoringService { return &MonitoringService{ - name: fmt.Sprintf("%s-monitoring", labeller.ComponentLabel), + name: fmt.Sprintf("%s-monitoring", labeller.GetFullComponentLabel()), labeller: labeller, apiProxy: apiProxy, monitoringTargetPort: monitoringTargetPort, diff --git a/pkg/resources/statefulset.go b/pkg/resources/statefulset.go index 13b03740..e01d6535 100644 --- a/pkg/resources/statefulset.go +++ b/pkg/resources/statefulset.go @@ -78,7 +78,7 @@ func (s *StatefulSet) getPods(ctx context.Context) *corev1.PodList { podList := &corev1.PodList{} err := s.proxy.ListObjects(ctx, podList, s.labeller.GetListOptions()...) if err != nil { - logger.Error(err, "unable to list pods for component", "component", s.labeller.ComponentName) + logger.Error(err, "unable to list pods for component", "component", s.labeller.GetFullComponentName()) return nil } @@ -94,7 +94,7 @@ func (s *StatefulSet) ArePodsRemoved(ctx context.Context) bool { } podsCount := len(podList.Items) if podsCount != 0 { - logger.Info("there are pods", "podsCount", podsCount, "component", s.labeller.ComponentName) + logger.Info("there are pods", "podsCount", podsCount, "component", s.labeller.GetFullComponentName()) return false } return true @@ -124,7 +124,7 @@ func (s *StatefulSet) ArePodsReady(ctx context.Context, minReadyInstanceCount *i if readyInstanceCount < effectiveMinReadyInstanceCount { logger.Info( "not enough pods are running", - "component", s.labeller.ComponentName, + "component", s.labeller.GetFullComponentName(), "readyInstanceCount", readyInstanceCount, "minReadyInstanceCount", effectiveMinReadyInstanceCount, "totalInstanceCount", len(podList.Items)) diff --git a/pkg/testutil/spec_builders.go b/pkg/testutil/spec_builders.go index c40f7e95..edef2150 100644 --- a/pkg/testutil/spec_builders.go +++ b/pkg/testutil/spec_builders.go @@ -123,15 +123,21 @@ func CreateBaseYtsaurusResource(namespace string) *ytv1.Ytsaurus { // TODO (l0kix2): merge with ytconfig build spec helpers. func WithDataNodes(ytsaurus *ytv1.Ytsaurus) *ytv1.Ytsaurus { - return WithDataNodesCount(ytsaurus, 3) + return WithDataNodesCount(ytsaurus, 3, nil) } -func WithDataNodesCount(ytsaurus *ytv1.Ytsaurus, count int) *ytv1.Ytsaurus { - ytsaurus.Spec.DataNodes = []ytv1.DataNodesSpec{ - { - InstanceSpec: CreateDataNodeInstanceSpec(count), - }, +func WithNamedDataNodes(ytsaurus *ytv1.Ytsaurus, name *string) *ytv1.Ytsaurus { + return WithDataNodesCount(ytsaurus, 3, name) +} + +func WithDataNodesCount(ytsaurus *ytv1.Ytsaurus, count int, name *string) *ytv1.Ytsaurus { + dataNodeSpec := ytv1.DataNodesSpec{ + InstanceSpec: CreateDataNodeInstanceSpec(count), + } + if name != nil { + dataNodeSpec.Name = *name } + ytsaurus.Spec.DataNodes = append(ytsaurus.Spec.DataNodes, dataNodeSpec) return ytsaurus } diff --git a/pkg/ytconfig/names.go b/pkg/ytconfig/names.go index 3f54ee1e..c6a000e1 100644 --- a/pkg/ytconfig/names.go +++ b/pkg/ytconfig/names.go @@ -102,15 +102,15 @@ func (g *Generator) GetStrawberryControllerHeadlessServiceName() string { } func (g *Generator) GetHTTPProxiesServiceName(role string) string { - return g.getName(fmt.Sprintf("%s-lb", g.FormatComponentStringWithDefault("http-proxies", role))) + return g.getName(fmt.Sprintf("%s-lb", consts.FormatComponentStringWithDefault("http-proxies", role))) } func (g *Generator) GetHTTPProxiesHeadlessServiceName(role string) string { - return g.getName(g.FormatComponentStringWithDefault("http-proxies", role)) + return g.getName(consts.FormatComponentStringWithDefault("http-proxies", role)) } func (g *Generator) GetHTTPProxiesStatefulSetName(role string) string { - return g.getName(g.FormatComponentStringWithDefault("hp", role)) + return g.getName(consts.FormatComponentStringWithDefault("hp", role)) } func (g *Generator) GetHTTPProxiesAddress(role string) string { @@ -129,27 +129,27 @@ func (g *Generator) GetSchedulerServiceName() string { } func (g *Generator) GetRPCProxiesStatefulSetName(role string) string { - return g.getName(g.FormatComponentStringWithDefault("rp", role)) + return g.getName(consts.FormatComponentStringWithDefault("rp", role)) } func (g *Generator) GetRPCProxiesServiceName(role string) string { - return g.getName(fmt.Sprintf("%s-lb", g.FormatComponentStringWithDefault("rpc-proxies", role))) + return g.getName(fmt.Sprintf("%s-lb", consts.FormatComponentStringWithDefault("rpc-proxies", role))) } func (g *Generator) GetRPCProxiesHeadlessServiceName(role string) string { - return g.getName(g.FormatComponentStringWithDefault("rpc-proxies", role)) + return g.getName(consts.FormatComponentStringWithDefault("rpc-proxies", role)) } func (g *Generator) GetTCPProxiesStatefulSetName(role string) string { - return g.getName(g.FormatComponentStringWithDefault("tp", role)) + return g.getName(consts.FormatComponentStringWithDefault("tp", role)) } func (g *Generator) GetTCPProxiesServiceName(role string) string { - return g.getName(fmt.Sprintf("%s-lb", g.FormatComponentStringWithDefault("tcp-proxies", role))) + return g.getName(fmt.Sprintf("%s-lb", consts.FormatComponentStringWithDefault("tcp-proxies", role))) } func (g *Generator) GetTCPProxiesHeadlessServiceName(role string) string { - return g.getName(g.FormatComponentStringWithDefault("tcp-proxies", role)) + return g.getName(consts.FormatComponentStringWithDefault("tcp-proxies", role)) } func (g *Generator) GetQueryTrackerStatefulSetName() string { @@ -169,34 +169,27 @@ func (g *Generator) GetQueueAgentServiceName() string { } func (g *NodeGenerator) GetDataNodesStatefulSetName(name string) string { - return g.getName(g.FormatComponentStringWithDefault("dnd", name)) + return g.getName(consts.FormatComponentStringWithDefault("dnd", name)) } func (g *NodeGenerator) GetDataNodesServiceName(name string) string { - return g.getName(g.FormatComponentStringWithDefault("data-nodes", name)) + return g.getName(consts.FormatComponentStringWithDefault("data-nodes", name)) } func (g *NodeGenerator) GetExecNodesStatefulSetName(name string) string { - return g.getName(g.FormatComponentStringWithDefault("end", name)) + return g.getName(consts.FormatComponentStringWithDefault("end", name)) } func (g *NodeGenerator) GetExecNodesServiceName(name string) string { - return g.getName(g.FormatComponentStringWithDefault("exec-nodes", name)) + return g.getName(consts.FormatComponentStringWithDefault("exec-nodes", name)) } func (g *NodeGenerator) GetTabletNodesStatefulSetName(name string) string { - return g.getName(g.FormatComponentStringWithDefault("tnd", name)) + return g.getName(consts.FormatComponentStringWithDefault("tnd", name)) } func (g *NodeGenerator) GetTabletNodesServiceName(name string) string { - return g.getName(g.FormatComponentStringWithDefault("tablet-nodes", name)) -} - -func (g *BaseGenerator) FormatComponentStringWithDefault(base string, name string) string { - if name != consts.DefaultName { - return fmt.Sprintf("%s-%s", base, name) - } - return base + return g.getName(consts.FormatComponentStringWithDefault("tablet-nodes", name)) } func (g *BaseGenerator) GetMasterCachesStatefulSetName() string { diff --git a/test/e2e/helpers_test.go b/test/e2e/helpers_test.go index ad83b7a7..37d2846c 100644 --- a/test/e2e/helpers_test.go +++ b/test/e2e/helpers_test.go @@ -2,7 +2,6 @@ package controllers_test import ( "context" - mapset "github.com/deckarep/golang-set/v2" . "github.com/onsi/gomega" corev1 "k8s.io/api/core/v1" @@ -32,6 +31,13 @@ func getComponentPods(ctx context.Context, namespace string) map[string]corev1.P return result } +func getAllPods(ctx context.Context, namespace string) []corev1.Pod { + podList := corev1.PodList{} + err := k8sClient.List(ctx, &podList, ctrlcli.InNamespace(namespace)) + Expect(err).Should(Succeed()) + return podList.Items +} + type StringSet mapset.Set[string] func NewStringSet() StringSet { diff --git a/test/e2e/ytsaurus_controller_test.go b/test/e2e/ytsaurus_controller_test.go index 27bf306c..d0f86498 100644 --- a/test/e2e/ytsaurus_controller_test.go +++ b/test/e2e/ytsaurus_controller_test.go @@ -5,6 +5,7 @@ import ( "encoding/json" "fmt" "io" + "k8s.io/utils/ptr" "net" "net/http" "os" @@ -163,9 +164,10 @@ func runYtsaurus(ytsaurus *ytv1.Ytsaurus) { if ytsaurus.Spec.Discovery.InstanceCount != 0 { pods = append(pods, "ds-0") } - if len(ytsaurus.Spec.DataNodes) != 0 { - pods = append(pods, "dnd-0") + for _, dataNodeGroup := range ytsaurus.Spec.DataNodes { + pods = append(pods, fmt.Sprintf("%v-0", consts.FormatComponentStringWithDefault("dnd", dataNodeGroup.Name))) } + if len(ytsaurus.Spec.ExecNodes) != 0 { pods = append(pods, "end-0") } @@ -923,6 +925,67 @@ func checkClusterViability(ytClient yt.Client) { Expect(hasPermission.Action).Should(Equal(yt.ActionDeny)) } +func checkPodLabelCount(pods []corev1.Pod, labelKey string, labelValue string, expectedCount int) { + podCount := 0 + for _, pod := range pods { + if pod.Labels[labelKey] == labelValue { + podCount++ + } + } + Expect(podCount).Should(Equal(expectedCount)) +} + +func checkPodLabels(ctx context.Context, namespace string) { + cluster := testutil.YtsaurusName + pods := getAllPods(ctx, namespace) + + for _, pod := range pods { + fmt.Fprintf(GinkgoWriter, "PodName: %v, Labels: %v\n", pod.Name, pod.ObjectMeta.Labels) + } + + Expect(pods, ContainElement(And( + HaveField("Name", "dnd-0"), + HaveField("Labels", And( + HaveKeyWithValue("app.kubernetes.io/name", "yt-data-node"), + HaveKeyWithValue("app.kubernetes.io/component", "yt-data-node"), + HaveKeyWithValue("yt_component", fmt.Sprintf("%v-yt-data-node", cluster)), + HaveKeyWithValue("app.kubernetes.io/managed-by", "ytsaurus-k8s-operator"), + HaveKeyWithValue("app.kubernetes.io/part-of", fmt.Sprintf("yt-%v", cluster)), + HaveKeyWithValue("ytsaurus.tech/cluster-name", cluster), + )), + ))) + Expect(pods, ContainElement(And( + HaveField("Name", "dnd-dn-t-1"), + HaveField("Labels", And( + HaveKeyWithValue("app.kubernetes.io/name", "yt-data-node"), + HaveKeyWithValue("app.kubernetes.io/component", "yt-data-node-dn-t"), + HaveKeyWithValue("yt_component", fmt.Sprintf("%v-yt-data-node-dn-t", cluster)), + HaveKeyWithValue("app.kubernetes.io/managed-by", "ytsaurus-k8s-operator"), + HaveKeyWithValue("app.kubernetes.io/part-of", fmt.Sprintf("yt-%v", cluster)), + HaveKeyWithValue("ytsaurus.tech/cluster-name", cluster), + )), + ))) + checkPodLabelCount(pods, "app.kubernetes.io/name", "yt-data-node", 6) + checkPodLabelCount(pods, "app.kubernetes.io/component", "yt-data-node", 3) + checkPodLabelCount(pods, "app.kubernetes.io/component", "yt-data-node-dn-t", 3) + + Expect(pods, ContainElement(And( + HaveField("Name", "ms-0"), + HaveField("Labels", And( + HaveKeyWithValue("app.kubernetes.io/name", "yt-master"), + HaveKeyWithValue("app.kubernetes.io/component", "yt-master"), + HaveKeyWithValue("yt_component", fmt.Sprintf("%v-yt-master", cluster)), + HaveKeyWithValue("app.kubernetes.io/managed-by", "ytsaurus-k8s-operator"), + HaveKeyWithValue("app.kubernetes.io/part-of", fmt.Sprintf("yt-%v", cluster)), + HaveKeyWithValue("ytsaurus.tech/cluster-name", cluster), + )), + ))) + checkPodLabelCount(pods, "app.kubernetes.io/name", "yt-master", 1) + + // Init jobs have their own suffixes. + checkPodLabelCount(pods, "app.kubernetes.io/name", "yt-scheduler", 1) +} + func deployAndCheck(ytsaurus *ytv1.Ytsaurus, namespace string) { runYtsaurus(ytsaurus) @@ -940,6 +1003,7 @@ func getSimpleUpdateScenario(namespace, newImage string) func(ctx context.Contex return func(ctx context.Context) { By("Creating a Ytsaurus resource") ytsaurus := testutil.CreateBaseYtsaurusResource(namespace) + testutil.WithNamedDataNodes(ytsaurus, ptr.To("dn-t")) DeferCleanup(deleteYtsaurus, ytsaurus) name := types.NamespacedName{Name: ytsaurus.GetName(), Namespace: namespace} deployAndCheck(ytsaurus, namespace) @@ -947,6 +1011,9 @@ func getSimpleUpdateScenario(namespace, newImage string) func(ctx context.Contex By("Run cluster update") podsBeforeUpdate := getComponentPods(ctx, namespace) Expect(k8sClient.Get(ctx, name, ytsaurus)).Should(Succeed()) + + checkPodLabels(ctx, namespace) + ytsaurus.Spec.CoreImage = newImage Expect(k8sClient.Update(ctx, ytsaurus)).Should(Succeed()) EventuallyYtsaurus(ctx, name, reactionTimeout).Should(HaveClusterState(ytv1.ClusterStateUpdating))