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

Update if AlreadyExists #3202

Merged
merged 1 commit into from
Apr 15, 2024

Conversation

dtfranz
Copy link
Contributor

@dtfranz dtfranz commented Apr 12, 2024

Adds code to the client calls for Create to run an Update if the object already exists. This allows us to bypass issues where the object was not found in cache but already exists in the cluster.

@openshift-ci openshift-ci bot added do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. labels Apr 12, 2024
Copy link

openshift-ci bot commented Apr 12, 2024

Skipping CI for Draft Pull Request.
If you want CI signal for your change, please convert it to an actual PR.
You can still manually trigger a test run with /test all

@dtfranz dtfranz force-pushed the update-on-create-fail branch from 4418b49 to 95d3c37 Compare April 12, 2024 16:40
@tmshort
Copy link
Contributor

tmshort commented Apr 12, 2024

Would it make sense to add the olm.managed label to make sure everything is labeled everywhere we create resources?

@stevekuznetsov
Copy link
Contributor

@tmshort every create call should already be setting that in the object payload.

@tmshort
Copy link
Contributor

tmshort commented Apr 12, 2024

@tmshort every create call should already be setting that in the object payload.

"should"

It would mean that we guarantee adding the label, without having to remember everywhere... just a thought. Not necessary for this PR.

@stevekuznetsov
Copy link
Contributor

stevekuznetsov commented Apr 12, 2024

@tmshort we spent quite a lot of time making sure it was present everywhere. If you have any examples of that not being the case, please open a PR. Locality of behavior is a nice property - if you're looking at code that creates an object, you can see what that object looks like without spelunking into hack-ey wrapper bits. Respectfully, I understand where you're coming from but I don't think we have any evidence that we missed any spots where the label should have been present in a create call and I'd prefer us to do targeted, specific changes rather than shots-in-the-dark-just-in-case-who-knows.

@dtfranz dtfranz force-pushed the update-on-create-fail branch from 95d3c37 to 3e45d2e Compare April 12, 2024 22:05
@kuiwang02
Copy link

@dtfranz do we need to change code of CreateServiceAccount in serviceaccount.go to handle already exist? thanks

@dtfranz dtfranz force-pushed the update-on-create-fail branch from 3e45d2e to 01496f7 Compare April 15, 2024 17:34
@dtfranz
Copy link
Contributor Author

dtfranz commented Apr 15, 2024

@kuiwang02 I did this initially but adding that behavior universally to CreateServiceAccount caused an infinite creation loop for CatalogSource secrets, SAs, and pods because the registry code could not properly respond to AlreadyExists errors. For that reason ServiceAccounts and also a few other places in the code have been modified to use simple Create() calls because they already handle AlreadyExists errors in their own unique ways.

