Skip to content
This repository has been archived by the owner on Oct 29, 2021. It is now read-only.

Remove Core from Module type #77

Merged
merged 2 commits into from
Oct 14, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions internal/builder/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ const defaultOtelColVersion = "0.36.0"
// ErrInvalidGoMod indicates an invalid gomod
var ErrInvalidGoMod = errors.New("invalid gomod specification for module")

// ErrDeprecatedCore indicates deprecated core
var ErrDeprecatedCore = errors.New("mod.Core has deprecated, you should not be used anymore and required to be set mod.GoMod instead")

// Config holds the builder's configuration
type Config struct {
Logger logr.Logger
Expand Down Expand Up @@ -64,7 +67,8 @@ type Module struct {
Import string `mapstructure:"import"` // if not specified, this is the path part of the go mods
GoMod string `mapstructure:"gomod"` // a gomod-compatible spec for the module
Path string `mapstructure:"path"` // an optional path to the local version of this module
Core bool `mapstructure:"core"` // whether this module comes from core, meaning that no further dependencies will be added
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would say that we should keep this property for a couple of releases, telling users what to use instead.

Core *bool `mapstructure:"core"` // whether this module comes from core. For this property isn't referred from anywhere, it might be removed. please see #15.

}

// DefaultConfig creates a new config, with default values
Expand Down Expand Up @@ -134,7 +138,10 @@ func (c *Config) ParseModules() error {
func parseModules(mods []Module) ([]Module, error) {
var parsedModules []Module
for _, mod := range mods {
if mod.GoMod == "" && !mod.Core {
jpkrohling marked this conversation as resolved.
Show resolved Hide resolved
if mod.Core != nil {
return mods, ErrDeprecatedCore
}
if mod.GoMod == "" {
return mods, fmt.Errorf("%w, module: %q", ErrInvalidGoMod, mod.GoMod)
}

Expand Down
40 changes: 35 additions & 5 deletions internal/builder/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,17 @@ func TestRelativePath(t *testing.T) {
func TestModuleFromCore(t *testing.T) {
// prepare
cfg := Config{
Extensions: []Module{{
jpkrohling marked this conversation as resolved.
Show resolved Hide resolved
Core: true,
Import: "go.opentelemetry.io/collector/receiver/jaegerreceiver",
}},
Extensions: []Module{ // see issue-12
{
Import: "go.opentelemetry.io/collector/receiver/jaegerreceiver",
GoMod: "go.opentelemetry.io/collector v0.36.0",
},
{
Import: "go.opentelemetry.io/collector/receiver/jaegerreceiver",
GoMod: "go.opentelemetry.io/collector v0.36.0",
Core: nil,
},
},
}

// test
Expand All @@ -77,7 +84,30 @@ func TestModuleFromCore(t *testing.T) {

// verify
assert.True(t, strings.HasPrefix(cfg.Extensions[0].Name, "jaegerreceiver"))
assert.Empty(t, cfg.Extensions[0].GoMod)
}

func TestDeprecatedCore(t *testing.T) {
// prepare
coreTrue := true
coreFalse := false
cfg := Config{
Extensions: []Module{
{
Import: "go.opentelemetry.io/collector/receiver/jaegerreceiver",
Core: &coreTrue,
},
{
Import: "go.opentelemetry.io/collector/receiver/jaegerreceiver",
Core: &coreFalse,
},
},
}

// test
err := cfg.ParseModules()

// verify
assert.True(t, errors.Is(err, ErrDeprecatedCore))
}

func TestInvalidModule(t *testing.T) {
Expand Down
6 changes: 3 additions & 3 deletions test/nocore.builder.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ dist:

receivers:
- import: go.opentelemetry.io/collector/receiver/otlpreceiver
core: true
gomod: go.opentelemetry.io/collector v0.36.0
exporters:
- import: go.opentelemetry.io/collector/exporter/loggingexporter
core: true
gomod: go.opentelemetry.io/collector v0.36.0
extensions:
- import: go.opentelemetry.io/collector/extension/zpagesextension
core: true
gomod: go.opentelemetry.io/collector v0.36.0