Skip to content

Commit 6bb5e4a

Browse files
committed
enable CodeRabbit Multi-Repo Analysis
1 parent f69e0fd commit 6bb5e4a

11 files changed

Lines changed: 68 additions & 57 deletions

File tree

.coderabbit.yaml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
inheritance: true
2+
knowledge_base:
3+
linked_repositories:
4+
- repository: 'codeready-toolchain/api'
5+
instructions: >
6+
api contains the shared API types consumed by toolchain-common.
7+
When reviewing toolchain-common changes:
8+
- Check if toolchain-common is using deprecated or outdated fields or types from api - suggest migrating to the recommended alternatives.
9+
- Verify assumptions — if toolchain-common expects specific constants (condition types, reasons, labels) or type structures from api, check if those match the actual api definitions.
10+
- If toolchain-common duplicates constants or type definitions that already exist in api, suggest using the api definitions instead.
11+
- Flag if toolchain-common is making assumptions about api's internal state or behavior that isn't documented or guaranteed.
12+
- Check if changes in toolchain-common (especially in pkg/cluster, pkg/condition, pkg/configuration, pkg/status) align with api patterns and conventions.
13+

.github/workflows/test-with-coverage.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ jobs:
2828
make test-with-coverage
2929
3030
- name: Upload coverage artifact
31-
uses: actions/upload-artifact@v6
31+
uses: actions/upload-artifact@v7
3232
with:
3333
name: coverage
3434
path: ./out/coverage/coverage.txt

.github/workflows/upload-coverage.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ jobs:
1212

1313
steps:
1414
- name: Download coverage artifact
15-
uses: actions/download-artifact@v7
15+
uses: actions/download-artifact@v8
1616
with:
1717
name: coverage
1818
github-token: ${{ secrets.GITHUB_TOKEN }}

README.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ This repo is for controllers, libs, scripts, make files, etc to be shared betwee
88

99
== Build
1010

11-
Requires Go version 1.24.x (1.24.11 or higher) - download for your development environment https://golang.org/dl/[here].
11+
Requires Go version 1.24.x (1.24.13 or higher) - download for your development environment https://golang.org/dl/[here].
1212

1313
This repository uses https://github.com/golang/go/wiki/Modules[Go modules].
1414

codecov.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ coverage:
1010
# solid green color.
1111
range: "20...60"
1212

13-
# See https://docs.codecov.com/docs/commit-status
13+
# See https://docs.codecov.com/docs/commit-status
1414
status:
1515
# project will give us the diff in the total code coverage between a commit
1616
# and its parent
1717
project:
18-
default:
18+
default:
1919
# Allow the coverage to drop by 1% and posting a success status.
2020
threshold: 1%
2121
# Patch gives just the coverage of the patch

go.mod

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ module github.com/codeready-toolchain/toolchain-common
22

33
go 1.24.4
44

5-
toolchain go1.24.11
5+
toolchain go1.24.13
66

