@@ -30,11 +30,13 @@ import (
30
30
"k8s.io/apimachinery/pkg/runtime/schema"
31
31
"k8s.io/apiserver/pkg/registry/rest"
32
32
"kmodules.xyz/resource-metadata/apis/meta"
33
- rsapi "kmodules.xyz/resource-metadata/apis/meta /v1alpha1"
33
+ uiapi "kmodules.xyz/resource-metadata/apis/ui /v1alpha1"
34
34
"kmodules.xyz/resource-metadata/hub/clusterprofiles"
35
+ "sigs.k8s.io/controller-runtime/pkg/client"
35
36
)
36
37
37
38
type Storage struct {
39
+ kc client.Reader
38
40
convertor rest.TableConvertor
39
41
}
40
42
@@ -47,54 +49,57 @@ var (
47
49
_ rest.SingularNameProvider = & Storage {}
48
50
)
49
51
50
- func NewStorage () * Storage {
52
+ func NewStorage (kc client. Reader ) * Storage {
51
53
return & Storage {
54
+ kc : kc ,
52
55
convertor : rest .NewDefaultTableConvertor (schema.GroupResource {
53
- Group : rsapi .SchemeGroupVersion .Group ,
54
- Resource : rsapi .ResourceClusterProfiles ,
56
+ Group : uiapi .SchemeGroupVersion .Group ,
57
+ Resource : uiapi .ResourceClusterProfiles ,
55
58
}),
56
59
}
57
60
}
58
61
59
62
func (r * Storage ) GroupVersionKind (_ schema.GroupVersion ) schema.GroupVersionKind {
60
- return rsapi .SchemeGroupVersion .WithKind (rsapi .ResourceKindClusterProfile )
63
+ return uiapi .SchemeGroupVersion .WithKind (uiapi .ResourceKindClusterProfile )
61
64
}
62
65
63
66
func (r * Storage ) NamespaceScoped () bool {
64
67
return false
65
68
}
66
69
67
70
func (r * Storage ) GetSingularName () string {
68
- return strings .ToLower (rsapi .ResourceKindClusterProfile )
71
+ return strings .ToLower (uiapi .ResourceKindClusterProfile )
69
72
}
70
73
71
74
// Getter
72
75
func (r * Storage ) New () runtime.Object {
73
- return & rsapi .ClusterProfile {}
76
+ return & uiapi .ClusterProfile {}
74
77
}
75
78
76
79
func (r * Storage ) Destroy () {}
77
80
78
81
func (r * Storage ) Get (ctx context.Context , name string , options * metav1.GetOptions ) (runtime.Object , error ) {
79
- obj , err := clusterprofiles .LoadByName (name )
82
+ obj , err := clusterprofiles .LoadByName (r . kc , name )
80
83
if err != nil {
81
- return nil , kerr .NewNotFound (schema.GroupResource {Group : meta .GroupName , Resource : rsapi .ResourceKindClusterProfile }, name )
84
+ return nil , kerr .NewNotFound (schema.GroupResource {Group : meta .GroupName , Resource : uiapi .ResourceKindClusterProfile }, name )
82
85
}
83
86
return obj , err
84
87
}
85
88
86
89
// Lister
87
90
func (r * Storage ) NewList () runtime.Object {
88
- return & rsapi .ClusterProfileList {}
91
+ return & uiapi .ClusterProfileList {}
89
92
}
90
93
91
94
func (r * Storage ) List (ctx context.Context , options * metainternalversion.ListOptions ) (runtime.Object , error ) {
92
95
if options .FieldSelector != nil && ! options .FieldSelector .Empty () {
93
96
return nil , kerr .NewBadRequest ("fieldSelector is not a supported" )
94
97
}
95
98
96
- objs := clusterprofiles .List ()
97
-
99
+ objs , err := clusterprofiles .List (r .kc )
100
+ if err != nil {
101
+ return nil , err
102
+ }
98
103
if options .Continue != "" {
99
104
start , err := strconv .Atoi (options .Continue )
100
105
if err != nil {
@@ -109,15 +114,15 @@ func (r *Storage) List(ctx context.Context, options *metainternalversion.ListOpt
109
114
objs = objs [:options .Limit ]
110
115
}
111
116
112
- items := make ([]rsapi .ClusterProfile , 0 , len (objs ))
117
+ items := make ([]uiapi .ClusterProfile , 0 , len (objs ))
113
118
for _ , obj := range objs {
114
119
if options .LabelSelector != nil && ! options .LabelSelector .Matches (labels .Set (obj .GetLabels ())) {
115
120
continue
116
121
}
117
122
items = append (items , obj )
118
123
}
119
124
120
- return & rsapi .ClusterProfileList {Items : items }, nil
125
+ return & uiapi .ClusterProfileList {Items : items }, nil
121
126
}
122
127
123
128
func (r * Storage ) ConvertToTable (ctx context.Context , object runtime.Object , tableOptions runtime.Object ) (* metav1.Table , error ) {
0 commit comments