Skip to content

Commit

Permalink
exporter: make exporter.Config private
Browse files Browse the repository at this point in the history
Make the field `compression` private in case it is initialized
with nil compression.Type.

Signed-off-by: Yan Song <imeoer@linux.alibaba.com>
  • Loading branch information
imeoer committed Sep 30, 2022
1 parent 593840e commit 3c82a8b
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 16 deletions.
6 changes: 2 additions & 4 deletions exporter/containerimage/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,10 +190,8 @@ func (e *imageExporterInstance) Name() string {
return "exporting to image"
}

func (e *imageExporterInstance) Config() exporter.Config {
return exporter.Config{
Compression: e.opts.RefCfg.Compression,
}
func (e *imageExporterInstance) Config() *exporter.Config {
return exporter.NewConfigWithCompression(e.opts.RefCfg.Compression)
}

func (e *imageExporterInstance) Export(ctx context.Context, src *exporter.Source, sessionID string) (map[string]string, error) {
Expand Down
23 changes: 21 additions & 2 deletions exporter/exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,29 @@ type Exporter interface {

type ExporterInstance interface {
Name() string
Config() Config
Config() *Config
Export(ctx context.Context, src *Source, sessionID string) (map[string]string, error)
}

type Config struct {
Compression compression.Config
// Make the field private in case it is initialized with nil compression.Type
compression compression.Config
}

func NewConfig() *Config {
return &Config{
compression: compression.Config{
Type: compression.Default,
},
}
}

func NewConfigWithCompression(comp compression.Config) *Config {
return &Config{
compression: comp,
}
}

func (c *Config) Compression() compression.Config {
return c.compression
}
4 changes: 2 additions & 2 deletions exporter/local/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ func (e *localExporterInstance) Name() string {
return "exporting to client"
}

func (e *localExporter) Config() exporter.Config {
return exporter.Config{}
func (e *localExporter) Config() *exporter.Config {
return exporter.NewConfig()
}

func (e *localExporterInstance) Export(ctx context.Context, inp *exporter.Source, sessionID string) (map[string]string, error) {
Expand Down
6 changes: 2 additions & 4 deletions exporter/oci/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,8 @@ func (e *imageExporterInstance) Name() string {
return "exporting to oci image format"
}

func (e *imageExporterInstance) Config() exporter.Config {
return exporter.Config{
Compression: e.opts.RefCfg.Compression,
}
func (e *imageExporterInstance) Config() *exporter.Config {
return exporter.NewConfigWithCompression(e.opts.RefCfg.Compression)
}

func (e *imageExporterInstance) Export(ctx context.Context, src *exporter.Source, sessionID string) (map[string]string, error) {
Expand Down
4 changes: 2 additions & 2 deletions exporter/tar/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ func (e *localExporterInstance) Name() string {
return "exporting to client"
}

func (e *localExporterInstance) Config() exporter.Config {
return exporter.Config{}
func (e *localExporterInstance) Config() *exporter.Config {
return exporter.NewConfig()
}

func (e *localExporterInstance) Export(ctx context.Context, inp *exporter.Source, sessionID string) (map[string]string, error) {
Expand Down
4 changes: 2 additions & 2 deletions solver/llbsolver/solver.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ func (s *Solver) Solve(ctx context.Context, id string, sessionID string, req fro
if _, ok := asInlineCache(exp.CacheExporter); ok {
if err := inBuilderContext(ctx, j, "preparing layers for inline cache", j.SessionID+"-cache-inline", func(ctx context.Context, _ session.Group) error {
if cached.Ref != nil {
dtic, err := inlineCache(ctx, exp.CacheExporter, cached.Ref, e.Config().Compression, session.NewGroup(sessionID))
dtic, err := inlineCache(ctx, exp.CacheExporter, cached.Ref, e.Config().Compression(), session.NewGroup(sessionID))
if err != nil {
return err
}
Expand All @@ -224,7 +224,7 @@ func (s *Solver) Solve(ctx context.Context, id string, sessionID string, req fro
}
}
for k, res := range cached.Refs {
dtic, err := inlineCache(ctx, exp.CacheExporter, res, e.Config().Compression, session.NewGroup(sessionID))
dtic, err := inlineCache(ctx, exp.CacheExporter, res, e.Config().Compression(), session.NewGroup(sessionID))
if err != nil {
return err
}
Expand Down

0 comments on commit 3c82a8b

Please sign in to comment.