77
require (
88
github.com/go-logr/logr v1.4.2
@@ -26,7 +26,7 @@ require (
2626
)
2727

2828
require (
29-
github.com/codeready-toolchain/api v0.0.0-20260108115150-4c6695ed18de
29+
github.com/codeready-toolchain/api v0.0.0-20260305144020-4ff0e6b6e174
3030
github.com/ghodss/yaml v1.0.0
3131
github.com/google/go-cmp v0.7.0
3232
github.com/google/go-github/v52 v52.0.0
@@ -49,7 +49,7 @@ require (
4949
github.com/beorn7/perks v1.0.1 // indirect
5050
github.com/blang/semver/v4 v4.0.0 // indirect
5151
github.com/cespare/xxhash/v2 v2.3.0 // indirect
52-
github.com/cloudflare/circl v1.6.1 // indirect
52+
github.com/cloudflare/circl v1.6.3 // indirect
5353
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
5454
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.2.0 // indirect
5555
github.com/emicklei/go-restful/v3 v3.11.0 // indirect

go.sum

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ github.com/bwesterb/go-ristretto v1.2.0/go.mod h1:fUIoIZaG73pV5biE2Blr2xEzDoMj7N
1818
github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs=
1919
github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
2020
github.com/cloudflare/circl v1.1.0/go.mod h1:prBCrKB9DV4poKZY1l9zBXg2QJY7mvgRvtMxxK7fi4I=
21-
github.com/cloudflare/circl v1.6.1 h1:zqIqSPIndyBh1bjLVVDHMPpVKqp8Su/V+6MeDzzQBQ0=
22-
github.com/cloudflare/circl v1.6.1/go.mod h1:uddAzsPgqdMAYatqJ0lsjX1oECcQLIlRpzZh3pJrofs=
23-
github.com/codeready-toolchain/api v0.0.0-20260108115150-4c6695ed18de h1:rc39ZRUk2AyADzH+bt5On7V7qJz6syUrI4qNyCSXY3o=
24-
github.com/codeready-toolchain/api v0.0.0-20260108115150-4c6695ed18de/go.mod h1:O/HyAcz6fynt3LXr8wTGaIXt+0v6BpkiJvDxNQDCqyA=
21+
github.com/cloudflare/circl v1.6.3 h1:9GPOhQGF9MCYUeXyMYlqTR6a5gTrgR/fBLXvUgtVcg8=
22+
github.com/cloudflare/circl v1.6.3/go.mod h1:2eXP6Qfat4O/Yhh8BznvKnJ+uzEoTQ6jVKJRn81BiS4=
23+
github.com/codeready-toolchain/api v0.0.0-20260305144020-4ff0e6b6e174 h1:hed3ZyardxswS6yMB0ME9l3vEkO+pFouyk4dvIiAQOo=
24+
github.com/codeready-toolchain/api v0.0.0-20260305144020-4ff0e6b6e174/go.mod h1:PMg6kNHuCGNlu3MOdrCisqGkBpvzB0qS1+E6nrXxPAc=
2525
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
2626
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
2727
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=

pkg/owners/fetcher.go

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -72,14 +72,22 @@ func (o *OwnerFetcher) GetOwners(ctx context.Context, obj metav1.Object) ([]*Obj
7272
return nil, nil // No owner
7373
}
7474
// Get the GVR for the owner
75-
gvr, err := gvrForKind(ownerReference.Kind, ownerReference.APIVersion, o.resourceLists)
75+
gvr, namespaced, err := gvrForKind(ownerReference.Kind, ownerReference.APIVersion, o.resourceLists)
7676
if err != nil {
7777
return nil, err
7878
}
79-
// Get the owner object
80-
ownerObject, err := o.dynamicClient.Resource(*gvr).Namespace(obj.GetNamespace()).Get(ctx, ownerReference.Name, metav1.GetOptions{})
79+
// Get the owner object; use namespace only for namespaced resources
80+
resourceClient := o.dynamicClient.Resource(*gvr)
81+
var ownerObject *unstructured.Unstructured
82+
nsdName := ownerReference.Name
83+
if namespaced {
84+
ownerObject, err = resourceClient.Namespace(obj.GetNamespace()).Get(ctx, ownerReference.Name, metav1.GetOptions{})
85+
nsdName = fmt.Sprintf("%s/%s", obj.GetNamespace(), ownerReference.Name)
86+
} else {
87+
ownerObject, err = resourceClient.Get(ctx, ownerReference.Name, metav1.GetOptions{})
88+
}
8189
if err != nil {
82-
return nil, err
90+
return nil, fmt.Errorf("failed to fetch owner object %s %s : %w", nsdName, gvr.String(), err)
8391
}
8492
owner := &ObjectWithGVR{
8593
Object: ownerObject,
@@ -93,24 +101,26 @@ func (o *OwnerFetcher) GetOwners(ctx context.Context, obj metav1.Object) ([]*Obj
93101
return append(ownerOwners, owner), nil
94102
}
95103

96-
// gvrForKind returns GVR for the kind, if it's found in the available API list in the cluster
97-
// returns an error if not found or failed to parse the API version
98-
func gvrForKind(kind, apiVersion string, resourceLists []*metav1.APIResourceList) (*schema.GroupVersionResource, error) {
99-
gvr, err := findGVRForKind(kind, apiVersion, resourceLists)
104+
// gvrForKind returns GVR and whether the resource is namespaced for the kind,
105+
// if it's found in the available API list in the cluster.
106+
// Returns an error if not found or failed to parse the API version.
107+
func gvrForKind(kind, apiVersion string, resourceLists []*metav1.APIResourceList) (*schema.GroupVersionResource, bool, error) {
108+
gvr, namespaced, err := findGVRForKind(kind, apiVersion, resourceLists)
100109
if gvr == nil && err == nil {
101-
return nil, fmt.Errorf("no resource found for kind %s in %s", kind, apiVersion)
110+
return nil, false, fmt.Errorf("no resource found for kind %s in %s", kind, apiVersion)
102111
}
103-
return gvr, err
112+
return gvr, namespaced, err
104113
}
105114

106-
// findGVRForKind returns GVR for the kind, if it's found in the available API list in the cluster
107-
// if not found then returns nil, nil
108-
// returns nil, error if failed to parse the API version
109-
func findGVRForKind(kind, apiVersion string, resourceLists []*metav1.APIResourceList) (*schema.GroupVersionResource, error) {
115+
// findGVRForKind returns GVR and whether the resource is namespaced for the kind,
116+
// if it's found in the available API list in the cluster.
117+
// If not found then returns nil, false, nil.
118+
// Returns nil, false, error if failed to parse the API version.
119+
func findGVRForKind(kind, apiVersion string, resourceLists []*metav1.APIResourceList) (*schema.GroupVersionResource, bool, error) {
110120
// Parse the group and version from the APIVersion (e.g., "apps/v1" -> group: "apps", version: "v1")
111121
gv, err := schema.ParseGroupVersion(apiVersion)
112122
if err != nil {
113-
return nil, fmt.Errorf("failed to parse APIVersion %s: %w", apiVersion, err)
123+
return nil, false, fmt.Errorf("failed to parse APIVersion %s: %w", apiVersion, err)
114124
}
115125

116126
// Look for a matching resource
@@ -123,11 +133,11 @@ func findGVRForKind(kind, apiVersion string, resourceLists []*metav1.APIResource
123133
Group: gv.Group,
124134
Version: gv.Version,
125135
Resource: apiResource.Name,
126-
}, nil
136+
}, apiResource.Namespaced, nil
127137
}
128138
}
129139
}
130140
}
131141

132-
return nil, nil
142+
return nil, false, nil
133143
}

pkg/owners/fetcher_test.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ func TestGetOwners(t *testing.T) {
3636
replica := &appsv1.ReplicaSet{ObjectMeta: metav1.ObjectMeta{Name: "test-replica", Namespace: "test-namespace"}}
3737
deployment := &appsv1.Deployment{ObjectMeta: metav1.ObjectMeta{Name: "test-deployment", Namespace: "test-namespace"}}
3838
vm, vmi := newVMResources(t, "test-vm", "test-namespace")
39+
node := &corev1.Node{ObjectMeta: metav1.ObjectMeta{Name: "test-node"}}
3940

4041
testCases := map[string]struct {
4142
expectedOwners []client.Object
@@ -49,6 +50,9 @@ func TestGetOwners(t *testing.T) {
4950
"with deployment & replica as owners": {
5051
expectedOwners: []client.Object{deployment, replica},
5152
},
53+
"with cluster-scoped owner": {
54+
expectedOwners: []client.Object{node, replica},
55+
},
5256
"with vm, vmi, deployment & replica as owners": {
5357
expectedOwners: []client.Object{vm, vmi, deployment, replica},
5458
},
@@ -162,7 +166,8 @@ func TestGetOwnersFailures(t *testing.T) {
162166
require.ErrorContains(t, err, inaccessibleResource)
163167
assert.True(t, apierrors.IsNotFound(err))
164168
} else {
165-
require.EqualError(t, err, "some error")
169+
require.ErrorContains(t, err, "failed to fetch owner object")
170+
require.ErrorContains(t, err, "some error")
166171
}
167172
require.Nil(t, owners)
168173
})
@@ -192,7 +197,8 @@ func TestGetOwnersFailures(t *testing.T) {
192197
require.ErrorContains(t, err, inaccessibleResource)
193198
assert.True(t, apierrors.IsNotFound(err))
194199
} else {
195-
require.EqualError(t, err, "some error")
200+
require.ErrorContains(t, err, "failed to fetch owner object")
201+
require.ErrorContains(t, err, "some error")
196202
}
197203
require.Len(t, owners, 1)
198204
})
@@ -315,7 +321,7 @@ func apiSchemeResourceList(t *testing.T) []*metav1.APIResourceList {
315321
resources = append(resources, &metav1.APIResourceList{
316322
GroupVersion: gvk.GroupVersion().String(),
317323
APIResources: []metav1.APIResource{
318-
{Name: resource.Resource, Namespaced: true, Kind: gvk.Kind},
324+
{Name: resource.Resource, Namespaced: gvk.Kind != "Node", Kind: gvk.Kind},
319325
},
320326
})
321327
}

