Skip to content

Commit

Permalink
chore: add moc default
Browse files Browse the repository at this point in the history
  • Loading branch information
cyberchen98 committed Oct 16, 2024
1 parent d00f3b3 commit b8c6b62
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion pkg/webhook/matrixonecluster_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ package webhook
import (
"context"
"fmt"
admissionv1 "k8s.io/api/admission/v1"
"k8s.io/utils/pointer"

"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/util/validation"
Expand Down Expand Up @@ -68,7 +70,7 @@ type matrixOneClusterDefaulter struct {

var _ webhook.CustomDefaulter = &matrixOneClusterDefaulter{}

func (m *matrixOneClusterDefaulter) Default(_ context.Context, obj runtime.Object) error {
func (m *matrixOneClusterDefaulter) Default(ctx context.Context, obj runtime.Object) error {
moc, ok := obj.(*v1alpha1.MatrixOneCluster)
if !ok {
return unexpectedKindError("MatrixOneCluster", obj)
Expand All @@ -89,6 +91,13 @@ func (m *matrixOneClusterDefaulter) Default(_ context.Context, obj runtime.Objec
for i := range moc.Spec.CNGroups {
m.cn.DefaultSpec(&moc.Spec.CNGroups[i].CNSetSpec)
}
req, err := admission.RequestFromContext(ctx)
if err != nil {
return err
}
if req.AdmissionRequest.Operation == admissionv1.Create && moc.Spec.OperatorVersion == nil {
moc.Spec.OperatorVersion = pointer.String(v1alpha1.LatestOpVersion.String())
}
return nil
}

Expand Down

0 comments on commit b8c6b62

Please sign in to comment.