Skip to content
Draft
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
5 changes: 4 additions & 1 deletion internal/controller/spinapp_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"fmt"
"hash/adler32"
"maps"
"time"

"github.com/pelletier/go-toml/v2"
appsv1 "k8s.io/api/apps/v1"
Expand Down Expand Up @@ -110,7 +111,9 @@ func (r *SpinAppReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ct
log.Error(err, "unable to fetch executor")
r.Recorder.Event(&spinApp, "Warning", "MissingExecutor",
fmt.Sprintf("Could not find SpinAppExecutor %s/%s", req.NamespacedName.Namespace, spinApp.Spec.Executor))
return ctrl.Result{}, err
return ctrl.Result{
RequeueAfter: 15 * time.Second,
}, err
}

// Update the status of the SpinApp
Expand Down
31 changes: 0 additions & 31 deletions internal/webhook/spinapp_validating.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,16 +54,9 @@ func (v *SpinAppValidator) ValidateDelete(ctx context.Context, obj runtime.Objec

func (v *SpinAppValidator) validateSpinApp(ctx context.Context, spinApp *spinv1alpha1.SpinApp) error {
var allErrs field.ErrorList
executor, err := validateExecutor(spinApp.Spec, v.fetchExecutor(ctx, spinApp.Namespace))
if err != nil {
allErrs = append(allErrs, err)
}
if err := validateReplicas(spinApp.Spec); err != nil {
allErrs = append(allErrs, err)
}
if err := validateAnnotations(spinApp.Spec, executor); err != nil {
allErrs = append(allErrs, err)
}
if len(allErrs) == 0 {
return nil
}
Expand Down Expand Up @@ -113,27 +106,3 @@ func validateReplicas(spec spinv1alpha1.SpinAppSpec) *field.Error {

return nil
}

func validateAnnotations(spec spinv1alpha1.SpinAppSpec, executor *spinv1alpha1.SpinAppExecutor) *field.Error {
// We can't do any validation if the executor isn't available, but validation
// will fail because of earlier errors.
if executor == nil {
return nil
}

if executor.Spec.CreateDeployment {
return nil
}
// TODO: Make these validations opt in for executors? - Some runtimes may want these regardless.
if len(spec.DeploymentAnnotations) != 0 {
return field.Invalid(
field.NewPath("spec").Child("deploymentAnnotations"),
spec.DeploymentAnnotations,
"deploymentAnnotations can't be set when the executor does not use operator deployments")
}
if len(spec.PodAnnotations) != 0 {
return field.Invalid(field.NewPath("spec").Child("podAnnotations"), spec.PodAnnotations, "podAnnotations can't be set when the executor does not use operator deployments")
}

return nil
}
59 changes: 0 additions & 59 deletions internal/webhook/spinapp_validating_test.go
Original file line number Diff line number Diff line change
@@ -1,29 +1,12 @@
package webhook

import (
"errors"
"testing"

spinv1alpha1 "github.com/spinkube/spin-operator/api/v1alpha1"
"github.com/spinkube/spin-operator/internal/constants"
"github.com/stretchr/testify/require"
)

func TestValidateExecutor(t *testing.T) {
t.Parallel()

_, fldErr := validateExecutor(spinv1alpha1.SpinAppSpec{}, func(string) (*spinv1alpha1.SpinAppExecutor, error) { return nil, nil })
require.EqualError(t, fldErr, "spec.executor: Invalid value: \"\": executor must be set, likely no default executor was set because you have no executors installed")

_, fldErr = validateExecutor(
spinv1alpha1.SpinAppSpec{Executor: constants.CyclotronExecutor},
func(string) (*spinv1alpha1.SpinAppExecutor, error) { return nil, errors.New("executor not found?") })
require.EqualError(t, fldErr, "spec.executor: Invalid value: \"cyclotron\": executor does not exist in namespace")

_, fldErr = validateExecutor(spinv1alpha1.SpinAppSpec{Executor: constants.ContainerDShimSpinExecutor}, func(string) (*spinv1alpha1.SpinAppExecutor, error) { return nil, nil })
require.Nil(t, fldErr)
}

func TestValidateReplicas(t *testing.T) {
t.Parallel()

Expand All @@ -33,45 +16,3 @@ func TestValidateReplicas(t *testing.T) {
fldErr = validateReplicas(spinv1alpha1.SpinAppSpec{Replicas: 1})
require.Nil(t, fldErr)
}

func TestValidateAnnotations(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How come we're getting rid of these?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They only make sense in the context of an executor right now - which when it's not necessarily there already, would cause inconsistent validation

t.Parallel()

deploymentlessExecutor := &spinv1alpha1.SpinAppExecutor{
Spec: spinv1alpha1.SpinAppExecutorSpec{
CreateDeployment: false,
},
}
deploymentfullExecutor := &spinv1alpha1.SpinAppExecutor{
Spec: spinv1alpha1.SpinAppExecutorSpec{
CreateDeployment: true,
},
}

fldErr := validateAnnotations(spinv1alpha1.SpinAppSpec{
Executor: "an-executor",
DeploymentAnnotations: map[string]string{"key": "asdf"},
}, deploymentlessExecutor)
require.EqualError(t, fldErr,
`spec.deploymentAnnotations: Invalid value: map[string]string{"key":"asdf"}: `+
`deploymentAnnotations can't be set when the executor does not use operator deployments`)

fldErr = validateAnnotations(spinv1alpha1.SpinAppSpec{
Executor: "an-executor",
PodAnnotations: map[string]string{"key": "asdf"},
}, deploymentlessExecutor)
require.EqualError(t, fldErr,
`spec.podAnnotations: Invalid value: map[string]string{"key":"asdf"}: `+
`podAnnotations can't be set when the executor does not use operator deployments`)

fldErr = validateAnnotations(spinv1alpha1.SpinAppSpec{
Executor: "an-executor",
DeploymentAnnotations: map[string]string{"key": "asdf"},
}, deploymentfullExecutor)
require.Nil(t, fldErr)

fldErr = validateAnnotations(spinv1alpha1.SpinAppSpec{
Executor: "an-executor",
}, deploymentlessExecutor)
require.Nil(t, fldErr)
}