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

Closes #5565: Helm reconcile period from CR annotations or watches.yaml #5585

Merged

Conversation

VenkatRamaraju
Copy link
Contributor

@VenkatRamaraju VenkatRamaraju commented Mar 7, 2022

Description of the change:

  1. Added the parsing of the helm.sdk.operatorframework.io/reconcile-period key in the custom resource's annotations.
  2. Added the option to specify the reconcile-period through the watches.yaml file.

The value obtained from either of these two is set to the RequeueAfter field of the reconciler for Helm. If both are specified, then the CR annotations takes precedence.

Motivation for the change:
Close #5565

Checklist

  • Add a new changelog fragment in changelog/fragments
  • Add or update relevant sections of the docs website in website/content/en/docs

Note:
As mentioned in my comment on the issue: this functionality already exists via a command line flag. This PR is to provide the user with the option of doing the same in the CR annotations or watches.yaml, which there seems to be a demand for. This feature already exists for the Ansible-based operator, so I thought it would be a good idea to do the same for the Helm-based operator.

The current order of precedence is: flag < watches < CR annotations.

@openshift-ci openshift-ci bot requested review from asmacdo and joelanford March 7, 2022 22:56
@VenkatRamaraju VenkatRamaraju force-pushed the helm-reconcile-period branch 3 times, most recently from ee557c0 to 2dc8eea Compare March 7, 2022 23:41
metadata:
name: nginx-sample
annotations:
helm.operator-sdk/reconcile-period: "5s"
Copy link
Contributor

@camilamacedo86 camilamacedo86 Mar 8, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens if the reconciliation period not be informed?
What is the default behaviour?
Have we the same behaviour for Ansible and Helm in this case?
Also, is not it an issue for Ansible as well?

Copy link
Contributor Author

@VenkatRamaraju VenkatRamaraju Mar 8, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If no reconcile period is specified in the CR annotations, then the default value is 1m as indicated here.

This behavior exists for Ansible: https://sdk.operatorframework.io/docs/building-operators/ansible/development-tips/#annotations-for-custom-resource.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, it shows that we also need to check/fix it for Ansible.
Historic we try to keep help/ansible working similar as much as possible since it helps keep both maintained, help us and the users switch easily between the languages as well.

Could we ensure the changes for ansible here as well?

c/c @asmacdo @fabianvf

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can be a follow up either, but should we not. ensure that same for Ansible?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@camilamacedo86: So we are now going to accept reconcile Period through 3 ways:

  1. from CR annotations
  2. command line flags
  3. through watches.yaml
    The order of precedence imo should be CR annotations > watches.yaml > cmd line flags. We want it to be in sync with ansible, but ansible does not accept it from flags and neither does the hybrid helm implementation. We would want to eventually remove accepting it through cmd line flags, but I think that should be a follow up. From discussion with @VenkatRamaraju, looks like CR annotations override values from watches.yaml in ansible. So I think we are good with that.

Copy link
Member

@jmrodri jmrodri left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a couple of suggestions and a question

@@ -388,9 +389,33 @@ func (r HelmOperatorReconciler) Reconcile(ctx context.Context, request reconcile
Manifest: expectedRelease.Manifest,
}
err = r.updateResourceStatus(ctx, o, status)

// Parse the reconcile period from CR's annotations
annotationsReconcilePeriod := parseReconcilePeriod(o)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the record, o is a horrible variable name for this but since it is an existing structure, I won't make you rewrite it here.


The value that is present under this key must be in the h/m/s format. For example, 1h2m4s, 3m0s, 4s are all valid values, but 1x3m9s is invalid.

**NOTE**: This is just one way of specifying the reconcile period for helm operators. Another way is using the `--reconcile-period` command line flag while running the operator. However, if both
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
**NOTE**: This is just one way of specifying the reconcile period for helm operators. Another way is using the `--reconcile-period` command line flag while running the operator. However, if both
**NOTE**: This is just one way of specifying the reconcile period for Helm-based operators. Another way is using the `--reconcile-period` command line flag while running the operator. However, if both

@varshaprasad96
Copy link
Member

@VenkatRamaraju if possible, can you also add this in https://github.com/operator-framework/helm-operator-plugins?

@VenkatRamaraju
Copy link
Contributor Author

@varshaprasad96 yup, I can do that.

@VenkatRamaraju VenkatRamaraju force-pushed the helm-reconcile-period branch from 64bf0e5 to 7193943 Compare March 8, 2022 20:44
// Parse the reconcile period from CR's annotations
annotationsReconcilePeriod := parseReconcilePeriod(o)

if annotationsReconcilePeriod != "" {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we a have a small test that verifies the overriding hierarchy, just to make sure that when a flag is passed the annotation values (if present) override them?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yup, I just added a couple of tests to verify the order of precedence and parsing of the field in the annotations.

I had to modify the signature of the function to make it easier to test.

@VenkatRamaraju VenkatRamaraju force-pushed the helm-reconcile-period branch from 7193943 to f34d901 Compare March 9, 2022 02:16
@VenkatRamaraju VenkatRamaraju force-pushed the helm-reconcile-period branch 3 times, most recently from fed8ef4 to 1cd6231 Compare March 9, 2022 16:53
@VenkatRamaraju VenkatRamaraju changed the title Closes #5565: Helm reconcile period from CR annotations Closes #5565: Helm reconcile period from CR annotations or watches.yaml Mar 9, 2022
@VenkatRamaraju VenkatRamaraju force-pushed the helm-reconcile-period branch from 23cf6e1 to 3bc5570 Compare March 9, 2022 19:35
@@ -49,7 +49,7 @@ type WatchOptions struct {
Namespace string
GVK schema.GroupVersionKind
ManagerFactory release.ManagerFactory
ReconcilePeriod time.Duration
ReconcilePeriod string
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we revert this? Eventually watches struct would be exposed in hybrid implementation. To remain backwards compatible, let's avoid making changes to it.

@VenkatRamaraju VenkatRamaraju force-pushed the helm-reconcile-period branch 2 times, most recently from 6fcd943 to cad82fa Compare March 10, 2022 01:41
@VenkatRamaraju VenkatRamaraju force-pushed the helm-reconcile-period branch 3 times, most recently from 9f4ff38 to 2c13436 Compare March 10, 2022 18:55
Copy link
Member

@varshaprasad96 varshaprasad96 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just one nit and /lgtm!

Comment on lines 4 to 5
value from the custom resource annotations for helm operators. This value is set to
then set to the 'reconcile-period' field of the reconciler to reconcile the cluster
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit:

Suggested change
value from the custom resource annotations for helm operators. This value is set to
then set to the 'reconcile-period' field of the reconciler to reconcile the cluster
value from the custom resource annotations for helm operators. This value is
then set to the 'reconcile-period' field of the reconciler to reconcile the cluster

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

reconcile-period and default value
4 participants