Skip to content

Commit f505ba5

Browse files
committed
chore(refactor): implement gvks for all static modules
Signed-off-by: Oliver Bähler <[email protected]>
1 parent 4705a99 commit f505ba5

File tree

27 files changed

+261
-234
lines changed

27 files changed

+261
-234
lines changed

internal/controllers/watchdog/crds_watcher.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ func (c *CRDWatcher) SetupWithManager(ctx context.Context, mgr manager.Manager)
161161
}
162162

163163
return ctrl.NewControllerManagedBy(mgr).
164-
WatchesRawSource(&source.Channel{Source: c.requeue}, &handler.EnqueueRequestForObject{}).
164+
WatchesRawSource(source.Channel(c.requeue, &handler.EnqueueRequestForObject{})).
165165
For(&apiextensionsv1.CustomResourceDefinition{}, builder.WithPredicates(predicate.NewPredicateFuncs(func(object client.Object) bool {
166166
crd := object.(*apiextensionsv1.CustomResourceDefinition)
167167

internal/modules/clusterscoped/get.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ func Get(discovery *discovery.DiscoveryClient, client client.Reader, writer clie
4141
}
4242
}
4343

44+
func (g get) GroupVersionKind() schema.GroupVersionKind {
45+
return schema.GroupVersionKind{}
46+
}
47+
4448
func (g get) GroupKind() schema.GroupKind {
4549
return schema.GroupKind{}
4650
}
@@ -58,7 +62,7 @@ func (g get) Handle(proxyTenants []*tenant.ProxyTenant, proxyRequest request.Req
5862

5963
gvk := utils.GetGVKFromURL(proxyRequest.GetHTTPRequest().URL.Path)
6064

61-
operations, requirements := getRequirements(gvk, proxyTenants)
65+
operations, requirements := utils.GetClusterScopeRequirements(gvk, proxyTenants)
6266
if len(requirements) > 0 {
6367
// Verify if the list operation is allowed
6468
if slices.Contains(operations, v1beta1.ClusterResourceOperationList) {

internal/modules/clusterscoped/list.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ func List(client client.Reader, writer client.Writer, path string) modules.Modul
3434
}
3535
}
3636

37+
func (l list) GroupVersionKind() schema.GroupVersionKind {
38+
return schema.GroupVersionKind{}
39+
}
40+
3741
func (l list) GroupKind() schema.GroupKind {
3842
return schema.GroupKind{}
3943
}
@@ -49,7 +53,7 @@ func (l list) Methods() []string {
4953
func (l list) Handle(proxyTenants []*tenant.ProxyTenant, proxyRequest request.Request) (selector labels.Selector, err error) {
5054
gvk := utils.GetGVKFromURL(proxyRequest.GetHTTPRequest().URL.Path)
5155

52-
operations, requirements := getRequirements(gvk, proxyTenants)
56+
operations, requirements := utils.GetClusterScopeRequirements(gvk, proxyTenants)
5357
if len(requirements) > 0 {
5458
// Verify if the list operation is allowed
5559
if slices.Contains(operations, v1beta1.ClusterResourceOperationList) {

internal/modules/clusterscoped/utils.go

Lines changed: 0 additions & 92 deletions
This file was deleted.

internal/modules/ingressclass/get.go

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,24 +25,29 @@ import (
2525
type get struct {
2626
client client.Reader
2727
log logr.Logger
28-
gk schema.GroupKind
28+
gk schema.GroupVersionKind
2929
}
3030

3131
func Get(client client.Reader) modules.Module {
3232
return &get{
3333
client: client,
3434
log: ctrl.Log.WithName("ingressclass_get"),
35-
gk: schema.GroupKind{
36-
Group: networkingv1.GroupName,
37-
Kind: "ingressclasses",
35+
gk: schema.GroupVersionKind{
36+
Group: networkingv1.GroupName,
37+
Version: "*",
38+
Kind: "ingressclasses",
3839
},
3940
}
4041
}
4142

42-
func (g get) GroupKind() schema.GroupKind {
43+
func (g get) GroupVersionKind() schema.GroupVersionKind {
4344
return g.gk
4445
}
4546

47+
func (g get) GroupKind() schema.GroupKind {
48+
return g.gk.GroupKind()
49+
}
50+
4651
func (g get) Path() string {
4752
return "/apis/networking.k8s.io/{version}/{endpoint:ingressclasses}/{name}"
4853
}
@@ -60,19 +65,19 @@ func (g get) Handle(proxyTenants []*tenant.ProxyTenant, proxyRequest request.Req
6065
if len(requirements) > 0 {
6166
ic, errIc := getIngressClassFromRequest(httpRequest)
6267
if errIc != nil {
63-
return nil, errors.NewBadRequest(errIc, g.gk)
68+
return nil, errors.NewBadRequest(errIc, g.GroupKind())
6469
}
6570

66-
return utils.HandleGetSelector(httpRequest.Context(), ic, g.client, requirements, name, g.gk)
71+
return utils.HandleGetSelector(httpRequest.Context(), ic, g.client, requirements, name, g.GroupKind())
6772
}
6873

6974
icl, err := getIngressClassListFromRequest(httpRequest)
7075
if err != nil {
71-
return nil, errors.NewBadRequest(err, g.gk)
76+
return nil, errors.NewBadRequest(err, g.GroupKind())
7277
}
7378

7479
if err = g.client.List(httpRequest.Context(), icl, client.MatchingLabels{corev1.LabelMetadataName: name}); err != nil {
75-
return nil, errors.NewBadRequest(err, g.gk)
80+
return nil, errors.NewBadRequest(err, g.GroupKind())
7681
}
7782

7883
var r *labels.Requirement
@@ -83,7 +88,7 @@ func (g get) Handle(proxyTenants []*tenant.ProxyTenant, proxyRequest request.Req
8388

8489
switch httpRequest.Method {
8590
case http.MethodGet:
86-
return nil, errors.NewNotFoundError(name, g.gk)
91+
return nil, errors.NewNotFoundError(name, g.GroupKind())
8792
default:
8893
return nil, nil
8994
}

internal/modules/ingressclass/list.go

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,24 +22,29 @@ import (
2222
type list struct {
2323
client client.Reader
2424
log logr.Logger
25-
gk schema.GroupKind
25+
gk schema.GroupVersionKind
2626
}
2727

2828
func List(client client.Reader) modules.Module {
2929
return &list{
3030
client: client,
3131
log: ctrl.Log.WithName("ingressclass_list"),
32-
gk: schema.GroupKind{
33-
Group: networkingv1.GroupName,
34-
Kind: "ingressclasses",
32+
gk: schema.GroupVersionKind{
33+
Group: networkingv1.GroupName,
34+
Version: "*",
35+
Kind: "ingressclasses",
3536
},
3637
}
3738
}
3839

39-
func (l list) GroupKind() schema.GroupKind {
40+
func (l list) GroupVersionKind() schema.GroupVersionKind {
4041
return l.gk
4142
}
4243

44+
func (l list) GroupKind() schema.GroupKind {
45+
return l.gk.GroupKind()
46+
}
47+
4348
func (l list) Path() string {
4449
return "/apis/networking.k8s.io/{version}/{endpoint:ingressclasses/?}"
4550
}
@@ -58,18 +63,18 @@ func (l list) Handle(proxyTenants []*tenant.ProxyTenant, proxyRequest request.Re
5863

5964
icl, err := getIngressClassListFromRequest(httpRequest)
6065
if err != nil {
61-
return nil, errors.NewBadRequest(err, l.gk)
66+
return nil, errors.NewBadRequest(err, l.GroupKind())
6267
}
6368

6469
if err = l.client.List(httpRequest.Context(), icl); err != nil {
65-
return nil, errors.NewBadRequest(err, l.gk)
70+
return nil, errors.NewBadRequest(err, l.GroupKind())
6671
}
6772

6873
var r *labels.Requirement
6974

7075
if r, err = getIngressClassSelector(icl, exactMatch, regexMatch); err != nil {
7176
if !allowed {
72-
return nil, errors.NewNotAllowed(l.gk)
77+
return nil, errors.NewNotAllowed(l.GroupKind())
7378
}
7479

7580
r, _ = labels.NewRequirement("dontexistsignoreme", selection.Exists, []string{})

internal/modules/lease/get.go

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,24 +22,29 @@ import (
2222
type get struct {
2323
client client.Reader
2424
log logr.Logger
25-
gk schema.GroupKind
25+
gk schema.GroupVersionKind
2626
}
2727

2828
func Get(client client.Reader) modules.Module {
2929
return &get{
3030
client: client,
3131
log: ctrl.Log.WithName("node_get"),
32-
gk: schema.GroupKind{
33-
Group: corev1.GroupName,
34-
Kind: "nodes",
32+
gk: schema.GroupVersionKind{
33+
Group: corev1.GroupName,
34+
Version: "*",
35+
Kind: "nodes",
3536
},
3637
}
3738
}
3839

39-
func (g get) GroupKind() schema.GroupKind {
40+
func (g get) GroupVersionKind() schema.GroupVersionKind {
4041
return g.gk
4142
}
4243

44+
func (g get) GroupKind() schema.GroupKind {
45+
return g.gk.GroupKind()
46+
}
47+
4348
func (g get) Path() string {
4449
return "/apis/coordination.k8s.io/v1/namespaces/kube-node-lease/leases/{name}"
4550
}

internal/modules/metric/get.go

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,24 +24,29 @@ import (
2424
type get struct {
2525
client client.Reader
2626
log logr.Logger
27-
gk schema.GroupKind
27+
gk schema.GroupVersionKind
2828
}
2929

3030
func Get(client client.Reader) modules.Module {
3131
return &get{
3232
client: client,
3333
log: ctrl.Log.WithName("metric_get"),
34-
gk: schema.GroupKind{
35-
Group: "metrics.k8s.io",
36-
Kind: "nodes",
34+
gk: schema.GroupVersionKind{
35+
Group: "metrics.k8s.io",
36+
Version: "*",
37+
Kind: "nodes",
3738
},
3839
}
3940
}
4041

41-
func (g get) GroupKind() schema.GroupKind {
42+
func (g get) GroupVersionKind() schema.GroupVersionKind {
4243
return g.gk
4344
}
4445

46+
func (g get) GroupKind() schema.GroupKind {
47+
return g.gk.GroupKind()
48+
}
49+
4550
func (g get) Path() string {
4651
return "/apis/metrics.k8s.io/{version}/nodes/{name}"
4752
}
@@ -59,7 +64,7 @@ func (g get) Handle(proxyTenants []*tenant.ProxyTenant, proxyRequest request.Req
5964

6065
nl := &corev1.NodeList{}
6166
if err = g.client.List(httpRequest.Context(), nl, client.MatchingLabels{"kubernetes.io/hostname": name}); err != nil {
62-
return nil, errors.NewBadRequest(err, g.gk)
67+
return nil, errors.NewBadRequest(err, g.GroupKind())
6368
}
6469

6570
var r *labels.Requirement
@@ -69,7 +74,7 @@ func (g get) Handle(proxyTenants []*tenant.ProxyTenant, proxyRequest request.Req
6974
}
7075

7176
if httpRequest.Method == http.MethodGet {
72-
return nil, errors.NewNotFoundError(name, g.gk)
77+
return nil, errors.NewNotFoundError(name, g.GroupKind())
7378
}
7479

7580
return nil, nil

internal/modules/metric/list.go

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,24 +22,29 @@ import (
2222
type list struct {
2323
client client.Reader
2424
log logr.Logger
25-
gk schema.GroupKind
25+
gk schema.GroupVersionKind
2626
}
2727

2828
func List(client client.Reader) modules.Module {
2929
return &list{
3030
client: client,
3131
log: ctrl.Log.WithName("metric_list"),
32-
gk: schema.GroupKind{
33-
Group: "metrics.k8s.io",
34-
Kind: "nodes",
32+
gk: schema.GroupVersionKind{
33+
Group: "metrics.k8s.io",
34+
Version: "*",
35+
Kind: "nodes",
3536
},
3637
}
3738
}
3839

39-
func (l list) GroupKind() schema.GroupKind {
40+
func (l list) GroupVersionKind() schema.GroupVersionKind {
4041
return l.gk
4142
}
4243

44+
func (l list) GroupKind() schema.GroupKind {
45+
return l.gk.GroupKind()
46+
}
47+
4348
func (l list) Path() string {
4449
return "/apis/metrics.k8s.io/{version}/{endpoint:nodes/?}"
4550
}
@@ -55,7 +60,7 @@ func (l list) Handle(proxyTenants []*tenant.ProxyTenant, proxyRequest request.Re
5560

5661
nl := &corev1.NodeList{}
5762
if err = l.client.List(httpRequest.Context(), nl); err != nil {
58-
return nil, errors.NewBadRequest(err, l.gk)
63+
return nil, errors.NewBadRequest(err, l.GroupKind())
5964
}
6065

6166
var r *labels.Requirement

0 commit comments

Comments
 (0)