Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
davidkarlsen committed Dec 31, 2020
1 parent b91e518 commit 4553049
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
10 changes: 10 additions & 0 deletions api/v1alpha1/githubactionrunner_types.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package v1alpha1

import (
"errors"
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"time"
Expand Down Expand Up @@ -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)
Expand Down
6 changes: 1 addition & 5 deletions controllers/githubactionrunner_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 4553049

Please sign in to comment.