Skip to content

Commit

Permalink
on premises automation has been removed by default
Browse files Browse the repository at this point in the history
  • Loading branch information
testisnullus committed Jan 22, 2024
1 parent 8ff29e9 commit ad1c45f
Show file tree
Hide file tree
Showing 29 changed files with 208 additions and 51 deletions.
29 changes: 20 additions & 9 deletions apis/clusters/v1beta1/cadence_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (

"k8s.io/apimachinery/pkg/runtime"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
logf "sigs.k8s.io/controller-runtime/pkg/log"
"sigs.k8s.io/controller-runtime/pkg/webhook"

Expand All @@ -33,13 +34,15 @@ import (
var cadencelog = logf.Log.WithName("cadence-resource")

type cadenceValidator struct {
API validation.Validation
API validation.Validation
Client client.Client
}

func (c *Cadence) SetupWebhookWithManager(mgr ctrl.Manager, api validation.Validation) error {
return ctrl.NewWebhookManagedBy(mgr).
For(c).WithValidator(webhook.CustomValidator(&cadenceValidator{
API: api,
API: api,
Client: mgr.GetClient(),
})).
Complete()
}
Expand Down Expand Up @@ -86,7 +89,15 @@ func (cv *cadenceValidator) ValidateCreate(ctx context.Context, obj runtime.Obje
return err
}

if c.Spec.OnPremisesSpec != nil {
contains, err := ContainsKubeVirtAddon(ctx, cv.Client)
if err != nil {
return err
}

if c.Spec.OnPremisesSpec != nil && c.Spec.OnPremisesSpec.EnableAutomation {
if !contains {
return models.ErrKubeVirtAddonNotFound
}
err = c.Spec.OnPremisesSpec.ValidateCreation()
if err != nil {
return err
Expand Down Expand Up @@ -135,7 +146,7 @@ func (cv *cadenceValidator) ValidateCreate(ctx context.Context, obj runtime.Obje
}

for _, awsArchival := range c.Spec.AWSArchival {
err := awsArchival.validate()
err = awsArchival.validate()
if err != nil {
return err
}
Expand All @@ -146,7 +157,7 @@ func (cv *cadenceValidator) ValidateCreate(ctx context.Context, obj runtime.Obje
return fmt.Errorf("AdvancedVisibility array size must be between 0 and 1")
}

err := sp.validate()
err = sp.validate()
if err != nil {
return err
}
Expand All @@ -158,7 +169,7 @@ func (cv *cadenceValidator) ValidateCreate(ctx context.Context, obj runtime.Obje
}

if pp.BundledKafkaSpec != nil {
err := pp.BundledKafkaSpec.validate()
err = pp.BundledKafkaSpec.validate()
if err != nil {
return err
}
Expand Down Expand Up @@ -194,12 +205,12 @@ func (cv *cadenceValidator) ValidateCreate(ctx context.Context, obj runtime.Obje

for _, dc := range c.Spec.DataCentres {
if c.Spec.OnPremisesSpec != nil {
err := dc.DataCentre.ValidateOnPremisesCreation()
err = dc.DataCentre.ValidateOnPremisesCreation()
if err != nil {
return err
}
} else {
err := dc.DataCentre.ValidateCreation()
err = dc.DataCentre.ValidateCreation()
if err != nil {
return err
}
Expand All @@ -215,7 +226,7 @@ func (cv *cadenceValidator) ValidateCreate(ctx context.Context, obj runtime.Obje
}

for _, rs := range c.Spec.ResizeSettings {
err := validateSingleConcurrentResize(rs.Concurrency)
err = validateSingleConcurrentResize(rs.Concurrency)
if err != nil {
return err
}
Expand Down
24 changes: 19 additions & 5 deletions apis/clusters/v1beta1/cassandra_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (

"k8s.io/apimachinery/pkg/runtime"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
logf "sigs.k8s.io/controller-runtime/pkg/log"
"sigs.k8s.io/controller-runtime/pkg/webhook"

Expand All @@ -32,20 +33,24 @@ import (
var cassandralog = logf.Log.WithName("cassandra-resource")

type cassandraValidator struct {
API validation.Validation
Client client.Client
API validation.Validation
}

func (r *Cassandra) SetupWebhookWithManager(mgr ctrl.Manager, api validation.Validation) error {
return ctrl.NewWebhookManagedBy(mgr).
For(r).WithValidator(webhook.CustomValidator(&cassandraValidator{
API: api,
Client: mgr.GetClient(),
API: api,
})).
Complete()
}

// TODO(user): change verbs to "verbs=create;update;delete" if you want to enable deletion validation.
//+kubebuilder:webhook:path=/mutate-clusters-instaclustr-com-v1beta1-cassandra,mutating=true,failurePolicy=fail,sideEffects=None,groups=clusters.instaclustr.com,resources=cassandras,verbs=create;update,versions=v1beta1,name=mcassandra.kb.io,admissionReviewVersions=v1
//+kubebuilder:webhook:path=/validate-clusters-instaclustr-com-v1beta1-cassandra,mutating=false,failurePolicy=fail,sideEffects=None,groups=clusters.instaclustr.com,resources=cassandras,verbs=create;update,versions=v1beta1,name=vcassandra.kb.io,admissionReviewVersions=v1
//+kubebuilder:rbac:groups="",resources=namespaces,verbs=get;list;watch
//+kubebuilder:rbac:groups="apps",resources=deployments,verbs=get;list;watch

var _ webhook.CustomValidator = &cassandraValidator{}
var _ webhook.Defaulter = &Cassandra{}
Expand Down Expand Up @@ -91,7 +96,16 @@ func (cv *cassandraValidator) ValidateCreate(ctx context.Context, obj runtime.Ob
return err
}

if c.Spec.OnPremisesSpec != nil {
contains, err := ContainsKubeVirtAddon(ctx, cv.Client)
if err != nil {
return err
}

if c.Spec.OnPremisesSpec != nil && c.Spec.OnPremisesSpec.EnableAutomation {
if !contains {
return models.ErrKubeVirtAddonNotFound
}

err = c.Spec.OnPremisesSpec.ValidateCreation()
if err != nil {
return err
Expand Down Expand Up @@ -126,12 +140,12 @@ func (cv *cassandraValidator) ValidateCreate(ctx context.Context, obj runtime.Ob

for _, dc := range c.Spec.DataCentres {
if c.Spec.OnPremisesSpec != nil {
err := dc.DataCentre.ValidateOnPremisesCreation()
err = dc.DataCentre.ValidateOnPremisesCreation()
if err != nil {
return err
}
} else {
err := dc.DataCentre.ValidateCreation()
err = dc.DataCentre.ValidateCreation()
if err != nil {
return err
}
Expand Down
24 changes: 17 additions & 7 deletions apis/clusters/v1beta1/kafka_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ package v1beta1
import (
"context"
"fmt"

"k8s.io/apimachinery/pkg/runtime"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
logf "sigs.k8s.io/controller-runtime/pkg/log"
"sigs.k8s.io/controller-runtime/pkg/webhook"

Expand All @@ -32,13 +32,15 @@ import (
var kafkalog = logf.Log.WithName("kafka-resource")

type kafkaValidator struct {
API validation.Validation
API validation.Validation
Client client.Client
}

func (r *Kafka) SetupWebhookWithManager(mgr ctrl.Manager, api validation.Validation) error {
return ctrl.NewWebhookManagedBy(mgr).
For(r).WithValidator(webhook.CustomValidator(&kafkaValidator{
API: api,
API: api,
Client: mgr.GetClient(),
})).
Complete()
}
Expand Down Expand Up @@ -85,7 +87,15 @@ func (kv *kafkaValidator) ValidateCreate(ctx context.Context, obj runtime.Object
return err
}

if k.Spec.OnPremisesSpec != nil {
contains, err := ContainsKubeVirtAddon(ctx, kv.Client)
if err != nil {
return err
}

if k.Spec.OnPremisesSpec != nil && k.Spec.OnPremisesSpec.EnableAutomation {
if !contains {
return models.ErrKubeVirtAddonNotFound
}
err = k.Spec.OnPremisesSpec.ValidateCreation()
if err != nil {
return err
Expand Down Expand Up @@ -120,12 +130,12 @@ func (kv *kafkaValidator) ValidateCreate(ctx context.Context, obj runtime.Object

for _, dc := range k.Spec.DataCentres {
if k.Spec.OnPremisesSpec != nil {
err := dc.DataCentre.ValidateOnPremisesCreation()
err = dc.DataCentre.ValidateOnPremisesCreation()
if err != nil {
return err
}
} else {
err := dc.DataCentre.ValidateCreation()
err = dc.DataCentre.ValidateCreation()
if err != nil {
return err
}
Expand Down Expand Up @@ -170,7 +180,7 @@ func (kv *kafkaValidator) ValidateCreate(ctx context.Context, obj runtime.Object
}

for _, rs := range k.Spec.ResizeSettings {
err := validateSingleConcurrentResize(rs.Concurrency)
err = validateSingleConcurrentResize(rs.Concurrency)
if err != nil {
return err
}
Expand Down
21 changes: 16 additions & 5 deletions apis/clusters/v1beta1/kafkaconnect_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (

"k8s.io/apimachinery/pkg/runtime"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
logf "sigs.k8s.io/controller-runtime/pkg/log"
"sigs.k8s.io/controller-runtime/pkg/webhook"

Expand All @@ -33,13 +34,15 @@ import (
var kafkaconnectlog = logf.Log.WithName("kafkaconnect-resource")

type kafkaConnectValidator struct {
API validation.Validation
API validation.Validation
Client client.Client
}

func (r *KafkaConnect) SetupWebhookWithManager(mgr ctrl.Manager, api validation.Validation) error {
return ctrl.NewWebhookManagedBy(mgr).
For(r).WithValidator(webhook.CustomValidator(&kafkaConnectValidator{
API: api,
API: api,
Client: mgr.GetClient(),
})).
Complete()
}
Expand Down Expand Up @@ -86,7 +89,15 @@ func (kcv *kafkaConnectValidator) ValidateCreate(ctx context.Context, obj runtim
return err
}

if kc.Spec.OnPremisesSpec != nil {
contains, err := ContainsKubeVirtAddon(ctx, kcv.Client)
if err != nil {
return err
}

if kc.Spec.OnPremisesSpec != nil && kc.Spec.OnPremisesSpec.EnableAutomation {
if !contains {
return models.ErrKubeVirtAddonNotFound
}
err = kc.Spec.OnPremisesSpec.ValidateCreation()
if err != nil {
return err
Expand Down Expand Up @@ -157,12 +168,12 @@ func (kcv *kafkaConnectValidator) ValidateCreate(ctx context.Context, obj runtim

for _, dc := range kc.Spec.DataCentres {
if kc.Spec.OnPremisesSpec != nil {
err := dc.DataCentre.ValidateOnPremisesCreation()
err = dc.DataCentre.ValidateOnPremisesCreation()
if err != nil {
return err
}
} else {
err := dc.DataCentre.ValidateCreation()
err = dc.DataCentre.ValidateCreation()
if err != nil {
return err
}
Expand Down
16 changes: 12 additions & 4 deletions apis/clusters/v1beta1/postgresql_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,15 @@ func (pgv *pgValidator) ValidateCreate(ctx context.Context, obj runtime.Object)
return err
}

if pg.Spec.OnPremisesSpec != nil {
contains, err := ContainsKubeVirtAddon(ctx, pgv.K8sClient)
if err != nil {
return err
}

if pg.Spec.OnPremisesSpec != nil && pg.Spec.OnPremisesSpec.EnableAutomation {
if !contains {
return models.ErrKubeVirtAddonNotFound
}
err = pg.Spec.OnPremisesSpec.ValidateCreation()
if err != nil {
return err
Expand Down Expand Up @@ -138,12 +146,12 @@ func (pgv *pgValidator) ValidateCreate(ctx context.Context, obj runtime.Object)

for _, dc := range pg.Spec.DataCentres {
if pg.Spec.OnPremisesSpec != nil {
err := dc.DataCentre.ValidateOnPremisesCreation()
err = dc.DataCentre.ValidateOnPremisesCreation()
if err != nil {
return err
}
} else {
err := dc.DataCentre.ValidateCreation()
err = dc.DataCentre.ValidateCreation()
if err != nil {
return err
}
Expand All @@ -170,7 +178,7 @@ func (pgv *pgValidator) ValidateCreate(ctx context.Context, obj runtime.Object)
}

for _, rs := range pg.Spec.ResizeSettings {
err := validateSingleConcurrentResize(rs.Concurrency)
err = validateSingleConcurrentResize(rs.Concurrency)
if err != nil {
return err
}
Expand Down
23 changes: 17 additions & 6 deletions apis/clusters/v1beta1/redis_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (

"k8s.io/apimachinery/pkg/runtime"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
logf "sigs.k8s.io/controller-runtime/pkg/log"
"sigs.k8s.io/controller-runtime/pkg/webhook"

Expand All @@ -32,13 +33,15 @@ import (
var redislog = logf.Log.WithName("redis-resource")

type redisValidator struct {
API validation.Validation
API validation.Validation
Client client.Client
}

func (r *Redis) SetupWebhookWithManager(mgr ctrl.Manager, api validation.Validation) error {
return ctrl.NewWebhookManagedBy(mgr).
For(r).WithValidator(webhook.CustomValidator(&redisValidator{
API: api,
API: api,
Client: mgr.GetClient(),
})).
Complete()
}
Expand Down Expand Up @@ -94,7 +97,15 @@ func (rv *redisValidator) ValidateCreate(ctx context.Context, obj runtime.Object
return err
}

if r.Spec.OnPremisesSpec != nil {
contains, err := ContainsKubeVirtAddon(ctx, rv.Client)
if err != nil {
return err
}

if r.Spec.OnPremisesSpec != nil && r.Spec.OnPremisesSpec.EnableAutomation {
if !contains {
return models.ErrKubeVirtAddonNotFound
}
err = r.Spec.OnPremisesSpec.ValidateCreation()
if err != nil {
return err
Expand Down Expand Up @@ -136,12 +147,12 @@ func (rv *redisValidator) ValidateCreate(ctx context.Context, obj runtime.Object

for _, dc := range r.Spec.DataCentres {
if r.Spec.OnPremisesSpec != nil {
err := dc.DataCentre.ValidateOnPremisesCreation()
err = dc.DataCentre.ValidateOnPremisesCreation()
if err != nil {
return err
}
} else {
err := dc.ValidateCreate()
err = dc.DataCentre.ValidateCreation()
if err != nil {
return err
}
Expand All @@ -153,7 +164,7 @@ func (rv *redisValidator) ValidateCreate(ctx context.Context, obj runtime.Object
}

for _, rs := range r.Spec.ResizeSettings {
err := validateSingleConcurrentResize(rs.Concurrency)
err = validateSingleConcurrentResize(rs.Concurrency)
if err != nil {
return err
}
Expand Down
Loading

0 comments on commit ad1c45f

Please sign in to comment.