Skip to content

Commit

Permalink
fix errorneoous previous commit
Browse files Browse the repository at this point in the history
Signed-off-by: Fotis Nikolaidis <[email protected]>
  • Loading branch information
fnikolai committed Jan 12, 2023
1 parent 0b491bc commit f60f59c
Show file tree
Hide file tree
Showing 165 changed files with 22,790 additions and 22,699 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ certs: ## Download certs under 'certs' folder

build: generate fmt vet ## Build manager binary.
go build -o bin/manager cmd/manager/main.go
go build -o bin/kubectl-frisbee cmd/kubectl-frisbee/main.go

run: generate fmt vet certs ## Run a controller from your host.
@echo "===> Run Frisbee Controller on Namespace ${FRISBEE_NAMESPACE} <==="
Expand Down
27 changes: 15 additions & 12 deletions api/v1alpha1/admission_call.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2022 ICS-FORTH.
Copyright 2022-2023 ICS-FORTH.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -47,21 +47,23 @@ func (in *Call) SetupWebhookWithManager(mgr ctrl.Manager) error {

// Default implements webhook.Defaulter so a webhook will be registered for the type.
func (in *Call) Default() {
calllog.V(5).Info("default", "name", in.Name)
calllog.Info("SetDefaults",
"name", in.GetNamespace()+"/"+in.GetName(),
)

// Schedule field
if schedule := in.Spec.Schedule; schedule != nil {
if schedule.StartingDeadlineSeconds == nil {
schedule.StartingDeadlineSeconds = &DefaultStartingDeadlineSeconds
}
}

// TODO(user): fill in your defaulting logic.
}

// ValidateCreate implements webhook.Validator so a webhook will be registered for the type.
func (in *Call) ValidateCreate() error {
calllog.V(5).Info("validate create", "name", in.Name)
calllog.Info("ValidateCreateRequest",
"name", in.GetNamespace()+"/"+in.GetName(),
)

// Expect field
if expect := in.Spec.Expect; expect != nil {
Expand All @@ -77,16 +79,20 @@ func (in *Call) ValidateCreate() error {
}
}

// Until field
if until := in.Spec.Until; until != nil {
// SuspendWhen field
if until := in.Spec.SuspendWhen; until != nil {
if err := ValidateExpr(until); err != nil {
return errors.Wrapf(err, "until error")
return errors.Wrapf(err, "SuspendWhen error")
}
}

// Schedule field
if schedule := in.Spec.Schedule; schedule != nil {
if err := ValidateScheduler(len(in.Spec.Services), schedule); err != nil {
if len(in.Spec.Services) < 1 {
return errors.Errorf("scheduling requires at least one instance")
}

if err := ValidateTaskScheduler(schedule); err != nil {
return errors.Wrapf(err, "schedule error")
}
}
Expand All @@ -103,9 +109,6 @@ func (in *Call) ValidateCreate() error {

// ValidateUpdate implements webhook.Validator so a webhook will be registered for the type.
func (in *Call) ValidateUpdate(runtime.Object) error {
calllog.Info("validate update", "name", in.Name)

// TODO(user): fill in your validation logic upon object update.
return nil
}

Expand Down
27 changes: 15 additions & 12 deletions api/v1alpha1/admission_cascade.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2022 ICS-FORTH.
Copyright 2022-2023 ICS-FORTH.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -47,49 +47,52 @@ func (in *Cascade) SetupWebhookWithManager(mgr ctrl.Manager) error {

// Default implements webhook.Defaulter so a webhook will be registered for the type.
func (in *Cascade) Default() {
cascadelog.V(5).Info("default", "name", in.Name)
cascadelog.Info("SetDefaults",
"name", in.GetNamespace()+"/"+in.GetName(),
)

// Schedule field
if schedule := in.Spec.Schedule; schedule != nil {
if schedule.StartingDeadlineSeconds == nil {
schedule.StartingDeadlineSeconds = &DefaultStartingDeadlineSeconds
}
}
// TODO(user): fill in your defaulting logic.
}

// ValidateCreate implements webhook.Validator so a webhook will be registered for the type.
func (in *Cascade) ValidateCreate() error {
cascadelog.Info("ValidateCreateRequest",
"name", in.GetNamespace()+"/"+in.GetName(),
)

// Set missing values for the template
if err := in.Spec.GenerateObjectFromTemplate.Prepare(true); err != nil {
clusterlog.Error(err, "template error")
}

// Until field
if until := in.Spec.Until; until != nil {
if until := in.Spec.SuspendWhen; until != nil {
if err := ValidateExpr(until); err != nil {
return errors.Wrapf(err, "until error")
return errors.Wrapf(err, "SuspendWhen error")
}
}

// Schedule field
if schedule := in.Spec.Schedule; schedule != nil {
if err := ValidateScheduler(in.Spec.MaxInstances, schedule); err != nil {
if in.Spec.MaxInstances < 1 {
return errors.Errorf("scheduling requires at least one instance")
}

if err := ValidateTaskScheduler(schedule); err != nil {
return errors.Wrapf(err, "schedule error")
}
}

cascadelog.V(5).Info("validate create", "name", in.Name)

// TODO(user): fill in your validation logic upon object creation.
return nil
}

// ValidateUpdate implements webhook.Validator so a webhook will be registered for the type.
func (in *Cascade) ValidateUpdate(runtime.Object) error {
cascadelog.Info("validate update", "name", in.Name)

// TODO(user): fill in your validation logic upon object update.
return nil
}

Expand Down
15 changes: 7 additions & 8 deletions api/v1alpha1/admission_chaos.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2021 ICS-FORTH.
Copyright 2021-2023 ICS-FORTH.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -45,23 +45,22 @@ func (in *Chaos) SetupWebhookWithManager(mgr ctrl.Manager) error {

// Default implements webhook.Defaulter so a webhook will be registered for the type.
func (in *Chaos) Default() {
chaoslog.Info("default", "name", in.Name)
// TODO(user): fill in your defaulting logic.
chaoslog.Info("SetDefaults",
"name", in.GetNamespace()+"/"+in.GetName(),
)
}

// ValidateCreate implements webhook.Validator so a webhook will be registered for the type.
func (in *Chaos) ValidateCreate() error {
chaoslog.Info("validate create", "name", in.Name)
chaoslog.Info("ValidateCreateRequest",
"name", in.GetNamespace()+"/"+in.GetName(),
)

// TODO(user): fill in your validation logic upon object creation.
return nil
}

// ValidateUpdate implements webhook.Validator so a webhook will be registered for the type.
func (in *Chaos) ValidateUpdate(runtime.Object) error {
chaoslog.Info("validate update", "name", in.Name)

// TODO(user): fill in your validation logic upon object update.
return nil
}

Expand Down
29 changes: 16 additions & 13 deletions api/v1alpha1/admission_cluster.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2021 ICS-FORTH.
Copyright 2021-2023 ICS-FORTH.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -43,7 +43,9 @@ func (in *Cluster) SetupWebhookWithManager(mgr ctrl.Manager) error {

// Default implements webhook.Defaulter so a webhook will be registered for the type.
func (in *Cluster) Default() {
clusterlog.Info("default", "name", in.Name)
clusterlog.Info("SetDefaults",
"name", in.GetNamespace()+"/"+in.GetName(),
)

// Schedule field
if schedule := in.Spec.Schedule; schedule != nil {
Expand All @@ -55,13 +57,13 @@ func (in *Cluster) Default() {
if in.Spec.DefaultDistributionSpec != nil {
in.Spec.DefaultDistributionSpec = &DistributionSpec{Name: DistributionUniform}
}

// TODO(user): fill in your defaulting logic.
}

// ValidateCreate implements webhook.Validator so a webhook will be registered for the type.
func (in *Cluster) ValidateCreate() error {
clusterlog.Info("validate create", "name", in.Name)
clusterlog.Info("ValidateCreateRequest",
"name", in.GetNamespace()+"/"+in.GetName(),
)

// Set missing values for the template
if err := in.Spec.GenerateObjectFromTemplate.Prepare(true); err != nil {
Expand All @@ -70,8 +72,8 @@ func (in *Cluster) ValidateCreate() error {

// Resources field
if resources := in.Spec.Resources; resources != nil {
if in.Spec.Until != nil {
return errors.Errorf("resource distribution conflicts with Until conditions")
if in.Spec.SuspendWhen != nil {
return errors.Errorf("resource distribution conflicts with SuspendWhen conditions")
}

if in.Spec.MaxInstances < 1 {
Expand All @@ -97,15 +99,19 @@ func (in *Cluster) ValidateCreate() error {
}

// Until field
if until := in.Spec.Until; until != nil {
if until := in.Spec.SuspendWhen; until != nil {
if err := ValidateExpr(until); err != nil {
return errors.Wrapf(err, "until error")
return errors.Wrapf(err, "SuspendWhen error")
}
}

// Schedule field
if schedule := in.Spec.Schedule; schedule != nil {
if err := ValidateScheduler(in.Spec.MaxInstances, schedule); err != nil {
if in.Spec.MaxInstances < 1 {
return errors.Errorf("scheduling requires at least one instance")
}

if err := ValidateTaskScheduler(schedule); err != nil {
return errors.Wrapf(err, "schedule error")
}
}
Expand All @@ -125,9 +131,6 @@ func (in *Cluster) ValidateCreate() error {

// ValidateUpdate implements webhook.Validator so a webhook will be registered for the type.
func (in *Cluster) ValidateUpdate(runtime.Object) error {
clusterlog.Info("validate update", "name", in.Name)

// TODO(user): fill in your validation logic upon object update.
return nil
}

Expand Down
37 changes: 24 additions & 13 deletions api/v1alpha1/admission_common.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2022 ICS-FORTH.
Copyright 2022-2023 ICS-FORTH.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand All @@ -17,6 +17,7 @@ limitations under the License.
package v1alpha1

import (
"github.com/hashicorp/go-multierror"
"github.com/pkg/errors"
"github.com/robfig/cron/v3"
)
Expand Down Expand Up @@ -45,39 +46,49 @@ func ValidateExpr(expr *ConditionalExpr) error {
return nil
}

func ValidateScheduler(instances int, sch *SchedulerSpec) error {
if instances < 1 {
return errors.Errorf("scheduling requires at least one instance")
}
func ValidateTaskScheduler(sch *TaskSchedulerSpec) error {
var merr *multierror.Error

var enabledPolicies uint8

// Cron and Timeline can be active at the same time.
// However, both Cron and Timeline can be used in conjuction with Events.
if sch.Cron != nil && sch.Timeline != nil {
return errors.Errorf("cron and timeline distribution cannot be activated in paralle")
// sequential
if sch.Sequential != nil && *sch.Sequential {
enabledPolicies++
}

// cron
if cronspec := sch.Cron; cronspec != nil {
enabledPolicies++

if _, err := cron.ParseStandard(*cronspec); err != nil {
return errors.Wrapf(err, "invalid schedule %q", *cronspec)
merr = multierror.Append(merr, errors.Wrapf(err, "CronError"))
}
}

// event
if conditions := sch.Event; conditions != nil {
enabledPolicies++

if err := ValidateExpr(conditions); err != nil {
return errors.Wrapf(err, "conditions error")
merr = multierror.Append(merr, errors.Wrapf(err, "EventError"))
}
}

// timeline
if timeline := sch.Timeline; timeline != nil {
enabledPolicies++

if err := ValidateDistribution(timeline.DistributionSpec); err != nil {
return errors.Wrapf(err, "conditions error")
merr = multierror.Append(merr, errors.Wrapf(err, "TimelineError"))
}
}

return nil
// check for conflicts
if enabledPolicies != 1 {
merr = multierror.Append(merr, errors.Errorf("Expected 1 scheduling policy but got %d", enabledPolicies))
}

return merr.ErrorOrNil()
}

func ValidateDistribution(dist *DistributionSpec) error {
Expand Down
5 changes: 1 addition & 4 deletions api/v1alpha1/admission_scenario.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2021 ICS-FORTH.
Copyright 2021-2023 ICS-FORTH.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -312,9 +312,6 @@ func CheckAction(action *Action, references map[string]*Action) error {

// ValidateUpdate implements webhook.Validator so a webhook will be registered for the type.
func (in *Scenario) ValidateUpdate(runtime.Object) error {
scenariolog.Info("validate update", "name", in.Name)

// TODO(user): fill in your validation logic upon object update.
return nil
}

Expand Down
13 changes: 7 additions & 6 deletions api/v1alpha1/admission_service.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2021 ICS-FORTH.
Copyright 2021-2023 ICS-FORTH.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -50,12 +50,16 @@ func (in *Service) SetupWebhookWithManager(mgr ctrl.Manager) error {

// Default implements webhook.Defaulter so a webhook will be registered for the type.
func (in *Service) Default() {
servicelog.Info("default", "name", in.Name)
servicelog.Info("SetDefaults",
"name", in.GetNamespace()+"/"+in.GetName(),
)
}

// ValidateCreate implements webhook.Validator so a webhook will be registered for the type.
func (in *Service) ValidateCreate() error {
servicelog.Info("validate create", "name", in.GetName())
servicelog.Info("ValidateCreateRequest",
"name", in.GetNamespace()+"/"+in.GetName(),
)

for i := range in.Spec.Containers {
container := in.Spec.Containers[i]
Expand Down Expand Up @@ -127,9 +131,6 @@ func (in *Service) validateSidecarContainer(container *corev1.Container) error {

// ValidateUpdate implements webhook.Validator so a webhook will be registered for the type.
func (in *Service) ValidateUpdate(_ runtime.Object) error {
servicelog.Info("validate update", "name", in.Name)

// TODO(user): fill in your validation logic upon object update.
return nil
}

Expand Down
Loading

0 comments on commit f60f59c

Please sign in to comment.