Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update controller-runtime #250

Merged
merged 1 commit into from
Feb 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:1.21 as builder
FROM golang:1.23 as builder

WORKDIR /workspace
# ENV GOPROXY https://goproxy.cn
Expand All @@ -23,7 +23,7 @@ RUN make docker-prepare
#
# # Use distroless as minimal base image to package the manager binary
# # Refer to https://github.com/GoogleContainerTools/distroless for more details
FROM alpine:3.18
FROM alpine:3.21
WORKDIR /
COPY --from=builder /workspace/out/ /

Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ deploy-cert-manager:
kubectl wait --timeout=3m --for=condition=Ready pods -l app.kubernetes.io/instance=cert-manager -n cert-manager

undeploy-cert-manager:
kubectl delete -f ${CERT_MANAGER_MANIFEST}
kubectl delete -f ${CERT_MANAGER_MANIFEST}

deploy-manifests: manifests kustomize helm-generate
# add namespace
Expand Down Expand Up @@ -214,7 +214,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.14.0)
$(call go-get-tool,$(CONTROLLER_GEN),sigs.k8s.io/controller-tools/cmd/controller-gen@v0.15.0)

KUSTOMIZE = $(shell pwd)/bin/kustomize
kustomize: ## Download kustomize locally if necessary.
Expand Down
4 changes: 2 additions & 2 deletions apis/milvus.io/v1alpha1/groupversion_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ limitations under the License.
*/

// Package v1alpha1 contains API Schema definitions for the v1alpha1 API group
//+kubebuilder:object:generate=true
//+groupName=milvus.io
// +kubebuilder:object:generate=true
// +groupName=milvus.io
package v1alpha1

import (
Expand Down
8 changes: 4 additions & 4 deletions apis/milvus.io/v1alpha1/milvuscluster_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,9 @@ type MilvusCondition struct {
// +genclient
// +genclient:noStatus

//+kubebuilder:object:root=true
//+kubebuilder:subresource:status
//+kubebuilder:resource:path=milvusclusters,singular=milvuscluster,shortName=mc;mic
// +kubebuilder:object:root=true
// +kubebuilder:subresource:status
// +kubebuilder:resource:path=milvusclusters,singular=milvuscluster,shortName=mc;mic
// MilvusCluster is the Schema for the milvusclusters API
type MilvusCluster struct {
metav1.TypeMeta `json:",inline"`
Expand Down Expand Up @@ -175,7 +175,7 @@ func (r *MilvusCluster) UpdateStatusFrom(src *v1beta1.Milvus) {
r.Status = src.Status
}

//+kubebuilder:object:root=true
// +kubebuilder:object:root=true
// MilvusClusterList contains a list of MilvusCluster
type MilvusClusterList struct {
metav1.TypeMeta `json:",inline"`
Expand Down
4 changes: 2 additions & 2 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.

4 changes: 2 additions & 2 deletions apis/milvus.io/v1beta1/groupversion_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ limitations under the License.
*/

// package v1beta1 contains API Schema definitions for the v1beta1 API group
//+kubebuilder:object:generate=true
//+groupName=milvus.io
// +kubebuilder:object:generate=true
// +groupName=milvus.io
package v1beta1

import (
Expand Down
19 changes: 10 additions & 9 deletions apis/milvus.io/v1beta1/milvus_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
ctrl "sigs.k8s.io/controller-runtime"
logf "sigs.k8s.io/controller-runtime/pkg/log"
"sigs.k8s.io/controller-runtime/pkg/webhook"
"sigs.k8s.io/controller-runtime/pkg/webhook/admission"
)

// log is for logging in this package.
Expand Down Expand Up @@ -64,7 +65,7 @@
var _ webhook.Validator = &Milvus{}

// ValidateCreate implements webhook.Validator so a webhook will be registered for the type
func (r *Milvus) ValidateCreate() error {
func (r *Milvus) ValidateCreate() (admission.Warnings, error) {
var allErrs field.ErrorList
if err := r.validateCommon(); err != nil {
allErrs = append(allErrs, err)
Expand All @@ -75,10 +76,10 @@
}

if len(allErrs) == 0 {
return nil
return nil, nil
}

return apierrors.NewInvalid(schema.GroupKind{Group: GroupVersion.Group, Kind: "Milvus"}, r.Name, allErrs)
return nil, apierrors.NewInvalid(schema.GroupKind{Group: GroupVersion.Group, Kind: "Milvus"}, r.Name, allErrs)
}

func (r *Milvus) validateCommon() *field.Error {
Expand Down Expand Up @@ -130,10 +131,10 @@
}

// ValidateUpdate implements webhook.Validator so a webhook will be registered for the type
func (r *Milvus) ValidateUpdate(old runtime.Object) error {
func (r *Milvus) ValidateUpdate(old runtime.Object) (admission.Warnings, error) {
_, ok := old.(*Milvus)
if !ok {
return errors.Errorf("failed type assertion on kind: %s", old.GetObjectKind().GroupVersionKind().String())
return nil, errors.Errorf("failed type assertion on kind: %s", old.GetObjectKind().GroupVersionKind().String())
}

var allErrs field.ErrorList
Expand All @@ -146,15 +147,15 @@
}

if len(allErrs) == 0 {
return nil
return nil, nil
}

return apierrors.NewInvalid(schema.GroupKind{Group: GroupVersion.Group, Kind: "Milvus"}, r.Name, allErrs)
return nil, apierrors.NewInvalid(schema.GroupKind{Group: GroupVersion.Group, Kind: "Milvus"}, r.Name, allErrs)
}

// ValidateDelete implements webhook.Validator so a webhook will be registered for the type
func (r *Milvus) ValidateDelete() error {
return nil
func (r *Milvus) ValidateDelete() (admission.Warnings, error) {
return nil, nil

Check warning on line 158 in apis/milvus.io/v1beta1/milvus_webhook.go

View check run for this annotation

Codecov / codecov/patch

apis/milvus.io/v1beta1/milvus_webhook.go#L157-L158

Added lines #L157 - L158 were not covered by tests
}

func (r *Milvus) validateExternal() field.ErrorList {
Expand Down
12 changes: 6 additions & 6 deletions apis/milvus.io/v1beta1/milvus_webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ func TestMilvus_Default_DeleteUnSetableOK(t *testing.T) {
func TestMilvus_ValidateCreate_NoError(t *testing.T) {
mc := Milvus{}
mc.Default()
err := mc.ValidateCreate()
_, err := mc.ValidateCreate()
assert.NoError(t, err)
}

Expand All @@ -244,7 +244,7 @@ func TestMilvus_ValidateCreate_Invalid1(t *testing.T) {
},
},
}
err := mc.ValidateCreate()
_, err := mc.ValidateCreate()
assert.Error(t, err)
}

Expand All @@ -265,13 +265,13 @@ func TestMilvus_ValidateCreate_Invalid3(t *testing.T) {
},
}
mc.Default()
err := mc.ValidateCreate()
_, err := mc.ValidateCreate()
assert.Error(t, err)
}

func TestMilvus_ValidateUpdate_NoError(t *testing.T) {
mc := Milvus{}
err := mc.ValidateUpdate(&mc)
_, err := mc.ValidateUpdate(&mc)
assert.NoError(t, err)
}

Expand All @@ -286,14 +286,14 @@ func TestMilvus_ValidateUpdate_Invalid(t *testing.T) {
},
}
old := Milvus{}
err := new.ValidateUpdate(&old)
_, err := new.ValidateUpdate(&old)
assert.Error(t, err)
}

func TestMilvus_ValidateUpdate_KindAssertionFailed(t *testing.T) {
new := Milvus{}
old := appsv1.Deployment{}
err := new.ValidateUpdate(&old)
_, err := new.ValidateUpdate(&old)
assert.Error(t, err)
}

Expand Down
13 changes: 7 additions & 6 deletions apis/milvus.io/v1beta1/milvusupgrade_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
ctrl "sigs.k8s.io/controller-runtime"
logf "sigs.k8s.io/controller-runtime/pkg/log"
"sigs.k8s.io/controller-runtime/pkg/webhook"
"sigs.k8s.io/controller-runtime/pkg/webhook/admission"
)

