Skip to content

Commit 274c755

Browse files
committed
*: upgrade kubebuilder and add go/v3-alpha to the list of available
plugins testdata: regenerate samples with go/v3-alpha test: test go/v3-alpha
1 parent f246ef7 commit 274c755

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+1202
-483
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ require (
3434
rsc.io/letsencrypt v0.0.3 // indirect
3535
sigs.k8s.io/controller-runtime v0.6.3
3636
sigs.k8s.io/controller-tools v0.3.0
37-
sigs.k8s.io/kubebuilder/v2 v2.3.2-0.20201111001842-c158f4fa4207
37+
sigs.k8s.io/kubebuilder/v2 v2.3.2-0.20201204182959-6b775b860148
3838
sigs.k8s.io/yaml v1.2.0
3939
)
4040

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1229,8 +1229,8 @@ sigs.k8s.io/controller-runtime v0.6.3 h1:SBbr+inLPEKhvlJtrvDcwIpm+uhDvp63Bl72xYJ
12291229
sigs.k8s.io/controller-runtime v0.6.3/go.mod h1:WlZNXcM0++oyaQt4B7C2lEE5JYRs8vJUzRP4N4JpdAY=
12301230
sigs.k8s.io/controller-tools v0.3.0 h1:y3YD99XOyWaXkiF1kd41uRvfp/64teWcrEZFuHxPhJ4=
12311231
sigs.k8s.io/controller-tools v0.3.0/go.mod h1:enhtKGfxZD1GFEoMgP8Fdbu+uKQ/cq1/WGJhdVChfvI=
1232-
sigs.k8s.io/kubebuilder/v2 v2.3.2-0.20201111001842-c158f4fa4207 h1:JtlaBrtWymJbh6ea+TJUZkzBb0x0dMKV+P0+ZPaldxk=
1233-
sigs.k8s.io/kubebuilder/v2 v2.3.2-0.20201111001842-c158f4fa4207/go.mod h1:J/D/179LBZhQOhRvmMRNbje/Bk+PjbN0/fzUupmO7+U=
1232+
sigs.k8s.io/kubebuilder/v2 v2.3.2-0.20201204182959-6b775b860148 h1:Wcp7eE1mnaXcmI2ltDoAaCKmX1cE4sGkd70JNQ49gBY=
1233+
sigs.k8s.io/kubebuilder/v2 v2.3.2-0.20201204182959-6b775b860148/go.mod h1:J/D/179LBZhQOhRvmMRNbje/Bk+PjbN0/fzUupmO7+U=
12341234
sigs.k8s.io/kustomize v2.0.3+incompatible h1:JUufWFNlI44MdtnjUqVnvh29rR37PQFzPbLXqhyOyX0=
12351235
sigs.k8s.io/kustomize v2.0.3+incompatible/go.mod h1:MkjgH3RdOWrievjo6c9T245dYlB5QeXV4WCbnt/PEpU=
12361236
sigs.k8s.io/structured-merge-diff/v3 v3.0.0-20200116222232-67a7b8c61874/go.mod h1:PlARxl6Hbt/+BC80dRLi1qAmnMqwqDg62YvvVkZjemw=

