Skip to content

Commit ccd621b

Browse files
author
Eric Stroczynski
authored
internal/plugins: scaffold a vanilla go.kubebuilder.io/v2 project when --project-version=2 (#3697)
The SDK should be scaffolding the vanilla `go.kubebuilder.io/v2` plugin if `--project-version 2` is set, since the `go.sdk.operatorframework.io` phase 2 plugin requires a 3-alpha project. internal/plugins: only run phase 2 plugins for project versions >= 3-alpha.
1 parent 2a654eb commit ccd621b

File tree

9 files changed

+57
-12
lines changed

9 files changed

+57
-12
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
entries:
2+
- description: >
3+
Changed the `go.sdk.operatorframework.io` plugin to only write a `plugins` PROJECT field and
4+
run the OLM integration and scorecard plugins if the project version is "3-alpha" or above.
5+
kind: change
6+
breaking: true
7+
migration:
8+
header: Upgrade your project from version "2" to "3-alpha"
9+
body: >
10+
The SDK's default Go plugin no longer supports OLM- or scorecard-related project files
11+
nor writes a `plugins` PROJECT field for projects scaffolded previously with
12+
`operator-sdk init --project-version=2`, Please migrate to project version "3-alpha"
13+
for support of these features by adding the following to your `PROJECT` file:
14+
15+
```yaml
16+
version: "3-alpha" # Updated from "2"
17+
projectName: <output of $(basename $(pwd))>
18+
layout: go.kubebuilder.io/v2
19+
plugins:
20+
go.sdk.operatorframework.io/v2-alpha: {}
21+
```

internal/plugins/golang/v2/api.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,13 @@ func (p *createAPIPlugin) Run() error {
4848
return err
4949
}
5050

51-
// Emulate plugins phase 2 behavior by checking the config for this plugin's
52-
// config object.
51+
// Emulate plugins phase 2 behavior by checking the config for this plugin's config object.
5352
if !hasPluginConfig(p.config) {
5453
return nil
5554
}
5655

57-
// Find the new resource. Here we shouldn't worry about checking if one was found, since downstream
58-
// plugins will do so.
56+
// Find the new resource. Here we shouldn't worry about checking if one was found,
57+
// since downstream plugins will do so.
5958
var newResource config.GVK
6059
for _, r := range p.config.Resources {
6160
if _, hasResource := oldResources[r]; !hasResource {

internal/plugins/golang/v2/config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ type Config struct{}
2121

2222
// hasPluginConfig returns true if cfg.Plugins contains an exact match for this plugin's key.
2323
func hasPluginConfig(cfg *config.Config) bool {
24-
if len(cfg.Plugins) == 0 {
24+
if !cfg.IsV3() || len(cfg.Plugins) == 0 {
2525
return false
2626
}
2727
_, hasKey := cfg.Plugins[pluginConfigKey]

internal/plugins/golang/v2/init.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,12 @@ func (p *initPlugin) Run() error {
5151
return err
5252
}
5353

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

6062
return nil

internal/plugins/manifests/api.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ import (
2727

2828
// RunCreateAPI runs the manifests SDK phase 2 plugin.
2929
func RunCreateAPI(cfg *config.Config, gvk config.GVK) error {
30+
// Only run these if project version is v3.
31+
if !cfg.IsV3() {
32+
return nil
33+
}
3034

3135
if err := newAPIScaffolder(cfg, gvk).scaffold(); err != nil {
3236
return err

internal/plugins/manifests/init.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ import (
2626

2727
// RunInit modifies the project scaffolded by kubebuilder's Init plugin.
2828
func RunInit(cfg *config.Config) error {
29+
// Only run these if project version is v3.
30+
if !cfg.IsV3() {
31+
return nil
32+
}
33+
2934
// Update the scaffolded Makefile with operator-sdk recipes.
3035
if err := initUpdateMakefile(cfg, "Makefile"); err != nil {
3136
return fmt.Errorf("error updating Makefile: %v", err)
@@ -73,12 +78,11 @@ ifneq ($(origin DEFAULT_CHANNEL), undefined)
7378
BUNDLE_DEFAULT_CHANNEL := --default-channel=$(DEFAULT_CHANNEL)
7479
endif
7580
BUNDLE_METADATA_OPTS ?= $(BUNDLE_CHANNELS) $(BUNDLE_DEFAULT_CHANNEL)
76-
77-
.PHONY: bundle
7881
`
7982

8083
makefileBundleFragmentGo = `
8184
# Generate bundle manifests and metadata, then validate generated files.
85+
.PHONY: bundle
8286
bundle: manifests
8387
operator-sdk generate kustomize manifests -q
8488
cd config/manager && $(KUSTOMIZE) edit set image controller=$(IMG)
@@ -88,6 +92,7 @@ bundle: manifests
8892

8993
makefileBundleFragmentNonGo = `
9094
# Generate bundle manifests and metadata, then validate generated files.
95+
.PHONY: bundle
9196
bundle: kustomize
9297
operator-sdk generate kustomize manifests -q
9398
cd config/manager && $(KUSTOMIZE) edit set image controller=$(IMG)
@@ -97,6 +102,7 @@ bundle: kustomize
97102

98103
makefileBundleBuildFragment = `
99104
# Build the bundle image.
105+
.PHONY: bundle-build
100106
bundle-build:
101107
docker build -f bundle.Dockerfile -t $(BUNDLE_IMG) .
102108
`

internal/plugins/scorecard/init.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,12 @@ const (
6969
var defaultDir = filepath.Join("config", "scorecard")
7070

7171
// RunInit scaffolds kustomize files for kustomizing a scorecard componentconfig.
72-
func RunInit(*config.Config) error {
72+
func RunInit(cfg *config.Config) error {
73+
// Only run these if project version is v3.
74+
if !cfg.IsV3() {
75+
return nil
76+
}
77+
7378
return generate(defaultTestImageTag, defaultDir)
7479
}
7580

website/content/en/docs/olm-integration/quickstart-bundle.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ explanations of certain steps for brevity. The following documents contain more
1616
If you are working with package manifests, see the [package manifests quickstart][quickstart-package-manifests]
1717
once you have completed the *Setup* section below.
1818

19+
**Important:** this guide assumes your project was scaffolded with `operator-sdk init --project-version=3-alpha`.
20+
These features are unavailable to projects of version `2` or less; this information can be found by inspecting
21+
your `PROJECT` file's `version` value.
22+
1923
## Setup
2024

2125
Let's first walk through creating an Operator for `memcached`, a distributed key-value store.

website/content/en/docs/olm-integration/quickstart-package-manifests.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ weight: 2
77
This guide assumes you have followed the introduction and *Setup* section of the [bundle quickstart][quickstart-bundle],
88
and have added the `packagemanifests` target to your `Makefile` as described [here][doc-olm-generate].
99

10+
**Important:** this guide assumes your project was scaffolded with `operator-sdk init --project-version=3-alpha`.
11+
These features are unavailable to projects of version `2` or less; this information can be found by inspecting
12+
your `PROJECT` file's `version` value.
13+
1014
## Creating package manifests
1115

1216
We will now create a package manifests format by running `make packagemanifests` in the root of the memcached-operator project:

0 commit comments

Comments
 (0)