Skip to content

Commit

Permalink
remove strict-versioning flag
Browse files Browse the repository at this point in the history
  • Loading branch information
Kristina Pathak committed Apr 5, 2024
1 parent b7d0161 commit 8585de4
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 94 deletions.
2 changes: 1 addition & 1 deletion .chloggen/builder-skip-module.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ change_type: enhancement
component: builder

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Add a --skip-new-go-module flag to skip creating a module in the output directory, and a --strict-versioning flag to error on mismatch between the otelcol_version configurted and the builder version or versions in the go.mod.
note: Add a --skip-new-go-module flag to skip creating a module in the output directory.

# One or more tracking issues or pull requests related to the change
issues: [9252]
Expand Down
21 changes: 0 additions & 21 deletions cmd/builder/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -165,24 +165,3 @@ This mode cannot be used in conjunction with several features that
control the generated `go.mod` file, including `replaces`, `excludes`,
and the component `path` override. For each of these features, users
are expected to modify the enclosing `go.mod` directly.

### Strict versioning checks

There is an option that controls version strictness applied by the
builder. When the `--strict-versioning` command-line flag is used,
the following additional checks apply to the finished `go.mod` file
after getting all the components and tidying the result.

1. The `dist::otelcol_version` field in the build configuration must
match the core library version calculated by the Go toolchain,
considering all components. A mismatch could happen, for example,
when one of the components depends on a newer release of the core
collector library.
2. For each component in the build configuration, the version included
in the `gomod` module specifier must match the one calculated by
the Go toolchain, considering all components. A mismatch could
happen, for example, when the enclosing Go module uses a newer
release of the core collector library.

When `--skip-new-go-module` is used, these checks apply to the
enclosing Go module; otherwise, they apply to the generated module.
15 changes: 7 additions & 8 deletions cmd/builder/internal/builder/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,13 @@ var (

// Config holds the builder's configuration
type Config struct {
Logger *zap.Logger
SkipGenerate bool `mapstructure:"-"`
SkipCompilation bool `mapstructure:"-"`
SkipGetModules bool `mapstructure:"-"`
SkipNewGoModule bool `mapstructure:"-"`
StrictVersioning bool `mapstructure:"-"`
LDFlags string `mapstructure:"-"`
Verbose bool `mapstructure:"-"`
Logger *zap.Logger
SkipGenerate bool `mapstructure:"-"`
SkipCompilation bool `mapstructure:"-"`
SkipGetModules bool `mapstructure:"-"`
SkipNewGoModule bool `mapstructure:"-"`
LDFlags string `mapstructure:"-"`
Verbose bool `mapstructure:"-"`

Distribution Distribution `mapstructure:"dist"`
Exporters []Module `mapstructure:"exporters"`
Expand Down
40 changes: 1 addition & 39 deletions cmd/builder/internal/builder/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,6 @@ func Generate(cfg Config) error {
}
// create a warning message for non-aligned builder and collector base
if cfg.Distribution.OtelColVersion != defaultOtelColVersion {
if cfg.StrictVersioning {
return fmt.Errorf("builder version %q does not match build configuration version %q: %w", cfg.Distribution.OtelColVersion, defaultOtelColVersion, ErrStrictMode)
}

cfg.Logger.Info("You're building a distribution with non-aligned version of the builder. Compilation may fail due to API changes. Please upgrade your builder or API", zap.String("builder-version", defaultOtelColVersion))
}
// if the file does not exist, try to create it
Expand Down Expand Up @@ -147,10 +143,6 @@ func Compile(cfg Config) error {
return nil
}

if err := downloadModules(cfg); err != nil {
return err
}

cfg.Logger.Info("Compiling")

var ldflags = "-s -w"
Expand Down Expand Up @@ -197,37 +189,7 @@ func GetModules(cfg Config) error {
return fmt.Errorf("failed to update go.mod: %w", err)
}

if !cfg.StrictVersioning {
return nil
}

// Perform strict version checking. For each component listed and the
// otelcol core dependency, check that the enclosing go module matches.
mf, mvm, err := cfg.readGoModFile()
if err != nil {
return err
}

coremod, corever := cfg.coreModuleAndVersion()
if mvm[coremod] != corever {
return fmt.Errorf("core collector version calculated by component dependencies %q does not match configured version %q: %w", mvm[coremod], corever, ErrStrictMode)
}

for _, mod := range cfg.allComponents() {
module, version, _ := strings.Cut(mod.GoMod, " ")
if module == mf.Module.Path {
// Main module is not checked, by definition. This happens
// with --skip-new-go-module where the enclosing module
// contains the components used in the build.
continue
}

if mvm[module] != version {
return fmt.Errorf("component %q version calculated by dependencies %q does not match configured version %q: %w", module, mvm[module], version, ErrStrictMode)
}
}

return nil
return downloadModules(cfg)
}

func downloadModules(cfg Config) error {
Expand Down
43 changes: 18 additions & 25 deletions cmd/builder/internal/builder/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,6 @@ func TestGenerateInvalidOutputPath(t *testing.T) {
require.Contains(t, err.Error(), "failed to create output path")
}

func TestStrictVersioning(t *testing.T) {
cfg := NewDefaultConfig()
cfg.Distribution.OtelColVersion = "0.0.0"
cfg.StrictVersioning = true
err := Generate(cfg)
require.ErrorIs(t, err, ErrStrictMode)
}

func TestSkipGenerate(t *testing.T) {
cfg := NewDefaultConfig()
cfg.Distribution.OutputPath = t.TempDir()
Expand Down Expand Up @@ -235,23 +227,24 @@ func TestGetModules(t *testing.T) {
return cfg
},
},
{
description: "Skip New Gomod Success with Strict Versioning",
cfgBuilder: func(t *testing.T) Config {
cfg := NewDefaultConfig()
cfg.downloadModules.wait = 0
cfg.Distribution.Go = "go"
cfg.StrictVersioning = true
tempDir := t.TempDir()
require.NoError(t, makeModule(tempDir, goModTestFile))
outputDir := filepath.Clean(filepath.Join(tempDir, "output"))
cfg.Distribution.OutputPath = outputDir
cfg.Replaces = nil
cfg.Excludes = nil
cfg.SkipNewGoModule = true
return cfg
},
},
// this test requires SkipNewGoModule and StrictVersioning
//{
// description: "Skip New Gomod Success with Strict Versioning",
// cfgBuilder: func(t *testing.T) Config {
// cfg := NewDefaultConfig()
// cfg.downloadModules.wait = 0
// cfg.Distribution.Go = "go"
// cfg.StrictVersioning = true
// tempDir := t.TempDir()
// require.NoError(t, makeModule(tempDir, goModTestFile))
// outputDir := filepath.Clean(filepath.Join(tempDir, "output"))
// cfg.Distribution.OutputPath = outputDir
// cfg.Replaces = nil
// cfg.Excludes = nil
// cfg.SkipNewGoModule = true
// return cfg
// },
//},
{
description: "No Go Distribution",
cfgBuilder: func(_ *testing.T) Config {
Expand Down

0 comments on commit 8585de4

Please sign in to comment.