Skip to content

Commit 37b3d00

Browse files
Remove errReplicaInstance and handling
The error is never returned anywhere in the code outside of tests.
1 parent 52072b8 commit 37b3d00

File tree

2 files changed

+0
-73
lines changed

2 files changed

+0
-73
lines changed

internal/sidecar/scale_to_zero.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,6 @@ const (
5656
defaultCheckInterval = 1 * time.Minute // default check interval for cluster activity
5757
)
5858

59-
var errReplicaInstance = errors.New("current pod is not the primary instance")
60-
6159
// newScaleToZero creates a new scaleToZero instance with the provided configuration and client.
6260
func newScaleToZero(ctx context.Context, cfg config, client client.Client) (*scaleToZero, error) {
6361
s := &scaleToZero{
@@ -125,10 +123,6 @@ func (s *scaleToZero) Start(ctx context.Context) error {
125123
if !isActive {
126124
if err := s.hibernate(ctx); err != nil {
127125
contextLogger.Error(err, "hibernation failed")
128-
// we stop the scale to zero sidecar if this is not the primary instance
129-
if errors.Is(err, errReplicaInstance) {
130-
return nil
131-
}
132126
// if hibernation fails, do not try pausing the scheduled backup
133127
continue
134128
}

internal/sidecar/scale_to_zero_test.go

Lines changed: 0 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -440,54 +440,6 @@ func TestScaleToZero_Start(t *testing.T) {
440440

441441
wantErr: nil,
442442
},
443-
{
444-
name: "cluster with scale to zero enabled and inactive cluster, hibernation error replica instance stops the process",
445-
client: func(done chan struct{}) *mockClusterClient {
446-
return &mockClusterClient{
447-
getClusterFunc: func(ctx context.Context, forceUpdate bool) (*cnpgv1.Cluster, error) {
448-
return &cnpgv1.Cluster{
449-
Status: cnpgv1.ClusterStatus{
450-
Phase: healthyClusterStatus,
451-
CurrentPrimary: "test-pod-1",
452-
},
453-
ObjectMeta: metav1.ObjectMeta{
454-
Annotations: map[string]string{
455-
scaleToZeroEnabledAnnotation: "true",
456-
inactivityMinutesAnnotation: "5",
457-
},
458-
},
459-
}, nil
460-
},
461-
updateClusterFunc: func(ctx context.Context, cluster *cnpgv1.Cluster) error {
462-
defer func() { done <- struct{}{} }()
463-
require.NotNil(t, cluster)
464-
require.Equal(t, "on", cluster.Annotations[hibernationAnnotation])
465-
return errReplicaInstance
466-
},
467-
getClusterScheduledBackupFunc: func(ctx context.Context) (*cnpgv1.ScheduledBackup, error) {
468-
return nil, fmt.Errorf("scheduledbackups.postgresql.cnpg.io \"test-cluster\" not found")
469-
},
470-
}
471-
},
472-
querier: func(_ chan struct{}) *mockQuerier {
473-
return &mockQuerier{
474-
queryFunc: func(ctx context.Context, query string, args ...any) (postgres.Row, error) {
475-
return &mockRow{
476-
scanFn: func(dest ...any) error {
477-
require.Len(t, dest, 1)
478-
count, ok := dest[0].(*int)
479-
require.True(t, ok)
480-
*count = 0 // Simulate an inactive cluster
481-
return nil
482-
},
483-
}, nil
484-
},
485-
}
486-
},
487-
lastActive: time.Now().Add(-time.Minute * 10), // Simulate inactivity
488-
489-
wantErr: nil,
490-
},
491443
{
492444
name: "cluster with scale to zero enabled, unable to check activity, error ignored",
493445
client: func(done chan struct{}) *mockClusterClient {
@@ -941,25 +893,6 @@ func Test_hibernate(t *testing.T) {
941893
},
942894
wantErr: errTest,
943895
},
944-
{
945-
name: "updateCluster returns errReplicaInstance",
946-
client: &mockClusterClient{
947-
getClusterFunc: func(ctx context.Context, forceUpdate bool) (*cnpgv1.Cluster, error) {
948-
return &cnpgv1.Cluster{
949-
Status: cnpgv1.ClusterStatus{
950-
Phase: healthyClusterStatus,
951-
},
952-
ObjectMeta: metav1.ObjectMeta{
953-
Annotations: map[string]string{},
954-
},
955-
}, nil
956-
},
957-
updateClusterFunc: func(ctx context.Context, cluster *cnpgv1.Cluster) error {
958-
return errReplicaInstance
959-
},
960-
},
961-
wantErr: errReplicaInstance,
962-
},
963896
}
964897

965898
for _, tc := range tests {

0 commit comments

Comments
 (0)