Skip to content

Commit

Permalink
upgrade controller-runtime to 0.14.6, go to 1.19, k8s client go to 0.…
Browse files Browse the repository at this point in the history
…26.3 (#148)

Signed-off-by: haorenfsa <[email protected]>
  • Loading branch information
haorenfsa authored Jul 16, 2024
1 parent 018d757 commit 9b5cad7
Show file tree
Hide file tree
Showing 39 changed files with 2,613 additions and 803 deletions.
8 changes: 4 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ RELEASE_IMG ?= milvusdb/milvus-operator:v$(VERSION)
TOOL_RELEASE_IMG ?= milvusdb/milvus-config-tool:v$(TOOL_VERSION)
KIND_CLUSTER ?= kind

# Produce CRDs that work back to Kubernetes 1.11 (no version conversion)
CRD_OPTIONS ?= "crd:preserveUnknownFields=false,maxDescLen=0"
# Produce remove descriptions, it's too long
CRD_OPTIONS ?= "crd:maxDescLen=0"
# cert-manager
CERT_MANAGER_MANIFEST ?= "https://github.com/jetstack/cert-manager/releases/download/v1.5.3/cert-manager.yaml"

Expand Down Expand Up @@ -61,7 +61,7 @@ generate: controller-gen go-generate ## Generate code containing DeepCopy, DeepC
generate-all: generate deploy-manifests

go-generate:
go install github.com/golang/mock/mockgen@v1.6.0
go install go.uber.org/mock/mockgen@v0.4.0
go generate ./...

generate-client-groups:
Expand Down Expand Up @@ -212,7 +212,7 @@ dev-cert-apply: dev-cert

CONTROLLER_GEN = $(shell pwd)/bin/controller-gen
controller-gen: ## Download controller-gen locally if necessary.
$(call go-get-tool,$(CONTROLLER_GEN),sigs.k8s.io/controller-tools/cmd/controller-gen@v0.6.0)
$(call go-get-tool,$(CONTROLLER_GEN),sigs.k8s.io/controller-tools/cmd/controller-gen@v0.14.0)

KUSTOMIZE = $(shell pwd)/bin/kustomize
kustomize: ## Download kustomize locally if necessary.
Expand Down
1 change: 1 addition & 0 deletions apis/milvus.io/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions apis/milvus.io/v1beta1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

668 changes: 647 additions & 21 deletions charts/milvus-operator/templates/crds.yaml

Large diffs are not rendered by default.

317 changes: 309 additions & 8 deletions config/crd/bases/milvus.io_milvusclusters.yaml

Large diffs are not rendered by default.

345 changes: 337 additions & 8 deletions config/crd/bases/milvus.io_milvuses.yaml

Large diffs are not rendered by default.

9 changes: 1 addition & 8 deletions config/crd/bases/milvus.io_milvusupgrades.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@

---
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.6.0
controller-gen.kubebuilder.io/version: v0.9.2
creationTimestamp: null
name: milvusupgrades.milvus.io
spec:
Expand Down Expand Up @@ -148,9 +147,3 @@ spec:
storage: true
subresources:
status: {}
status:
acceptedNames:
kind: ""
plural: ""
conditions: []
storedVersions: []
1 change: 0 additions & 1 deletion config/rbac/role.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
Expand Down
2 changes: 0 additions & 2 deletions config/webhook/manifests.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

---
apiVersion: admissionregistration.k8s.io/v1
kind: MutatingWebhookConfiguration
Expand Down Expand Up @@ -46,7 +45,6 @@ webhooks:
resources:
- milvusupgrades
sideEffects: None

---
apiVersion: admissionregistration.k8s.io/v1
kind: ValidatingWebhookConfiguration
Expand Down
668 changes: 647 additions & 21 deletions deploy/manifests/deployment.yaml

Large diffs are not rendered by default.

193 changes: 89 additions & 104 deletions go.mod

Large diffs are not rendered by default.

934 changes: 458 additions & 476 deletions go.sum

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion pkg/controllers/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import (
"context"
"testing"

"github.com/golang/mock/gomock"
"github.com/milvus-io/milvus-operator/apis/milvus.io/v1beta1"
"github.com/milvus-io/milvus-operator/pkg/config"
"github.com/milvus-io/milvus-operator/pkg/util"
"go.uber.org/mock/gomock"
"helm.sh/helm/v3/pkg/cli"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
Expand Down
2 changes: 1 addition & 1 deletion pkg/controllers/component_condition_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ import (
"testing"
"time"

"github.com/golang/mock/gomock"
"github.com/milvus-io/milvus-operator/apis/milvus.io/v1beta1"
"github.com/milvus-io/milvus-operator/pkg/util/rest"
"github.com/pkg/errors"
"github.com/prashantv/gostub"
"github.com/stretchr/testify/assert"
"go.uber.org/mock/gomock"
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down
6 changes: 3 additions & 3 deletions pkg/controllers/components.go
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ func GetMilvusConfCheckSum(spec v1beta1.MilvusSpec) string {

func GetStartupProbe() *corev1.Probe {
return &corev1.Probe{
Handler: corev1.Handler{
ProbeHandler: corev1.ProbeHandler{
HTTPGet: &corev1.HTTPGetAction{
Path: "/healthz",
Port: intstr.FromInt(9091),
Expand All @@ -455,7 +455,7 @@ func GetStartupProbe() *corev1.Probe {

func GetLivenessProbe() *corev1.Probe {
return &corev1.Probe{
Handler: corev1.Handler{
ProbeHandler: corev1.ProbeHandler{
HTTPGet: &corev1.HTTPGetAction{
Path: "/healthz",
Port: intstr.FromInt(9091),
Expand All @@ -471,7 +471,7 @@ func GetLivenessProbe() *corev1.Probe {

func GetReadinessProbe() *corev1.Probe {
return &corev1.Probe{
Handler: corev1.Handler{
ProbeHandler: corev1.ProbeHandler{
HTTPGet: &corev1.HTTPGetAction{
Path: "/healthz",
Port: intstr.FromInt(9091),
Expand Down
45 changes: 24 additions & 21 deletions pkg/controllers/conditions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,20 @@ import (
"testing"

"github.com/apache/pulsar-client-go/pulsar"
"github.com/golang/mock/gomock"
"github.com/milvus-io/milvus-operator/apis/milvus.io/v1beta1"
"github.com/milvus-io/milvus-operator/pkg/external"
"github.com/prashantv/gostub"
"github.com/stretchr/testify/assert"
pb "go.etcd.io/etcd/api/v3/etcdserverpb"
"go.etcd.io/etcd/api/v3/v3rpc/rpctypes"
clientv3 "go.etcd.io/etcd/client/v3"
"go.uber.org/mock/gomock"
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
k8sErrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/runtime/schema"
ctrl "sigs.k8s.io/controller-runtime"
fake "sigs.k8s.io/controller-runtime/pkg/client/fake"
logf "sigs.k8s.io/controller-runtime/pkg/log"
)

Expand Down Expand Up @@ -199,8 +200,8 @@ func TestGetMinioCondition(t *testing.T) {
defer ctrl.Finish()
stubs := gostub.Stub(&checkMinIO, getMockCheckMinIOFunc(errTest))
defer stubs.Reset()
mockK8sCli.EXPECT().Get(gomock.Any(), gomock.Any(), gomock.Any()).
Do(func(ctx interface{}, key interface{}, secret *corev1.Secret) {
mockK8sCli.EXPECT().Get(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).
Do(func(ctx interface{}, key interface{}, secret *corev1.Secret, opt ...any) {
secret.Data = map[string][]byte{
AccessKey: []byte("accessKeyID"),
SecretKey: []byte("secretAccessKey"),
Expand All @@ -216,7 +217,7 @@ func TestGetMinioCondition(t *testing.T) {
stubs := gostub.Stub(&checkMinIO, getMockCheckMinIOFunc(nil))
defer stubs.Reset()
mockK8sCli.EXPECT().Get(gomock.Any(), gomock.Any(), gomock.Any()).
Do(func(ctx interface{}, key interface{}, secret *corev1.Secret) {
Do(func(ctx interface{}, key interface{}, secret *corev1.Secret, opt ...any) {
secret.Data = map[string][]byte{
AccessKey: []byte("accessKeyID"),
SecretKey: []byte("secretAccessKey"),
Expand All @@ -231,7 +232,7 @@ func TestGetMinioCondition(t *testing.T) {
stubs := gostub.Stub(&checkMinIO, getMockCheckMinIOFunc(nil))
defer stubs.Reset()
mockK8sCli.EXPECT().Get(gomock.Any(), gomock.Any(), gomock.Any()).
Do(func(ctx interface{}, key interface{}, secret *corev1.Secret) {
Do(func(ctx interface{}, key interface{}, secret *corev1.Secret, opt ...any) {
secret.Data = map[string][]byte{
AccessKey: []byte("accessKeyID"),
SecretKey: []byte("secretAccessKey"),
Expand Down Expand Up @@ -305,7 +306,7 @@ func TestGetEtcdCondition(t *testing.T) {
func TestGetMilvusEndpoint(t *testing.T) {
ctrl := gomock.NewController(t)
defer ctrl.Finish()
mockClient := NewMockK8sClient(ctrl)
fakeClient := fake.NewClientBuilder().Build()
ctx := context.TODO()
logger := logf.Log.WithName("test")

Expand All @@ -316,31 +317,33 @@ func TestGetMilvusEndpoint(t *testing.T) {
ServiceType: corev1.ServiceTypeNodePort,
Port: 10086,
}
assert.Empty(t, GetMilvusEndpoint(ctx, logger, mockClient, info))
assert.Empty(t, GetMilvusEndpoint(ctx, logger, fakeClient, info))

// clusterIP
info.ServiceType = corev1.ServiceTypeClusterIP
assert.Equal(t, "name-milvus.ns:10086", GetMilvusEndpoint(ctx, logger, mockClient, info))
assert.Equal(t, "name-milvus.ns:10086", GetMilvusEndpoint(ctx, logger, fakeClient, info))

// loadbalancer failed
// query loadbalancer failed
info.ServiceType = corev1.ServiceTypeLoadBalancer
mockClient.EXPECT().Get(gomock.Any(), gomock.Any(), gomock.Any()).Return(errors.New("test"))
assert.Empty(t, GetMilvusEndpoint(ctx, logger, mockClient, info))
assert.Empty(t, GetMilvusEndpoint(ctx, logger, fakeClient, info))

// loadbalancer not created, empty
// svc loadbalancer not created, empty
info.ServiceType = corev1.ServiceTypeLoadBalancer
mockClient.EXPECT().Get(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil)
assert.Empty(t, GetMilvusEndpoint(ctx, logger, mockClient, info))
svc := &corev1.Service{}
svc.Name = "name-milvus"
svc.Namespace = "ns"
fakeClient = fake.NewClientBuilder().
WithObjects(svc).Build()
assert.Empty(t, GetMilvusEndpoint(ctx, logger, fakeClient, info))

// loadbalancer
info.ServiceType = corev1.ServiceTypeLoadBalancer
mockClient.EXPECT().Get(gomock.Any(), gomock.Any(), gomock.Any()).Do(
func(ctx, k interface{}, v *corev1.Service) {
v.Status.LoadBalancer.Ingress = []corev1.LoadBalancerIngress{
{IP: "1.1.1.1"},
}
})
assert.Equal(t, "1.1.1.1:10086", GetMilvusEndpoint(ctx, logger, mockClient, info))
svc.Status.LoadBalancer.Ingress = []corev1.LoadBalancerIngress{
{IP: "1.1.1.1"},
}
fakeClient = fake.NewClientBuilder().
WithObjects(svc).Build()
assert.Equal(t, "1.1.1.1:10086", GetMilvusEndpoint(ctx, logger, fakeClient, info))

}

Expand Down
10 changes: 5 additions & 5 deletions pkg/controllers/configmaps_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import (
k8sErrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/runtime/schema"

"github.com/golang/mock/gomock"
"github.com/stretchr/testify/assert"
"go.uber.org/mock/gomock"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/yaml"
)
Expand Down Expand Up @@ -69,7 +69,7 @@ func TestReconcileConfigMaps_Existed(t *testing.T) {
gomock.InOrder(
mockClient.EXPECT().
Get(gomock.Any(), gomock.Any(), gomock.AssignableToTypeOf(&corev1.ConfigMap{})).
DoAndReturn(func(ctx context.Context, key client.ObjectKey, obj client.Object) error {
DoAndReturn(func(ctx context.Context, key client.ObjectKey, obj client.Object, opts ...any) error {
cm := obj.(*corev1.ConfigMap)
cm.Namespace = "ns"
cm.Name = "cm1"
Expand All @@ -88,7 +88,7 @@ func TestReconcileConfigMaps_Existed(t *testing.T) {
assert.NoError(t, err)
mockClient.EXPECT().
Get(gomock.Any(), gomock.Any(), gomock.AssignableToTypeOf(&corev1.ConfigMap{})).
DoAndReturn(func(ctx context.Context, key client.ObjectKey, obj client.Object) error {
DoAndReturn(func(ctx context.Context, key client.ObjectKey, obj client.Object, opts ...any) error {
cm := obj.(*corev1.ConfigMap)
cm.Name = "cm1"
cm.Namespace = "ns"
Expand Down Expand Up @@ -118,7 +118,7 @@ func TestReconcileConfigMaps_Existed(t *testing.T) {
gomock.InOrder(
mockClient.EXPECT().
Get(gomock.Any(), gomock.Any(), gomock.AssignableToTypeOf(&corev1.ConfigMap{})).
DoAndReturn(func(ctx context.Context, key client.ObjectKey, obj client.Object) error {
DoAndReturn(func(ctx context.Context, key client.ObjectKey, obj client.Object, opts ...any) error {
cm := obj.(*corev1.ConfigMap)
cm.Namespace = "ns"
cm.Name = "cm1"
Expand All @@ -138,7 +138,7 @@ func TestReconcileConfigMaps_Existed(t *testing.T) {
gomock.InOrder(
mockClient.EXPECT().
Get(gomock.Any(), gomock.Any(), gomock.AssignableToTypeOf(&corev1.ConfigMap{})).
DoAndReturn(func(ctx context.Context, key client.ObjectKey, obj client.Object) error {
DoAndReturn(func(ctx context.Context, key client.ObjectKey, obj client.Object, opts ...any) error {
cm := obj.(*corev1.ConfigMap)
cm.Namespace = "ns"
cm.Name = "cm1"
Expand Down
2 changes: 1 addition & 1 deletion pkg/controllers/dependencies_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ import (
"os"
"testing"

"github.com/golang/mock/gomock"
"github.com/milvus-io/milvus-operator/apis/milvus.io/v1beta1"
"github.com/milvus-io/milvus-operator/pkg/helm"
"github.com/milvus-io/milvus-operator/pkg/util"
"github.com/stretchr/testify/assert"
"go.uber.org/mock/gomock"
"helm.sh/helm/v3/pkg/action"
"helm.sh/helm/v3/pkg/cli"
"helm.sh/helm/v3/pkg/release"
Expand Down
2 changes: 1 addition & 1 deletion pkg/controllers/deploy_ctrl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import (
"errors"
"testing"

"github.com/golang/mock/gomock"
"github.com/milvus-io/milvus-operator/apis/milvus.io/v1beta1"
"github.com/stretchr/testify/assert"
"go.uber.org/mock/gomock"
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
)
Expand Down
2 changes: 1 addition & 1 deletion pkg/controllers/deploy_ctrl_util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import (
"context"
"testing"

"github.com/golang/mock/gomock"
"github.com/milvus-io/milvus-operator/apis/milvus.io/v1beta1"
"github.com/pkg/errors"
"github.com/stretchr/testify/assert"
"go.uber.org/mock/gomock"
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
kerrors "k8s.io/apimachinery/pkg/api/errors"
Expand Down
2 changes: 1 addition & 1 deletion pkg/controllers/deploy_mode_changer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import (
"errors"
"testing"

"github.com/golang/mock/gomock"
"github.com/milvus-io/milvus-operator/apis/milvus.io/v1beta1"
"github.com/stretchr/testify/assert"
"go.uber.org/mock/gomock"
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
kerrors "k8s.io/apimachinery/pkg/api/errors"
Expand Down
2 changes: 1 addition & 1 deletion pkg/controllers/deployment_updater.go
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ func updateSomeFieldsOnlyWhenRolling(template *corev1.PodTemplateSpec, updater d
// We add sleep 30s to hold the SIGTERM so that
// the load balancer controller has enough time to remove it.
container.Lifecycle = &corev1.Lifecycle{
PreStop: &corev1.Handler{
PreStop: &corev1.LifecycleHandler{
Exec: &corev1.ExecAction{
Command: []string{
"sleep",
Expand Down
6 changes: 3 additions & 3 deletions pkg/controllers/deployments_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import (
"context"
"testing"

"github.com/golang/mock/gomock"
"github.com/milvus-io/milvus-operator/apis/milvus.io/v1beta1"
"github.com/pkg/errors"
"github.com/stretchr/testify/assert"
"go.uber.org/mock/gomock"
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
k8sErrors "k8s.io/apimachinery/pkg/api/errors"
Expand Down Expand Up @@ -133,7 +133,7 @@ func TestClusterReconciler_ReconcileDeployments_Existed(t *testing.T) {
mockClient.EXPECT().List(gomock.Any(), gomock.AssignableToTypeOf(&appsv1.DeploymentList{}), gomock.Any()).Return(nil)
mockClient.EXPECT().
Get(gomock.Any(), gomock.Any(), gomock.AssignableToTypeOf(&appsv1.Deployment{})).
DoAndReturn(func(ctx context.Context, key client.ObjectKey, obj client.Object) error {
DoAndReturn(func(ctx context.Context, key client.ObjectKey, obj client.Object, opt ...any) error {
cm := obj.(*appsv1.Deployment)
cm.Namespace = "ns"
cm.Name = "mc"
Expand All @@ -152,7 +152,7 @@ func TestClusterReconciler_ReconcileDeployments_Existed(t *testing.T) {
mockClient.EXPECT().List(gomock.Any(), gomock.AssignableToTypeOf(&appsv1.DeploymentList{}), gomock.Any()).Return(nil)
mockClient.EXPECT().
Get(gomock.Any(), gomock.Any(), gomock.AssignableToTypeOf(&appsv1.Deployment{})).
DoAndReturn(func(ctx context.Context, key client.ObjectKey, obj client.Object) error {
DoAndReturn(func(ctx context.Context, key client.ObjectKey, obj client.Object, opt ...any) error {
cm := obj.(*appsv1.Deployment)
cm.Namespace = "ns"
cm.Name = "mc-xxx"
Expand Down
16 changes: 15 additions & 1 deletion pkg/controllers/external_interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,23 @@ type K8sClient interface {
client.Client
}

// K8sStatusClient for mock K8sClient.Status()
type K8sStatusClient interface {
client.SubResourceWriter
}

// Logger for mock
type Logger interface {
logr.Logger
Enabled() bool
Error(err error, msg string, keysAndValues ...interface{})
GetSink() logr.LogSink
Info(msg string, keysAndValues ...interface{})
V(level int) logr.Logger
WithCallDepth(depth int) logr.Logger
WithCallStackHelper() (func(), logr.Logger)
WithName(name string) logr.Logger
WithSink(sink logr.LogSink) logr.Logger
WithValues(keysAndValues ...interface{}) logr.Logger
}

// PulsarClient for mock
Expand Down
Loading

0 comments on commit 9b5cad7

Please sign in to comment.