Skip to content

Commit

Permalink
style fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
koct9i committed Oct 18, 2024
1 parent 6b95fea commit 86454fa
Show file tree
Hide file tree
Showing 14 changed files with 40 additions and 56 deletions.
7 changes: 3 additions & 4 deletions api/v1/ytsaurus_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ func (r *ytsaurusValidator) validateSecondaryMasters(newYtsaurus *Ytsaurus) fiel
for i, sm := range newYtsaurus.Spec.SecondaryMasters {
path := field.NewPath("spec").Child("secondaryMasters").Index(i)
allErrors = append(allErrors, r.validateInstanceSpec(sm.InstanceSpec, path)...)
// allErrors = append(allErrors, r.validateHostAddresses(newYtsaurus.Spec.PrimaryMasters, path)...)
allErrors = append(allErrors, r.validateHostAddresses(newYtsaurus, path)...)
}

Expand Down Expand Up @@ -270,7 +269,7 @@ func (r *ytsaurusValidator) validateExecNodes(newYtsaurus *Ytsaurus) field.Error
}
}

if newYtsaurus.Spec.ExecNodes != nil && len(newYtsaurus.Spec.ExecNodes) > 0 {
if len(newYtsaurus.Spec.ExecNodes) > 0 {
if newYtsaurus.Spec.Schedulers == nil {
allErrors = append(allErrors, field.Required(field.NewPath("spec").Child("schedulers"), "execNodes doesn't make sense without schedulers"))
}
Expand Down Expand Up @@ -352,7 +351,7 @@ func (r *ytsaurusValidator) validateQueryTrackers(newYtsaurus *Ytsaurus) field.E
path := field.NewPath("spec").Child("queryTrackers")
allErrors = append(allErrors, r.validateInstanceSpec(newYtsaurus.Spec.QueryTrackers.InstanceSpec, path)...)

if newYtsaurus.Spec.TabletNodes == nil || len(newYtsaurus.Spec.TabletNodes) == 0 {
if len(newYtsaurus.Spec.TabletNodes) == 0 {
allErrors = append(allErrors, field.Required(field.NewPath("spec").Child("tabletNodes"), "tabletNodes are required for queryTrackers"))
}

Expand All @@ -371,7 +370,7 @@ func (r *ytsaurusValidator) validateQueueAgents(newYtsaurus *Ytsaurus) field.Err
path := field.NewPath("spec").Child("queueAgents")
allErrors = append(allErrors, r.validateInstanceSpec(newYtsaurus.Spec.QueueAgents.InstanceSpec, path)...)

if newYtsaurus.Spec.TabletNodes == nil || len(newYtsaurus.Spec.TabletNodes) == 0 {
if len(newYtsaurus.Spec.TabletNodes) == 0 {
allErrors = append(allErrors, field.Required(field.NewPath("spec").Child("tabletNodes"), "tabletNodes are required for queueAgents"))
}
}
Expand Down
14 changes: 7 additions & 7 deletions controllers/component_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func NewComponentManager(

var dnds []components.Component
nodeCfgGen := ytconfig.NewLocalNodeGenerator(ytsaurus.GetResource(), clusterDomain)
if resource.Spec.DataNodes != nil && len(resource.Spec.DataNodes) > 0 {
if len(resource.Spec.DataNodes) > 0 {
for _, dndSpec := range ytsaurus.GetResource().Spec.DataNodes {
dnds = append(dnds, components.NewDataNode(nodeCfgGen, ytsaurus, m, dndSpec))
}
Expand All @@ -68,15 +68,15 @@ func NewComponentManager(
allComponents = append(allComponents, ui)
}

if resource.Spec.RPCProxies != nil && len(resource.Spec.RPCProxies) > 0 {
if len(resource.Spec.RPCProxies) > 0 {
var rps []components.Component
for _, rpSpec := range ytsaurus.GetResource().Spec.RPCProxies {
rps = append(rps, components.NewRPCProxy(cfgen, ytsaurus, m, rpSpec))
}
allComponents = append(allComponents, rps...)
}

if resource.Spec.TCPProxies != nil && len(resource.Spec.TCPProxies) > 0 {
if len(resource.Spec.TCPProxies) > 0 {
var tps []components.Component
for _, tpSpec := range ytsaurus.GetResource().Spec.TCPProxies {
tps = append(tps, components.NewTCPProxy(cfgen, ytsaurus, m, tpSpec))
Expand All @@ -85,15 +85,15 @@ func NewComponentManager(
}

var ends []components.Component
if resource.Spec.ExecNodes != nil && len(resource.Spec.ExecNodes) > 0 {
if len(resource.Spec.ExecNodes) > 0 {
for _, endSpec := range ytsaurus.GetResource().Spec.ExecNodes {
ends = append(ends, components.NewExecNode(nodeCfgGen, ytsaurus, m, endSpec))
}
}
allComponents = append(allComponents, ends...)

var tnds []components.Component
if resource.Spec.TabletNodes != nil && len(resource.Spec.TabletNodes) > 0 {
if len(resource.Spec.TabletNodes) > 0 {
for idx, tndSpec := range ytsaurus.GetResource().Spec.TabletNodes {
tnds = append(tnds, components.NewTabletNode(nodeCfgGen, ytsaurus, yc, tndSpec, idx == 0))
}
Expand All @@ -111,12 +111,12 @@ func NewComponentManager(
}

var q components.Component
if resource.Spec.QueryTrackers != nil && resource.Spec.Schedulers != nil && resource.Spec.TabletNodes != nil && len(resource.Spec.TabletNodes) > 0 {
if resource.Spec.QueryTrackers != nil && resource.Spec.Schedulers != nil && len(resource.Spec.TabletNodes) > 0 {
q = components.NewQueryTracker(cfgen, ytsaurus, yc, tnds)
allComponents = append(allComponents, q)
}

if resource.Spec.QueueAgents != nil && resource.Spec.TabletNodes != nil && len(resource.Spec.TabletNodes) > 0 {
if resource.Spec.QueueAgents != nil && len(resource.Spec.TabletNodes) > 0 {
qa := components.NewQueueAgent(cfgen, ytsaurus, yc, m, tnds)
allComponents = append(allComponents, qa)
}
Expand Down
8 changes: 1 addition & 7 deletions controllers/remotedatanodes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,13 +272,7 @@ func buildDataNodePod(h *testutil.TestHelper) corev1.Pod {
Name: "dn-0",
Namespace: h.Namespace,
Labels: map[string]string{
consts.YTComponentLabelName: strings.Join(
[]string{
remoteDataNodesName,
consts.ComponentLabel(consts.DataNodeType),
},
"-",
),
consts.YTComponentLabelName: remoteDataNodesName + "-" + consts.ComponentLabel(consts.DataNodeType),
},
},
Spec: corev1.PodSpec{
Expand Down
9 changes: 1 addition & 8 deletions controllers/remoteexecnodes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,6 @@ func TestRemoteExecNodesStatusRunningZeroPods(t *testing.T) {
// TestRemoteExecNodesStatusRunningZeroPods ensures that remote exec nodes CRD reaches correct release status
// in non-zero pods case.
func TestRemoteExecNodesStatusRunningWithPods(t *testing.T) {
// h := startHelperWithController(t, "remote-exec-nodes-test-status-running-with-pods")
h := startHelperWithController(t, "remote-exec-nodes-test-status-running-with-pods",
setupRemoteExecNodesReconciler(),
)
Expand Down Expand Up @@ -273,13 +272,7 @@ func buildExecNodePod(h *testutil.TestHelper) corev1.Pod {
Name: "end-0",
Namespace: h.Namespace,
Labels: map[string]string{
consts.YTComponentLabelName: strings.Join(
[]string{
remoteExecNodesName,
consts.ComponentLabel(consts.ExecNodeType),
},
"-",
),
consts.YTComponentLabelName: remoteExecNodesName + "-" + consts.ComponentLabel(consts.ExecNodeType),
},
},
Spec: corev1.PodSpec{
Expand Down
4 changes: 2 additions & 2 deletions pkg/canonize/canonize.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ const (
envDoCanonize = "CANONIZE"
canonDirName = "canondata"
canonFileName = "test.canondata"
defaultFilePermissions = 0644
defaultDirPermissions = 0755
defaultFilePermissions = 0o644
defaultDirPermissions = 0o755
)

func Assert(t *testing.T, data []byte) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/components/init_job.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ func (j *InitJob) Build() *batchv1.Job {
if j.builtJob != nil {
return j.builtJob
}
var defaultMode int32 = 0500
var defaultMode int32 = 0o500
job := j.initJob.Build()
job.Spec.Template = corev1.PodTemplateSpec{
ObjectMeta: j.baseComponent.labeller.GetInitJobObjectMeta(),
Expand Down
2 changes: 1 addition & 1 deletion pkg/components/query_tracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ func (qt *QueryTracker) doSync(ctx context.Context, dry bool) (ComponentStatus,
}

// Wait for tablet nodes to proceed with query tracker state init.
if qt.tabletNodes == nil || len(qt.tabletNodes) == 0 {
if len(qt.tabletNodes) == 0 {
return WaitingStatus(SyncStatusBlocked, "tablet nodes"), fmt.Errorf("cannot initialize query tracker without tablet nodes")
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/components/queue_agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ func (qa *QueueAgent) doSync(ctx context.Context, dry bool) (ComponentStatus, er
}

// It makes no sense to start queue agents without tablet nodes.
if qa.tabletNodes == nil || len(qa.tabletNodes) == 0 {
if len(qa.tabletNodes) == 0 {
return WaitingStatus(SyncStatusBlocked, "tablet nodes"), fmt.Errorf("cannot initialize queue agent without tablet nodes")
}
for _, tnd := range qa.tabletNodes {
Expand Down
20 changes: 9 additions & 11 deletions pkg/components/scheduler.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,16 +164,14 @@ func (s *Scheduler) doSync(ctx context.Context, dry bool) (ComponentStatus, erro
return WaitingStatus(SyncStatusBlocked, s.master.GetName()), err
}

if s.execNodes == nil || len(s.execNodes) > 0 {
for _, end := range s.execNodes {
endStatus, err := end.Status(ctx)
if err != nil {
return endStatus, err
}
if !IsRunningStatus(endStatus.SyncStatus) {
// It makes no sense to start scheduler without exec nodes.
return WaitingStatus(SyncStatusBlocked, end.GetName()), err
}
for _, end := range s.execNodes {
endStatus, err := end.Status(ctx)
if err != nil {
return endStatus, err
}
if !IsRunningStatus(endStatus.SyncStatus) {
// It makes no sense to start scheduler without exec nodes.
return WaitingStatus(SyncStatusBlocked, end.GetName()), err
}
}

Expand Down Expand Up @@ -263,7 +261,7 @@ func (s *Scheduler) updateOpArchive(ctx context.Context, dry bool) (*ComponentSt
}

func (s *Scheduler) needOpArchiveInit() bool {
return s.tabletNodes != nil && len(s.tabletNodes) > 0
return len(s.tabletNodes) > 0
}

func (s *Scheduler) setConditionNotNecessaryToUpdateOpArchive(ctx context.Context) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/components/ytsaurus_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ func (yc *YtsaurusClient) handleUpdatingState(ctx context.Context) (ComponentSta
}

if !yc.ytsaurus.IsUpdateStatusConditionTrue(consts.ConditionSnapshotsBuildingStarted) {
if err = yc.StartBuildMasterSnapshots(ctx, yc.ytsaurus.GetResource().Status.UpdateStatus.MasterMonitoringPaths); err != nil {
if err := yc.StartBuildMasterSnapshots(ctx, yc.ytsaurus.GetResource().Status.UpdateStatus.MasterMonitoringPaths); err != nil {
return SimpleStatus(SyncStatusUpdating), err
}

Expand Down
12 changes: 6 additions & 6 deletions pkg/testutil/spec_builders.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ 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 {
func WithDataNodesCount(ytsaurus *ytv1.Ytsaurus, count int32, name *string) *ytv1.Ytsaurus {
dataNodeSpec := ytv1.DataNodesSpec{
InstanceSpec: CreateDataNodeInstanceSpec(count),
}
Expand All @@ -145,7 +145,7 @@ func WithTabletNodes(ytsaurus *ytv1.Ytsaurus) *ytv1.Ytsaurus {
return WithTabletNodesCount(ytsaurus, 3)
}

func WithTabletNodesCount(ytsaurus *ytv1.Ytsaurus, count int) *ytv1.Ytsaurus {
func WithTabletNodesCount(ytsaurus *ytv1.Ytsaurus, count int32) *ytv1.Ytsaurus {
ytsaurus.Spec.TabletNodes = []ytv1.TabletNodesSpec{
{
InstanceSpec: CreateTabletNodeSpec(count),
Expand Down Expand Up @@ -301,9 +301,9 @@ func CreateExecNodeInstanceSpec() ytv1.InstanceSpec {
}
}

func CreateDataNodeInstanceSpec(instanceCount int) ytv1.InstanceSpec {
func CreateDataNodeInstanceSpec(instanceCount int32) ytv1.InstanceSpec {
return ytv1.InstanceSpec{
InstanceCount: int32(instanceCount),
InstanceCount: instanceCount,
Locations: []ytv1.LocationSpec{
{
LocationType: "ChunkStore",
Expand All @@ -329,9 +329,9 @@ func CreateDataNodeInstanceSpec(instanceCount int) ytv1.InstanceSpec {
}
}

func CreateTabletNodeSpec(instanceCount int) ytv1.InstanceSpec {
func CreateTabletNodeSpec(instanceCount int32) ytv1.InstanceSpec {
return ytv1.InstanceSpec{
InstanceCount: int32(instanceCount),
InstanceCount: instanceCount,
Loggers: createLoggersSpec(),
}
}
4 changes: 2 additions & 2 deletions pkg/ytconfig/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ type IOEngine struct {

func createLogging(spec *ytv1.InstanceSpec, componentName string, defaultLoggerSpecs []ytv1.TextLoggerSpec) Logging {
loggingBuilder := newLoggingBuilder(ytv1.FindFirstLocation(spec.Locations, ytv1.LocationTypeLogs), componentName)
if spec.Loggers != nil && len(spec.Loggers) > 0 {
if len(spec.Loggers) > 0 {
for _, loggerSpec := range spec.Loggers {
loggingBuilder.addLogger(loggerSpec)
}
Expand All @@ -143,7 +143,7 @@ func createLogging(spec *ytv1.InstanceSpec, componentName string, defaultLoggerS
loggingBuilder.addLogger(defaultLoggerSpec)
}
}
if spec.StructuredLoggers != nil && len(spec.StructuredLoggers) > 0 {
if len(spec.StructuredLoggers) > 0 {
for _, loggerSpec := range spec.StructuredLoggers {
loggingBuilder.addStructuredLogger(loggerSpec)
}
Expand Down
8 changes: 4 additions & 4 deletions pkg/ytconfig/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,8 @@ func (g *BaseGenerator) fillClusterConnection(c *ClusterConnection, s *ytv1.RPCT
c.MasterCache.CellID = generateCellID(g.masterConnectionSpec.CellTag)
}

func (g *BaseGenerator) fillCypressAnnotations(c *map[string]any) {
*c = map[string]any{
func (g *BaseGenerator) fillCypressAnnotations(c *CommonServer) {
c.CypressAnnotations = map[string]any{
"k8s_pod_name": "{K8S_POD_NAME}",
"k8s_pod_namespace": "{K8S_POD_NAMESPACE}",
"k8s_node_name": "{K8S_NODE_NAME}",
Expand All @@ -210,7 +210,7 @@ func (g *BaseGenerator) fillCommonService(c *CommonServer, s *ytv1.InstanceSpec)
g.fillAddressResolver(&c.AddressResolver)
g.fillSolomonExporter(&c.SolomonExporter)
g.fillClusterConnection(&c.ClusterConnection, s.NativeTransport)
g.fillCypressAnnotations(&c.CypressAnnotations)
g.fillCypressAnnotations(c)
c.TimestampProviders.Addresses = g.getMasterAddresses()
}

Expand Down Expand Up @@ -386,7 +386,7 @@ func (g *Generator) getSchedulerConfigImpl(spec *ytv1.SchedulersSpec) (Scheduler
return SchedulerServer{}, err
}

if g.ytsaurus.Spec.TabletNodes == nil || len(g.ytsaurus.Spec.TabletNodes) == 0 {
if len(g.ytsaurus.Spec.TabletNodes) == 0 {
c.Scheduler.OperationsCleaner.EnableOperationArchivation = ptr.To(false)
}
g.fillCommonService(&c.CommonServer, &spec.InstanceSpec)
Expand Down
2 changes: 1 addition & 1 deletion pkg/ytconfig/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,7 @@ func getExecNodeServerCarcass(spec *ytv1.ExecNodesSpec, commonSpec *ytv1.CommonS
c.Logging = getExecNodeLogging(spec)

jobProxyLoggingBuilder := newJobProxyLoggingBuilder()
if spec.JobProxyLoggers != nil && len(spec.JobProxyLoggers) > 0 {
if len(spec.JobProxyLoggers) > 0 {
for _, loggerSpec := range spec.JobProxyLoggers {
jobProxyLoggingBuilder.addLogger(loggerSpec)
}
Expand Down

0 comments on commit 86454fa

Please sign in to comment.