-
Notifications
You must be signed in to change notification settings - Fork 545
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
Handles incorrect CatalogSource interval values. #2294
Conversation
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: DhritiShikhar 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 |
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 Once the patch is verified, the new status will be reflected by the 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. |
/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. |
cd01fcc
to
34ba3b4
Compare
There was a problem hiding this 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
}
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 |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
/ok-to-test |
|
@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>
afa0f12
to
0ce9dff
Compare
@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 |
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. |
/close in favor of #2447 |
Description of the change:
Handles incorrect CatalogSource interval values.
Example:
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
/doc