@@ -734,6 +734,9 @@ func (c *ConfigMapUnpacker) ensureRole(cmRef *corev1.ObjectReference) (role *rba
if err != nil {
if apierrors.IsNotFound(err) {
role, err = c.client.RbacV1().Roles(fresh.GetNamespace()).Create(context.TODO(), fresh, metav1.CreateOptions{})
if apierrors.IsAlreadyExists(err) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

bundle_unpacker.go does not have the wrapper client; I made the changes this way instead of spending the time to plumb the client in to keep the PR simpler and spend time on more important changes.

@@ -150,7 +150,10 @@ func (r *OperatorConditionReconciler) ensureOperatorConditionRole(operatorCondit
if !apierrors.IsNotFound(err) {
return err
}
return r.Client.Create(context.TODO(), role)
err = r.Client.Create(context.TODO(), role)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

As in bundler_unpacker.go, client wrapper is not available here.

Adds code to the client calls for Create to run an Update if the object already exists. This allows us to bypass issues where the object was not found in cache but already exists in the cluster.

Signed-off-by: Daniel Franz <[email protected]>
@dtfranz dtfranz force-pushed the update-on-create-fail branch from 01496f7 to 9b1be42 Compare April 15, 2024 18:13
@dtfranz dtfranz marked this pull request as ready for review April 15, 2024 18:13
@dtfranz dtfranz changed the title WIP: Update if AlreadyExists Update if AlreadyExists Apr 15, 2024
@openshift-ci openshift-ci bot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Apr 15, 2024
@openshift-ci openshift-ci bot requested review from anik120 and grokspawn April 15, 2024 18:13
Comment on lines +112 to 115
} else if err != nil {
return false, err
}
return true, nil
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit, This could be:

return err == nil, err

For most, if not all, of the returns.

return c.AppsV1().Deployments(dep.Namespace).Create(context.TODO(), dep, metav1.CreateOptions{})
createdDep, err := c.AppsV1().Deployments(dep.Namespace).Create(context.TODO(), dep, metav1.CreateOptions{})
if apierrors.IsAlreadyExists(err) {
updatedDep, _, err := c.UpdateDeployment(dep)
Copy link
Contributor

Choose a reason for hiding this comment

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

Three returns? Compared to the others that just have two? (Just whining)

Copy link
Contributor

@tmshort tmshort left a comment

Choose a reason for hiding this comment

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

/lgtm
Just a few not-important comments.

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Apr 15, 2024
@dtfranz
Copy link
Contributor Author

dtfranz commented Apr 15, 2024

Removed hold comment from above but I guess it needs a whole new comment.
/unhold

@openshift-ci openshift-ci bot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Apr 15, 2024
@kevinrizza
Copy link
Member

/approve

@kevinrizza kevinrizza added this pull request to the merge queue Apr 15, 2024
Merged via the queue into operator-framework:master with commit a7b6658 Apr 15, 2024
14 checks passed
kevinrizza added a commit to kevinrizza/operator-lifecycle-manager that referenced this pull request Apr 17, 2024
In the same vein as
operator-framework#3202,
use update if the unpack job already exists but isn't cached

Signed-off-by: kevinrizza <[email protected]>
kevinrizza added a commit to kevinrizza/operator-lifecycle-manager that referenced this pull request Apr 17, 2024
In the same vein as
operator-framework#3202,
use update if the unpack job already exists but isn't cached

Signed-off-by: kevinrizza <[email protected]>
github-merge-queue bot pushed a commit that referenced this pull request Apr 17, 2024
In the same vein as
#3202,
use update if the unpack job already exists but isn't cached

Signed-off-by: kevinrizza <[email protected]>
openshift-bot pushed a commit to openshift-bot/operator-framework-olm that referenced this pull request Apr 18, 2024
In the same vein as
operator-framework/operator-lifecycle-manager#3202,
use update if the unpack job already exists but isn't cached

Signed-off-by: kevinrizza <[email protected]>
Upstream-repository: operator-lifecycle-manager
Upstream-commit: 47aaa6be4a951c6bd8be016f6610c5319adc6a47
kevinrizza added a commit to kevinrizza/operator-framework-olm that referenced this pull request Apr 18, 2024
In the same vein as
operator-framework/operator-lifecycle-manager#3202,
use update if the unpack job already exists but isn't cached

Signed-off-by: kevinrizza <[email protected]>
Upstream-repository: operator-lifecycle-manager
Upstream-commit: 47aaa6be4a951c6bd8be016f6610c5319adc6a47
openshift-cherrypick-robot pushed a commit to openshift-cherrypick-robot/operator-framework-olm that referenced this pull request Apr 18, 2024
In the same vein as
operator-framework/operator-lifecycle-manager#3202,
use update if the unpack job already exists but isn't cached

Signed-off-by: kevinrizza <[email protected]>
Upstream-repository: operator-lifecycle-manager
Upstream-commit: 47aaa6be4a951c6bd8be016f6610c5319adc6a47
perdasilva pushed a commit to perdasilva/operator-framework-olm that referenced this pull request May 6, 2024
In the same vein as
operator-framework/operator-lifecycle-manager#3202,
use update if the unpack job already exists but isn't cached

Signed-off-by: kevinrizza <[email protected]>
Upstream-repository: operator-lifecycle-manager
Upstream-commit: 47aaa6be4a951c6bd8be016f6610c5319adc6a47
perdasilva pushed a commit to perdasilva/operator-framework-olm that referenced this pull request Jun 4, 2024
In the same vein as
operator-framework/operator-lifecycle-manager#3202,
use update if the unpack job already exists but isn't cached

Signed-off-by: kevinrizza <[email protected]>
Upstream-repository: operator-lifecycle-manager
Upstream-commit: 47aaa6be4a951c6bd8be016f6610c5319adc6a47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lgtm Indicates that a PR is ready to be merged.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants