-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Fix a bug in olm install #6490
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
Merged
everettraven
merged 1 commit into
operator-framework:master
from
nunnatsa:fix-olm-install
Jul 17, 2023
Merged
Fix a bug in olm install #6490
Changes from all commits
Commits
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 hidden or 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 |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# entries is a list of entries to include in | ||
# release notes and/or the migration guide | ||
entries: | ||
- description: > | ||
Fix a bug where `olm install` command is failed fo "no-match" error. | ||
|
||
The output in this case is something like: | ||
|
||
``` | ||
$ operator-sdk olm install --verbose | ||
... | ||
FATA[0001] Failed to install OLM version "latest": failed to create CRDs and resources: no matches for kind "OLMConfig" in version "operators.coreos.com/v1" | ||
``` | ||
|
||
Now, in this case, operator-sdk tries to create the resource again, until it succeed (or until the timeout exceeded). | ||
|
||
kind: "bugfix" | ||
|
||
# Is this a breaking change? | ||
breaking: false |
This file contains hidden or 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 |
---|---|---|
|
@@ -30,7 +30,6 @@ import ( | |
log "github.com/sirupsen/logrus" | ||
appsv1 "k8s.io/api/apps/v1" | ||
corev1 "k8s.io/api/core/v1" | ||
|
||
apierrors "k8s.io/apimachinery/pkg/api/errors" | ||
"k8s.io/apimachinery/pkg/api/meta" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
|
@@ -112,18 +111,50 @@ func NewClientForConfig(cfg *rest.Config) (*Client, error) { | |
func (c Client) DoCreate(ctx context.Context, objs ...client.Object) error { | ||
for _, obj := range objs { | ||
kind := obj.GetObjectKind().GroupVersionKind().Kind | ||
log.Infof(" Creating %s %q", kind, getName(obj.GetNamespace(), obj.GetName())) | ||
err := c.KubeClient.Create(ctx, obj) | ||
if err != nil { | ||
if !apierrors.IsAlreadyExists(err) { | ||
return err | ||
} | ||
log.Infof(" %s %q already exists", kind, getName(obj.GetNamespace(), obj.GetName())) | ||
resourceName := getName(obj.GetNamespace(), obj.GetName()) | ||
|
||
log.Infof(" Creating %s %q", kind, resourceName) | ||
|
||
if err := c.safeCreateOneResource(ctx, obj, kind, resourceName); err != nil { | ||
log.Infof(" failed to create %s %q; %v", kind, resourceName, err) | ||
return err | ||
} | ||
} | ||
return nil | ||
} | ||
|
||
// try to create 10 times before giving up | ||
func (c Client) safeCreateOneResource(ctx context.Context, obj client.Object, kind string, resourceName string) error { | ||
backoff := wait.Backoff{ | ||
// retrying every one seconds. We're relaying on the timeout context, so the number of steps is very large, so | ||
// we could use the timeout flag (or its default value), as it used to create the context. | ||
Duration: time.Second, | ||
Steps: 1000, | ||
Factor: 1, | ||
} | ||
|
||
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. It would be a bit more idiomatic (at least from our kubernetes adjacency) to use the client-go retry package. 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. +1 to using the retry package |
||
err := wait.ExponentialBackoffWithContext(ctx, backoff, func() (bool, error) { | ||
err := c.KubeClient.Create(ctx, obj) | ||
if err == nil || apierrors.IsAlreadyExists(err) { | ||
log.Infof(" %s %q created", kind, resourceName) | ||
return true, nil | ||
} | ||
|
||
if meta.IsNoMatchError(err) { | ||
oceanc80 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
log.Infof(" Failed to create %s %q. CRD is not ready yet. Retrying...", kind, resourceName) | ||
return false, nil | ||
} | ||
|
||
return false, err | ||
}) | ||
|
||
if err != nil && errors.Is(err, context.DeadlineExceeded) { | ||
return fmt.Errorf("timeout") | ||
} | ||
|
||
return err | ||
} | ||
|
||
func (c Client) DoDelete(ctx context.Context, objs ...client.Object) error { | ||
for _, obj := range objs { | ||
kind := obj.GetObjectKind().GroupVersionKind().Kind | ||
|
This file contains hidden or 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.
Uh oh!
There was an error while loading. Please reload this page.