diff --git a/api/v1alpha1/mysqlcluster_webhook.go b/api/v1alpha1/mysqlcluster_webhook.go index ff67071e..249971bc 100644 --- a/api/v1alpha1/mysqlcluster_webhook.go +++ b/api/v1alpha1/mysqlcluster_webhook.go @@ -65,6 +65,9 @@ func (r *MysqlCluster) ValidateCreate() error { if err := r.ValidMySQLTemplate(); err != nil { return err } + if err := r.validateMysqlVersion(); err != nil { + return err + } return nil } @@ -89,6 +92,12 @@ func (r *MysqlCluster) ValidateUpdate(old runtime.Object) error { if err := r.ValidMySQLTemplate(); err != nil { return err } + if err := r.validateMysqlVersion(); err != nil { + return err + } + if err := r.validateNFSServerAddress(oldCluster); err != nil { + return err + } return nil } @@ -183,3 +192,21 @@ func (r *MysqlCluster) validateMysqlVersionAndImage() error { } return nil } + +// Validate MySQL version and related image. +func (r *MysqlCluster) validateMysqlVersion() error { + switch r.Spec.MysqlVersion { + case "5.7": + if !strings.Contains(r.Spec.PodPolicy.SidecarImage, "57") { + return apierrors.NewForbidden(schema.GroupResource{}, "", fmt.Errorf("spec.MysqlVersion is 5.7, but spec.PodPolicy.SidecarImage is not 5.7")) + } + case "8.0": + if !strings.Contains(r.Spec.PodPolicy.SidecarImage, "80") { + return apierrors.NewForbidden(schema.GroupResource{}, "", fmt.Errorf("spec.MysqlVersion is 8.0, but spec.PodPolicy.SidecarImage is not 8.0")) + } + default: + return apierrors.NewForbidden(schema.GroupResource{}, "", fmt.Errorf("spec.MysqlVersion is not provided")) + + } + return nil +}