Skip to content

Commit

Permalink
Use expected instance count as default for minimal ready count (#395)
Browse files Browse the repository at this point in the history
Currently operator has silly assumption that all pods are always created.
  • Loading branch information
koct9i authored Nov 20, 2024
1 parent 1cb91db commit e126e5a
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
17 changes: 17 additions & 0 deletions controllers/ytsaurus_local_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (
"testing"
"time"

"k8s.io/utils/ptr"

"github.com/stretchr/testify/require"
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
Expand Down Expand Up @@ -56,6 +58,11 @@ func TestYtsaurusFromScratch(t *testing.T) {
defer h.Stop()

ytsaurusResource := testutil.BuildMinimalYtsaurus(namespace, ytsaurusName)
// FIXME(khlebnikov): This test is broken by design.
ytsaurusResource.Spec.PrimaryMasters.MinReadyInstanceCount = ptr.To(0)
ytsaurusResource.Spec.Discovery.MinReadyInstanceCount = ptr.To(0)
ytsaurusResource.Spec.HTTPProxies[0].MinReadyInstanceCount = ptr.To(0)
ytsaurusResource.Spec.DataNodes[0].MinReadyInstanceCount = ptr.To(0)
testutil.DeployObject(h, &ytsaurusResource)

for _, compName := range []string{
Expand Down Expand Up @@ -109,6 +116,11 @@ func TestYtsaurusUpdateStatelessComponent(t *testing.T) {
defer h.Stop()

ytsaurusResource := testutil.BuildMinimalYtsaurus(namespace, ytsaurusName)
// FIXME(khlebnikov): This test is broken by design.
ytsaurusResource.Spec.PrimaryMasters.MinReadyInstanceCount = ptr.To(0)
ytsaurusResource.Spec.Discovery.MinReadyInstanceCount = ptr.To(0)
ytsaurusResource.Spec.HTTPProxies[0].MinReadyInstanceCount = ptr.To(0)
ytsaurusResource.Spec.DataNodes[0].MinReadyInstanceCount = ptr.To(0)
testutil.DeployObject(h, &ytsaurusResource)

waitClusterState(h, ytv1.ClusterStateRunning)
Expand All @@ -132,6 +144,11 @@ func TestYtsaurusUpdateMasterBlocked(t *testing.T) {
defer h.Stop()

ytsaurusResource := testutil.BuildMinimalYtsaurus(namespace, ytsaurusName)
// FIXME(khlebnikov): This test is broken by design.
ytsaurusResource.Spec.PrimaryMasters.MinReadyInstanceCount = ptr.To(0)
ytsaurusResource.Spec.Discovery.MinReadyInstanceCount = ptr.To(0)
ytsaurusResource.Spec.HTTPProxies[0].MinReadyInstanceCount = ptr.To(0)
ytsaurusResource.Spec.DataNodes[0].MinReadyInstanceCount = ptr.To(0)
testutil.DeployObject(h, &ytsaurusResource)

waitClusterState(h, ytv1.ClusterStateRunning)
Expand Down
2 changes: 1 addition & 1 deletion pkg/components/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ func (s *serverImpl) needUpdate() bool {
}

func (s *serverImpl) arePodsReady(ctx context.Context) bool {
return s.statefulSet.ArePodsReady(ctx, s.instanceSpec.MinReadyInstanceCount)
return s.statefulSet.ArePodsReady(ctx, int(s.instanceSpec.InstanceCount), s.instanceSpec.MinReadyInstanceCount)
}

func (s *serverImpl) buildStatefulSet() *appsv1.StatefulSet {
Expand Down
6 changes: 3 additions & 3 deletions pkg/resources/statefulset.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,15 +100,15 @@ func (s *StatefulSet) ArePodsRemoved(ctx context.Context) bool {
return true
}

func (s *StatefulSet) ArePodsReady(ctx context.Context, minReadyInstanceCount *int) bool {
func (s *StatefulSet) ArePodsReady(ctx context.Context, instanceCount int, minReadyInstanceCount *int) bool {
logger := log.FromContext(ctx)
podList := s.getPods(ctx)
if podList == nil {
return false
}

effectiveMinReadyInstanceCount := len(podList.Items)
if minReadyInstanceCount != nil && *minReadyInstanceCount < len(podList.Items) {
effectiveMinReadyInstanceCount := instanceCount
if minReadyInstanceCount != nil && *minReadyInstanceCount < instanceCount {
effectiveMinReadyInstanceCount = *minReadyInstanceCount
}

Expand Down

0 comments on commit e126e5a

Please sign in to comment.