mirror of
https://github.com/actions/actions-runner-controller.git
synced 2025-12-11 03:57:01 +00:00
Add validation webhooks
This commit is contained in:
@@ -66,7 +66,7 @@ func (r *RunnerReconciler) Reconcile(req ctrl.Request) (ctrl.Result, error) {
|
||||
return ctrl.Result{}, client.IgnoreNotFound(err)
|
||||
}
|
||||
|
||||
err := validateRunnerSpec(&runner.Spec)
|
||||
err := runner.Validate()
|
||||
if err != nil {
|
||||
log.Info("Failed to validate runner spec", "error", err.Error())
|
||||
return ctrl.Result{}, nil
|
||||
@@ -88,7 +88,7 @@ func (r *RunnerReconciler) Reconcile(req ctrl.Request) (ctrl.Result, error) {
|
||||
}
|
||||
} else {
|
||||
finalizers, removed := removeFinalizer(runner.ObjectMeta.Finalizers)
|
||||
|
||||
|
||||
if removed {
|
||||
if len(runner.Status.Registration.Token) > 0 {
|
||||
ok, err := r.unregisterRunner(ctx, runner.Spec.Organization, runner.Spec.Repository, runner.Name)
|
||||
@@ -449,15 +449,3 @@ func removeFinalizer(finalizers []string) ([]string, bool) {
|
||||
|
||||
return result, removed
|
||||
}
|
||||
|
||||
// organization & repository are both exclusive - however this cannot be checked with kubebuilder
|
||||
// therefore have an additional check here to log an error in case spec is invalid
|
||||
func validateRunnerSpec(spec *v1alpha1.RunnerSpec) error {
|
||||
if len(spec.Organization) == 0 && len(spec.Repository) == 0 {
|
||||
return fmt.Errorf("RunnerSpec needs organization or repository")
|
||||
}
|
||||
if len(spec.Organization) > 0 && len(spec.Repository) > 0 {
|
||||
return fmt.Errorf("RunnerSpec cannot have both organization and repository")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user