-
Notifications
You must be signed in to change notification settings - Fork 6
/
spec.go
76 lines (63 loc) · 1.53 KB
/
spec.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package catalog
import (
"context"
applicationv1alpha1 "github.com/giantswarm/apiextensions-application/api/v1alpha1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/apimachinery/pkg/runtime"
)
// Catalog abstracts away the custom resource so it can be returned as a runtime
// object or a typed custom resource.
type Catalog struct {
CR *applicationv1alpha1.Catalog
Entries *applicationv1alpha1.AppCatalogEntryList
}
// Collection wraps a list of catalogs.
type Collection struct {
Items []Catalog
}
// GetOptions are the parameters that the Get method takes.
type GetOptions struct {
AllNamespaces bool
LabelSelector labels.Selector
Name string
Namespace string
}
type Resource interface {
Object() runtime.Object
}
// Interface represents the contract for the appcatalog data service.
// Using this instead of a regular 'struct' makes mocking the
// service in tests much simpler.
type Interface interface {
Get(context.Context, GetOptions) (Resource, error)
}
func (a *Catalog) Object() runtime.Object {
if a.CR != nil {
return a.CR
}
if a.Entries != nil {
return a.Entries
}
return nil
}
func (cc *Collection) Object() runtime.Object {
list := &metav1.List{
TypeMeta: metav1.TypeMeta{
Kind: "List",
APIVersion: "v1",
},
ListMeta: metav1.ListMeta{},
}
for _, item := range cc.Items {
obj := item.Object()
if obj == nil {
continue
}
raw := runtime.RawExtension{
Object: obj,
}
list.Items = append(list.Items, raw)
}
return list
}