From cb5c371a4f86090574c95bef7d290f84a4b86c55 Mon Sep 17 00:00:00 2001 From: Maidul Islam Date: Thu, 29 Jun 2023 15:02:53 -0400 Subject: [PATCH] add re-sync interval --- helm-charts/secrets-operator/Chart.yaml | 2 +- .../secrets-operator/templates/infisicalsecret-crd.yaml | 4 ++++ k8-operator/api/v1alpha1/infisicalsecret_types.go | 3 +++ .../bases/secrets.infisical.com_infisicalsecrets.yaml | 4 ++++ k8-operator/config/samples/sample.yaml | 1 + k8-operator/controllers/infisicalsecret_controller.go | 9 ++++++++- .../kubectl-install/install-secrets-operator.yaml | 4 ++++ 7 files changed, 25 insertions(+), 2 deletions(-) diff --git a/helm-charts/secrets-operator/Chart.yaml b/helm-charts/secrets-operator/Chart.yaml index 6a290b96c..c3e0073b5 100644 --- a/helm-charts/secrets-operator/Chart.yaml +++ b/helm-charts/secrets-operator/Chart.yaml @@ -18,4 +18,4 @@ version: 0.1.6 # incremented each time you make changes to the application. Versions are not expected to # follow Semantic Versioning. They should reflect the version the application is using. # It is recommended to use it with quotes. -appVersion: "0.1.7" +appVersion: "0.1.8" diff --git a/helm-charts/secrets-operator/templates/infisicalsecret-crd.yaml b/helm-charts/secrets-operator/templates/infisicalsecret-crd.yaml index eee275f5e..ceeac6709 100644 --- a/helm-charts/secrets-operator/templates/infisicalsecret-crd.yaml +++ b/helm-charts/secrets-operator/templates/infisicalsecret-crd.yaml @@ -95,6 +95,9 @@ spec: - secretName - secretNamespace type: object + resyncInterval: + default: 60 + type: integer tokenSecretReference: properties: secretName: @@ -109,6 +112,7 @@ spec: type: object required: - managedSecretReference + - resyncInterval type: object status: description: InfisicalSecretStatus defines the observed state of InfisicalSecret diff --git a/k8-operator/api/v1alpha1/infisicalsecret_types.go b/k8-operator/api/v1alpha1/infisicalsecret_types.go index 96364bf86..203394417 100644 --- a/k8-operator/api/v1alpha1/infisicalsecret_types.go +++ b/k8-operator/api/v1alpha1/infisicalsecret_types.go @@ -42,6 +42,9 @@ type InfisicalSecretSpec struct { // +kubebuilder:validation:Required ManagedSecretReference KubeSecretReference `json:"managedSecretReference"` + // +kubebuilder:default:=60 + ResyncInterval int `json:"resyncInterval"` + // Infisical host to pull secrets from // +kubebuilder:validation:Optional HostAPI string `json:"hostAPI"` diff --git a/k8-operator/config/crd/bases/secrets.infisical.com_infisicalsecrets.yaml b/k8-operator/config/crd/bases/secrets.infisical.com_infisicalsecrets.yaml index 3bcdb0020..f47efb061 100644 --- a/k8-operator/config/crd/bases/secrets.infisical.com_infisicalsecrets.yaml +++ b/k8-operator/config/crd/bases/secrets.infisical.com_infisicalsecrets.yaml @@ -95,6 +95,9 @@ spec: - secretName - secretNamespace type: object + resyncInterval: + default: 60 + type: integer tokenSecretReference: properties: secretName: @@ -109,6 +112,7 @@ spec: type: object required: - managedSecretReference + - resyncInterval type: object status: description: InfisicalSecretStatus defines the observed state of InfisicalSecret diff --git a/k8-operator/config/samples/sample.yaml b/k8-operator/config/samples/sample.yaml index 110965421..971df9f7c 100644 --- a/k8-operator/config/samples/sample.yaml +++ b/k8-operator/config/samples/sample.yaml @@ -4,6 +4,7 @@ metadata: name: infisicalsecret-sample spec: hostAPI: http://localhost:7070/api + resyncInterval: 60 authentication: serviceAccount: serviceAccountSecretReference: diff --git a/k8-operator/controllers/infisicalsecret_controller.go b/k8-operator/controllers/infisicalsecret_controller.go index ddfc39e02..7aca83651 100644 --- a/k8-operator/controllers/infisicalsecret_controller.go +++ b/k8-operator/controllers/infisicalsecret_controller.go @@ -33,8 +33,8 @@ type InfisicalSecretReconciler struct { // For more details, check Reconcile and its Result here: // - https://pkg.go.dev/sigs.k8s.io/controller-runtime@v0.13.1/pkg/reconcile func (r *InfisicalSecretReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) { - requeueTime := time.Minute * 1 var infisicalSecretCR v1alpha1.InfisicalSecret + requeueTime := time.Minute // seconds err := r.Get(ctx, req.NamespacedName, &infisicalSecretCR) if err != nil { @@ -51,6 +51,13 @@ func (r *InfisicalSecretReconciler) Reconcile(ctx context.Context, req ctrl.Requ } } + if infisicalSecretCR.Spec.ResyncInterval != 0 { + requeueTime = time.Second * time.Duration(infisicalSecretCR.Spec.ResyncInterval) + fmt.Println("Manual re-sync interval set", "requeueAfter", requeueTime) + } + + fmt.Println("Requeue duration set", "requeueAfter", requeueTime) + // Check if the resource is already marked for deletion if infisicalSecretCR.GetDeletionTimestamp() != nil { return ctrl.Result{ diff --git a/k8-operator/kubectl-install/install-secrets-operator.yaml b/k8-operator/kubectl-install/install-secrets-operator.yaml index 6c9d5ef0d..f362bcfa1 100644 --- a/k8-operator/kubectl-install/install-secrets-operator.yaml +++ b/k8-operator/kubectl-install/install-secrets-operator.yaml @@ -101,6 +101,9 @@ spec: - secretName - secretNamespace type: object + resyncInterval: + default: 60 + type: integer tokenSecretReference: properties: secretName: @@ -115,6 +118,7 @@ spec: type: object required: - managedSecretReference + - resyncInterval type: object status: description: InfisicalSecretStatus defines the observed state of InfisicalSecret