Skip to content

Commit

Permalink
*: make go/v3 the default plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
estroz committed Dec 9, 2020
1 parent 71c4019 commit b600940
Show file tree
Hide file tree
Showing 18 changed files with 94 additions and 76 deletions.
12 changes: 12 additions & 0 deletions changelog/fragments/go-v3-default.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
entries:
- description: >
Go CLI plugin go/v3 is now the default.
kind: change
breaking: false
migration:
header: Upgrade your Go project from "go.kubebuilder.io/v2" to "go.kubebuilder.io/v3"
body: >
The newly released go/v3 plugin has many new features and (breaking) changes
incompatible with projects created by go/v2. You are not required to upgrade
and your project will continue to work with new operator-sdk versions.
If you wish to upgrade, check out the upstream [migration guide](https://book.kubebuilder.io/migrations.html).
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ require (
k8s.io/client-go v0.19.4
k8s.io/kubectl v0.19.4
rsc.io/letsencrypt v0.0.3 // indirect
sigs.k8s.io/controller-runtime v0.7.0-alpha.7
sigs.k8s.io/controller-tools v0.3.0
sigs.k8s.io/kubebuilder/v2 v2.3.2-0.20201204230216-593f2e80cdf6
sigs.k8s.io/controller-runtime v0.7.0-alpha.8.0.20201208205534-3410e75b0878
sigs.k8s.io/controller-tools v0.4.1
sigs.k8s.io/kubebuilder/v2 v2.3.2-0.20201207103326-37d82017a290
sigs.k8s.io/yaml v1.2.0
)

Expand Down
11 changes: 7 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1141,6 +1141,7 @@ golang.org/x/tools v0.0.0-20200103221440-774c71fcf114/go.mod h1:TB2adYChydJhpapK
golang.org/x/tools v0.0.0-20200403190813-44a64ad78b9b h1:AFZdJUT7jJYXQEC29hYH/WZkoV7+KhwxQGmdZ19yYoY=
golang.org/x/tools v0.0.0-20200403190813-44a64ad78b9b/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE=
golang.org/x/tools v0.0.0-20200616133436-c1934b75d054/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE=
golang.org/x/tools v0.0.0-20200616195046-dc31b401abb5/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE=
golang.org/x/tools v0.0.0-20201014231627-1610a49f37af h1:VIUWFyOgzG3c0t9KYop5Ybp4m56LupfOnFYX7Ipnz+I=
golang.org/x/tools v0.0.0-20201014231627-1610a49f37af/go.mod h1:z6u4i615ZeAfBE4XtMziQW1fSVJXACjjbWkB/mvPzlU=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
Expand Down Expand Up @@ -1357,12 +1358,14 @@ sigs.k8s.io/apiserver-network-proxy/konnectivity-client v0.0.9/go.mod h1:dzAXnQb
sigs.k8s.io/controller-runtime v0.6.0/go.mod h1:CpYf5pdNY/B352A1TFLAS2JVSlnGQ5O2cftPHndTroo=
sigs.k8s.io/controller-runtime v0.7.0-alpha.6 h1:ieFqEijQyDEZVIGwI5sYkk7VTa8Itim0kU/TCOnCkto=
sigs.k8s.io/controller-runtime v0.7.0-alpha.6/go.mod h1:03b1n6EtlDvuBPPEOHadJUusruwLWgoT4BDCybMibnA=
sigs.k8s.io/controller-runtime v0.7.0-alpha.7 h1:KtMmb2Ef/S38GNbf0Jpa+FWXqnxFYeWAyhipMmmPCcQ=
sigs.k8s.io/controller-runtime v0.7.0-alpha.7/go.mod h1:pJ3YBrJiAqMAZKi6UVGuE98ZrroV1p+pIhoHsMm9wdU=
sigs.k8s.io/controller-runtime v0.7.0-alpha.8.0.20201208205534-3410e75b0878 h1:kSOrkhl+glrp0EIMQE/8qt2zLmX43Erp1WP7y18jdUI=
sigs.k8s.io/controller-runtime v0.7.0-alpha.8.0.20201208205534-3410e75b0878/go.mod h1:pJ3YBrJiAqMAZKi6UVGuE98ZrroV1p+pIhoHsMm9wdU=
sigs.k8s.io/controller-tools v0.3.0 h1:y3YD99XOyWaXkiF1kd41uRvfp/64teWcrEZFuHxPhJ4=
sigs.k8s.io/controller-tools v0.3.0/go.mod h1:enhtKGfxZD1GFEoMgP8Fdbu+uKQ/cq1/WGJhdVChfvI=
sigs.k8s.io/kubebuilder/v2 v2.3.2-0.20201204230216-593f2e80cdf6 h1:SE+xhj4aauOCSeZKjRizd6VwHgkVfJABJpVk/xqYTiI=
sigs.k8s.io/kubebuilder/v2 v2.3.2-0.20201204230216-593f2e80cdf6/go.mod h1:J/D/179LBZhQOhRvmMRNbje/Bk+PjbN0/fzUupmO7+U=
sigs.k8s.io/controller-tools v0.4.1 h1:VkuV0MxlRPmRu5iTgBZU4UxUX2LiR99n3sdQGRxZF4w=
sigs.k8s.io/controller-tools v0.4.1/go.mod h1:G9rHdZMVlBDocIxGkK3jHLWqcTMNvveypYJwrvYKjWU=
sigs.k8s.io/kubebuilder/v2 v2.3.2-0.20201207103326-37d82017a290 h1:D/jndpb//FMJg8zDodivbTu1FVPXiw/RgcTZn1tYhW8=
sigs.k8s.io/kubebuilder/v2 v2.3.2-0.20201207103326-37d82017a290/go.mod h1:J/D/179LBZhQOhRvmMRNbje/Bk+PjbN0/fzUupmO7+U=
sigs.k8s.io/kustomize v2.0.3+incompatible h1:JUufWFNlI44MdtnjUqVnvh29rR37PQFzPbLXqhyOyX0=
sigs.k8s.io/kustomize v2.0.3+incompatible/go.mod h1:MkjgH3RdOWrievjo6c9T245dYlB5QeXV4WCbnt/PEpU=
sigs.k8s.io/structured-merge-diff/v3 v3.0.0-20200116222232-67a7b8c61874/go.mod h1:PlARxl6Hbt/+BC80dRLi1qAmnMqwqDg62YvvVkZjemw=
Expand Down
11 changes: 4 additions & 7 deletions hack/generate/samples/internal/go/v2/memcached_with_webhooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ func (mh *MemcachedGoWithWebhooks) Prepare() {
func (mh *MemcachedGoWithWebhooks) Run() {
log.Infof("creating the project")
err := mh.ctx.Init(
// TODO(estroz): change this to 3 when stabilized.
"--project-version", "3-alpha",
"--plugins", "go/v2",
"--repo", "github.com/example/memcached-operator",
"--domain",
Expand Down Expand Up @@ -176,13 +178,8 @@ func (mh *MemcachedGoWithWebhooks) implementingWebhooks() {
// Add imports
err = kbtestutils.InsertCode(webhookPath,
"import (",
"\n\t\"errors\"")
pkg.CheckError("adding errors import", err)

err = kbtestutils.InsertCode(webhookPath,
"\n\t\"errors\"",
"\n\t\"k8s.io/apimachinery/pkg/runtime\"")
pkg.CheckError("adding k8s.io/apimachinery/pkg/runtime import", err)
"\"errors\"\n\n\"k8s.io/apimachinery/pkg/runtime\"")
pkg.CheckError("adding webhook imports", err)
}

// implementingController will customize the Controller
Expand Down
10 changes: 6 additions & 4 deletions hack/generate/samples/internal/go/v3/memcached_with_webhooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,9 @@ func (mh *MemcachedGoWithWebhooks) Prepare() {
func (mh *MemcachedGoWithWebhooks) Run() {
log.Infof("creating the project")
err := mh.ctx.Init(
// TODO(estroz): change this to go/v3 is stabilized.
// TODO(estroz): change this to 3 when stabilized.
"--project-version", "3-alpha",
// TODO(estroz): change this to go/v3 when stabilized.
"--plugins", "go/v3-alpha",
"--repo", "github.com/example/memcached-operator",
"--domain",
Expand Down Expand Up @@ -168,11 +170,11 @@ func (mh *MemcachedGoWithWebhooks) implementingWebhooks() {
err := kbtestutils.InsertCode(webhookPath,
"// TODO(user): fill in your defaulting logic.\n}",
webhooksFragment)
pkg.CheckError("replacing reconcile", err)
pkg.CheckError("replacing webhook validate implementation", err)

err = testutils.ReplaceInFile(webhookPath,
"// TODO(user): fill in your defaulting logic.", "if r.Spec.Size == 0 {\n\t\tr.Spec.Size = 3\n\t}")
pkg.CheckError("replacing default webhook implementation", err)
pkg.CheckError("replacing webhook default implementation", err)

// Add imports
err = kbtestutils.InsertCode(webhookPath,
Expand Down Expand Up @@ -420,7 +422,7 @@ const watchCustomizedFragment = `return ctrl.NewControllerManagedBy(mgr).

const webhooksFragment = `
// TODO(user): change verbs to "verbs=create;update;delete" if you want to enable deletion validation.
// +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}
// +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={v1,v1beta1}
var _ webhook.Validator = &Memcached{}
Expand Down
34 changes: 17 additions & 17 deletions internal/ansible/controller/reconcile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func TestReconcile(t *testing.T) {
Runner: &fake.Runner{
JobEvents: []eventapi.JobEvent{},
},
Client: fakeclient.NewFakeClient(),
Client: fakeclient.NewClientBuilder().Build(),
Result: reconcile.Result{},
Request: reconcile.Request{
NamespacedName: types.NamespacedName{
Expand All @@ -84,7 +84,7 @@ func TestReconcile(t *testing.T) {
},
},
},
Client: fakeclient.NewFakeClient(&unstructured.Unstructured{
Client: fakeclient.NewClientBuilder().WithObjects(&unstructured.Unstructured{
Object: map[string]interface{}{
"metadata": map[string]interface{}{
"name": "reconcile",
Expand All @@ -93,7 +93,7 @@ func TestReconcile(t *testing.T) {
"apiVersion": "operator-sdk/v1beta1",
"kind": "Testing",
},
}),
}).Build(),
Result: reconcile.Result{
RequeueAfter: 5 * time.Second,
},
Expand Down Expand Up @@ -153,7 +153,7 @@ func TestReconcile(t *testing.T) {
},
},
},
Client: fakeclient.NewFakeClient(&unstructured.Unstructured{
Client: fakeclient.NewClientBuilder().WithObjects(&unstructured.Unstructured{
Object: map[string]interface{}{
"metadata": map[string]interface{}{
"name": "reconcile",
Expand All @@ -163,7 +163,7 @@ func TestReconcile(t *testing.T) {
"kind": "Testing",
"spec": map[string]interface{}{},
},
}),
}).Build(),
Request: reconcile.Request{
NamespacedName: types.NamespacedName{
Name: "reconcile",
Expand Down Expand Up @@ -227,7 +227,7 @@ func TestReconcile(t *testing.T) {
},
},
},
Client: fakeclient.NewFakeClient(&unstructured.Unstructured{
Client: fakeclient.NewClientBuilder().WithObjects(&unstructured.Unstructured{
Object: map[string]interface{}{
"metadata": map[string]interface{}{
"name": "reconcile",
Expand All @@ -237,7 +237,7 @@ func TestReconcile(t *testing.T) {
"kind": "Testing",
"spec": map[string]interface{}{},
},
}),
}).Build(),
Request: reconcile.Request{
NamespacedName: types.NamespacedName{
Name: "reconcile",
Expand All @@ -260,7 +260,7 @@ func TestReconcile(t *testing.T) {
},
Finalizer: "testing.io",
},
Client: fakeclient.NewFakeClient(&unstructured.Unstructured{
Client: fakeclient.NewClientBuilder().WithObjects(&unstructured.Unstructured{
Object: map[string]interface{}{
"metadata": map[string]interface{}{
"name": "reconcile",
Expand All @@ -273,7 +273,7 @@ func TestReconcile(t *testing.T) {
"kind": "Testing",
"spec": map[string]interface{}{},
},
}),
}).Build(),
Result: reconcile.Result{
RequeueAfter: 3 * time.Second,
},
Expand Down Expand Up @@ -331,7 +331,7 @@ func TestReconcile(t *testing.T) {
},
Finalizer: "testing.io",
},
Client: fakeclient.NewFakeClient(&unstructured.Unstructured{
Client: fakeclient.NewClientBuilder().WithObjects(&unstructured.Unstructured{
Object: map[string]interface{}{
"metadata": map[string]interface{}{
"name": "reconcile",
Expand All @@ -345,7 +345,7 @@ func TestReconcile(t *testing.T) {
"kind": "Testing",
"spec": map[string]interface{}{},
},
}),
}).Build(),
Result: reconcile.Result{},
Request: reconcile.Request{
NamespacedName: types.NamespacedName{
Expand All @@ -368,7 +368,7 @@ func TestReconcile(t *testing.T) {
},
Finalizer: "testing.io",
},
Client: fakeclient.NewFakeClient(&unstructured.Unstructured{
Client: fakeclient.NewClientBuilder().WithObjects(&unstructured.Unstructured{
Object: map[string]interface{}{
"metadata": map[string]interface{}{
"name": "reconcile",
Expand Down Expand Up @@ -399,7 +399,7 @@ func TestReconcile(t *testing.T) {
},
},
},
}),
}).Build(),
Result: reconcile.Result{
RequeueAfter: 5 * time.Second,
},
Expand Down Expand Up @@ -449,7 +449,7 @@ func TestReconcile(t *testing.T) {
},
},
},
Client: fakeclient.NewFakeClient(&unstructured.Unstructured{
Client: fakeclient.NewClientBuilder().WithObjects(&unstructured.Unstructured{
Object: map[string]interface{}{
"metadata": map[string]interface{}{
"name": "reconcile",
Expand All @@ -475,7 +475,7 @@ func TestReconcile(t *testing.T) {
},
},
},
}),
}).Build(),
Result: reconcile.Result{
RequeueAfter: 5 * time.Second,
},
Expand All @@ -500,7 +500,7 @@ func TestReconcile(t *testing.T) {
},
},
},
Client: fakeclient.NewFakeClient(&unstructured.Unstructured{
Client: fakeclient.NewClientBuilder().WithObjects(&unstructured.Unstructured{
Object: map[string]interface{}{
"metadata": map[string]interface{}{
"name": "reconcile",
Expand All @@ -509,7 +509,7 @@ func TestReconcile(t *testing.T) {
"apiVersion": "operator-sdk/v1beta1",
"kind": "Testing",
},
}),
}).Build(),
Result: reconcile.Result{
RequeueAfter: 5 * time.Second,
},
Expand Down
3 changes: 1 addition & 2 deletions internal/cmd/operator-sdk/cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,7 @@ func GetPluginsCLIAndRoot() (cli.CLI, *cobra.Command) {
&ansiblev1.Plugin{},
),
cli.WithDefaultPlugins(config.Version2, &golangv2.Plugin{}),
// TODO(estroz): make go/v3-alpha plugin the default once stabilized.
cli.WithDefaultPlugins(config.Version3Alpha, &golangv2.Plugin{}),
cli.WithDefaultPlugins(config.Version3Alpha, &golangv3.Plugin{}),
cli.WithExtraCommands(commands...),
)
if err != nil {
Expand Down
17 changes: 8 additions & 9 deletions internal/olm/client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,7 @@ var _ = Describe("Client", func() {
})
Context("with a valid csv", func() {
It("check error string for pod errors", func() {
fakeClient = fake.NewFakeClient(

fakeClient = fake.NewClientBuilder().WithObjects(
&corev1.Pod{
ObjectMeta: metav1.ObjectMeta{
Name: "test-operator-kc44t",
Expand Down Expand Up @@ -119,7 +118,7 @@ var _ = Describe("Client", func() {
},
},
},
)
).Build()
key := types.NamespacedName{
Name: "test.operator",
Namespace: "test-operator-system",
Expand All @@ -130,7 +129,7 @@ var _ = Describe("Client", func() {
})

It("check error string for multiple pod failures", func() {
fakeClt := fake.NewFakeClient(
fakeClt := fake.NewClientBuilder().WithObjects(
&corev1.Pod{
ObjectMeta: metav1.ObjectMeta{
Name: "test-operator-jjj",
Expand Down Expand Up @@ -196,7 +195,7 @@ var _ = Describe("Client", func() {
},
},
},
)
).Build()
key := types.NamespacedName{
Name: "test.operator",
Namespace: "test-operator-system",
Expand All @@ -208,7 +207,7 @@ var _ = Describe("Client", func() {
})

It("check error string for deployment errors,when no pods exist", func() {
fakeClient = fake.NewFakeClient(
fakeClient = fake.NewClientBuilder().WithObjects(
&appsv1.Deployment{
ObjectMeta: metav1.ObjectMeta{
Name: "test-operator-controller-manager",
Expand All @@ -227,7 +226,7 @@ var _ = Describe("Client", func() {
},
},
},
)
).Build()
key := types.NamespacedName{
Name: "test-operator",
Namespace: "test-operator-system",
Expand All @@ -238,7 +237,7 @@ var _ = Describe("Client", func() {
})

It("check error string,when no deployments exist for given CSV", func() {
fakeClient = fake.NewFakeClient()
fakeClient = fake.NewClientBuilder().Build()
olmclient := Client{KubeClient: fakeClient}
key := types.NamespacedName{
Name: "test-operator",
Expand All @@ -249,7 +248,7 @@ var _ = Describe("Client", func() {
Expect(err.Error()).To(ContainSubstring("\"dummy-operator\" not found"))
})
It("check error string,when no namespace provided", func() {
fakeClient = fake.NewFakeClient()
fakeClient = fake.NewClientBuilder().Build()
olmclient := Client{KubeClient: fakeClient}
key := types.NamespacedName{
Name: "test-operator",
Expand Down
4 changes: 2 additions & 2 deletions internal/olm/operator/registry/configmap/configmap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ var _ = Describe("ConfigMap", func() {
e error
)
BeforeEach(func() {
fakeclient := fake.NewFakeClient(
fakeclient := fake.NewClientBuilder().WithObjects(
&corev1.ConfigMap{
ObjectMeta: metav1.ObjectMeta{
Namespace: "testns",
Expand All @@ -256,7 +256,7 @@ var _ = Describe("ConfigMap", func() {
Labels: makeRegistryLabels("test"),
},
},
)
).Build()
rr = RegistryResources{
Client: &client.Client{
KubeClient: fakeclient,
Expand Down
Loading

0 comments on commit b600940

Please sign in to comment.