Skip to content

Commit 75a55c9

Browse files
authored
convertor: reduce default logging (#14)
**What this PR does / why we need it**: Sets the default log level in the convertor tool to info, and makes most logs debug. These can still be enabled with the `--verbose` flag if needed. **Which issue(s) this PR fixes** *(optional, in `fixes #<issue number>(, fixes #<issue_number>, ...)` format, will close the issue(s) when PR gets merged)*: **Please check the following list**: - [ ] Does the affected code have corresponding tests, e.g. unit test, E2E test? - [ ] Does this change require a documentation update? - [ ] Does this introduce breaking changes that would require an announcement or bumping the major version? - [ ] Do all new files have an appropriate license header? <!-- If this is a security issue, please do not discuss on GitHub. Please report any suspected or confirmed security issues directly to https://github.com/containerd/accelerated-container-image/blob/main/MAINTAINERS. -->
1 parent bd4b105 commit 75a55c9

5 files changed

Lines changed: 46 additions & 44 deletions

File tree

cmd/convertor/builder/builder.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ func (b *graphBuilder) Build(ctx context.Context) error {
130130
if err != nil {
131131
return fmt.Errorf("failed to build %q: %w", src.Digest, err)
132132
}
133-
log.G(gctx).Infof("converted to %q, digest: %q", b.TargetRef, target.Digest)
133+
log.G(gctx).Debugf("converted to %q, digest: %q", b.TargetRef, target.Digest)
134134
return nil
135135
})
136136
return g.Wait()
@@ -141,7 +141,7 @@ func (b *graphBuilder) process(ctx context.Context, src v1.Descriptor, tag bool)
141141
if src.Platform != nil && src.Platform.OS == "unknown" && src.Platform.Architecture == "unknown" {
142142
// This might be a provenance manifest, check if it should be skipped
143143
if utils.IsProvenanceDescriptor(src) {
144-
log.G(ctx).Infof("skipping provenance manifest: %s (platform: %s/%s)", src.Digest, src.Platform.OS, src.Platform.Architecture)
144+
log.G(ctx).Debugf("skipping provenance manifest: %s (platform: %s/%s)", src.Digest, src.Platform.OS, src.Platform.Architecture)
145145
// Return a special "skipped" descriptor instead of an error
146146
return v1.Descriptor{}, nil
147147
}
@@ -229,7 +229,7 @@ func (b *graphBuilder) process(ctx context.Context, src v1.Descriptor, tag bool)
229229
if err := uploadBytesWithRetry(ctx, pusher, expected, indexBytes, b.RetryCount); err != nil {
230230
return v1.Descriptor{}, fmt.Errorf("failed to upload index: %w", err)
231231
}
232-
log.G(ctx).Infof("index uploaded, %s", expected.Digest)
232+
log.G(ctx).Debugf("index uploaded, %s", expected.Digest)
233233
return expected, nil
234234
default:
235235
return v1.Descriptor{}, fmt.Errorf("unsupported media type %q", src.MediaType)
@@ -262,7 +262,7 @@ func (b *graphBuilder) buildOne(ctx context.Context, src v1.Descriptor, tag bool
262262
ctx = log.WithLogger(ctx, log.G(ctx).WithField("platform", platform))
263263
}
264264
workdir := filepath.Join(b.WorkDir, fmt.Sprintf("%d-%s-%s", id, strings.ReplaceAll(platform, "/", "_"), src.Digest.Encoded()))
265-
log.G(ctx).Infof("building %s ...", workdir)
265+
log.G(ctx).Debugf("building %s ...", workdir)
266266

267267
// init build engine
268268
manifest, config, err := fetchManifestAndConfig(ctx, b.fetcher, src)
@@ -335,10 +335,10 @@ func Build(ctx context.Context, opt BuilderOptions) error {
335335

336336
// Use custom resolver if provided, otherwise create default docker resolver
337337
if opt.CustomResolver != nil {
338-
log.G(ctx).Info("using custom resolver (tar import mode)")
338+
log.G(ctx).Debug("using custom resolver (tar import mode)")
339339
resolver = opt.CustomResolver
340340
} else {
341-
log.G(ctx).Info("using docker registry resolver")
341+
log.G(ctx).Debug("using docker registry resolver")
342342
tlsConfig, err := loadTLSConfig(opt.CertOption)
343343
if err != nil {
344344
return fmt.Errorf("failed to load certifications: %w", err)
@@ -403,7 +403,7 @@ func (b *overlaybdBuilder) Build(ctx context.Context) (v1.Descriptor, error) {
403403
// check if manifest conversion result is already present in registry, if so, we can avoid conversion.
404404
// when errors are encountered fallback to regular conversion
405405
if convertedDesc, err := b.engine.CheckForConvertedManifest(ctx); err == nil && convertedDesc.Digest != "" {
406-
logrus.Infof("Image found already converted in registry with digest %s", convertedDesc.Digest)
406+
logrus.Debugf("Image found already converted in registry with digest %s", convertedDesc.Digest)
407407
// Even if the image has been found we still need to make sure the requested tag is set
408408
// fetch the manifest then push again with the requested tag
409409
if err := b.engine.TagPreviouslyConvertedManifest(ctx, convertedDesc); err != nil {
@@ -453,7 +453,7 @@ func (b *overlaybdBuilder) Build(ctx context.Context) (v1.Descriptor, error) {
453453
// download the converted layer
454454
err := b.engine.DownloadConvertedLayer(rctx, idx, *cachedLayer)
455455
if err == nil {
456-
logrus.Infof("downloaded cached layer %d", idx)
456+
logrus.Debugf("downloaded cached layer %d", idx)
457457
sendToChannel(rctx, downloaded[idx], nil)
458458
return nil
459459
}
@@ -463,7 +463,7 @@ func (b *overlaybdBuilder) Build(ctx context.Context) (v1.Descriptor, error) {
463463
if err := b.engine.DownloadLayer(rctx, idx); err != nil {
464464
return err
465465
}
466-
logrus.Infof("downloaded layer %d", idx)
466+
logrus.Debugf("downloaded layer %d", idx)
467467
sendToChannel(rctx, downloaded[idx], nil)
468468
return nil
469469
})
@@ -482,7 +482,7 @@ func (b *overlaybdBuilder) Build(ctx context.Context) (v1.Descriptor, error) {
482482
if err := b.engine.BuildLayer(rctx, idx); err != nil {
483483
return fmt.Errorf("failed to convert layer %d: %w", idx, err)
484484
}
485-
logrus.Infof("layer %d converted", idx)
485+
logrus.Debugf("layer %d converted", idx)
486486
// send to upload(idx) and convert(idx+1) once each
487487
sendToChannel(rctx, converted[idx], nil)
488488
if idx+1 < b.layers {
@@ -499,7 +499,7 @@ func (b *overlaybdBuilder) Build(ctx context.Context) (v1.Descriptor, error) {
499499
return fmt.Errorf("failed to upload layer %d: %w", idx, err)
500500
}
501501
b.engine.StoreConvertedLayerDetails(rctx, idx)
502-
logrus.Infof("layer %d uploaded", idx)
502+
logrus.Debugf("layer %d uploaded", idx)
503503
return nil
504504
})
505505
}

cmd/convertor/builder/builder_utils.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ func fetch(ctx context.Context, fetcher remotes.Fetcher, desc specs.Descriptor,
135135

136136
func fetchManifest(ctx context.Context, fetcher remotes.Fetcher, desc specs.Descriptor) (*specs.Manifest, error) {
137137
platformMatcher := platforms.Default()
138-
log.G(ctx).Infof("fetching manifest %v with type %v", desc.Digest, desc.MediaType)
138+
log.G(ctx).Debugf("fetching manifest %v with type %v", desc.Digest, desc.MediaType)
139139
switch desc.MediaType {
140140
case images.MediaTypeDockerSchema2Manifest, specs.MediaTypeImageManifest:
141141
manifest := specs.Manifest{}
@@ -279,7 +279,7 @@ func uploadBlobWithRetry(ctx context.Context, pusher remotes.Pusher, path string
279279
cw, err := pusher.Push(ctx, desc)
280280
if err != nil {
281281
if errdefs.IsAlreadyExists(err) {
282-
logrus.Infof("layer %s exists", desc.Digest.String())
282+
logrus.Debugf("layer %s exists", desc.Digest.String())
283283
return nil
284284
}
285285
return err

cmd/convertor/builder/content_store_resolver.go

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -113,47 +113,47 @@ func NewContentStoreResolverFromTar(ctx context.Context, tarPath string) (*Conte
113113
}
114114

115115
// Store image references (skip provenance layers)
116-
log.G(ctx).Infof("processing %d manifests from index", len(index.Manifests))
116+
log.G(ctx).Debugf("processing %d manifests from index", len(index.Manifests))
117117
for i, manifest := range index.Manifests {
118-
log.G(ctx).Infof("=== Processing manifest %d/%d ===", i+1, len(index.Manifests))
119-
log.G(ctx).Infof(" MediaType: %s", manifest.MediaType)
120-
log.G(ctx).Infof(" Digest: %s", manifest.Digest)
121-
log.G(ctx).Infof(" Size: %d bytes", manifest.Size)
118+
log.G(ctx).Debugf("=== Processing manifest %d/%d ===", i+1, len(index.Manifests))
119+
log.G(ctx).Debugf(" MediaType: %s", manifest.MediaType)
120+
log.G(ctx).Debugf(" Digest: %s", manifest.Digest)
121+
log.G(ctx).Debugf(" Size: %d bytes", manifest.Size)
122122

123123
if manifest.Platform != nil {
124-
log.G(ctx).Infof(" Platform: %s/%s", manifest.Platform.OS, manifest.Platform.Architecture)
124+
log.G(ctx).Debugf(" Platform: %s/%s", manifest.Platform.OS, manifest.Platform.Architecture)
125125
if manifest.Platform.Variant != "" {
126-
log.G(ctx).Infof(" Platform Variant: %s", manifest.Platform.Variant)
126+
log.G(ctx).Debugf(" Platform Variant: %s", manifest.Platform.Variant)
127127
}
128128
}
129129

130130
if manifest.ArtifactType != "" {
131-
log.G(ctx).Infof(" ArtifactType: %s", manifest.ArtifactType)
131+
log.G(ctx).Debugf(" ArtifactType: %s", manifest.ArtifactType)
132132
}
133133

134134
if manifest.Annotations != nil && len(manifest.Annotations) > 0 {
135-
log.G(ctx).Infof(" Annotations:")
135+
log.G(ctx).Debugf(" Annotations:")
136136
for key, value := range manifest.Annotations {
137-
log.G(ctx).Infof(" %s: %s", key, value)
137+
log.G(ctx).Debugf(" %s: %s", key, value)
138138
}
139139
}
140140

141141
// Skip provenance and attestation manifests
142142
if isProvenanceManifestWithContent(ctx, store, manifest) {
143-
log.G(ctx).Infof(" ❌ SKIPPING: Detected as provenance/attestation manifest")
143+
log.G(ctx).Debugf(" ❌ SKIPPING: Detected as provenance/attestation manifest")
144144
continue
145145
}
146146

147147
// Check if this is an image index (multi-arch)
148148
if manifest.MediaType == v1.MediaTypeImageIndex || manifest.MediaType == "application/vnd.docker.distribution.manifest.list.v2+json" {
149-
log.G(ctx).Infof(" 📁 FOUND IMAGE INDEX: Importing as-is for multi-arch conversion")
149+
log.G(ctx).Debugf(" 📁 FOUND IMAGE INDEX: Importing as-is for multi-arch conversion")
150150

151151
// Import the index itself - let the builder handle platform traversal
152152
ref := fmt.Sprintf("imported:%s", manifest.Digest.Encoded()[:12])
153153
if manifest.Annotations != nil {
154154
if name, ok := manifest.Annotations["org.opencontainers.image.ref.name"]; ok {
155155
ref = name
156-
log.G(ctx).Infof(" Using annotation-based ref: %s", ref)
156+
log.G(ctx).Debugf(" Using annotation-based ref: %s", ref)
157157
}
158158
}
159159

@@ -162,18 +162,18 @@ func NewContentStoreResolverFromTar(ctx context.Context, tarPath string) (*Conte
162162
Target: manifest,
163163
}
164164
imageStore.Create(ctx, image)
165-
log.G(ctx).Infof(" ✅ IMPORTED INDEX: %s -> %s (will be processed as multi-arch)", ref, manifest.Digest)
165+
log.G(ctx).Debugf(" ✅ IMPORTED INDEX: %s -> %s (will be processed as multi-arch)", ref, manifest.Digest)
166166
continue
167167
}
168168

169-
log.G(ctx).Infof(" ✅ PROCESSING: Regular container manifest")
169+
log.G(ctx).Debugf(" ✅ PROCESSING: Regular container manifest")
170170

171171
// Generate a reference name for the imported image
172172
ref := fmt.Sprintf("imported:%s", manifest.Digest.Encoded()[:12])
173173
if manifest.Annotations != nil {
174174
if name, ok := manifest.Annotations["org.opencontainers.image.ref.name"]; ok {
175175
ref = name
176-
log.G(ctx).Infof(" Using annotation-based ref: %s", ref)
176+
log.G(ctx).Debugf(" Using annotation-based ref: %s", ref)
177177
}
178178
}
179179

@@ -182,7 +182,7 @@ func NewContentStoreResolverFromTar(ctx context.Context, tarPath string) (*Conte
182182
Target: manifest,
183183
}
184184
imageStore.Create(ctx, image)
185-
log.G(ctx).Infof(" ✅ IMPORTED: %s -> %s", ref, manifest.Digest)
185+
log.G(ctx).Debugf(" ✅ IMPORTED: %s -> %s", ref, manifest.Digest)
186186
}
187187

188188
return NewContentStoreResolver(store, imageStore), nil

cmd/convertor/builder/overlaybd_builder.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -486,7 +486,7 @@ func (e *overlaybdBuilderEngine) uploadBaseLayer(ctx context.Context) (specs.Des
486486
if err = uploadBlobWithRetry(ctx, e.pusher, tarFile, baseDesc, e.retryCount); err != nil {
487487
return specs.Descriptor{}, errors.Wrapf(err, "failed to upload baselayer")
488488
}
489-
logrus.Infof("baselayer uploaded")
489+
logrus.Debugf("baselayer uploaded")
490490
}
491491
return baseDesc, nil
492492
}
@@ -526,7 +526,7 @@ func (e *overlaybdBuilderEngine) commit(ctx context.Context, dir string, idx int
526526
if err := utils.Commit(ctx, dir, dir, false, opts...); err != nil {
527527
return err
528528
}
529-
logrus.Infof("layer %d committed, uuid: %s, parent uuid: %s", idx, curUUID, parentUUID)
529+
logrus.Debugf("layer %d committed, uuid: %s, parent uuid: %s", idx, curUUID, parentUUID)
530530
return nil
531531
}
532532

cmd/convertor/main.go

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@ Description: overlaybd convertor is a standalone userspace image conversion tool
8484
8585
Version: ` + commitID,
8686
Run: func(cmd *cobra.Command, args []string) {
87+
// Set default log level to Info, enable Debug with --verbose
88+
logrus.SetLevel(logrus.InfoLevel)
8789
if verbose {
8890
logrus.SetLevel(logrus.DebugLevel)
8991
}
@@ -127,7 +129,7 @@ Version: ` + commitID,
127129

128130
if importTar != "" {
129131
// Import mode - create content store resolver from tar
130-
logrus.Infof("importing from tar file: %s", importTar)
132+
logrus.Debugf("importing from tar file: %s", importTar)
131133
var err error
132134
importResolver, err = builder.NewContentStoreResolverFromTar(ctx, importTar)
133135
if err != nil {
@@ -159,23 +161,23 @@ Version: ` + commitID,
159161
if ref == "" {
160162
ref = images[0].Name
161163
isMultiArch = (images[0].Target.MediaType == "application/vnd.oci.image.index.v1+json")
162-
logrus.Warnf("no main index found, using first image: %s", ref)
164+
logrus.Debugf("no main index found, using first image: %s", ref)
163165
} else {
164-
logrus.Infof("found main image reference: %s", ref)
166+
logrus.Debugf("found main image reference: %s", ref)
165167
}
166168

167169
// Log what we're building
168170
if isMultiArch {
169-
logrus.Infof("building multi-arch image with %d total imported images", len(images))
171+
logrus.Debugf("building multi-arch image with %d total imported images", len(images))
170172
} else {
171-
logrus.Infof("building single-arch image: %s", ref)
173+
logrus.Debugf("building single-arch image: %s", ref)
172174
}
173175

174176
// Choose resolver based on export mode
175177
var customResolver remotes.Resolver
176178
if exportTar != "" {
177179
// For tar export, use FileBasedResolver to capture converted layers locally
178-
logrus.Infof("tar export mode: using file-based resolver to capture converted layers")
180+
logrus.Debugf("tar export mode: using file-based resolver to capture converted layers")
179181
var err error
180182
exportResolver, err = builder.NewFileBasedResolver(importResolver.Store(), importResolver.ImageStore())
181183
if err != nil {
@@ -199,7 +201,7 @@ Version: ` + commitID,
199201
logrus.Error("repository is required when not using export-tar")
200202
os.Exit(1)
201203
}
202-
logrus.Infof("registry export mode: creating hybrid resolver for tar import -> registry push")
204+
logrus.Debugf("registry export mode: creating hybrid resolver for tar import -> registry push")
203205

204206
// Create registry resolver for pushing (simplified TLS config)
205207
tlsConfig := &tls.Config{
@@ -318,7 +320,7 @@ Version: ` + commitID,
318320
switch dbType {
319321
case "mysql":
320322
if dbstr == "" {
321-
logrus.Warnf("no db-str was provided, falling back to no deduplication")
323+
logrus.Debugf("no db-str was provided, falling back to no deduplication")
322324
}
323325
db, err := sql.Open("mysql", dbstr)
324326
if err != nil {
@@ -328,8 +330,8 @@ Version: ` + commitID,
328330
opt.DB = database.NewSqlDB(db)
329331
case "":
330332
default:
331-
logrus.Warnf("db-type %s was provided but is not one of known db types. Available: mysql", dbType)
332-
logrus.Warnf("falling back to no deduplication")
333+
logrus.Debugf("db-type %s was provided but is not one of known db types. Available: mysql", dbType)
334+
logrus.Debugf("falling back to no deduplication")
333335
}
334336

335337
if err := builder.Build(ctx, opt); err != nil {
@@ -340,7 +342,7 @@ Version: ` + commitID,
340342

341343
// Handle tar export if requested
342344
if exportTar != "" && exportResolver != nil {
343-
logrus.Infof("exporting converted overlaybd layers to tar file: %s", exportTar)
345+
logrus.Debugf("exporting converted overlaybd layers to tar file: %s", exportTar)
344346
if err := builder.ExportContentStoreToTar(ctx, exportResolver.OutputStore(), exportResolver.OutputImageStore(), exportTar); err != nil {
345347
logrus.Errorf("failed to export tar file: %v", err)
346348
os.Exit(1)
@@ -360,7 +362,7 @@ Version: ` + commitID,
360362

361363
// Handle tar export if requested
362364
if exportTar != "" && exportResolver != nil {
363-
logrus.Infof("exporting converted turboOCI layers to tar file: %s", exportTar)
365+
logrus.Debugf("exporting converted turboOCI layers to tar file: %s", exportTar)
364366
if err := builder.ExportContentStoreToTar(ctx, exportResolver.OutputStore(), exportResolver.OutputImageStore(), exportTar); err != nil {
365367
logrus.Errorf("failed to export tar file: %v", err)
366368
os.Exit(1)

0 commit comments

Comments
 (0)