-
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
fix(subscriptions): fix race between subscription sync and cache #689
Merged
openshift-merge-robot
merged 3 commits into
operator-framework:master
from
njhale:fix-ip-race
Jan 29, 2019
Merged
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -47,6 +47,8 @@ const ( | |
serviceKind = "Service" | ||
roleKind = "Role" | ||
roleBindingKind = "RoleBinding" | ||
|
||
generatedByKey = "olm/generated-by" | ||
) | ||
|
||
// for test stubbing and for ensuring standardization of timezones to UTC | ||
|
@@ -675,33 +677,29 @@ func (o *Operator) ensureSubscriptionInstallPlanState(logger *logrus.Entry, sub | |
|
||
// check if there's an installplan that created this subscription (only if it doesn't have a reference yet) | ||
// this indicates it was newly resolved by another operator, and we should reference that installplan in the status | ||
ips, err := o.lister.OperatorsV1alpha1().InstallPlanLister().InstallPlans(sub.GetNamespace()).List(labels.Everything()) | ||
if err != nil { | ||
logger.WithError(err).Debug("couldn't get installplans") | ||
// if we can't list, just continue processing | ||
ipName, ok := sub.GetAnnotations()[generatedByKey] | ||
if !ok { | ||
// err := fmt.Errorf("no installplan reference or %s annotation found", generatedByKey) | ||
// logger.WithField("err", err.Error()).Error("an error occurred while associating a subscription with an installplan") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remove commented code? |
||
return sub, nil | ||
} | ||
|
||
out := sub.DeepCopy() | ||
ip, err := o.lister.OperatorsV1alpha1().InstallPlanLister().InstallPlans(sub.GetNamespace()).Get(ipName) | ||
if err != nil { | ||
logger.WithField("installplan", ipName).Warn("unable to get installplan from cache") | ||
return nil, err | ||
} | ||
logger.WithField("installplan", ipName).Debug("found installplan that generated subscription") | ||
|
||
for _, ip := range ips { | ||
for _, step := range ip.Status.Plan { | ||
// TODO: is this enough? should we check equality of pkg/channel? | ||
if step != nil && step.Resource.Kind == v1alpha1.SubscriptionKind && step.Resource.Name == sub.GetName() { | ||
logger.WithField("installplan", ip.GetName()).Debug("found subscription in steps of existing installplan") | ||
out.Status.Install = o.referenceForInstallPlan(ip) | ||
out.Status.State = v1alpha1.SubscriptionStateUpgradePending | ||
if updated, err := o.client.OperatorsV1alpha1().Subscriptions(sub.GetNamespace()).UpdateStatus(out); err != nil { | ||
return nil, err | ||
} else { | ||
return updated, nil | ||
} | ||
} | ||
} | ||
out := sub.DeepCopy() | ||
out.Status.Install = o.referenceForInstallPlan(ip) | ||
out.Status.State = v1alpha1.SubscriptionStateUpgradePending | ||
updated, err := o.client.OperatorsV1alpha1().Subscriptions(sub.GetNamespace()).UpdateStatus(out) | ||
if err != nil { | ||
return nil, err | ||
} | ||
logger.Debug("did not find subscription in steps of existing installplan") | ||
|
||
return sub, nil | ||
return updated, nil | ||
} | ||
|
||
func (o *Operator) ensureSubscriptionCSVState(logger *logrus.Entry, sub *v1alpha1.Subscription) (*v1alpha1.Subscription, error) { | ||
|
@@ -1001,6 +999,13 @@ func (o *Operator) ExecutePlan(plan *v1alpha1.InstallPlan) error { | |
return errorwrap.Wrapf(err, "error parsing step manifest: %s", step.Resource.Name) | ||
} | ||
|
||
// Add the InstallPlan's name as an annotation | ||
if annotations := sub.GetAnnotations(); annotations != nil { | ||
annotations[generatedByKey] = plan.GetName() | ||
} else { | ||
sub.SetAnnotations(map[string]string{generatedByKey: plan.GetName()}) | ||
} | ||
|
||
// Attempt to create the Subscription | ||
sub.SetNamespace(namespace) | ||
_, err = o.client.OperatorsV1alpha1().Subscriptions(sub.GetNamespace()).Create(&sub) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -567,6 +567,7 @@ func TestCreateInstallPlanWithPreExistingCRDOwners(t *testing.T) { | |
// existing cleanup should remove this | ||
createSubscriptionForCatalog(t, crc, testNamespace, subscriptionName, mainCatalogSourceName, mainPackageName, betaChannel, v1alpha1.ApprovalAutomatic) | ||
|
||
// time.Sleep(5 * time.Minute) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. commented |
||
subscription, err = fetchSubscription(t, crc, testNamespace, subscriptionName, subscriptionHasInstallPlanChecker) | ||
require.NoError(t, err) | ||
require.NotNil(t, subscription) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
elsewhere we used
olm.
as a prefix. Also gofmt