Update to controller-runtime 0.7.0
controller-runtime methods now accept `client.Object` and `client.ObjectList` rather than `runtime.Object`. This means the adapter interfaces need to change signature, but happily, little else. Since the list adapter is now distinct to the object adapter, `len()` can go there instead of the command-specific interfaces. Signed-off-by: Michael Bridgen <michael@weave.works>
This commit is contained in:
@@ -55,8 +55,7 @@ type exportable interface {
|
||||
// exportableList represents a type that has a list of values, each of
|
||||
// which is exportable.
|
||||
type exportableList interface {
|
||||
adapter
|
||||
len() int
|
||||
listAdapter
|
||||
exportItem(i int) interface{}
|
||||
}
|
||||
|
||||
@@ -79,7 +78,7 @@ func (export exportCommand) run(cmd *cobra.Command, args []string) error {
|
||||
}
|
||||
|
||||
if exportAll {
|
||||
err = kubeClient.List(ctx, export.list.asRuntimeObject(), client.InNamespace(namespace))
|
||||
err = kubeClient.List(ctx, export.list.asRuntimeList(), client.InNamespace(namespace))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -45,8 +45,7 @@ func init() {
|
||||
}
|
||||
|
||||
type summarisable interface {
|
||||
adapter
|
||||
len() int
|
||||
listAdapter
|
||||
summariseItem(i int, includeNamespace bool) []string
|
||||
headers(includeNamespace bool) []string
|
||||
}
|
||||
@@ -87,7 +86,7 @@ func (get getCommand) run(cmd *cobra.Command, args []string) error {
|
||||
if !allNamespaces {
|
||||
listOpts = append(listOpts, client.InNamespace(namespace))
|
||||
}
|
||||
err = kubeClient.List(ctx, get.list.asRuntimeObject(), listOpts...)
|
||||
err = kubeClient.List(ctx, get.list.asRuntimeList(), listOpts...)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ limitations under the License.
|
||||
package main
|
||||
|
||||
import (
|
||||
"k8s.io/apimachinery/pkg/runtime"
|
||||
"sigs.k8s.io/controller-runtime/pkg/client"
|
||||
|
||||
autov1 "github.com/fluxcd/image-automation-controller/api/v1alpha1"
|
||||
imagev1 "github.com/fluxcd/image-reflector-controller/api/v1alpha1"
|
||||
@@ -38,7 +38,7 @@ type imageRepositoryAdapter struct {
|
||||
*imagev1.ImageRepository
|
||||
}
|
||||
|
||||
func (a imageRepositoryAdapter) asRuntimeObject() runtime.Object {
|
||||
func (a imageRepositoryAdapter) asRuntimeObject() client.Object {
|
||||
return a.ImageRepository
|
||||
}
|
||||
|
||||
@@ -48,7 +48,7 @@ type imageRepositoryListAdapter struct {
|
||||
*imagev1.ImageRepositoryList
|
||||
}
|
||||
|
||||
func (a imageRepositoryListAdapter) asRuntimeObject() runtime.Object {
|
||||
func (a imageRepositoryListAdapter) asRuntimeList() client.ObjectList {
|
||||
return a.ImageRepositoryList
|
||||
}
|
||||
|
||||
@@ -67,7 +67,7 @@ type imagePolicyAdapter struct {
|
||||
*imagev1.ImagePolicy
|
||||
}
|
||||
|
||||
func (a imagePolicyAdapter) asRuntimeObject() runtime.Object {
|
||||
func (a imagePolicyAdapter) asRuntimeObject() client.Object {
|
||||
return a.ImagePolicy
|
||||
}
|
||||
|
||||
@@ -77,7 +77,7 @@ type imagePolicyListAdapter struct {
|
||||
*imagev1.ImagePolicyList
|
||||
}
|
||||
|
||||
func (a imagePolicyListAdapter) asRuntimeObject() runtime.Object {
|
||||
func (a imagePolicyListAdapter) asRuntimeList() client.ObjectList {
|
||||
return a.ImagePolicyList
|
||||
}
|
||||
|
||||
@@ -96,7 +96,7 @@ type imageUpdateAutomationAdapter struct {
|
||||
*autov1.ImageUpdateAutomation
|
||||
}
|
||||
|
||||
func (a imageUpdateAutomationAdapter) asRuntimeObject() runtime.Object {
|
||||
func (a imageUpdateAutomationAdapter) asRuntimeObject() client.Object {
|
||||
return a.ImageUpdateAutomation
|
||||
}
|
||||
|
||||
@@ -106,7 +106,7 @@ type imageUpdateAutomationListAdapter struct {
|
||||
*autov1.ImageUpdateAutomationList
|
||||
}
|
||||
|
||||
func (a imageUpdateAutomationListAdapter) asRuntimeObject() runtime.Object {
|
||||
func (a imageUpdateAutomationListAdapter) asRuntimeList() client.ObjectList {
|
||||
return a.ImageUpdateAutomationList
|
||||
}
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ limitations under the License.
|
||||
package main
|
||||
|
||||
import (
|
||||
"k8s.io/apimachinery/pkg/runtime"
|
||||
"sigs.k8s.io/controller-runtime/pkg/client"
|
||||
)
|
||||
|
||||
// Most commands need one or both of the kind (e.g.,
|
||||
@@ -35,16 +35,24 @@ type apiType struct {
|
||||
// use values of the wrapper with `client.Client`, which only deals
|
||||
// with types that have been added to the schema.
|
||||
type adapter interface {
|
||||
asRuntimeObject() runtime.Object
|
||||
asRuntimeObject() client.Object
|
||||
}
|
||||
|
||||
// universalAdapter is an adapter for any runtime.Object. Use this if
|
||||
// listAdapater is the analogue to adapter, but for lists; the
|
||||
// controller runtime distinguishes between methods dealing with
|
||||
// objects and lists.
|
||||
type listAdapter interface {
|
||||
asRuntimeList() client.ObjectList
|
||||
len() int
|
||||
}
|
||||
|
||||
// universalAdapter is an adapter for any client.Object. Use this if
|
||||
// there are no other methods needed.
|
||||
type universalAdapter struct {
|
||||
obj runtime.Object
|
||||
obj client.Object
|
||||
}
|
||||
|
||||
func (c universalAdapter) asRuntimeObject() runtime.Object {
|
||||
func (c universalAdapter) asRuntimeObject() client.Object {
|
||||
return c.obj
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user