Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
9abe27b
Enhance GitHub actions CI
Adirio Mar 16, 2021
e3437d6
Merge pull request #2095 from Adirio/enhance-gh-actions
k8s-ci-robot Mar 23, 2021
d7bd9c7
Allow to modify the root's command description
Adirio Mar 24, 2021
2d0bae4
Merge pull request #2105 from Adirio/cli-description
k8s-ci-robot Mar 24, 2021
f5d2f6a
Split GH Actions jobs into separate workflows
Adirio Mar 25, 2021
825b347
Merge pull request #2107 from Adirio/split-GH-workflows
k8s-ci-robot Mar 25, 2021
beecada
:bug: do not generate the cert-manager directory by default.
camilamacedo86 Mar 25, 2021
b828d86
Merge pull request #2111 from camilamacedo86/fix-certmanager
k8s-ci-robot Mar 25, 2021
39ec8f8
Allow bundles to be used as input to other bundles
Adirio Mar 26, 2021
9d1fd06
:warning: move declarative plugin to golang domain
camilamacedo86 Mar 26, 2021
f65ddb2
Merge pull request #2114 from camilamacedo86/declarative-org
k8s-ci-robot Mar 26, 2021
84f357b
Merge pull request #2112 from Adirio/bundle-recursion
k8s-ci-robot Mar 27, 2021
9e816f5
:sparkles: add the common plugin(s) to allow it to be used by consumers
camilamacedo86 Apr 1, 2021
3da7f18
change scale example attribute
huiwq1990 Apr 7, 2021
3eb373c
Merge pull request #2127 from huiwq1990/fix-bookScaleExample
k8s-ci-robot Apr 7, 2021
d5e70a5
Merge pull request #2106 from camilamacedo86/config-base
k8s-ci-robot Apr 7, 2021
3eaa8c0
:seeding: fix lint issue on master for the release
camilamacedo86 Apr 7, 2021
72f7c2e
Merge pull request #2132 from camilamacedo86/fix-lint-master
k8s-ci-robot Apr 7, 2021
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
Prev Previous commit
Next Next commit
Allow bundles to be used as input to other bundles
Signed-off-by: Adrian Orive <[email protected]>
  • Loading branch information
Adirio committed Mar 26, 2021
commit 39ec8f862756ddb7b9d8603318a1962b8864e20a
14 changes: 13 additions & 1 deletion pkg/plugin/bundle.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,22 @@ func NewBundle(name string, version Version, plugins ...Plugin) (Bundle, error)
return nil, fmt.Errorf("in order to bundle plugins, they must all support at least one common project version")
}

// Plugins may be bundles themselves, so unbundle here
// NOTE(Adirio): unbundling here ensures that Bundle.Plugin always returns a flat list of Plugins instead of also
// including Bundles, and therefore we don't have to use a recursive algorithm when resolving.
allPlugins := make([]Plugin, 0, len(plugins))
for _, plugin := range plugins {
if pluginBundle, isBundle := plugin.(Bundle); isBundle {
allPlugins = append(allPlugins, pluginBundle.Plugins()...)
} else {
allPlugins = append(allPlugins, plugin)
}
}

return bundle{
name: name,
version: version,
plugins: plugins,
plugins: allPlugins,
supportedProjectVersions: supportedProjectVersions,
}, nil
}
Expand Down
20 changes: 20 additions & 0 deletions pkg/plugin/bundle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,26 @@ var _ = Describe("Bundle", func() {
}
})

It("should accept bundles as input", func() {
var a, b Bundle
var err error
plugins := []Plugin{p1, p2, p3}
a, err = NewBundle("a", version, p1, p2)
Expect(err).NotTo(HaveOccurred())
b, err = NewBundle("b", version, a, p3)
Expect(err).NotTo(HaveOccurred())
versions := b.SupportedProjectVersions()
sort.Slice(versions, func(i int, j int) bool {
return versions[i].Compare(versions[j]) == -1
})
expectedVersions := CommonSupportedProjectVersions(plugins...)
sort.Slice(expectedVersions, func(i int, j int) bool {
return expectedVersions[i].Compare(expectedVersions[j]) == -1
})
Expect(versions).To(Equal(expectedVersions))
Expect(b.Plugins()).To(Equal(plugins))
})

It("should fail for plugins with no common supported project version", func() {
for _, plugins := range [][]Plugin{
{p2, p4},
Expand Down
17 changes: 9 additions & 8 deletions pkg/plugin/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
"sigs.k8s.io/kubebuilder/v3/pkg/config"
)

// Plugin is an interface that defines the common base for all plugins
// Plugin is an interface that defines the common base for all plugins.
type Plugin interface {
// Name returns a DNS1123 label string identifying the plugin uniquely. This name should be fully-qualified,
// i.e. have a short prefix describing the plugin type (like a language) followed by a domain.
Expand All @@ -41,45 +41,46 @@ type Deprecated interface {
DeprecationWarning() string
}

// Init is an interface for plugins that provide an `init` subcommand
// Init is an interface for plugins that provide an `init` subcommand.
type Init interface {
Plugin
// GetInitSubcommand returns the underlying InitSubcommand interface.
GetInitSubcommand() InitSubcommand
}

// CreateAPI is an interface for plugins that provide a `create api` subcommand
// CreateAPI is an interface for plugins that provide a `create api` subcommand.
type CreateAPI interface {
Plugin
// GetCreateAPISubcommand returns the underlying CreateAPISubcommand interface.
GetCreateAPISubcommand() CreateAPISubcommand
}

// CreateWebhook is an interface for plugins that provide a `create webhook` subcommand
// CreateWebhook is an interface for plugins that provide a `create webhook` subcommand.
type CreateWebhook interface {
Plugin
// GetCreateWebhookSubcommand returns the underlying CreateWebhookSubcommand interface.
GetCreateWebhookSubcommand() CreateWebhookSubcommand
}

// Edit is an interface for plugins that provide a `edit` subcommand
// Edit is an interface for plugins that provide a `edit` subcommand.
type Edit interface {
Plugin
// GetEditSubcommand returns the underlying EditSubcommand interface.
GetEditSubcommand() EditSubcommand
}

// Full is an interface for plugins that provide `init`, `create api`, `create webhook` and `edit` subcommands
// Full is an interface for plugins that provide `init`, `create api`, `create webhook` and `edit` subcommands.
type Full interface {
Init
CreateAPI
CreateWebhook
Edit
}

// Bundle allows to group plugins under a single key
// Bundle allows to group plugins under a single key.
type Bundle interface {
Plugin
// Plugins returns a list of the bundled plugins
// Plugins returns a list of the bundled plugins.
// The returned list should be flattened, i.e., no plugin bundles should be part of this list.
Plugins() []Plugin
}