Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: adding annotation to define reconciliation frequency #297

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions config/samples/annotation.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
apiVersion: validation.spectrocloud.labs/v1alpha1
kind: OciValidator
metadata:
name: ocivalidator-sample-public-oci-registries
namespace: validator
annotations:
validation.validator.labs/reconciliation-frequency: "10"
spec:
ociRegistryRules:
# public oci registry artifact with tag
- name: "public oci registry with tag"
host: "docker.io"
artifacts:
- ref: "library/redis:7.2.4"
21 changes: 19 additions & 2 deletions internal/controller/ocivalidator_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"context"
"fmt"
"os"
"strconv"
"strings"
"time"

Expand All @@ -37,6 +38,7 @@ import (
vres "github.com/validator-labs/validator/pkg/validationresult"

"github.com/validator-labs/validator-plugin-oci/api/v1alpha1"
"github.com/validator-labs/validator-plugin-oci/pkg/constants"
"github.com/validator-labs/validator-plugin-oci/pkg/validate"
)

Expand Down Expand Up @@ -120,8 +122,23 @@ func (r *OciValidatorReconciler) Reconcile(ctx context.Context, req ctrl.Request
return ctrl.Result{}, err
}

l.Info("Requeuing for re-validation in two minutes.")
return ctrl.Result{RequeueAfter: time.Second * 120}, nil
// Capturing reconciliation frequency from annotations .
// Defaulting to 120 seconds if annotation is not found.
var frequency time.Duration
if secondsString, ok := validator.Annotations[constants.ReconciliationFrequencyAnnotation]; ok {
seconds, err := strconv.Atoi(secondsString)
if err != nil {
l.Info("failed to convert frequency annotation: defaulting to 120 seconds")
frequency = time.Second * 120
} else {
frequency = time.Second * time.Duration(seconds)
}
} else {
frequency = time.Second * 120
}

l.Info("Requeuing for re-validation.")
return ctrl.Result{RequeueAfter: frequency}, nil
}

// SetupWithManager sets up the controller with the Manager.
Expand Down
3 changes: 3 additions & 0 deletions pkg/constants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,7 @@ const (
AwsSecretAccessKey = "AWS_SECRET_ACCESS_KEY" // #nosec
// AwsSessionToken is the key for the AWS session token
AwsSessionToken = "AWS_SESSION_TOKEN" // #nosec

// ReconciliationFrequencyAnnotation is annotation key for reconciliation frequency
ReconciliationFrequencyAnnotation = "validation.validator.labs/reconciliation-frequency"
)