hack/generate/samples/internal/go/memcached_with_webhooks.go

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ package gosamples
1717
import (
1818
"fmt"
1919
"os"
20+
"os/exec"
2021
"path/filepath"
2122
"strings"
2223

@@ -59,6 +60,8 @@ func (mh *MemcachedGoWithWebhooks) Prepare() {
5960
func (mh *MemcachedGoWithWebhooks) Run() {
6061
log.Infof("creating the project")
6162
err := mh.ctx.Init(
63+
// TODO(estroz): remove this once go/v3-alpha is stabilized and the default plugin.
64+
"--plugins", "go/v3-alpha",
6265
"--repo", "github.com/example/memcached-operator",
6366
"--domain",
6467
mh.ctx.Domain)
@@ -92,6 +95,9 @@ func (mh *MemcachedGoWithWebhooks) Run() {
9295

9396
mh.ctx.CreateBundle()
9497

98+
_, err = mh.ctx.Run(exec.Command("go", "fmt", "./..."))
99+
pkg.CheckError("formatting project", err)
100+
95101
// Clean up built binaries, if any.
96102
pkg.CheckError("cleaning up", os.RemoveAll(filepath.Join(mh.ctx.Dir, "bin")))
97103
}
@@ -129,15 +135,15 @@ func (mh *MemcachedGoWithWebhooks) uncommentKustomizationFile() {
129135
# objref:
130136
# kind: Certificate
131137
# group: cert-manager.io
132-
# version: v1alpha2
138+
# version: v1
133139
# name: serving-cert # this name should match the one in certificate.yaml
134140
# fieldref:
135141
# fieldpath: metadata.namespace
136142
#- name: CERTIFICATE_NAME
137143
# objref:
138144
# kind: Certificate
139145
# group: cert-manager.io
140-
# version: v1alpha2
146+
# version: v1
141147
# name: serving-cert # this name should match the one in certificate.yaml
142148
#- name: SERVICE_NAMESPACE # namespace of the service
143149
# objref:
@@ -173,7 +179,8 @@ func (mh *MemcachedGoWithWebhooks) implementingWebhooks() {
173179
// Add imports
174180
err = kbtestutils.InsertCode(webhookPath,
175181
"import (",
176-
"\"errors\"")
182+
// TODO(estroz): remove runtime dep when --programmatic-validation is added to `ccreate webhook` above.
183+
"\"errors\"\n\n\"k8s.io/apimachinery/pkg/runtime\"")
177184
pkg.CheckError("adding imports", err)
178185
}
179186

@@ -195,9 +202,6 @@ func (mh *MemcachedGoWithWebhooks) implementingController() {
195202
pkg.CheckError("adding rbac", err)
196203

197204
// Replace reconcile content
198-
err = testutils.ReplaceInFile(controllerPath, "_ = context.Background()", "ctx := context.Background()")
199-
pkg.CheckError("replacing reconcile content", err)
200-
201205
err = testutils.ReplaceInFile(controllerPath,
202206
fmt.Sprintf("_ = r.Log.WithValues(\"%s\", req.NamespacedName)", strings.ToLower(mh.ctx.Kind)),
203207
fmt.Sprintf("log := r.Log.WithValues(\"%s\", req.NamespacedName)", strings.ToLower(mh.ctx.Kind)))
@@ -410,8 +414,9 @@ const watchCustomizedFragment = `return ctrl.NewControllerManagedBy(mgr).
410414
Complete(r)
411415
`
412416

413-
const webhooksFragment = `// TODO(user): change verbs to "verbs=create;update;delete" if you want to enable deletion validation.
414-
// +kubebuilder:webhook:verbs=create;update,path=/validate-cache-example-com-v1alpha1-memcached,mutating=false,failurePolicy=fail,groups=cache.example.com,resources=memcacheds,versions=v1alpha1,name=vmemcached.kb.io
417+
const webhooksFragment = `
418+
// TODO(user): change verbs to "verbs=create;update;delete" if you want to enable deletion validation.
419+
// +kubebuilder:webhook:path=/validate-cache-example-com-v1alpha1-memcached,mutating=false,failurePolicy=fail,sideEffects=None,groups=cache.example.com,resources=memcacheds,verbs=create;update,versions=v1alpha1,name=vmemcached.kb.io,admissionReviewVersions={v1beta1}
415420
416421
var _ webhook.Validator = &Memcached{}
417422

hack/generate/samples/internal/pkg/context.go

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,6 @@
1515
package pkg
1616

1717
import (
18-
"fmt"
19-
"path/filepath"
20-
"strings"
21-
2218
"github.com/operator-framework/operator-sdk/internal/testutils"
2319
)
2420

@@ -29,18 +25,6 @@ type SampleContext struct {
2925

3026
// NewSampleContext returns a SampleContext containing a new kubebuilder TestContext.
3127
func NewSampleContext(binary string, path string, env ...string) (s SampleContext, err error) {
32-
s.TestContext, err = testutils.NewTestContext(binary, env...)
33-
// If the path was informed then this should be the dir used
34-
if strings.TrimSpace(path) != "" {
35-
path, err = filepath.Abs(path)
36-
if err != nil {
37-
return s, err
38-
}
39-
s.CmdContext.Dir = path
40-
s.ProjectName = strings.ToLower(filepath.Base(s.Dir))
41-
s.ImageName = fmt.Sprintf("quay.io/example/%s:v0.0.1", s.ProjectName)
42-
s.BundleImageName = fmt.Sprintf("quay.io/example/%s-bundle:v0.0.1", s.ProjectName)
43-
}
44-
28+
s.TestContext, err = testutils.NewPartialTestContext(binary, path, env...)
4529
return s, err
4630
}

internal/cmd/operator-sdk/cli/cli.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ import (
2222
"github.com/operator-framework/operator-sdk/internal/cmd/operator-sdk/olm"
2323
"github.com/operator-framework/operator-sdk/internal/cmd/operator-sdk/run"
2424
"github.com/operator-framework/operator-sdk/internal/cmd/operator-sdk/scorecard"
25-
"github.com/operator-framework/operator-sdk/internal/cmd/operator-sdk/version"
2625
"github.com/operator-framework/operator-sdk/internal/flags"
2726
ansiblev1 "github.com/operator-framework/operator-sdk/internal/plugins/ansible/v1"
2827
golangv2 "github.com/operator-framework/operator-sdk/internal/plugins/golang/v2"
28+
golangv3 "github.com/operator-framework/operator-sdk/internal/plugins/golang/v3"
2929
helmv1 "github.com/operator-framework/operator-sdk/internal/plugins/helm/v1"
3030
"github.com/operator-framework/operator-sdk/internal/util/projutil"
3131

@@ -43,7 +43,6 @@ var commands = []*cobra.Command{
4343
olm.NewCmd(),
4444
run.NewCmd(),
4545
scorecard.NewCmd(),
46-
version.NewCmd(),
4746
}
4847

4948
func Run() error {
@@ -57,12 +56,15 @@ func Run() error {
5756
func GetPluginsCLIAndRoot() (cli.CLI, *cobra.Command) {
5857
c, err := cli.New(
5958
cli.WithCommandName("operator-sdk"),
59+
cli.WithVersion(makeVersionString()),
6060
cli.WithPlugins(
6161
&golangv2.Plugin{},
62+
&golangv3.Plugin{},
6263
&helmv1.Plugin{},
6364
&ansiblev1.Plugin{},
6465
),
6566
cli.WithDefaultPlugins(
67+
// TODO(estroz): make go/v3-alpha plugin the default once stabilized.
6668
&golangv2.Plugin{},
6769
),
6870
cli.WithExtraCommands(commands...),

internal/cmd/operator-sdk/version/version_suite_test.go renamed to internal/cmd/operator-sdk/cli/cli_suite_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
package version_test
15+
package cli
1616

1717
import (
1818
"testing"
@@ -23,5 +23,5 @@ import (
2323

2424
func TestVersion(t *testing.T) {
2525
RegisterFailHandler(Fail)
26-
RunSpecs(t, "Version Cmd Suite")
26+
RunSpecs(t, "CLI Suite")
2727
}

internal/cmd/operator-sdk/version/cmd.go renamed to internal/cmd/operator-sdk/cli/version.go

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,29 +12,16 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
package version
15+
package cli
1616

1717
import (
1818
"fmt"
1919
"runtime"
2020

21-
"github.com/spf13/cobra"
22-
2321
ver "github.com/operator-framework/operator-sdk/internal/version"
2422
)
2523

26-
func NewCmd() *cobra.Command {
27-
versionCmd := &cobra.Command{
28-
Use: "version",
29-
Short: "Prints the version of operator-sdk",
30-
Run: func(cmd *cobra.Command, args []string) {
31-
run()
32-
},
33-
}
34-
return versionCmd
35-
}
36-
37-
func run() {
38-
fmt.Printf("operator-sdk version: %q, commit: %q, kubernetes version: %q, go version: %q, GOOS: %q, GOARCH: %q\n",
24+
func makeVersionString() string {
25+
return fmt.Sprintf("operator-sdk version: %q, commit: %q, kubernetes version: %q, go version: %q, GOOS: %q, GOARCH: %q",
3926
ver.GitVersion, ver.GitCommit, ver.KubernetesVersion, runtime.Version(), runtime.GOOS, runtime.GOARCH)
4027
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// Copyright 2020 The Operator-SDK Authors
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package cli
16+
17+
import (
18+
"fmt"
19+
"runtime"
20+
21+
. "github.com/onsi/ginkgo"
22+
. "github.com/onsi/gomega"
23+
24+
ver "github.com/operator-framework/operator-sdk/internal/version"
25+
)
26+
27+
var _ = Describe("printVersion", func() {
28+
It("prints the correct version info", func() {
29+
expVersion := makeVersionString()
30+
version := ver.GitVersion
31+
if version == "unknown" {
32+
version = ver.Version
33+
}
34+
Expect(expVersion).To(ContainSubstring(fmt.Sprintf("version: %q", version)))
35+
Expect(expVersion).To(ContainSubstring(fmt.Sprintf("commit: %q", ver.GitCommit)))
36+
Expect(expVersion).To(ContainSubstring(fmt.Sprintf("kubernetes version: %q", ver.KubernetesVersion)))
37+
Expect(expVersion).To(ContainSubstring(fmt.Sprintf("go version: %q", runtime.Version())))
38+
Expect(expVersion).To(ContainSubstring(fmt.Sprintf("GOOS: %q", runtime.GOOS)))
39+
Expect(expVersion).To(ContainSubstring(fmt.Sprintf("GOARCH: %q", runtime.GOARCH)))
40+
})
41+
})

internal/cmd/operator-sdk/version/cmd_test.go

Lines changed: 0 additions & 65 deletions
This file was deleted.

internal/kubebuilder/cmdutil/cmdutil.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,18 @@ limitations under the License.
1616

1717
package cmdutil
1818

19-
import "sigs.k8s.io/kubebuilder/v2/pkg/plugin/scaffold"
19+
// Scaffolder interface creates files to set up a controller manager
20+
type Scaffolder interface {
21+
// Scaffold performs the scaffolding
22+
Scaffold() error
23+
}
2024

2125
// RunOptions represent the types used to implement the different commands
2226
type RunOptions interface {
2327
// - Step 1: verify that the command can be run (e.g., go version, project version, arguments, ...)
2428
Validate() error
2529
// - Step 2: create the Scaffolder instance
26-
GetScaffolder() (scaffold.Scaffolder, error)
30+
GetScaffolder() (Scaffolder, error)
2731
// - Step 3: call the Scaffold method of the Scaffolder instance. Doesn't need any method
2832
// - Step 4: finish the command execution
2933
PostScaffold() error

0 commit comments

Comments
 (0)