Skip to content

Commit c7b07d1

Browse files
committed
removed the interface as it was not needed
1 parent d088748 commit c7b07d1

File tree

8 files changed

+30
-89
lines changed

8 files changed

+30
-89
lines changed

api/v1alpha1/componentversion_types.go

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import (
1111
"github.com/fluxcd/pkg/apis/meta"
1212
v1 "k8s.io/api/core/v1"
1313
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
14-
"sigs.k8s.io/controller-runtime/pkg/client"
1514
)
1615

1716
const (
@@ -190,16 +189,6 @@ func (in ComponentVersion) GetRequeueAfter() time.Duration {
190189
return in.Spec.Interval.Duration
191190
}
192191

193-
func (in *ComponentVersionList) List() []client.Object {
194-
var result []client.Object
195-
for _, o := range in.Items {
196-
o := o
197-
result = append(result, &o)
198-
}
199-
200-
return result
201-
}
202-
203192
//+kubebuilder:object:root=true
204193
//+kubebuilder:resource:shortName=cv
205194
//+kubebuilder:subresource:status

api/v1alpha1/configuration_types.go

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88
"time"
99

1010
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
11-
"sigs.k8s.io/controller-runtime/pkg/client"
1211
)
1312

1413
//+kubebuilder:object:root=true
@@ -77,16 +76,6 @@ func (in *Configuration) GetStatus() *MutationStatus {
7776
return &in.Status
7877
}
7978

80-
func (in *ConfigurationList) List() []client.Object {
81-
var result []client.Object
82-
for _, o := range in.Items {
83-
o := o
84-
result = append(result, &o)
85-
}
86-
87-
return result
88-
}
89-
9079
//+kubebuilder:object:root=true
9180

9281
// ConfigurationList contains a list of Configuration

api/v1alpha1/localization_types.go

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88
"time"
99

1010
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
11-
"sigs.k8s.io/controller-runtime/pkg/client"
1211
)
1312

1413
//+kubebuilder:object:root=true
@@ -76,16 +75,6 @@ func (in *Localization) GetStatus() *MutationStatus {
7675
return &in.Status
7776
}
7877

79-
func (in *LocalizationList) List() []client.Object {
80-
var result []client.Object
81-
for _, o := range in.Items {
82-
o := o
83-
result = append(result, &o)
84-
}
85-
86-
return result
87-
}
88-
8978
//+kubebuilder:object:root=true
9079

9180
// LocalizationList contains a list of Localization

api/v1alpha1/resource_types.go

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99

1010
ocmmetav1 "github.com/open-component-model/ocm/pkg/contexts/ocm/compdesc/meta/v1"
1111
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
12-
"sigs.k8s.io/controller-runtime/pkg/client"
1312
)
1413

1514
// ResourceSpec defines the desired state of Resource
@@ -116,16 +115,6 @@ func (in Resource) GetSnapshotName() string {
116115
return in.Status.SnapshotName
117116
}
118117

119-
func (in *ResourceList) List() []client.Object {
120-
var result []client.Object
121-
for _, o := range in.Items {
122-
o := o
123-
result = append(result, &o)
124-
}
125-
126-
return result
127-
}
128-
129118
//+kubebuilder:object:root=true
130119

131120
// ResourceList contains a list of Resource

controllers/componentversion_controller.go

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ import (
1818
corev1 "k8s.io/api/core/v1"
1919
apierrors "k8s.io/apimachinery/pkg/api/errors"
2020
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
21+
"k8s.io/apimachinery/pkg/fields"
2122
"k8s.io/apimachinery/pkg/runtime"
23+
"k8s.io/apimachinery/pkg/types"
2224
kuberecorder "k8s.io/client-go/tools/record"
2325
ctrl "sigs.k8s.io/controller-runtime"
2426
"sigs.k8s.io/controller-runtime/pkg/builder"
@@ -27,6 +29,7 @@ import (
2729
"sigs.k8s.io/controller-runtime/pkg/handler"
2830
"sigs.k8s.io/controller-runtime/pkg/log"
2931
"sigs.k8s.io/controller-runtime/pkg/predicate"
32+
"sigs.k8s.io/controller-runtime/pkg/reconcile"
3033
"sigs.k8s.io/controller-runtime/pkg/source"
3134

3235
"github.com/open-component-model/ocm/pkg/contexts/ocm"
@@ -83,10 +86,34 @@ func (r *ComponentVersionReconciler) SetupWithManager(mgr ctrl.Manager) error {
8386
For(&v1alpha1.ComponentVersion{}, builder.WithPredicates(predicate.GenerationChangedPredicate{})).
8487
Watches(
8588
&source.Kind{Type: &corev1.Secret{}},
86-
handler.EnqueueRequestsFromMapFunc(findRegistrySecrets(r.Client, sourceKey, &v1alpha1.ComponentVersionList{}))).
89+
handler.EnqueueRequestsFromMapFunc(r.findObjects(sourceKey))).
8790
Complete(r)
8891
}
8992

93+
// findObjects finds component versions that have a key for the secret that triggered this watch event.
94+
func (r *ComponentVersionReconciler) findObjects(key string) handler.MapFunc {
95+
return func(obj client.Object) []reconcile.Request {
96+
list := &v1alpha1.ComponentVersionList{}
97+
if err := r.List(context.Background(), list, &client.ListOptions{
98+
FieldSelector: fields.OneTermEqualSelector(key, client.ObjectKeyFromObject(obj).String()),
99+
}); err != nil {
100+
return []reconcile.Request{}
101+
}
102+
103+
requests := make([]reconcile.Request, len(list.Items))
104+
for i, item := range list.Items {
105+
requests[i] = reconcile.Request{
106+
NamespacedName: types.NamespacedName{
107+
Name: item.GetName(),
108+
Namespace: item.GetNamespace(),
109+
},
110+
}
111+
}
112+
113+
return requests
114+
}
115+
}
116+
90117
// Reconcile is part of the main kubernetes reconciliation loop which aims to
91118
// move the current state of the cluster closer to the desired state.
92119
func (r *ComponentVersionReconciler) Reconcile(ctx context.Context, req ctrl.Request) (_ ctrl.Result, retErr error) {

controllers/configuration_controller.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ func (r *ConfigurationReconciler) reconcile(
309309
return ctrl.Result{RequeueAfter: obj.GetRequeueAfter()}, nil
310310
}
311311

312-
// The purpose of the findRegistrySecrets function is to identify whether a given Kubernetes object
312+
// The purpose of the findObjects function is to identify whether a given Kubernetes object
313313
// is referenced by a Configuration. This is done by checking whether the object is a ComponentVersion
314314
// or a Snapshot. If it's a ComponentVersion, we look for all Configurations that reference
315315
// it by name. If it's a Snapshot, we first identify its owner and then look for Configurations

controllers/find_registry_secrets.go

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

controllers/localization_controller.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ func (r *LocalizationReconciler) reconcile(
290290
return ctrl.Result{RequeueAfter: obj.GetRequeueAfter()}, nil
291291
}
292292

293-
// The purpose of the findRegistrySecrets function is to identify whether a given Kubernetes object
293+
// The purpose of the findObjects function is to identify whether a given Kubernetes object
294294
// is referenced by a Localization. This is done by checking whether the object is a ComponentVersion
295295
// or a Snapshot. If it's a ComponentVersion, we look for all Configurations that reference
296296
// it by name. If it's a Snapshot, we first identify its owner and then look for Localization

0 commit comments

Comments
 (0)