Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: validate plugins : allow many versions of the same plugin #1535

Merged
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
10 changes: 5 additions & 5 deletions pkg/cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -351,12 +351,12 @@ func validatePlugins(plugins ...plugin.Base) error {
pluginName, projectVersion, err)
}
}
// Check for duplicate plugin names. Names outside of a version can
// conflict because multiple project versions of a plugin may exist.
if _, seen := pluginNameSet[pluginName]; seen {
return fmt.Errorf("two plugins have the same name: %q", pluginName)
// Check for duplicate plugin keys.
pluginKey := plugin.KeyFor(p)
if _, seen := pluginNameSet[pluginKey]; seen {
return fmt.Errorf("two plugins have the same key: %q", pluginKey)
}
pluginNameSet[pluginName] = struct{}{}
pluginNameSet[pluginKey] = struct{}{}
}
return nil
}
Expand Down
29 changes: 0 additions & 29 deletions pkg/cli/cli_suite_test.go

This file was deleted.

29 changes: 29 additions & 0 deletions pkg/cli/cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,19 @@ limitations under the License.
package cli

import (
"testing"

. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"

"sigs.k8s.io/kubebuilder/pkg/plugin"
)

func TestCLI(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecs(t, "CLI Suite")
}

var _ = Describe("CLI", func() {
Describe("resolvePluginsByKey", func() {
plugins := makePluginsForKeys(
Expand Down Expand Up @@ -78,6 +85,28 @@ var _ = Describe("CLI", func() {
Expect(err).To(MatchError(`plugin key "foo" matches more than one known plugin`))
})
})

Describe("Check if has duplicate plugins", func() {
It("should work successfully when a plugin has many versions", func() {
plugins := makePluginsForKeys(
"foo.example.com/v1.0.0",
"foo.example.com/v2.0.0",
"foo.example.com/v3.0.0",
)

err := validatePlugins(plugins...)
Expect(err).NotTo(HaveOccurred())
})
It("should fail when found more than one plugin with the same name and version", func() {
plugins := makePluginsForKeys(
"foo.example.com/v1.0.0",
"foo.example.com/v1.0.0",
)

err := validatePlugins(plugins...)
Expect(err).To(HaveOccurred())
})
})
})

type mockPlugin struct {
Expand Down