Skip to content

Commit

Permalink
Parameterize Requeue Time
Browse files Browse the repository at this point in the history
  • Loading branch information
DharmitD committed Nov 11, 2023
1 parent 95e1ba2 commit d3f0796
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 2 deletions.
8 changes: 8 additions & 0 deletions config/base/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -113,5 +113,13 @@ vars:
apiVersion: v1
fieldref:
fieldpath: data.MAX_CONCURRENT_RECONCILES
- name: REQUEUE_TIME
objref:
kind: ConfigMap
name: dspo-parameters
apiVersion: v1
fieldref:
fieldpath: data.REQUEUE_TIME

configurations:
- params.yaml
1 change: 1 addition & 0 deletions config/base/params.env
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ IMAGES_MARIADB=registry.redhat.io/rhel8/mariadb-103:1
IMAGES_OAUTHPROXY=registry.redhat.io/openshift4/ose-oauth-proxy@sha256:ab112105ac37352a2a4916a39d6736f5db6ab4c29bad4467de8d613e80e9bb33
ZAP_LOG_LEVEL=info
MAX_CONCURRENT_RECONCILES=10
DSPO_REQUEUE_TIME=2m
3 changes: 3 additions & 0 deletions config/configmaps/files/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,6 @@ Images:
MlmdEnvoy: $(IMAGES_MLMDENVOY)
MlmdGRPC: $(IMAGES_MLMDGRPC)
MlmdWriter: $(IMAGES_MLMDWRITER)
DSPO:
RequeueTime: $(DSPO_REQUEUE_TIME)

2 changes: 2 additions & 0 deletions config/manager/manager.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ spec:
value: $(ZAP_LOG_LEVEL)
- name: MAX_CONCURRENT_RECONCILES
value: $(MAX_CONCURRENT_RECONCILES)
- name: REQUEUE_TIME
value: $(REQUEUE_TIME)
securityContext:
allowPrivilegeEscalation: false
capabilities:
Expand Down
10 changes: 10 additions & 0 deletions controllers/config/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ const (
MlmdEnvoyImagePath = "Images.MlmdEnvoy"
MlmdGRPCImagePath = "Images.MlmdGRPC"
MlmdWriterImagePath = "Images.MlmdWriter"
RequeueTimeConfigName = "DSPO.RequeueTime"
)

// DSPA Status Condition Types
Expand Down Expand Up @@ -112,6 +113,8 @@ const DefaultObjStoreConnectionTimeout = time.Second * 15

const DefaultMaxConcurrentReconciles = 10

const DefaultRequeueTime = 2 * time.Minute

func GetConfigRequiredFields() []string {
return requiredFields
}
Expand Down Expand Up @@ -148,3 +151,10 @@ func GetStringConfigWithDefault(configName, value string) string {
}
return viper.GetString(configName)
}

func GetDurationConfigWithDefault(configName string, value time.Duration) time.Duration {
if !viper.IsSet(configName) {
return value
}
return viper.GetDuration(configName)
}
5 changes: 3 additions & 2 deletions controllers/dspipeline_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
"context"
"fmt"
"sigs.k8s.io/controller-runtime/pkg/controller"
"time"
// "time"

"github.com/go-logr/logr"
mf "github.com/manifestival/manifestival"
Expand Down Expand Up @@ -206,10 +206,11 @@ func (r *DSPAReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.
return ctrl.Result{}, nil
}

requeueTime := config.GetDurationConfigWithDefault(config.RequeueTimeConfigName, config.DefaultRequeueTime)
err = params.ExtractParams(ctx, dspa, r.Client, r.Log)
if err != nil {
log.Info(fmt.Sprintf("Encountered error when parsing CR: [%s]", err))
return ctrl.Result{Requeue: true, RequeueAfter: 2 * time.Minute}, nil
return ctrl.Result{Requeue: true, RequeueAfter: requeueTime}, nil
}

err = r.ReconcileDatabase(ctx, dspa, params)
Expand Down

0 comments on commit d3f0796

Please sign in to comment.