organization and repository are now exclusive

This commit is contained in:
Reinier Timmer
2020-04-28 07:24:37 +02:00
parent 8c5b776807
commit 9f57f52e36
6 changed files with 102 additions and 48 deletions

View File

@@ -66,6 +66,12 @@ func (r *RunnerReconciler) Reconcile(req ctrl.Request) (ctrl.Result, error) {
return ctrl.Result{}, client.IgnoreNotFound(err)
}
err := validateRunnerSpec(&runner.Spec)
if err != nil {
log.Info("Failed to validate runner spec", "error", err.Error())
return ctrl.Result{}, nil
}
if runner.ObjectMeta.DeletionTimestamp.IsZero() {
finalizers, added := addFinalizer(runner.ObjectMeta.Finalizers)
@@ -439,3 +445,15 @@ 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
}