diff --git a/pkg/index/job/readreplica/rotate/config/config.go b/pkg/index/job/readreplica/rotate/config/config.go index be17a970f28..f96b59ae96c 100644 --- a/pkg/index/job/readreplica/rotate/config/config.go +++ b/pkg/index/job/readreplica/rotate/config/config.go @@ -18,6 +18,11 @@ import ( "github.com/vdaas/vald/internal/errors" ) +// RotateAllID is the value to be embed as MY_TARGET_REPLICA_ID when you need to rotate all read replicas. +// Declaring here to avoid kubeconfig flag confliction between our e2e and some k8s packages +// Exporting this for testing +const RotateAllID = "rotate-all" + // GlobalConfig is a type alias of config.GlobalConfig representing application base configurations. type GlobalConfig = config.GlobalConfig diff --git a/pkg/index/job/readreplica/rotate/service/rotator.go b/pkg/index/job/readreplica/rotate/service/rotator.go index b03fd77585c..7abb249c9ee 100644 --- a/pkg/index/job/readreplica/rotate/service/rotator.go +++ b/pkg/index/job/readreplica/rotate/service/rotator.go @@ -27,6 +27,7 @@ import ( "github.com/vdaas/vald/internal/observability/trace" "github.com/vdaas/vald/internal/safety" "github.com/vdaas/vald/internal/sync/errgroup" + "github.com/vdaas/vald/pkg/index/job/readreplica/rotate/config" appsv1 "k8s.io/api/apps/v1" v1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -34,8 +35,7 @@ import ( ) const ( - apiName = "vald/index/job/readreplica/rotate" - rotateAllId = "rotate-all" + apiName = "vald/index/job/readreplica/rotate" ) // Rotator represents an interface for indexing. @@ -81,7 +81,7 @@ func New(replicaID string, opts ...Option) (Rotator, error) { return nil, fmt.Errorf("failed to create kubernetes client: %w", err) } - if replicaID == rotateAllId { + if replicaID == config.RotateAllID { var deploymentList appsv1.DeploymentList selector, err := c.LabelSelector(r.readReplicaLabelKey, client.SelectionOpExists, []string{}) if err != nil { diff --git a/tests/e2e/crud/crud_test.go b/tests/e2e/crud/crud_test.go index 237d33be2c3..c8ee8524358 100644 --- a/tests/e2e/crud/crud_test.go +++ b/tests/e2e/crud/crud_test.go @@ -25,7 +25,6 @@ import ( "fmt" "os" "os/exec" - "strconv" "testing" "time" @@ -33,6 +32,7 @@ import ( "github.com/vdaas/vald/internal/file" "github.com/vdaas/vald/internal/net/grpc/codes" "github.com/vdaas/vald/internal/net/grpc/status" + "github.com/vdaas/vald/pkg/index/job/readreplica/rotate/config" "github.com/vdaas/vald/tests/e2e/hdf5" "github.com/vdaas/vald/tests/e2e/kubernetes/client" "github.com/vdaas/vald/tests/e2e/kubernetes/kubectl" @@ -867,9 +867,10 @@ func TestE2EReadReplica(t *testing.T) { t.Fatalf("ListCronJob failed: %s", err) } cronJob := cronJobs[0] - for id := 0; id < len(pods); id++ { - cronJob.Spec.JobTemplate.Spec.Template.Spec.Containers[0].Env[0].Value = strconv.Itoa(id) - kubeClient.CreateJobFromCronJob(ctx, "vald-readreplica-rotate-"+strconv.Itoa(id), namespace, &cronJob) + + cronJob.Spec.JobTemplate.Spec.Template.Spec.Containers[0].Env[0].Value = config.RotateAllID + if err := kubeClient.CreateJobFromCronJob(ctx, "vald-readreplica-rotate", namespace, &cronJob); err != nil { + t.Fatalf("failed to create job from cronjob: %s", err) } t.Log("waiting for read replica rotator jobs to complete...")