Skip to content

Instantly share code, notes, and snippets.

@alexeldeib
Last active June 18, 2019 17:30
Show Gist options
  • Save alexeldeib/bc4e77ce6b677bd99ccb071d15fdd82d to your computer and use it in GitHub Desktop.
Save alexeldeib/bc4e77ce6b677bd99ccb071d15fdd82d to your computer and use it in GitHub Desktop.
Migrating Cluster API from Kubebuilder v1 => v2

CAPI Kubebuilder v1 => v2 Migration

Go modules

Kubebuilder makes it a bit annoying to figure out the versions you need properly. As of this writing, v0.2.0-beta.2 was working against Kubernetes 1.14.1.

To use this with Go Modules, put the following in your Go.mod:

module sigs.k8s.io/cluster-api

go 1.12

require (
  k8s.io/api kubernetes-1.14.1
	k8s.io/apimachinery kubernetes-1.14.1
	k8s.io/client-go kubernetes-1.14.1
	sigs.k8s.io/controller-runtime v0.2.0-beta.2
)

replace (
	k8s.io/api kubernetes-1.14.1
	k8s.io/apimachinery kubernetes-1.14.1
	k8s.io/client-go kubernetes-1.14.1
)

Package renaming

  • "sigs.k8s.io/controller-runtime/pkg/runtime/scheme" => "sigs.k8s.io/controller-runtime/pkg/runtime/scheme"
  • "k8s.io/client-go/util/integer" => "k8s.io/utils/integer"

Function signatures

  • In List calls, the object struct now comes before the ListOptions.
  • In List calls, the ListOptions object changed to use convenience functions. e.g.
listOpts := client.ListOptions{Namespace: ms.Namespace}
r.Client.List(context.Background(), &v1alpha1.MachineDeploymentList{}, listOpts)

vs

listOpts := client.InNamespace(ms.Namespace)
r.Client.List(context.Background(), &v1alpha1.MachineDeploymentList{}, listOpts)

Function renaming

  • manager.GetRecorder(name) => manager.GetEventRecorderFor(name)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment