diff --git a/api/v1alpha1/githubactionrunner_types.go b/api/v1alpha1/githubactionrunner_types.go index 392f173e..a20ccb53 100644 --- a/api/v1alpha1/githubactionrunner_types.go +++ b/api/v1alpha1/githubactionrunner_types.go @@ -1,6 +1,7 @@ package v1alpha1 import ( + "errors" v1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "time" @@ -41,6 +42,15 @@ type GithubActionRunnerSpec struct { ReconciliationPeriod string `json:"reconciliationPeriod"` } +// Spec level validation that is not covered by basic OpenAPI constraints +func (r GithubActionRunnerSpec) IsValid() (bool, error){ + if r.MaxRunners < r.MinRunners { + return false, errors.New("MaxRunners must be greater or equal to minRunners") + } + + return true, nil +} + // GetReconciliationPeriod returns period as a Duration func (r GithubActionRunnerSpec) GetReconciliationPeriod() time.Duration { duration, err := time.ParseDuration(r.ReconciliationPeriod) diff --git a/controllers/githubactionrunner_controller.go b/controllers/githubactionrunner_controller.go index 08c2365f..f2889f82 100644 --- a/controllers/githubactionrunner_controller.go +++ b/controllers/githubactionrunner_controller.go @@ -55,11 +55,7 @@ func (r *GithubActionRunnerReconciler) IsValid(obj metav1.Object) (bool, error) if !ok { return false, errors.New("not a GithubActionRunner object") } - if instance.Spec.MaxRunners < instance.Spec.MinRunners { - return false, errors.New("MaxRunners must be greater or equal to minRunners") - } - - return true, nil + return instance.Spec.IsValid() } // +kubebuilder:rbac:groups=garo.tietoevry.com,resources=githubactionrunners,verbs=get;list;watch;create;update;patch;delete