Skip to content

Commit

Permalink
update deps
Browse files Browse the repository at this point in the history
Signed-off-by: obaydullahmhs <[email protected]>
  • Loading branch information
obaydullahmhs committed Jul 30, 2024
1 parent ba04974 commit c17db0a
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func (k *ConnectCluster) ValidateCreate() (admission.Warnings, error) {
if len(allErr) == 0 {
return nil, nil
}
return nil, apierrors.NewInvalid(schema.GroupKind{Group: "kafka.kubedb.com", Kind: "Kafka"}, k.Name, allErr)
return nil, apierrors.NewInvalid(schema.GroupKind{Group: "kafka.kubedb.com", Kind: "ConnectCluster"}, k.Name, allErr)
}

// ValidateUpdate implements webhook.Validator so a webhook will be registered for the type
Expand Down Expand Up @@ -87,9 +87,9 @@ func (k *ConnectCluster) ValidateDelete() (admission.Warnings, error) {

var allErr field.ErrorList
if k.Spec.DeletionPolicy == dbapi.DeletionPolicyDoNotTerminate {
allErr = append(allErr, field.Invalid(field.NewPath("spec").Child("terminationPolicy"),
allErr = append(allErr, field.Invalid(field.NewPath("spec").Child("deletionPolicy"),
k.Name,
"Can not delete as terminationPolicy is set to \"DoNotTerminate\""))
"Can not delete as deletionPolicy is set to \"DoNotTerminate\""))
return nil, apierrors.NewInvalid(schema.GroupKind{Group: "kafka.kubedb.com", Kind: "ConnectCluster"}, k.Name, allErr)
}
return nil, nil
Expand All @@ -112,7 +112,7 @@ func (k *ConnectCluster) ValidateCreateOrUpdate() field.ErrorList {
}

if k.Spec.DeletionPolicy == dbapi.DeletionPolicyHalt {
allErr = append(allErr, field.Invalid(field.NewPath("spec").Child("terminationPolicy"),
allErr = append(allErr, field.Invalid(field.NewPath("spec").Child("deletionPolicy"),
k.Name,
"DeletionPolicyHalt is not supported for ConnectCluster"))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ func (k *Connector) ValidateDelete() (admission.Warnings, error) {

var allErr field.ErrorList
if k.Spec.DeletionPolicy == dbapi.DeletionPolicyDoNotTerminate {
allErr = append(allErr, field.Invalid(field.NewPath("spec").Child("terminationPolicy"),
allErr = append(allErr, field.Invalid(field.NewPath("spec").Child("deletionPolicy"),
k.Name,
"Can not delete as terminationPolicy is set to \"DoNotTerminate\""))
"Can not delete as deletionPolicy is set to \"DoNotTerminate\""))
return nil, apierrors.NewInvalid(schema.GroupKind{Group: "kafka.kubedb.com", Kind: "Connector"}, k.Name, allErr)
}
return nil, nil
Expand All @@ -75,7 +75,7 @@ func (k *Connector) ValidateDelete() (admission.Warnings, error) {
func (k *Connector) ValidateCreateOrUpdate() error {
var allErr field.ErrorList
if k.Spec.DeletionPolicy == dbapi.DeletionPolicyHalt {
allErr = append(allErr, field.Invalid(field.NewPath("spec").Child("terminationPolicy"),
allErr = append(allErr, field.Invalid(field.NewPath("spec").Child("deletionPolicy"),
k.Name,
"DeletionPolicyHalt isn't supported for Connector"))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package v1alpha1

import (
"context"
"fmt"

catalog "kubedb.dev/apimachinery/apis/catalog/v1alpha1"
dbapi "kubedb.dev/apimachinery/apis/kubedb/v1"
Expand Down Expand Up @@ -85,9 +86,9 @@ func (k *RestProxy) ValidateDelete() (admission.Warnings, error) {

var allErr field.ErrorList
if k.Spec.DeletionPolicy == dbapi.DeletionPolicyDoNotTerminate {
allErr = append(allErr, field.Invalid(field.NewPath("spec").Child("terminationPolicy"),
allErr = append(allErr, field.Invalid(field.NewPath("spec").Child("deletionPolicy"),
k.Name,
"Can not delete as terminationPolicy is set to \"DoNotTerminate\""))
"Can not delete as deletionPolicy is set to \"DoNotTerminate\""))
return nil, apierrors.NewInvalid(schema.GroupKind{Group: "kafka.kubedb.com", Kind: "RestProxy"}, k.Name, allErr)
}
return nil, nil
Expand All @@ -96,8 +97,16 @@ func (k *RestProxy) ValidateDelete() (admission.Warnings, error) {
func (k *RestProxy) ValidateCreateOrUpdate() field.ErrorList {
var allErr field.ErrorList

err := k.validateVersion()
if err != nil {
allErr = append(allErr, field.Invalid(field.NewPath("spec").Child("version"),
k.Name,
err.Error()))
return allErr
}

if k.Spec.DeletionPolicy == dbapi.DeletionPolicyHalt {
allErr = append(allErr, field.Invalid(field.NewPath("spec").Child("terminationPolicy"),
allErr = append(allErr, field.Invalid(field.NewPath("spec").Child("deletionPolicy"),
k.Name,
"DeletionPolicyHalt is not supported for RestProxy"))
}
Expand All @@ -109,13 +118,6 @@ func (k *RestProxy) ValidateCreateOrUpdate() field.ErrorList {
"number of replicas can not be 0 or less"))
}

err := k.validateVersion()
if err != nil {
allErr = append(allErr, field.Invalid(field.NewPath("spec").Child("version"),
k.Name,
err.Error()))
}

err = k.validateVolumes()
if err != nil {
allErr = append(allErr, field.Invalid(field.NewPath("spec").Child("podTemplate").Child("spec").Child("volumes"),
Expand All @@ -130,37 +132,27 @@ func (k *RestProxy) ValidateCreateOrUpdate() field.ErrorList {
err.Error()))
}

err = k.validateEnvVars()
if err != nil {
allErr = append(allErr, field.Invalid(field.NewPath("spec").Child("podTemplate").Child("spec").Child("containers").Child("envs"),
k.Name,
err.Error()))
}

if len(allErr) == 0 {
return nil
}
return allErr
}

func (k *RestProxy) validateEnvVars() error {
return nil
}

func (k *RestProxy) validateVersion() error {
ksrVersion := &catalog.SchemaRegistryVersion{}
err := DefaultClient.Get(context.TODO(), types.NamespacedName{Name: k.Spec.Version}, ksrVersion)
if err != nil {
return errors.New("version not supported")
}
if ksrVersion.Spec.Distribution == catalog.SchemaRegistryDistroApicurio {
return errors.New("Distribution Apicurio is not supported")
if ksrVersion.Spec.Distribution != catalog.SchemaRegistryDistroAiven {
return errors.New(fmt.Sprintf("Distribution %s is not supported, only supported distribution is Aiven", ksrVersion.Spec.Distribution))
}
return nil
}

var restProxyReservedVolumes = []string{
KafkaClientCertVolumeName,
RestProxyOperatorVolumeConfig,
}

func (k *RestProxy) validateVolumes() error {
Expand All @@ -182,6 +174,7 @@ func (k *RestProxy) validateVolumes() error {

var restProxyReservedVolumeMountPaths = []string{
KafkaClientCertDir,
RestProxyOperatorVolumeConfig,
}

func (k *RestProxy) validateContainerVolumeMountPaths() error {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,9 @@ func (k *SchemaRegistry) ValidateDelete() (admission.Warnings, error) {

var allErr field.ErrorList
if k.Spec.DeletionPolicy == dbapi.DeletionPolicyDoNotTerminate {
allErr = append(allErr, field.Invalid(field.NewPath("spec").Child("terminationPolicy"),
allErr = append(allErr, field.Invalid(field.NewPath("spec").Child("deletionPolicy"),
k.Name,
"Can not delete as terminationPolicy is set to \"DoNotTerminate\""))
"Can not delete as deletionPolicy is set to \"DoNotTerminate\""))
return nil, apierrors.NewInvalid(schema.GroupKind{Group: "kafka.kubedb.com", Kind: "SchemaRegistry"}, k.Name, allErr)
}
return nil, nil
Expand All @@ -97,7 +97,7 @@ func (k *SchemaRegistry) ValidateCreateOrUpdate() field.ErrorList {
var allErr field.ErrorList

if k.Spec.DeletionPolicy == dbapi.DeletionPolicyHalt {
allErr = append(allErr, field.Invalid(field.NewPath("spec").Child("terminationPolicy"),
allErr = append(allErr, field.Invalid(field.NewPath("spec").Child("deletionPolicy"),
k.Name,
"DeletionPolicyHalt is not supported for SchemaRegistry"))
}
Expand Down

0 comments on commit c17db0a

Please sign in to comment.