pkg/test/config/toolchainconfig.go

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -145,24 +145,6 @@ func (o DeactivationOption) UserSignupUnverifiedRetentionDays(value int) Deactiv
145145
return o
146146
}
147147

148-
type MetricsOption struct {
149-
*ToolchainConfigOptionImpl
150-
}
151-
152-
func Metrics() *MetricsOption {
153-
o := &MetricsOption{
154-
ToolchainConfigOptionImpl: &ToolchainConfigOptionImpl{},
155-
}
156-
return o
157-
}
158-
159-
func (o MetricsOption) ForceSynchronization(value bool) MetricsOption {
160-
o.addFunction(func(config *toolchainv1alpha1.ToolchainConfig) {
161-
config.Spec.Host.Metrics.ForceSynchronization = &value
162-
})
163-
return o
164-
}
165-
166148
type NotificationsOption struct {
167149
*ToolchainConfigOptionImpl
168150
}
@@ -586,13 +568,6 @@ func (o TiersOption) DefaultSpaceTier(value string) TiersOption {
586568
return o
587569
}
588570

589-
func (o TiersOption) DurationBeforeChangeTierRequestDeletion(value string) TiersOption {
590-
o.addFunction(func(config *toolchainv1alpha1.ToolchainConfig) {
591-
config.Spec.Host.Tiers.DurationBeforeChangeTierRequestDeletion = &value
592-
})
593-
return o
594-
}
595-
596571
func (o TiersOption) FeatureToggle(name string, weight *uint) TiersOption {
597572
o.addFunction(func(config *toolchainv1alpha1.ToolchainConfig) {
598573
if config.Spec.Host.Tiers.FeatureToggles == nil {

0 commit comments

Comments
 (0)