Skip to content

Commit abdc20c

Browse files
authored
fix run bundle(-upgrade) to no longer stall (#6040)
* fix run bundle(-upgrade) to no longer stall Signed-off-by: Bryce Palmer <[email protected]> * add changelog Signed-off-by: Bryce Palmer <[email protected]> * add err check and log warning for linter Signed-off-by: Bryce Palmer <[email protected]> Signed-off-by: Bryce Palmer <[email protected]>
1 parent 79afd93 commit abdc20c

File tree

3 files changed

+28
-28
lines changed

3 files changed

+28
-28
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# entries is a list of entries to include in
2+
# release notes and/or the migration guide
3+
entries:
4+
- description: >
5+
`operator-sdk run bundle(-upgrade)`: fixed bug causing `operator-sdk run bundle-upgrade` and `operator-sdk run bundle ... --index-image=...` to stall indefinitely.
6+
kind: "bugfix"
7+
breaking: false
8+

internal/olm/fbcutil/util.go

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"fmt"
2222
"io/ioutil"
2323
"os"
24+
"strings"
2425

2526
"github.com/operator-framework/operator-registry/alpha/action"
2627
"github.com/operator-framework/operator-registry/alpha/declcfg"
@@ -32,9 +33,10 @@ import (
3233
)
3334

3435
const (
35-
SchemaChannel = "olm.channel"
36-
SchemaPackage = "olm.package"
37-
DefaultChannel = "operator-sdk-run-bundle"
36+
SchemaChannel = "olm.channel"
37+
SchemaPackage = "olm.package"
38+
DefaultChannel = "operator-sdk-run-bundle"
39+
DefaultCacheDir = "operator-sdk-run-bundle-cache"
3840
)
3941

4042
const (
@@ -132,16 +134,26 @@ func NullLogger() *log.Entry {
132134
// RenderRefs will invoke Operator Registry APIs and return a declarative config object representation
133135
// of the references that are passed in as a string array.
134136
func RenderRefs(ctx context.Context, refs []string, skipTLSVerify bool, useHTTP bool) (*declarativeconfig.DeclarativeConfig, error) {
135-
137+
cacheDir := strings.ReplaceAll(strings.Join(refs, "_"), "/", "-")
138+
if cacheDir == "" {
139+
cacheDir = DefaultCacheDir
140+
}
136141
reg, err := containerdregistry.NewRegistry(
137142
containerdregistry.WithLog(NullLogger()),
138143
containerdregistry.SkipTLSVerify(skipTLSVerify),
139-
containerdregistry.WithPlainHTTP(useHTTP))
140-
144+
containerdregistry.WithPlainHTTP(useHTTP),
145+
containerdregistry.WithCacheDir(cacheDir))
141146
if err != nil {
142147
return nil, fmt.Errorf("error creating new image registry: %v", err)
143148
}
144149

150+
defer func() {
151+
err = reg.Destroy()
152+
if err != nil {
153+
log.Warn(fmt.Sprintf("Unable to cleanup registry. You may have to manually cleanup by removing the %q directory", cacheDir))
154+
}
155+
}()
156+
145157
render := action.Render{
146158
Refs: refs,
147159
Registry: reg,

internal/olm/operator/bundle/install.go

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,13 @@ package bundle
1717
import (
1818
"context"
1919
"fmt"
20-
"io/ioutil"
21-
"os"
2220
"strings"
2321

2422
log "github.com/sirupsen/logrus"
2523
"github.com/spf13/pflag"
2624

2725
"github.com/operator-framework/api/pkg/operators/v1alpha1"
28-
"github.com/operator-framework/operator-registry/alpha/action"
2926
declarativeconfig "github.com/operator-framework/operator-registry/alpha/declcfg"
30-
"github.com/operator-framework/operator-registry/pkg/image/containerdregistry"
3127
registrybundle "github.com/operator-framework/operator-registry/pkg/lib/bundle"
3228
fbcutil "github.com/operator-framework/operator-sdk/internal/olm/fbcutil"
3329
"github.com/operator-framework/operator-sdk/internal/olm/operator"
@@ -191,26 +187,10 @@ func generateFBCContent(ctx context.Context, f *fbcutil.FBCContext, bundleImage,
191187
// declarative config type.
192188
func generateExtraFBC(ctx context.Context, indexImage string, bundleDeclConfig fbcutil.BundleDeclcfg, skipTLSVerify bool, useHTTP bool) (*declarativeconfig.DeclarativeConfig, error) {
193189
log.Infof("Rendering a File-Based Catalog of the Index Image %q to verify if bundle %q is present", indexImage, bundleDeclConfig.Bundle.Name)
194-
log.SetOutput(ioutil.Discard)
195-
196-
reg, err := containerdregistry.NewRegistry(
197-
containerdregistry.WithLog(fbcutil.NullLogger()),
198-
containerdregistry.SkipTLSVerify(skipTLSVerify),
199-
containerdregistry.WithPlainHTTP(useHTTP))
200190

191+
imageDeclConfig, err := fbcutil.RenderRefs(ctx, []string{indexImage}, skipTLSVerify, useHTTP)
201192
if err != nil {
202-
return nil, fmt.Errorf("error creating new image registry: %v", err)
203-
}
204-
205-
render := action.Render{
206-
Refs: []string{indexImage},
207-
Registry: reg,
208-
}
209-
210-
imageDeclConfig, err := render.Run(ctx)
211-
log.SetOutput(os.Stdout)
212-
if err != nil {
213-
return nil, fmt.Errorf("error rendering the index image %q: %v", indexImage, err)
193+
return nil, err
214194
}
215195

216196
for _, bundle := range imageDeclConfig.Bundles {

0 commit comments

Comments
 (0)