Update vendor

This commit is contained in:
Darren Shepherd
2020-03-21 07:52:11 -07:00
parent 4c13c6bd95
commit 7395e5b8c4
28 changed files with 373 additions and 81 deletions

View File

@@ -233,6 +233,7 @@ func (c *customResourceDefinitionCache) GetByIndex(indexName, key string) (resul
if err != nil {
return nil, err
}
result = make([]*v1beta1.CustomResourceDefinition, 0, len(objs))
for _, obj := range objs {
result = append(result, obj.(*v1beta1.CustomResourceDefinition))
}

View File

@@ -233,6 +233,7 @@ func (c *aPIServiceCache) GetByIndex(indexName, key string) (result []*v1.APISer
if err != nil {
return nil, err
}
result = make([]*v1.APIService, 0, len(objs))
for _, obj := range objs {
result = append(result, obj.(*v1.APIService))
}

View File

@@ -226,6 +226,7 @@ func (c *configMapCache) GetByIndex(indexName, key string) (result []*v1.ConfigM
if err != nil {
return nil, err
}
result = make([]*v1.ConfigMap, 0, len(objs))
for _, obj := range objs {
result = append(result, obj.(*v1.ConfigMap))
}

View File

@@ -226,6 +226,7 @@ func (c *endpointsCache) GetByIndex(indexName, key string) (result []*v1.Endpoin
if err != nil {
return nil, err
}
result = make([]*v1.Endpoints, 0, len(objs))
for _, obj := range objs {
result = append(result, obj.(*v1.Endpoints))
}

View File

@@ -226,6 +226,7 @@ func (c *eventCache) GetByIndex(indexName, key string) (result []*v1.Event, err
if err != nil {
return nil, err
}
result = make([]*v1.Event, 0, len(objs))
for _, obj := range objs {
result = append(result, obj.(*v1.Event))
}

View File

@@ -233,6 +233,7 @@ func (c *namespaceCache) GetByIndex(indexName, key string) (result []*v1.Namespa
if err != nil {
return nil, err
}
result = make([]*v1.Namespace, 0, len(objs))
for _, obj := range objs {
result = append(result, obj.(*v1.Namespace))
}

View File

@@ -233,6 +233,7 @@ func (c *nodeCache) GetByIndex(indexName, key string) (result []*v1.Node, err er
if err != nil {
return nil, err
}
result = make([]*v1.Node, 0, len(objs))
for _, obj := range objs {
result = append(result, obj.(*v1.Node))
}

View File

@@ -233,6 +233,7 @@ func (c *persistentVolumeClaimCache) GetByIndex(indexName, key string) (result [
if err != nil {
return nil, err
}
result = make([]*v1.PersistentVolumeClaim, 0, len(objs))
for _, obj := range objs {
result = append(result, obj.(*v1.PersistentVolumeClaim))
}

View File

@@ -233,6 +233,7 @@ func (c *podCache) GetByIndex(indexName, key string) (result []*v1.Pod, err erro
if err != nil {
return nil, err
}
result = make([]*v1.Pod, 0, len(objs))
for _, obj := range objs {
result = append(result, obj.(*v1.Pod))
}

View File

@@ -226,6 +226,7 @@ func (c *secretCache) GetByIndex(indexName, key string) (result []*v1.Secret, er
if err != nil {
return nil, err
}
result = make([]*v1.Secret, 0, len(objs))
for _, obj := range objs {
result = append(result, obj.(*v1.Secret))
}

View File

@@ -233,6 +233,7 @@ func (c *serviceCache) GetByIndex(indexName, key string) (result []*v1.Service,
if err != nil {
return nil, err
}
result = make([]*v1.Service, 0, len(objs))
for _, obj := range objs {
result = append(result, obj.(*v1.Service))
}

View File

@@ -226,6 +226,7 @@ func (c *serviceAccountCache) GetByIndex(indexName, key string) (result []*v1.Se
if err != nil {
return nil, err
}
result = make([]*v1.ServiceAccount, 0, len(objs))
for _, obj := range objs {
result = append(result, obj.(*v1.ServiceAccount))
}

View File

@@ -226,6 +226,7 @@ func (c *clusterRoleCache) GetByIndex(indexName, key string) (result []*v1.Clust
if err != nil {
return nil, err
}
result = make([]*v1.ClusterRole, 0, len(objs))
for _, obj := range objs {
result = append(result, obj.(*v1.ClusterRole))
}

View File

@@ -226,6 +226,7 @@ func (c *clusterRoleBindingCache) GetByIndex(indexName, key string) (result []*v
if err != nil {
return nil, err
}
result = make([]*v1.ClusterRoleBinding, 0, len(objs))
for _, obj := range objs {
result = append(result, obj.(*v1.ClusterRoleBinding))
}

View File

@@ -226,6 +226,7 @@ func (c *roleCache) GetByIndex(indexName, key string) (result []*v1.Role, err er
if err != nil {
return nil, err
}
result = make([]*v1.Role, 0, len(objs))
for _, obj := range objs {
result = append(result, obj.(*v1.Role))
}

View File

@@ -226,6 +226,7 @@ func (c *roleBindingCache) GetByIndex(indexName, key string) (result []*v1.RoleB
if err != nil {
return nil, err
}
result = make([]*v1.RoleBinding, 0, len(objs))
for _, obj := range objs {
result = append(result, obj.(*v1.RoleBinding))
}

View File

@@ -0,0 +1,22 @@
package client
import (
"github.com/rancher/wrangler/pkg/summary"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/watch"
)
type Interface interface {
Resource(resource schema.GroupVersionResource) NamespaceableResourceInterface
}
type ResourceInterface interface {
List(opts metav1.ListOptions) (*summary.SummarizedObjectList, error)
Watch(opts metav1.ListOptions) (watch.Interface, error)
}
type NamespaceableResourceInterface interface {
Namespace(string) ResourceInterface
ResourceInterface
}

View File

@@ -0,0 +1,109 @@
package client
import (
"github.com/rancher/wrangler/pkg/summary"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/watch"
"k8s.io/client-go/dynamic"
)
type summaryClient struct {
client dynamic.Interface
}
var _ Interface = &summaryClient{}
func NewForDynamicClient(client dynamic.Interface) Interface {
return &summaryClient{client: client}
}
type summaryResourceClient struct {
client dynamic.Interface
namespace string
resource schema.GroupVersionResource
}
func (c *summaryClient) Resource(resource schema.GroupVersionResource) NamespaceableResourceInterface {
return &summaryResourceClient{client: c.client, resource: resource}
}
func (c *summaryResourceClient) Namespace(ns string) ResourceInterface {
ret := *c
ret.namespace = ns
return &ret
}
func (c *summaryResourceClient) List(opts metav1.ListOptions) (*summary.SummarizedObjectList, error) {
var (
u *unstructured.UnstructuredList
err error
)
if c.namespace == "" {
u, err = c.client.Resource(c.resource).List(opts)
} else {
u, err = c.client.Resource(c.resource).Namespace(c.namespace).List(opts)
}
if err != nil {
return nil, err
}
list := &summary.SummarizedObjectList{
TypeMeta: metav1.TypeMeta{
Kind: u.GetKind(),
APIVersion: u.GetAPIVersion(),
},
ListMeta: metav1.ListMeta{
ResourceVersion: u.GetResourceVersion(),
Continue: u.GetContinue(),
RemainingItemCount: u.GetRemainingItemCount(),
},
}
for _, obj := range u.Items {
list.Items = append(list.Items, *summary.Summarized(&obj))
}
return list, nil
}
func (c *summaryResourceClient) Watch(opts metav1.ListOptions) (watch.Interface, error) {
var (
resp watch.Interface
err error
)
eventChan := make(chan watch.Event)
if c.namespace == "" {
resp, err = c.client.Resource(c.resource).Watch(opts)
} else {
resp, err = c.client.Resource(c.resource).Namespace(c.namespace).Watch(opts)
}
if err != nil {
return nil, err
}
go func() {
for event := range resp.ResultChan() {
event.Object = summary.Summarized(event.Object)
eventChan <- event
}
}()
return &watcher{
Interface: resp,
eventChan: eventChan,
}, nil
}
type watcher struct {
watch.Interface
eventChan chan watch.Event
}
func (w watcher) ResultChan() <-chan watch.Event {
return w.eventChan
}

View File

@@ -0,0 +1,157 @@
/*
Copyright 2018 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package informer
import (
"sync"
"time"
"github.com/rancher/wrangler/pkg/summary"
"github.com/rancher/wrangler/pkg/summary/client"
"github.com/rancher/wrangler/pkg/summary/lister"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/watch"
"k8s.io/client-go/informers"
"k8s.io/client-go/tools/cache"
)
// NewSummarySharedInformerFactory constructs a new instance of summarySharedInformerFactory for all namespaces.
func NewSummarySharedInformerFactory(client client.Interface, defaultResync time.Duration) SummarySharedInformerFactory {
return NewFilteredSummarySharedInformerFactory(client, defaultResync, metav1.NamespaceAll, nil)
}
// NewFilteredSummarySharedInformerFactory constructs a new instance of summarySharedInformerFactory.
// Listers obtained via this factory will be subject to the same filters as specified here.
func NewFilteredSummarySharedInformerFactory(client client.Interface, defaultResync time.Duration, namespace string, tweakListOptions TweakListOptionsFunc) SummarySharedInformerFactory {
return &summarySharedInformerFactory{
client: client,
defaultResync: defaultResync,
namespace: namespace,
informers: map[schema.GroupVersionResource]informers.GenericInformer{},
startedInformers: make(map[schema.GroupVersionResource]bool),
tweakListOptions: tweakListOptions,
}
}
type summarySharedInformerFactory struct {
client client.Interface
defaultResync time.Duration
namespace string
lock sync.Mutex
informers map[schema.GroupVersionResource]informers.GenericInformer
// startedInformers is used for tracking which informers have been started.
// This allows Start() to be called multiple times safely.
startedInformers map[schema.GroupVersionResource]bool
tweakListOptions TweakListOptionsFunc
}
var _ SummarySharedInformerFactory = &summarySharedInformerFactory{}
func (f *summarySharedInformerFactory) ForResource(gvr schema.GroupVersionResource) informers.GenericInformer {
f.lock.Lock()
defer f.lock.Unlock()
key := gvr
informer, exists := f.informers[key]
if exists {
return informer
}
informer = NewFilteredSummaryInformer(f.client, gvr, f.namespace, f.defaultResync, cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc}, f.tweakListOptions)
f.informers[key] = informer
return informer
}
// Start initializes all requested informers.
func (f *summarySharedInformerFactory) Start(stopCh <-chan struct{}) {
f.lock.Lock()
defer f.lock.Unlock()
for informerType, informer := range f.informers {
if !f.startedInformers[informerType] {
go informer.Informer().Run(stopCh)
f.startedInformers[informerType] = true
}
}
}
// WaitForCacheSync waits for all started informers' cache were synced.
func (f *summarySharedInformerFactory) WaitForCacheSync(stopCh <-chan struct{}) map[schema.GroupVersionResource]bool {
informers := func() map[schema.GroupVersionResource]cache.SharedIndexInformer {
f.lock.Lock()
defer f.lock.Unlock()
informers := map[schema.GroupVersionResource]cache.SharedIndexInformer{}
for informerType, informer := range f.informers {
if f.startedInformers[informerType] {
informers[informerType] = informer.Informer()
}
}
return informers
}()
res := map[schema.GroupVersionResource]bool{}
for informType, informer := range informers {
res[informType] = cache.WaitForCacheSync(stopCh, informer.HasSynced)
}
return res
}
// NewFilteredSummaryInformer constructs a new informer for a summary type.
func NewFilteredSummaryInformer(client client.Interface, gvr schema.GroupVersionResource, namespace string, resyncPeriod time.Duration, indexers cache.Indexers, tweakListOptions TweakListOptionsFunc) informers.GenericInformer {
return &summaryInformer{
gvr: gvr,
informer: cache.NewSharedIndexInformer(
&cache.ListWatch{
ListFunc: func(options metav1.ListOptions) (runtime.Object, error) {
if tweakListOptions != nil {
tweakListOptions(&options)
}
return client.Resource(gvr).Namespace(namespace).List(options)
},
WatchFunc: func(options metav1.ListOptions) (watch.Interface, error) {
if tweakListOptions != nil {
tweakListOptions(&options)
}
return client.Resource(gvr).Namespace(namespace).Watch(options)
},
},
&summary.SummarizedObject{},
resyncPeriod,
indexers,
),
}
}
type summaryInformer struct {
informer cache.SharedIndexInformer
gvr schema.GroupVersionResource
}
var _ informers.GenericInformer = &summaryInformer{}
func (d *summaryInformer) Informer() cache.SharedIndexInformer {
return d.informer
}
func (d *summaryInformer) Lister() cache.GenericLister {
return lister.NewRuntimeObjectShim(lister.New(d.informer.GetIndexer(), d.gvr))
}

View File

@@ -0,0 +1,34 @@
/*
Copyright 2018 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package informer
import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/client-go/informers"
)
// SummarySharedInformerFactory provides access to a shared informer and lister for dynamic client
type SummarySharedInformerFactory interface {
Start(stopCh <-chan struct{})
ForResource(gvr schema.GroupVersionResource) informers.GenericInformer
WaitForCacheSync(stopCh <-chan struct{}) map[schema.GroupVersionResource]bool
}
// TweakListOptionsFunc defines the signature of a helper function
// that wants to provide more listing options to API
type TweakListOptionsFunc func(*metav1.ListOptions)

View File

@@ -0,0 +1,40 @@
/*
Copyright 2018 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package lister
import (
"github.com/rancher/wrangler/pkg/summary"
"k8s.io/apimachinery/pkg/labels"
)
// Lister helps list resources.
type Lister interface {
// List lists all resources in the indexer.
List(selector labels.Selector) (ret []*summary.SummarizedObject, err error)
// Get retrieves a resource from the indexer with the given name
Get(name string) (*summary.SummarizedObject, error)
// Namespace returns an object that can list and get resources in a given namespace.
Namespace(namespace string) NamespaceLister
}
// NamespaceLister helps list and get resources.
type NamespaceLister interface {
// List lists all resources in the indexer for a given namespace.
List(selector labels.Selector) (ret []*summary.SummarizedObject, err error)
// Get retrieves a resource from the indexer for a given namespace and name.
Get(name string) (*summary.SummarizedObject, error)
}

View File

@@ -0,0 +1,91 @@
/*
Copyright 2018 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package lister
import (
"github.com/rancher/wrangler/pkg/summary"
"k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/client-go/tools/cache"
)
var _ Lister = &summaryLister{}
var _ NamespaceLister = &summaryNamespaceLister{}
// summaryLister implements the Lister interface.
type summaryLister struct {
indexer cache.Indexer
gvr schema.GroupVersionResource
}
// New returns a new Lister.
func New(indexer cache.Indexer, gvr schema.GroupVersionResource) Lister {
return &summaryLister{indexer: indexer, gvr: gvr}
}
// List lists all resources in the indexer.
func (l *summaryLister) List(selector labels.Selector) (ret []*summary.SummarizedObject, err error) {
err = cache.ListAll(l.indexer, selector, func(m interface{}) {
ret = append(ret, m.(*summary.SummarizedObject))
})
return ret, err
}
// Get retrieves a resource from the indexer with the given name
func (l *summaryLister) Get(name string) (*summary.SummarizedObject, error) {
obj, exists, err := l.indexer.GetByKey(name)
if err != nil {
return nil, err
}
if !exists {
return nil, errors.NewNotFound(l.gvr.GroupResource(), name)
}
return obj.(*summary.SummarizedObject), nil
}
// Namespace returns an object that can list and get resources from a given namespace.
func (l *summaryLister) Namespace(namespace string) NamespaceLister {
return &summaryNamespaceLister{indexer: l.indexer, namespace: namespace, gvr: l.gvr}
}
// summaryNamespaceLister implements the NamespaceLister interface.
type summaryNamespaceLister struct {
indexer cache.Indexer
namespace string
gvr schema.GroupVersionResource
}
// List lists all resources in the indexer for a given namespace.
func (l *summaryNamespaceLister) List(selector labels.Selector) (ret []*summary.SummarizedObject, err error) {
err = cache.ListAllByNamespace(l.indexer, l.namespace, selector, func(m interface{}) {
ret = append(ret, m.(*summary.SummarizedObject))
})
return ret, err
}
// Get retrieves a resource from the indexer for a given namespace and name.
func (l *summaryNamespaceLister) Get(name string) (*summary.SummarizedObject, error) {
obj, exists, err := l.indexer.GetByKey(l.namespace + "/" + name)
if err != nil {
return nil, err
}
if !exists {
return nil, errors.NewNotFound(l.gvr.GroupResource(), name)
}
return obj.(*summary.SummarizedObject), nil
}

View File

@@ -0,0 +1,87 @@
/*
Copyright 2018 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package lister
import (
"k8s.io/apimachinery/pkg/labels"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/client-go/tools/cache"
)
var _ cache.GenericLister = &summaryListerShim{}
var _ cache.GenericNamespaceLister = &summaryNamespaceListerShim{}
// summaryListerShim implements the cache.GenericLister interface.
type summaryListerShim struct {
lister Lister
}
// NewRuntimeObjectShim returns a new shim for Lister.
// It wraps Lister so that it implements cache.GenericLister interface
func NewRuntimeObjectShim(lister Lister) cache.GenericLister {
return &summaryListerShim{lister: lister}
}
// List will return all objects across namespaces
func (s *summaryListerShim) List(selector labels.Selector) (ret []runtime.Object, err error) {
objs, err := s.lister.List(selector)
if err != nil {
return nil, err
}
ret = make([]runtime.Object, len(objs))
for index, obj := range objs {
ret[index] = obj
}
return ret, err
}
// Get will attempt to retrieve assuming that name==key
func (s *summaryListerShim) Get(name string) (runtime.Object, error) {
return s.lister.Get(name)
}
func (s *summaryListerShim) ByNamespace(namespace string) cache.GenericNamespaceLister {
return &summaryNamespaceListerShim{
namespaceLister: s.lister.Namespace(namespace),
}
}
// summaryNamespaceListerShim implements the NamespaceLister interface.
// It wraps NamespaceLister so that it implements cache.GenericNamespaceLister interface
type summaryNamespaceListerShim struct {
namespaceLister NamespaceLister
}
// List will return all objects in this namespace
func (ns *summaryNamespaceListerShim) List(selector labels.Selector) (ret []runtime.Object, err error) {
objs, err := ns.namespaceLister.List(selector)
if err != nil {
return nil, err
}
ret = make([]runtime.Object, len(objs))
for index, obj := range objs {
ret[index] = obj
}
return ret, err
}
// Get will attempt to retrieve by namespace and name
func (ns *summaryNamespaceListerShim) Get(name string) (runtime.Object, error) {
return ns.namespaceLister.Get(name)
}

View File

@@ -0,0 +1,98 @@
package summary
import (
"k8s.io/apimachinery/pkg/api/meta"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
)
type SummarizedObject struct {
metav1.PartialObjectMetadata
Summary
}
type SummarizedObjectList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"`
Items []SummarizedObject `json:"items" protobuf:"bytes,2,rep,name=items"`
}
func Summarized(u runtime.Object) *SummarizedObject {
if s, ok := u.(*SummarizedObject); ok {
return s
}
s := &SummarizedObject{
Summary: Summarize(u),
}
s.APIVersion, s.Kind = u.GetObjectKind().GroupVersionKind().ToAPIVersionAndKind()
meta, err := meta.Accessor(u)
if err == nil {
s.Name = meta.GetName()
s.Namespace = meta.GetNamespace()
s.Generation = meta.GetGeneration()
s.UID = meta.GetUID()
s.ResourceVersion = meta.GetResourceVersion()
s.CreationTimestamp = meta.GetCreationTimestamp()
s.DeletionTimestamp = meta.GetDeletionTimestamp()
s.Labels = meta.GetLabels()
s.Annotations = meta.GetAnnotations()
}
return s
}
func (in *SummarizedObjectList) DeepCopyInto(out *SummarizedObjectList) {
*out = *in
out.TypeMeta = in.TypeMeta
in.ListMeta.DeepCopyInto(&out.ListMeta)
if in.Items != nil {
in, out := &in.Items, &out.Items
*out = make([]SummarizedObject, len(*in))
for i := range *in {
(*in)[i].DeepCopyInto(&(*out)[i])
}
}
return
}
func (in *SummarizedObjectList) DeepCopy() *SummarizedObjectList {
if in == nil {
return nil
}
out := new(SummarizedObjectList)
in.DeepCopyInto(out)
return out
}
func (in *SummarizedObjectList) DeepCopyObject() runtime.Object {
if c := in.DeepCopy(); c != nil {
return c
}
return nil
}
func (in *SummarizedObject) DeepCopyInto(out *SummarizedObject) {
*out = *in
out.TypeMeta = in.TypeMeta
out.ObjectMeta = *in.ObjectMeta.DeepCopy()
out.Summary = *in.Summary.DeepCopy()
return
}
func (in *SummarizedObject) DeepCopy() *SummarizedObject {
if in == nil {
return nil
}
out := new(SummarizedObject)
in.DeepCopyInto(out)
return out
}
func (in *SummarizedObject) DeepCopyObject() runtime.Object {
if c := in.DeepCopy(); c != nil {
return c
}
return nil
}

View File

@@ -3,6 +3,8 @@ package summary
import (
"strings"
"k8s.io/apimachinery/pkg/runtime"
"github.com/rancher/wrangler/pkg/data"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
)
@@ -14,6 +16,42 @@ type Summary struct {
Message []string
}
func (s Summary) String() string {
if !s.Transitioning && !s.Error {
return s.State
}
var msg string
if s.Transitioning {
msg = "[progressing"
}
if s.Error {
if len(msg) > 0 {
msg += ",error]"
} else {
msg = "error]"
}
} else {
msg += "]"
}
if len(s.Message) > 0 {
msg = msg + " " + s.Message[0]
}
return msg
}
func (s Summary) IsReady() bool {
return !s.Error && !s.Transitioning
}
func (s *Summary) DeepCopy() *Summary {
v := *s
return &v
}
func (s *Summary) DeepCopyInto(v *Summary) {
*v = *s
}
func dedupMessage(messages []string) []string {
if len(messages) <= 1 {
return messages
@@ -33,12 +71,21 @@ func dedupMessage(messages []string) []string {
return result
}
func Summarize(unstr *unstructured.Unstructured) Summary {
func Summarize(runtimeObj runtime.Object) Summary {
var (
obj data.Object
summary Summary
)
if s, ok := runtimeObj.(*SummarizedObject); ok {
return s.Summary
}
unstr, ok := runtimeObj.(*unstructured.Unstructured)
if !ok {
return summary
}
if unstr != nil {
obj = unstr.Object
}