Skip to content

Commit

Permalink
Update e2e
Browse files Browse the repository at this point in the history
  • Loading branch information
ykadowak committed Jan 23, 2024
1 parent ebf3855 commit 5038af4
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 11 deletions.
5 changes: 5 additions & 0 deletions pkg/index/job/readreplica/rotate/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 3 additions & 3 deletions pkg/index/job/readreplica/rotate/service/rotator.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ 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"
"k8s.io/utils/pointer"
)

const (
apiName = "vald/index/job/readreplica/rotate"
rotateAllId = "rotate-all"
apiName = "vald/index/job/readreplica/rotate"
)

// Rotator represents an interface for indexing.
Expand Down Expand Up @@ -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 {
Expand Down
13 changes: 5 additions & 8 deletions tests/e2e/crud/crud_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ import (
"fmt"
"os"
"os/exec"
"strconv"
"testing"
"time"

"github.com/vdaas/vald/internal/errors"
"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"
Expand Down Expand Up @@ -858,18 +858,15 @@ func TestE2EReadReplica(t *testing.T) {
}

t.Log("starting to create read replica rotators...")
pods, err := kubeClient.GetPods(ctx, namespace, "app=vald-agent-ngt")
if err != nil {
t.Fatalf("GetPods failed: %s", err)
}
cronJobs, err := kubeClient.ListCronJob(ctx, namespace, "app=vald-readreplica-rotate")
if err != nil {
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...")
Expand Down

0 comments on commit 5038af4

Please sign in to comment.