Skip to content
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
6 changes: 2 additions & 4 deletions apis/nodecore/v1alpha1/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,8 @@ type Configuration struct {

// LiqoCredentials contains the credentials of a Liqo cluster to enstablish a peering.
type LiqoCredentials struct {
ClusterID string `json:"clusterID"`
ClusterName string `json:"clusterName"`
Token string `json:"token"`
Endpoint string `json:"endpoint"`
ClusterID string `json:"liqoID"`
Kubeconfig string `json:"kubeconfig"`
}

// ParseConfiguration parses the configuration data into the correct type.
Expand Down
43 changes: 29 additions & 14 deletions apis/nodecore/v1alpha1/flavor_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
package v1alpha1

import (
"context"

"k8s.io/apimachinery/pkg/runtime"
ctrl "sigs.k8s.io/controller-runtime"
logf "sigs.k8s.io/controller-runtime/pkg/log"
Expand All @@ -28,34 +30,43 @@ var flavorlog = logf.Log.WithName("flavor-resource")
// SetupWebhookWithManager setups the webhooks for the Flavor resource with the manager.
func (r *Flavor) SetupWebhookWithManager(mgr ctrl.Manager) error {
return ctrl.NewWebhookManagedBy(mgr).
For(r).
For(&Flavor{}).
WithDefaulter(&Flavor{}).
WithValidator(&Flavor{}).
Complete()
}

//nolint:lll // kubebuilder directives are too long, but they must be on the same line
//+kubebuilder:webhook:path=/mutate-nodecore-fluidos-eu-v1alpha1-flavor,mutating=true,failurePolicy=fail,sideEffects=None,groups=nodecore.fluidos.eu,resources=flavors,verbs=create;update,versions=v1alpha1,name=mflavor.kb.io,admissionReviewVersions=v1

var _ webhook.Defaulter = &Flavor{}
var _ webhook.CustomDefaulter = &Flavor{}

// Default implements webhook.Defaulter so a webhook will be registered for the type.
func (r *Flavor) Default() {
func (r *Flavor) Default(ctx context.Context, obj runtime.Object) error {
_ = ctx
// Parse obj to Flavor
flavor := obj.(*Flavor)
flavorlog.Info("DEFAULT WEBHOOK")
flavorlog.Info("default", "name", r.Name)
flavorlog.Info("default", "name", flavor.Name)

return nil
}

// TODO(user): change verbs to "verbs=create;update;delete" if you want to enable deletion validation.
//nolint:lll // kubebuilder directives are too long, but they must be on the same line
//+kubebuilder:webhook:path=/validate-nodecore-fluidos-eu-v1alpha1-flavor,mutating=false,failurePolicy=fail,sideEffects=None,groups=nodecore.fluidos.eu,resources=flavors,verbs=create;update,versions=v1alpha1,name=vflavor.kb.io,admissionReviewVersions=v1

var _ webhook.Validator = &Flavor{}
var _ webhook.CustomValidator = &Flavor{}

// ValidateCreate implements webhook.Validator so a webhook will be registered for the type.
func (r *Flavor) ValidateCreate() (admission.Warnings, error) {
func (r *Flavor) ValidateCreate(ctx context.Context, obj runtime.Object) (admission.Warnings, error) {
_ = ctx
flavor := obj.(*Flavor)
flavorlog.Info("VALIDATE CREATE WEBHOOK")
flavorlog.Info("validate create", "name", r.Name)
flavorlog.Info("validate create", "name", flavor.Name)

// Validate creation of Flavor checking FlavorType->TypeIdenfier matches the struct inside the FlavorType->TypeData
typeIdenfier, _, err := ParseFlavorType(r)
typeIdenfier, _, err := ParseFlavorType(flavor)
if err != nil {
return nil, err
}
Expand All @@ -74,14 +85,16 @@ func (r *Flavor) ValidateCreate() (admission.Warnings, error) {
}

// ValidateUpdate implements webhook.Validator so a webhook will be registered for the type.
func (r *Flavor) ValidateUpdate(old runtime.Object) (admission.Warnings, error) {
func (r *Flavor) ValidateUpdate(ctx context.Context, oldObj, newObj runtime.Object) (admission.Warnings, error) {
_ = ctx
flavor := newObj.(*Flavor)
flavorlog.Info("VALIDATE UPDATE WEBHOOK")
flavorlog.Info("validate update", "name", r.Name)
flavorlog.Info("validate update", "name", flavor.Name)

flavorlog.Info("old", "old", old)
flavorlog.Info("old", "old", oldObj)

// Validate creation of Flavor checking FlavorType->TypeIdenfier matches the struct inside the FlavorType->TypeData
typeIdenfier, _, err := ParseFlavorType(r)
typeIdenfier, _, err := ParseFlavorType(flavor)
if err != nil {
return nil, err
}
Expand All @@ -100,9 +113,11 @@ func (r *Flavor) ValidateUpdate(old runtime.Object) (admission.Warnings, error)
}

// ValidateDelete implements webhook.Validator so a webhook will be registered for the type.
func (r *Flavor) ValidateDelete() (admission.Warnings, error) {
func (r *Flavor) ValidateDelete(ctx context.Context, obj runtime.Object) (admission.Warnings, error) {
_ = ctx
flavor := obj.(*Flavor)
flavorlog.Info("VALIDATE DELETE WEBHOOK")
flavorlog.Info("validate delete", "name", r.Name)
flavorlog.Info("validate delete", "name", flavor.Name)

// TODO(user): fill in your validation logic upon object deletion.
return nil, nil
Expand Down
42 changes: 28 additions & 14 deletions apis/nodecore/v1alpha1/service_blueprint_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
package v1alpha1

import (
"context"

"k8s.io/apimachinery/pkg/runtime"
ctrl "sigs.k8s.io/controller-runtime"
logf "sigs.k8s.io/controller-runtime/pkg/log"
Expand All @@ -28,34 +30,42 @@ var serviceblueprintlog = logf.Log.WithName("serviceblueprint-resource")
// SetupWebhookWithManager setups the webhooks for the ServiceBlueprint resource with the manager.
func (r *ServiceBlueprint) SetupWebhookWithManager(mgr ctrl.Manager) error {
return ctrl.NewWebhookManagedBy(mgr).
For(r).
For(&ServiceBlueprint{}).
WithDefaulter(&ServiceBlueprint{}).
WithValidator(&ServiceBlueprint{}).
Complete()
}

//nolint:lll // kubebuilder directives are too long, but they must be on the same line
//+kubebuilder:webhook:path=/mutate-nodecore-fluidos-eu-v1alpha1-serviceblueprint,mutating=true,failurePolicy=fail,sideEffects=None,groups=nodecore.fluidos.eu,resources=serviceblueprints,verbs=create;update,versions=v1alpha1,name=mserviceblueprint.kb.io,admissionReviewVersions=v1

var _ webhook.Defaulter = &ServiceBlueprint{}
var _ webhook.CustomDefaulter = &ServiceBlueprint{}

// Default implements webhook.Defaulter so a webhook will be registered for the type.
func (r *ServiceBlueprint) Default() {
func (r *ServiceBlueprint) Default(ctx context.Context, obj runtime.Object) error {
_ = ctx
serviceblueprint := obj.(*ServiceBlueprint)
serviceblueprintlog.Info("DEFAULT WEBHOOK")
serviceblueprintlog.Info("default", "name", r.Name)
serviceblueprintlog.Info("default", "name", serviceblueprint.Name)

return nil
}

// TODO(user): change verbs to "verbs=create;update;delete" if you want to enable deletion validation.
//nolint:lll // kubebuilder directives are too long, but they must be on the same line
//+kubebuilder:webhook:path=/validate-nodecore-fluidos-eu-v1alpha1-serviceblueprint,mutating=false,failurePolicy=fail,sideEffects=None,groups=nodecore.fluidos.eu,resources=serviceblueprints,verbs=create;update,versions=v1alpha1,name=vserviceblueprint.kb.io,admissionReviewVersions=v1

var _ webhook.Validator = &ServiceBlueprint{}
var _ webhook.CustomValidator = &ServiceBlueprint{}

// ValidateCreate implements webhook.Validator so a webhook will be registered for the type.
func (r *ServiceBlueprint) ValidateCreate() (admission.Warnings, error) {
func (r *ServiceBlueprint) ValidateCreate(ctx context.Context, obj runtime.Object) (admission.Warnings, error) {
_ = ctx
serviceblueprint := obj.(*ServiceBlueprint)
serviceblueprintlog.Info("VALIDATE CREATE WEBHOOK")
serviceblueprintlog.Info("validate create", "name", r.Name)
serviceblueprintlog.Info("validate create", "name", serviceblueprint.Name)

// Validate ServiceBlueprint templates
manifests, err := ValidateAndExtractManifests(r.Spec.Templates)
manifests, err := ValidateAndExtractManifests(serviceblueprint.Spec.Templates)
if err != nil {
return nil, err
}
Expand All @@ -67,14 +77,16 @@ func (r *ServiceBlueprint) ValidateCreate() (admission.Warnings, error) {
}

// ValidateUpdate implements webhook.Validator so a webhook will be registered for the type.
func (r *ServiceBlueprint) ValidateUpdate(old runtime.Object) (admission.Warnings, error) {
func (r *ServiceBlueprint) ValidateUpdate(ctx context.Context, oldObj, newObj runtime.Object) (admission.Warnings, error) {
_ = ctx
serviceblueprint := newObj.(*ServiceBlueprint)
serviceblueprintlog.Info("VALIDATE UPDATE WEBHOOK")
serviceblueprintlog.Info("validate update", "name", r.Name)
serviceblueprintlog.Info("validate update", "name", serviceblueprint.Name)

serviceblueprintlog.Info("old", "old", old)
serviceblueprintlog.Info("old", "old", oldObj)

// Validate ServiceBlueprint templates
manifests, err := ValidateAndExtractManifests(r.Spec.Templates)
manifests, err := ValidateAndExtractManifests(serviceblueprint.Spec.Templates)
if err != nil {
return nil, err
}
Expand All @@ -86,9 +98,11 @@ func (r *ServiceBlueprint) ValidateUpdate(old runtime.Object) (admission.Warning
}

// ValidateDelete implements webhook.Validator so a webhook will be registered for the type.
func (r *ServiceBlueprint) ValidateDelete() (admission.Warnings, error) {
func (r *ServiceBlueprint) ValidateDelete(ctx context.Context, obj runtime.Object) (admission.Warnings, error) {
_ = ctx
serviceblueprint := obj.(*ServiceBlueprint)
serviceblueprintlog.Info("VALIDATE DELETE WEBHOOK")
serviceblueprintlog.Info("validate delete", "name", r.Name)
serviceblueprintlog.Info("validate delete", "name", serviceblueprint.Name)

// TODO(user): fill in your validation logic upon object deletion.
return nil, nil
Expand Down
42 changes: 28 additions & 14 deletions apis/nodecore/v1alpha1/solver_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
package v1alpha1

import (
"context"

"k8s.io/apimachinery/pkg/runtime"
ctrl "sigs.k8s.io/controller-runtime"
logf "sigs.k8s.io/controller-runtime/pkg/log"
Expand All @@ -28,57 +30,69 @@ var solverlog = logf.Log.WithName("solver-resource")
// SetupWebhookWithManager sets up and registers the webhook with the manager.
func (r *Solver) SetupWebhookWithManager(mgr ctrl.Manager) error {
return ctrl.NewWebhookManagedBy(mgr).
For(r).
For(&Solver{}).
WithDefaulter(&Solver{}).
WithValidator(&Solver{}).
Complete()
}

//nolint:lll // kubebuilder directives are too long, but they must be on the same line
//+kubebuilder:webhook:path=/mutate-nodecore-fluidos-eu-v1alpha1-solver,mutating=true,failurePolicy=fail,sideEffects=None,groups=nodecore.fluidos.eu,resources=solvers,verbs=create;update,versions=v1alpha1,name=msolver.kb.io,admissionReviewVersions=v1

var _ webhook.Defaulter = &Solver{}
var _ webhook.CustomDefaulter = &Solver{}

// Default implements webhook.Defaulter so a webhook will be registered for the type.
func (r *Solver) Default() {
func (r *Solver) Default(ctx context.Context, obj runtime.Object) error {
_ = ctx
solver := obj.(*Solver)
solverlog.Info("DEFAULT WEBHOOK")
solverlog.Info("default", "name", r.Name)
solverlog.Info("default", "name", solver.Name)

return nil
}

// TODO(user): change verbs to "verbs=create;update;delete" if you want to enable deletion validation.
//nolint:lll // kubebuilder directives are too long, but they must be on the same line
//+kubebuilder:webhook:path=/validate-nodecore-fluidos-eu-v1alpha1-solver,mutating=false,failurePolicy=fail,sideEffects=None,groups=nodecore.fluidos.eu,resources=solvers,verbs=create;update,versions=v1alpha1,name=vsolver.kb.io,admissionReviewVersions=v1

var _ webhook.Validator = &Solver{}
var _ webhook.CustomValidator = &Solver{}

// ValidateCreate implements webhook.Validator so a webhook will be registered for the type.
func (r *Solver) ValidateCreate() (admission.Warnings, error) {
func (r *Solver) ValidateCreate(ctx context.Context, obj runtime.Object) (admission.Warnings, error) {
_ = ctx
solver := obj.(*Solver)
solverlog.Info("VALIDATE CREATE WEBHOOK")
solverlog.Info("validate create", "name", r.Name)
solverlog.Info("validate create", "name", solver.Name)

if err := validateSelector(r.Spec.Selector); err != nil {
if err := validateSelector(solver.Spec.Selector); err != nil {
return nil, err
}

return nil, nil
}

// ValidateUpdate implements webhook.Validator so a webhook will be registered for the type.
func (r *Solver) ValidateUpdate(old runtime.Object) (admission.Warnings, error) {
func (r *Solver) ValidateUpdate(ctx context.Context, oldObj, newObj runtime.Object) (admission.Warnings, error) {
_ = ctx
solver := newObj.(*Solver)
solverlog.Info("VALIDATE UPDATE WEBHOOK")
solverlog.Info("validate update", "name", r.Name)
solverlog.Info("validate update", "name", solver.Name)

solverlog.Info("old", "old", old)
solverlog.Info("old", "old", oldObj)

if err := validateSelector(r.Spec.Selector); err != nil {
if err := validateSelector(solver.Spec.Selector); err != nil {
return nil, err
}

return nil, nil
}

// ValidateDelete implements webhook.Validator so a webhook will be registered for the type.
func (r *Solver) ValidateDelete() (admission.Warnings, error) {
func (r *Solver) ValidateDelete(ctx context.Context, obj runtime.Object) (admission.Warnings, error) {
_ = ctx
solver := obj.(*Solver)
solverlog.Info("VALIDATE DELETE WEBHOOK")
solverlog.Info("validate delete", "name", r.Name)
solverlog.Info("validate delete", "name", solver.Name)

// TODO(user): fill in your validation logic upon object deletion.
return nil, nil
Expand Down
44 changes: 29 additions & 15 deletions apis/reservation/v1alpha1/contract_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
package v1alpha1

import (
"context"

"k8s.io/apimachinery/pkg/runtime"
ctrl "sigs.k8s.io/controller-runtime"
logf "sigs.k8s.io/controller-runtime/pkg/log"
Expand All @@ -27,60 +29,72 @@ import (
// log is for logging in this package.
var contractlog = logf.Log.WithName("contract-resource")

// SetupWebhookWithManager sets up and registers the webhook with the manager.
// SetupWebhookWithManager sets up and registers the webhook with the managecontract.
func (r *Contract) SetupWebhookWithManager(mgr ctrl.Manager) error {
return ctrl.NewWebhookManagedBy(mgr).
For(r).
For(&Contract{}).
WithDefaulter(&Contract{}).
WithValidator(&Contract{}).
Complete()
}

//nolint:lll // kubebuilder directives are too long, but they must be on the same line
//+kubebuilder:webhook:path=/mutate-contract-fluidos-eu-v1alpha1-contract,mutating=true,failurePolicy=fail,sideEffects=None,groups=contract.fluidos.eu,resources=contracts,verbs=create;update,versions=v1alpha1,name=mcontract.kb.io,admissionReviewVersions=v1

var _ webhook.Defaulter = &Contract{}
var _ webhook.CustomDefaulter = &Contract{}

// Default implements webhook.Defaulter so a webhook will be registered for the type.
func (r *Contract) Default() {
func (r *Contract) Default(ctx context.Context, obj runtime.Object) error {
_ = ctx
contract := obj.(*Contract)
contractlog.Info("CONTRACT DEFAULT WEBHOOK")
contractlog.Info("default", "name", r.Name)
contractlog.Info("default", "name", contract.Name)

return nil
}

// TODO(user): change verbs to "verbs=create;update;delete" if you want to enable deletion validation.
//nolint:lll // kubebuilder directives are too long, but they must be on the same line
//+kubebuilder:webhook:path=/validate-contract-fluidos-eu-v1alpha1-contract,mutating=false,failurePolicy=fail,sideEffects=None,groups=contract.fluidos.eu,resources=contracts,verbs=create;update,versions=v1alpha1,name=vcontract.kb.io,admissionReviewVersions=v1

var _ webhook.Validator = &Contract{}
var _ webhook.CustomValidator = &Contract{}

// ValidateCreate implements webhook.Validator so a webhook will be registered for the type.
func (r *Contract) ValidateCreate() (admission.Warnings, error) {
func (r *Contract) ValidateCreate(ctx context.Context, obj runtime.Object) (admission.Warnings, error) {
_ = ctx
contract := obj.(*Contract)
contractlog.Info("CONTRACT VALIDATE CREATE WEBHOOK")
contractlog.Info("validate create", "name", r.Name)
contractlog.Info("validate create", "name", contract.Name)

if err := validateConfiguration(r.Spec.Configuration, &r.Spec.Flavor); err != nil {
if err := validateConfiguration(contract.Spec.Configuration, &contract.Spec.Flavor); err != nil {
return nil, err
}

return nil, nil
}

// ValidateUpdate implements webhook.Validator so a webhook will be registered for the type.
func (r *Contract) ValidateUpdate(old runtime.Object) (admission.Warnings, error) {
func (r *Contract) ValidateUpdate(ctx context.Context, oldObj, newObj runtime.Object) (admission.Warnings, error) {
_ = ctx
contract := newObj.(*Contract)
contractlog.Info("CONTRACT VALIDATE UPDATE WEBHOOK")
contractlog.Info("validate update", "name", r.Name)
contractlog.Info("validate update", "name", contract.Name)

contractlog.Info("old", "old", old)
contractlog.Info("old", "old", oldObj)

if err := validateConfiguration(r.Spec.Configuration, &r.Spec.Flavor); err != nil {
if err := validateConfiguration(contract.Spec.Configuration, &contract.Spec.Flavor); err != nil {
return nil, err
}

return nil, nil
}

// ValidateDelete implements webhook.Validator so a webhook will be registered for the type.
func (r *Contract) ValidateDelete() (admission.Warnings, error) {
func (r *Contract) ValidateDelete(ctx context.Context, obj runtime.Object) (admission.Warnings, error) {
_ = ctx
contract := obj.(*Contract)
contractlog.Info("CONTRACT VALIDATE DELETE WEBHOOK")
contractlog.Info("validate delete", "name", r.Name)
contractlog.Info("validate delete", "name", contract.Name)

// TODO(user): fill in your validation logic upon object deletion.
return nil, nil
Expand Down
Loading
Loading