Skip to content

Commit

Permalink
Merge pull request #355 from stakater/add-requeue-time-flag
Browse files Browse the repository at this point in the history
Add Requeue time flag for setting reconciliation requeue time
  • Loading branch information
abdulhaseeb2 committed Aug 3, 2021
2 parents cb90ecc + 9e2b9a0 commit 524a419
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 19 deletions.
19 changes: 10 additions & 9 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@

Pull Requests are welcome. In general, we follow the "fork-and-pull" Git workflow.

1. **Fork** the repo on GitHub
2. **Clone** the project to your own machine
3. **Commit** changes to your own branch
4. **Push** your work back up to your fork
5. Submit a **Pull request** so that we can review your changes
1. **Fork** the repo on GitHub
2. **Clone** the project to your own machine
3. **Commit** changes to your own branch
4. **Push** your work back up to your fork
5. Submit a **Pull request** so that we can review your changes

NOTE: Be sure to merge the latest from "upstream" before making a pull request!

Expand Down Expand Up @@ -138,17 +138,18 @@ And then handle this configuration as handled in `processProviderConfig` in [upt

## Development

### Dependencies:
### Dependencies

1. GoLang v1.16
2. kubectl
3. operator-sdk v1.6.2

### Running Operator Locally

1. Create a namespace `test`
2. Create a secret with name `imc-config` and add your desired config in there
3. Run `make run`
1. Install CRDs by running `make install`
2. Create a namespace `test`
3. Create a secret with name `imc-config` and add your desired config in there
4. Run `OPERATOR_NAMESPACE=test make run`

**NOTE**: Ensure that all required resources are re-generated

Expand Down
11 changes: 6 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# ![](docs/images/IMC-round-100px.png) Ingress Monitor Controller
# ![imc-logo](docs/images/IMC-round-100px.png) Ingress Monitor Controller

An operator to watch ingresses/routes and create liveness alerts for your apps/microservices in Uptime checkers.

Expand Down Expand Up @@ -144,10 +144,11 @@ helm install stakater/ingressmonitorcontroller

### Environment Variables

| Key | Description |
| ------------------ | ------------------------------------------------------------------------------------------------------ |
| WATCH_NAMESPACE | Use comma separated list of namespaces or leave the field empty to watch all namespaces(cluster scope) |
| CONFIG_SECRET_NAME | Name of secret that holds the configuration |
| Key | Default | Description |
| ------------------ | --------------------------------------- | ------------------------------------------------------------------------------------------------------ |
| WATCH_NAMESPACE | Namespace in which operator is deployed | Use comma separated list of namespaces or leave the field empty to watch all namespaces(cluster scope) |
| CONFIG_SECRET_NAME | imc-config | Name of secret that holds the configuration |
| REQUEUE_TIME | 300 seconds | Integer value to specify number of seconds after which the resource should be reconciled again |

## Help

Expand Down
20 changes: 20 additions & 0 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package config
import (
"io/ioutil"
"os"
"strconv"
"time"

util "github.com/stakater/operator-utils/util"
Expand All @@ -16,8 +17,12 @@ import (
const (
IngressMonitorControllerSecretConfigKey = "config.yaml"
IngressMonitorControllerSecretDefaultName = "imc-config"
requeueTimeEnvVariable = "REQUEUE_TIME"
defaultRequeueTime = 300
)

var ReconciliationRequeueTime = getRequeueTime()

var (
IngressMonitorControllerConfig Config
log = logf.Log.WithName("config")
Expand Down Expand Up @@ -158,3 +163,18 @@ func ReadConfig(filePath string) Config {
IngressMonitorControllerConfig = config
return config
}

// getRequeueTime returns the Requeue Time for the objects
// https://sdk.operatorframework.io/docs/building-operators/golang/tutorial/#reconcile-loop
func getRequeueTime() time.Duration {
output := defaultRequeueTime * time.Second
requeueTime, found := os.LookupEnv(requeueTimeEnvVariable)
if found && len(requeueTime) > 0 {
requeueTimeInt, err := strconv.ParseInt(requeueTime, 10, 64)
if err == nil {
output = time.Duration(requeueTimeInt) * time.Second
}
}
log.Info("Reconciliation requeue time is set to %v", output)
return output
}
6 changes: 1 addition & 5 deletions pkg/controllers/endpointmonitor_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,6 @@ type EndpointMonitorReconciler struct {
MonitorServices []monitors.MonitorServiceProxy
}

const (
defaultRequeueTime = 60 * time.Second
)

//+kubebuilder:rbac:groups=endpointmonitor.stakater.com,resources=endpointmonitors,verbs=get;list;watch
//+kubebuilder:rbac:groups=endpointmonitor.stakater.com,resources=endpointmonitors/status,verbs=get;update;patch
//+kubebuilder:rbac:groups=endpointmonitor.stakater.com,resources=endpointmonitors/finalizers,verbs=update
Expand Down Expand Up @@ -104,7 +100,7 @@ func (r *EndpointMonitorReconciler) Reconcile(ctx context.Context, req ctrl.Requ
}
}

return reconcile.Result{RequeueAfter: defaultRequeueTime}, err
return reconcile.Result{RequeueAfter: config.ReconciliationRequeueTime}, err
}

// SetupWithManager sets up the controller with the Manager.
Expand Down

0 comments on commit 524a419

Please sign in to comment.