// log is for logging in this package.
Expand Down Expand Up @@ -47,8 +48,8 @@ func (r *MilvusUpgrade) Default() {
var _ webhook.Validator = &MilvusUpgrade{}

// ValidateCreate implements webhook.Validator so a webhook will be registered for the type
func (r *MilvusUpgrade) ValidateCreate() error {
return r.Validate()
func (r *MilvusUpgrade) ValidateCreate() (admission.Warnings, error) {
return nil, r.Validate()
}

func AddPrefixV(version string) string {
Expand Down Expand Up @@ -100,13 +101,13 @@ func (r MilvusUpgrade) Validate() error {
}

// ValidateUpdate implements webhook.Validator so a webhook will be registered for the type
func (r *MilvusUpgrade) ValidateUpdate(old runtime.Object) error {
func (r *MilvusUpgrade) ValidateUpdate(old runtime.Object) (admission.Warnings, error) {
mulog.Info("validate update", "name", r.Name)
return r.Validate()
return nil, r.Validate()
}

// ValidateDelete implements webhook.Validator so a webhook will be registered for the type
func (r *MilvusUpgrade) ValidateDelete() error {
func (r *MilvusUpgrade) ValidateDelete() (admission.Warnings, error) {
mulog.Info("validate delete", "name", r.Name)
return nil
return nil, nil
}
9 changes: 6 additions & 3 deletions apis/milvus.io/v1beta1/milvusupgrade_webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,11 @@ func TestMilvusUpgrade_Validate(t *testing.T) {
r.Spec.SourceVersion = "2.1.4"
r.Spec.TargetVersion = "2.2.0"
assert.NoError(t, r.Validate())
assert.NoError(t, r.ValidateCreate())
assert.NoError(t, r.ValidateUpdate(r))
assert.NoError(t, r.ValidateDelete())
_, err := r.ValidateCreate()
assert.NoError(t, err)
_, err = r.ValidateUpdate(r)
assert.NoError(t, err)
_, err = r.ValidateDelete()
assert.NoError(t, err)
})
}
4 changes: 2 additions & 2 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.

Loading
Loading