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
48 changes: 48 additions & 0 deletions changelog/fragments/phase-2-plugin-keys.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
entries:
- description: >
(go/v2) Changed `go` PROJECT plugin object to `manifests` and `scorecard` objects (`.sdk.operatorframework.io` suffix)
kind: change
breaking: false
migration:
header: (go/v2) Change `go` PROJECT plugin object to `manifests` and `scorecard` objects
body: >
The `manifests` and `scorecard` plugins that create OLM and scorecard manifests, respectively,
now have plugin objects that direct `create` subcommands to create related files.
While the old `go` plugin configuration object is still supported, these new objects will be useful
in the future as configuration options are added to their respective plugins:

Old:
```yaml
version: 3-alpha
...
plugins:
go.sdk.operatorframework.io/v2-alpha: {}
```

New:
```yaml
version: 3-alpha
...
plugins:
manifests.sdk.operatorframework.io/v2: {}
scorecard.sdk.operatorframework.io/v2: {}
```

- description: >
(ansible/v1, helm/v1) Added plugin objects for the `manifests` and `scorecard` phase 2 plugins
kind: addition
migration:
header: (ansible/v1, helm/v1) Add `manifests` and `scorecard` plugin objects to your PROJECT
body: >
The `manifests` and `scorecard` plugins that create OLM and scorecard manifests, respectively,
now have plugin objects that direct `create` subcommands to create related files. While not necessary
to add, these new plugin configuration objects in the PROJECT file will be useful in the future
as configuration options are added to their respective plugins:

```yaml
version: 3-alpha
...
plugins:
manifests.sdk.operatorframework.io/v2: {}
scorecard.sdk.operatorframework.io/v2: {}
```
21 changes: 19 additions & 2 deletions internal/plugins/ansible/v1/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"github.com/operator-framework/operator-sdk/internal/kubebuilder/cmdutil"
"github.com/operator-framework/operator-sdk/internal/plugins/ansible/v1/scaffolds"
"github.com/operator-framework/operator-sdk/internal/plugins/manifests"
manifestsv2 "github.com/operator-framework/operator-sdk/internal/plugins/manifests/v2"
)

