Skip to content

Commit

Permalink
Add rotate-all option to rotator (#2305)
Browse files Browse the repository at this point in the history
* Add rotate-all option to rotator

* Fix linter warnings

* Make it possible to choose multiple rotation target

* Add tests for parseReplicaID

* Add tests for parseReplicaID

* Hide testify in internal

* style: format code with Gofumpt and Prettier

This commit fixes the style issues introduced in dd84674 according to the output
from Gofumpt and Prettier.

Details: #2305

* Apply format

* Lint

* Lint

---------

Co-authored-by: deepsource-autofix[bot] <62050782+deepsource-autofix[bot]@users.noreply.github.com>
Co-authored-by: Yusuke Kato <[email protected]>
  • Loading branch information
3 people authored and vdaas-ci committed Feb 21, 2024
1 parent 42225c8 commit 535f7b2
Show file tree
Hide file tree
Showing 7 changed files with 347 additions and 53 deletions.
21 changes: 21 additions & 0 deletions internal/errors/rotator.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//
// Copyright (C) 2019-2024 vdaas.org vald team <[email protected]>
//
// Licensed under the Apache License, Version 2.0 (the "License");
// You may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

// Package errors provides error types and function
package errors

// ErrReadReplicaIDEmpty represents error when trying to rotate agents with empty replicaID.
var ErrReadReplicaIDEmpty = New("readreplica id is empty. it should be set via MY_TARGET_REPLICA_ID env var")
6 changes: 6 additions & 0 deletions internal/k8s/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (

snapshotv1 "github.com/kubernetes-csi/external-snapshotter/client/v6/apis/volumesnapshot/v1"
"github.com/vdaas/vald/internal/errors"
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/equality"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down Expand Up @@ -52,17 +53,22 @@ type (
MatchingLabels = cli.MatchingLabels
InNamespace = cli.InNamespace
VolumeSnapshot = snapshotv1.VolumeSnapshot
Deployment = appsv1.Deployment
DeploymentList = appsv1.DeploymentList
ObjectMeta = metav1.ObjectMeta
)

const (
DeletePropagationBackground = metav1.DeletePropagationBackground
WatchDeletedEvent = watch.Deleted
SelectionOpEquals = selection.Equals
SelectionOpExists = selection.Exists
)

var (
ServerSideApply = cli.Apply
MergePatch = cli.Merge
NewSelector = labels.NewSelector
)

type Client interface {
Expand Down
71 changes: 71 additions & 0 deletions internal/test/mock/k8s/client.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
// Copyright (C) 2019-2024 vdaas.org vald team <[email protected]>
//
// Licensed under the Apache License, Version 2.0 (the "License");
// You may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package k8s

import (
"context"

"github.com/stretchr/testify/mock"
"github.com/vdaas/vald/internal/k8s/client"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/apimachinery/pkg/selection"
"k8s.io/apimachinery/pkg/watch"
crclient "sigs.k8s.io/controller-runtime/pkg/client"
)

type ValdK8sClientMock struct {
mock.Mock
}

var _ client.Client = (*ValdK8sClientMock)(nil)

func (m *ValdK8sClientMock) Get(ctx context.Context, name string, namespace string, obj client.Object, opts ...crclient.GetOption) error {
args := m.Called(ctx, name, namespace, obj, opts)
return args.Error(0)

Check warning on line 35 in internal/test/mock/k8s/client.go

View check run for this annotation

Codecov / codecov/patch

internal/test/mock/k8s/client.go#L33-L35

Added lines #L33 - L35 were not covered by tests
}

func (m *ValdK8sClientMock) List(ctx context.Context, list crclient.ObjectList, opts ...client.ListOption) error {
args := m.Called(ctx, list, opts)
return args.Error(0)
}

func (m *ValdK8sClientMock) Create(ctx context.Context, obj client.Object, opts ...client.CreateOption) error {
args := m.Called(ctx, obj, opts)
return args.Error(0)

Check warning on line 45 in internal/test/mock/k8s/client.go

View check run for this annotation

Codecov / codecov/patch

internal/test/mock/k8s/client.go#L43-L45

Added lines #L43 - L45 were not covered by tests
}

func (m *ValdK8sClientMock) Delete(ctx context.Context, obj client.Object, opts ...crclient.DeleteOption) error {
args := m.Called(ctx, obj, opts)
return args.Error(0)

Check warning on line 50 in internal/test/mock/k8s/client.go

View check run for this annotation

Codecov / codecov/patch

internal/test/mock/k8s/client.go#L48-L50

Added lines #L48 - L50 were not covered by tests
}

func (m *ValdK8sClientMock) Update(ctx context.Context, obj client.Object, opts ...crclient.UpdateOption) error {
args := m.Called(ctx, obj, opts)
return args.Error(0)

Check warning on line 55 in internal/test/mock/k8s/client.go

View check run for this annotation

Codecov / codecov/patch

internal/test/mock/k8s/client.go#L53-L55

Added lines #L53 - L55 were not covered by tests
}

func (m *ValdK8sClientMock) Patch(ctx context.Context, obj client.Object, patch crclient.Patch, opts ...crclient.PatchOption) error {
args := m.Called(ctx, obj, patch, opts)
return args.Error(0)

Check warning on line 60 in internal/test/mock/k8s/client.go

View check run for this annotation

Codecov / codecov/patch

internal/test/mock/k8s/client.go#L58-L60

Added lines #L58 - L60 were not covered by tests
}

func (m *ValdK8sClientMock) Watch(ctx context.Context, obj crclient.ObjectList, opts ...client.ListOption) (watch.Interface, error) {
args := m.Called(ctx, obj, opts)
return args.Get(0).(watch.Interface), args.Error(1)

Check warning on line 65 in internal/test/mock/k8s/client.go

View check run for this annotation

Codecov / codecov/patch

internal/test/mock/k8s/client.go#L63-L65

Added lines #L63 - L65 were not covered by tests
}

func (m *ValdK8sClientMock) LabelSelector(key string, op selection.Operator, vals []string) (labels.Selector, error) {
args := m.Called(key, op, vals)
return args.Get(0).(labels.Selector), args.Error(1)
}
26 changes: 26 additions & 0 deletions internal/test/testify/testify.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Copyright (C) 2019-2024 vdaas.org vald team <[email protected]>
//
// Licensed under the Apache License, Version 2.0 (the "License");
// You may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package testify

import (
"github.com/stretchr/testify/mock"
)

type (
Arguments = mock.Arguments
)

const (
Anything = mock.Anything
)
2 changes: 1 addition & 1 deletion pkg/agent/core/faiss/service/option.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import (
"github.com/vdaas/vald/internal/timeutil"
)

// Option represent the functional option for faiss
// Option represent the functional option for faiss.
type Option func(f *faiss) error

var defaultOptions = []Option{
Expand Down
Loading

0 comments on commit 535f7b2

Please sign in to comment.