Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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: 10 additions & 1 deletion alpha/action/diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func (p Diff) validate() error {
}

// DiffIncludeConfig configures Diff.Run() to include a set of packages,
// channels, and/or bundle versions in the output DeclarativeConfig.
// channels, and/or bundles/versions in the output DeclarativeConfig.
// These override other diff mechanisms. For example, if running in
// heads-only mode but package "foo" channel "stable" is specified,
// the entire "stable" channel (all channel bundles) is added to the output.
Expand All @@ -110,6 +110,10 @@ type DiffIncludePackage struct {
// Versions to include. All channels containing these versions
// are parsed for an upgrade graph.
Versions []semver.Version `json:"versions,omitempty" yaml:"versions,omitempty"`
// Bundles are bundle names to include. All channels containing these bundles
// are parsed for an upgrade graph.
// Set this field only if the named bundle has no semantic version metadata.
Bundles []string `json:"bundles,omitempty" yaml:"bundles,omitempty"`
}

// DiffIncludeChannel contains a name (required) and versions (optional)
Expand All @@ -119,6 +123,9 @@ type DiffIncludeChannel struct {
Name string `json:"name" yaml:"name"`
// Versions to include.
Versions []semver.Version `json:"versions,omitempty" yaml:"versions,omitempty"`
// Bundles are bundle names to include.
// Set this field only if the named bundle has no semantic version metadata.
Bundles []string `json:"bundles,omitempty" yaml:"bundles,omitempty"`
}

// LoadDiffIncludeConfig loads a (YAML or JSON) DiffIncludeConfig from r.
Expand Down Expand Up @@ -154,13 +161,15 @@ func convertIncludeConfigToIncluder(c DiffIncludeConfig) (includer declcfg.DiffI
pkg := &includer.Packages[pkgI]
pkg.Name = cpkg.Name
pkg.AllChannels.Versions = cpkg.Versions
pkg.AllChannels.Bundles = cpkg.Bundles

if len(cpkg.Channels) != 0 {
pkg.Channels = make([]declcfg.DiffIncludeChannel, len(cpkg.Channels))
for chI, cch := range cpkg.Channels {
ch := &pkg.Channels[chI]
ch.Name = cch.Name
ch.Versions = cch.Versions
ch.Bundles = cch.Bundles
}
}
}
Expand Down
105 changes: 97 additions & 8 deletions alpha/action/diff_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,87 @@ func TestDiff(t *testing.T) {
expectedCfg: loadDirFS(t, indicesDir, filepath.Join("testdata", "index-declcfgs", "exp-headsonly")),
assertion: require.NoError,
},
{
name: "Success/IncludePackage",
diff: Diff{
Registry: registry,
NewRefs: []string{filepath.Join("testdata", "index-declcfgs", "latest")},
IncludeConfig: DiffIncludeConfig{
Packages: []DiffIncludePackage{{Name: "baz"}},
},
},
expectedCfg: loadDirFS(t, indicesDir, filepath.Join("testdata", "index-declcfgs", "exp-include-pkg")),
assertion: require.NoError,
},
{
name: "Success/IncludeChannel",
diff: Diff{
Registry: registry,
NewRefs: []string{filepath.Join("testdata", "index-declcfgs", "latest")},
IncludeConfig: DiffIncludeConfig{
Packages: []DiffIncludePackage{
{
Name: "baz",
Channels: []DiffIncludeChannel{{Name: "stable"}},
},
},
},
},
expectedCfg: loadDirFS(t, indicesDir, filepath.Join("testdata", "index-declcfgs", "exp-include-channel")),
assertion: require.NoError,
},
{
name: "Success/IncludeVersion",
diff: Diff{
Registry: registry,
NewRefs: []string{filepath.Join("testdata", "index-declcfgs", "latest")},
IncludeConfig: DiffIncludeConfig{
Packages: []DiffIncludePackage{
{
Name: "baz",
Versions: []semver.Version{semver.MustParse("1.0.0")},
},
},
},
},
expectedCfg: loadDirFS(t, indicesDir, filepath.Join("testdata", "index-declcfgs", "exp-include-channel")),
assertion: require.NoError,
},
{
name: "Success/IncludeBundle",
diff: Diff{
Registry: registry,
NewRefs: []string{filepath.Join("testdata", "index-declcfgs", "latest")},
IncludeConfig: DiffIncludeConfig{
Packages: []DiffIncludePackage{
{
Name: "baz",
Bundles: []string{"baz.v1.0.0"},
},
},
},
},
expectedCfg: loadDirFS(t, indicesDir, filepath.Join("testdata", "index-declcfgs", "exp-include-channel")),
assertion: require.NoError,
},
{
name: "Success/IncludeSameVersionAndBundle",
diff: Diff{
Registry: registry,
NewRefs: []string{filepath.Join("testdata", "index-declcfgs", "latest")},
IncludeConfig: DiffIncludeConfig{
Packages: []DiffIncludePackage{
{
Name: "baz",
Versions: []semver.Version{semver.MustParse("1.0.0")},
Bundles: []string{"baz.v1.0.0"},
},
},
},
},
expectedCfg: loadDirFS(t, indicesDir, filepath.Join("testdata", "index-declcfgs", "exp-include-channel")),
assertion: require.NoError,
},
{
name: "Fail/NewBundleImage",
diff: Diff{
Expand Down Expand Up @@ -125,6 +206,8 @@ packages:
- name: foo
channels:
- name: stable
bundles:
- foo.v0.3.0
versions:
- 0.1.0
- 0.2.0
Expand All @@ -137,16 +220,19 @@ packages:
- 0.1.0
versions:
- 1.0.0
bundles:
- bar.v1.2.0
`,
expectedCfg: DiffIncludeConfig{
Packages: []DiffIncludePackage{
{
Name: "foo",
Channels: []DiffIncludeChannel{
{Name: "stable", Versions: []semver.Version{
semver.MustParse("0.1.0"),
semver.MustParse("0.2.0"),
}},
{
Name: "stable",
Versions: []semver.Version{semver.MustParse("0.1.0"), semver.MustParse("0.2.0")},
Bundles: []string{"foo.v0.3.0"},
},
},
Versions: []semver.Version{semver.MustParse("1.0.0")},
},
Expand All @@ -158,6 +244,7 @@ packages:
}},
},
Versions: []semver.Version{semver.MustParse("1.0.0")},
Bundles: []string{"bar.v1.2.0"},
},
},
},
Expand All @@ -166,10 +253,11 @@ packages:
{
Name: "foo",
Channels: []declcfg.DiffIncludeChannel{
{Name: "stable", Versions: []semver.Version{
semver.MustParse("0.1.0"),
semver.MustParse("0.2.0"),
}},
{
Name: "stable",
Versions: []semver.Version{semver.MustParse("0.1.0"), semver.MustParse("0.2.0")},
Bundles: []string{"foo.v0.3.0"},
},
},
AllChannels: declcfg.DiffIncludeChannel{
Versions: []semver.Version{semver.MustParse("1.0.0")},
Expand All @@ -184,6 +272,7 @@ packages:
},
AllChannels: declcfg.DiffIncludeChannel{
Versions: []semver.Version{semver.MustParse("1.0.0")},
Bundles: []string{"bar.v1.2.0"},
},
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ entries:
- name: bar.v0.1.0
- name: bar.v0.2.0
replaces: bar.v0.1.0
skipRange: <0.2.0
skips:
- bar.v0.1.0
- name: bar.v1.0.0
Expand Down
Loading