const (
Expand Down Expand Up @@ -118,8 +119,24 @@ func (p *createAPIPSubcommand) Run() error {

// SDK phase 2 plugins.
func (p *createAPIPSubcommand) runPhase2() error {
gvk := p.createOptions.GVK
return manifests.RunCreateAPI(p.config, config.GVK{Group: gvk.Group, Version: gvk.Version, Kind: gvk.Kind})
ogvk := p.createOptions.GVK
gvk := config.GVK{Group: ogvk.Group, Version: ogvk.Version, Kind: ogvk.Kind}

// Initially the ansible/v1 plugin was written to not create a "plugins" config entry
// for any phase 2 plugin because they did not have their own keys. Now there are phase 2
// plugin keys, so those plugins should be run if keys exist. Otherwise, enact old behavior.

if manifestsv2.HasPluginConfig(p.config) {
if err := manifestsv2.RunCreateAPI(p.config, gvk); err != nil {
return err
}
} else {
if err := manifests.RunCreateAPI(p.config, gvk); err != nil {
return err
}
}

return nil
}

func (p *createAPIPSubcommand) Validate() error {
Expand Down
8 changes: 4 additions & 4 deletions internal/plugins/ansible/v1/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ import (

"github.com/operator-framework/operator-sdk/internal/kubebuilder/cmdutil"
"github.com/operator-framework/operator-sdk/internal/plugins/ansible/v1/scaffolds"
"github.com/operator-framework/operator-sdk/internal/plugins/manifests"
"github.com/operator-framework/operator-sdk/internal/plugins/scorecard"
manifestsv2 "github.com/operator-framework/operator-sdk/internal/plugins/manifests/v2"
scorecardv2 "github.com/operator-framework/operator-sdk/internal/plugins/scorecard/v2"
)

type initSubcommand struct {
Expand Down Expand Up @@ -118,10 +118,10 @@ func (p *initSubcommand) Run() error {

// SDK phase 2 plugins.
func (p *initSubcommand) runPhase2() error {
if err := manifests.RunInit(p.config); err != nil {
if err := manifestsv2.RunInit(p.config); err != nil {
return err
}
if err := scorecard.RunInit(p.config); err != nil {
if err := scorecardv2.RunInit(p.config); err != nil {
return err
}

Expand Down
22 changes: 16 additions & 6 deletions internal/plugins/golang/v2/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"sigs.k8s.io/kubebuilder/v2/pkg/plugin"

"github.com/operator-framework/operator-sdk/internal/plugins/manifests"
manifestsv2 "github.com/operator-framework/operator-sdk/internal/plugins/manifests/v2"
)

type createAPISubcommand struct {
Expand All @@ -46,15 +47,11 @@ func (p *createAPISubcommand) Run() error {
for _, r := range p.config.Resources {
oldResources[r] = struct{}{}
}

if err := p.CreateAPISubcommand.Run(); err != nil {
return err
}

// Emulate plugins phase 2 behavior by checking the config for this plugin's config object.
if !hasPluginConfig(p.config) {
return nil
}

// Find the new resource. Here we shouldn't worry about checking if one was found,
// since downstream plugins will do so.
var newResource config.GVK
Expand All @@ -71,5 +68,18 @@ func (p *createAPISubcommand) Run() error {

// SDK phase 2 plugins.
func (p *createAPISubcommand) runPhase2(gvk config.GVK) error {
return manifests.RunCreateAPI(p.config, gvk)
// Check if the generic "go" operator-sdk plugin (legacy) exists first.
if hasPluginConfig(p.config) {
if err := manifests.RunCreateAPI(p.config, gvk); err != nil {
return err
}
return nil
}

// v2 plugins will handle checking p.config for their key so we can call all of them below.
if err := manifestsv2.RunCreateAPI(p.config, gvk); err != nil {
return err
}

return nil
}
1 change: 1 addition & 0 deletions internal/plugins/golang/v2/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package v2
import "sigs.k8s.io/kubebuilder/v2/pkg/model/config"

// Config configures this plugin, and is saved in the project config file.
// Deprecated: use scorecard and manifests plugin configs directly.
type Config struct{}

// hasPluginConfig returns true if cfg.Plugins contains an exact match for this plugin's key.
Expand Down
18 changes: 4 additions & 14 deletions internal/plugins/golang/v2/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,13 @@
package v2

import (
"fmt"

"github.com/spf13/pflag"
"sigs.k8s.io/kubebuilder/v2/pkg/model/config"
"sigs.k8s.io/kubebuilder/v2/pkg/plugin"

"github.com/operator-framework/operator-sdk/internal/plugins/envtest"
"github.com/operator-framework/operator-sdk/internal/plugins/manifests"
"github.com/operator-framework/operator-sdk/internal/plugins/scorecard"
manifestsv2 "github.com/operator-framework/operator-sdk/internal/plugins/manifests/v2"
scorecardv2 "github.com/operator-framework/operator-sdk/internal/plugins/scorecard/v2"
)

type initSubcommand struct {
Expand Down Expand Up @@ -52,14 +50,6 @@ func (p *initSubcommand) Run() error {
return err
}

// Update plugin config section with this plugin's configuration for v3 projects.
if p.config.IsV3() {
cfg := Config{}
if err := p.config.EncodePluginConfig(pluginConfigKey, cfg); err != nil {
return fmt.Errorf("error writing plugin config for %s: %v", pluginConfigKey, err)
}
}

return nil
}

Expand All @@ -68,10 +58,10 @@ func (p *initSubcommand) runPhase2() error {
if err := envtest.RunInit(p.config); err != nil {
return err
}
if err := manifests.RunInit(p.config); err != nil {
if err := manifestsv2.RunInit(p.config); err != nil {
return err
}
if err := scorecard.RunInit(p.config); err != nil {
if err := scorecardv2.RunInit(p.config); err != nil {
return err
}
return nil
Expand Down
21 changes: 19 additions & 2 deletions internal/plugins/helm/v1/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"github.com/operator-framework/operator-sdk/internal/plugins/helm/v1/chartutil"
"github.com/operator-framework/operator-sdk/internal/plugins/helm/v1/scaffolds"
"github.com/operator-framework/operator-sdk/internal/plugins/manifests"
manifestsv2 "github.com/operator-framework/operator-sdk/internal/plugins/manifests/v2"
)

type createAPISubcommand struct {
Expand Down Expand Up @@ -136,8 +137,24 @@ func (p *createAPISubcommand) Run() error {

// SDK phase 2 plugins.
func (p *createAPISubcommand) runPhase2() error {
gvk := p.createOptions.GVK
return manifests.RunCreateAPI(p.config, config.GVK{Group: gvk.Group, Version: gvk.Version, Kind: gvk.Kind})
ogvk := p.createOptions.GVK
gvk := config.GVK{Group: ogvk.Group, Version: ogvk.Version, Kind: ogvk.Kind}

// Initially the helm/v1 plugin was written to not create a "plugins" config entry
// for any phase 2 plugin because they did not have their own keys. Now there are phase 2
// plugin keys, so those plugins should be run if keys exist. Otherwise, enact old behavior.

if manifestsv2.HasPluginConfig(p.config) {
if err := manifestsv2.RunCreateAPI(p.config, gvk); err != nil {
return err
}
} else {
if err := manifests.RunCreateAPI(p.config, gvk); err != nil {
return err
}
}

return nil
}

// Validate perform the required validations for this plugin
Expand Down
8 changes: 4 additions & 4 deletions internal/plugins/helm/v1/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ import (
"github.com/operator-framework/operator-sdk/internal/kubebuilder/cmdutil"
"github.com/operator-framework/operator-sdk/internal/plugins/helm/v1/chartutil"
"github.com/operator-framework/operator-sdk/internal/plugins/helm/v1/scaffolds"
"github.com/operator-framework/operator-sdk/internal/plugins/manifests"
"github.com/operator-framework/operator-sdk/internal/plugins/scorecard"
manifestsv2 "github.com/operator-framework/operator-sdk/internal/plugins/manifests/v2"
scorecardv2 "github.com/operator-framework/operator-sdk/internal/plugins/scorecard/v2"
)

type initSubcommand struct {
Expand Down Expand Up @@ -147,10 +147,10 @@ func (p *initSubcommand) Run() error {

// SDK phase 2 plugins.
func (p *initSubcommand) runPhase2() error {
if err := manifests.RunInit(p.config); err != nil {
if err := manifestsv2.RunInit(p.config); err != nil {
return err
}
if err := scorecard.RunInit(p.config); err != nil {
if err := scorecardv2.RunInit(p.config); err != nil {
return err
}

Expand Down
6 changes: 3 additions & 3 deletions internal/plugins/manifests/v2/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ var (
// Config configures this plugin, and is saved in the project config file.
type Config struct{}

// hasPluginConfig returns true if cfg.Plugins contains an exact match for this plugin's key.
func hasPluginConfig(cfg *config.Config) bool {
// HasPluginConfig returns true if cfg.Plugins contains an exact match for this plugin's key.
func HasPluginConfig(cfg *config.Config) bool {
if !cfg.IsV3() || len(cfg.Plugins) == 0 {
return false
}
Expand All @@ -63,7 +63,7 @@ func RunInit(cfg *config.Config) error {

// RunCreateAPI runs the manifests SDK phase 2 plugin.
func RunCreateAPI(cfg *config.Config, gvk config.GVK) error {
if !hasPluginConfig(cfg) {
if !HasPluginConfig(cfg) {
return nil
}
return manifests.RunCreateAPI(cfg, gvk)
Expand Down
3 changes: 3 additions & 0 deletions testdata/ansible/memcached-operator/PROJECT
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,6 @@ resources:
kind: Memcached
version: v1alpha1
version: 3-alpha
plugins:
manifests.sdk.operatorframework.io/v2: {}
scorecard.sdk.operatorframework.io/v2: {}
3 changes: 2 additions & 1 deletion testdata/go/v2/memcached-operator/PROJECT
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ resources:
version: v1alpha1
version: 3-alpha
plugins:
go.sdk.operatorframework.io/v2-alpha: {}
Comment thread
estroz marked this conversation as resolved.
manifests.sdk.operatorframework.io/v2: {}
scorecard.sdk.operatorframework.io/v2: {}
3 changes: 3 additions & 0 deletions testdata/helm/memcached-operator/PROJECT
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,6 @@ resources:
kind: Memcached
version: v1alpha1
version: 3-alpha
plugins:
manifests.sdk.operatorframework.io/v2: {}
scorecard.sdk.operatorframework.io/v2: {}