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

Handles incorrect CatalogSource interval values. #2294

Conversation

DhritiShikhar
Copy link

@DhritiShikhar DhritiShikhar commented Jul 27, 2021

Description of the change:

Handles incorrect CatalogSource interval values.

Example:

apiVersion: operators.coreos.com/v1alpha1
kind: CatalogSource
metadata:
  name: ibm-operator-catalog
  namespace: openshift-marketplace
spec:
  displayName: ibm-operator-catalog 
  publisher: IBM Content
  sourceType: grpc
  image: docker.io/ibmcom/ibm-operator-catalog
  updateStrategy:
    registryPoll:
      interval: 45mError code    ################### incorrect value

Note:
Made changes to the UpdateStrategy unmarshal inside the vendor folder for reviews. Actual PR is here -> operator-framework/api#142

will unhold once this and the api repo PR is lgtmed and changes from api is vendored in here.

Reviewer Checklist

  • Implementation matches the proposed design, or proposal is updated to match implementation
  • Sufficient unit test coverage
  • Sufficient end-to-end test coverage
  • Docs updated or added to /doc
  • Commit messages sensible and descriptive

@openshift-ci
Copy link

openshift-ci bot commented Jul 27, 2021

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: DhritiShikhar
To complete the pull request process, please assign awgreene after the PR has been reviewed.
You can assign the PR to them by writing /assign @awgreene in a comment when ready.

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-ci openshift-ci bot requested review from anik120 and hasbro17 July 27, 2021 18:52
@openshift-ci
Copy link

openshift-ci bot commented Jul 27, 2021

Hi @DhritiShikhar. Thanks for your PR.

I'm waiting for a operator-framework member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@openshift-ci openshift-ci bot added the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Jul 27, 2021
@DhritiShikhar
Copy link
Author

/hold

Made changes to the UpdateStrategy unmarshal inside the vendor folder for reviews. Actual PR is here -> operator-framework/api#142

will unhold once this and the api repo PR is lgtmed and changes from api is vendored in here.

@openshift-ci openshift-ci bot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Jul 28, 2021
Copy link
Contributor

@anik120 anik120 left a comment

Choose a reason for hiding this comment

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

Thanks for the PR @DhritiShikhar 🎉

An e2e here as proof of concept would be nice too.

Also, what you think of the following design:

In catalogsource_types.go we change the RegistryPoll struct to include a new field

type RegistryPoll struct {
	ParsingError error                                                               // new field
	Interval *metav1.Duration `json:"interval,omitempty"`        // existing field
}

so that we can set that field if there is any error while unmarshalling:

func (u *UpdateStrategy) UnmarshalJSON(b []byte) error {

	var data map[string]map[string]string
	err := json.Unmarshal(b, &data)

	registryPoll := &RegistryPoll{}
	pd, err := time.ParseDuration(data["registryPoll"]["interval"])
	if err != nil {
		registryPoll.ParsingError = fmt.Errorf("error parsing spec.updateStrategy.registryPoll.interval. Setting the default value of %v. Error:%v", DefaultRegistryPollDuration, err)
		defaultTime, _ := time.ParseDuration(DefaultRegistryPollDuration)
		registryPoll.Interval = &metav1.Duration{defaultTime}
	} else {
		registryPoll.ParsingError = nil
		registryPoll.Interval = &metav1.Duration{pd}
	}
	u.RegistryPoll = registryPoll
	return nil
}

That we can use here to 1. log the error 2. set a condition in the catsrc, so that the user is aware why the value that they put, eg 20 minutes got turned into 15m:

if out.Spec.UpdateStrategy != nil {
		if out.Spec.UpdateStrategy.RegistryPoll.ParsingError != nil {
			// set catsrc.status.conditions to let user know there was a problem, i.e explain why a default value is being used.
		}
		logger.Debugf("requeuing registry server sync based on polling interval %s", out.Spec.UpdateStrategy.Interval.Duration.String())
		resyncPeriod := reconciler.SyncRegistryUpdateInterval(out, time.Now())
		o.catsrcQueueSet.RequeueAfter(out.GetNamespace(), out.GetName(), queueinformer.ResyncWithJitter(resyncPeriod, 0.1)())
		return
	}

Comment on lines 727 to 731
if out.Spec.UpdateStrategy.RegistryPoll.Interval.Duration == queueinformer.DefaultResyncPeriod {
if _, err := o.client.OperatorsV1alpha1().CatalogSources(out.GetNamespace()).Update(context.TODO(), out, metav1.UpdateOptions{}); err != nil {
logger.Errorf("error while setting catalogsource interval - %v", err)
return
Copy link
Contributor

Choose a reason for hiding this comment

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

I am not sure I understand why this is needed. Aren't we already parsing the duration and setting it to a correct value while unmarshalling the catsrc object? What exactly are we changing here for the CatalogSource?

Copy link
Author

Choose a reason for hiding this comment

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

We parse the duration, we set the correct value to out.Spec.UpdateStrategy.RegistryPoll.Interval but this line is needed to write it back to the original CatalogSource.

@anik120
Copy link
Contributor

anik120 commented Jul 29, 2021

/ok-to-test

@openshift-ci openshift-ci bot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Jul 29, 2021
@DhritiShikhar
Copy link
Author

@anik120

  • Added ParsingError field and updated the CatalogSource status as per your suggestion

@dinhxuanvu
Copy link
Member

@DhritiShikhar Did you test this locally? I have a feeling that this will not work (hopefully I'm wrong). The reason is because this invalid interval value will break the informer so it will fail before it even reaches the check code that you add.

Signed-off-by: Dhriti Shikhar <dhriti.shikhar.rokz@gmail.com>
@DhritiShikhar
Copy link
Author

@dinhxuanvu Yes, tested this locally.

If the interval value is invalid, it's caught during the Unmarshalling and changed to default value -> operator-framework/api#142

@anik120
Copy link
Contributor

anik120 commented Sep 9, 2021

PR's looking to be in a good place. The API PR is failing the CI though, so if we can solve those errors, get that merged, and then vendor those changes in here, this PR should be ready to go in.

@anik120
Copy link
Contributor

anik120 commented Nov 12, 2021

/close in favor of #2447

@anik120 anik120 closed this Nov 12, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. ok-to-test Indicates a non-member PR verified by an org member that is safe to test.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants