Skip to content

Commit

Permalink
Added labels to ResourceOffer to be replicated by crdreplicator.
Browse files Browse the repository at this point in the history
Added filter to ResourceRequestOpertaor to be triggered just for replicated resources.

Add test for labels added by ResourceRequestcontroller.
  • Loading branch information
giuse2596 committed May 28, 2021
1 parent 1e9aabc commit 49c3163
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
Expand Up @@ -8,8 +8,10 @@ import (
"k8s.io/klog/v2"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/predicate"

discoveryv1alpha1 "github.com/liqotech/liqo/apis/discovery/v1alpha1"
crdreplicator "github.com/liqotech/liqo/internal/crdReplicator"
)

// ResourceRequestReconciler reconciles a ResourceRequest object.
Expand Down Expand Up @@ -50,7 +52,14 @@ func (r *ResourceRequestReconciler) Reconcile(ctx context.Context, req ctrl.Requ

// SetupWithManager is the setup function of the controller.
func (r *ResourceRequestReconciler) SetupWithManager(mgr ctrl.Manager) error {
// generate the predicate to filter just the ResourceRequest created by the remote cluster checking crdReplicator labels
p, err := predicate.LabelSelectorPredicate(crdreplicator.ReplicatedResourcesLabelSelector)
if err != nil {
klog.Error(err)
return err
}
return ctrl.NewControllerManagedBy(mgr).
WithEventFilter(p).
For(&discoveryv1alpha1.ResourceRequest{}).
Complete(r)
}
Expand Up @@ -2,6 +2,7 @@ package resourcerequestoperator

import (
"context"
crdreplicator "github.com/liqotech/liqo/internal/crdReplicator"
"time"

. "github.com/onsi/ginkgo"
Expand Down Expand Up @@ -64,6 +65,10 @@ var _ = Describe("ResourceRequest controller", func() {
ObjectMeta: metav1.ObjectMeta{
Name: ResourceRequestName,
Namespace: ResourcesNamespace,
Labels: map[string]string{
crdreplicator.RemoteLabelSelector: clusterId,
crdreplicator.ReplicationStatuslabel: "true",
},
},
Spec: discoveryv1alpha1.ResourceRequestSpec{
AuthURL: "https://127.0.0.1:39087",
Expand Down Expand Up @@ -95,7 +100,8 @@ var _ = Describe("ResourceRequest controller", func() {

Expect(createdResourceOffer.Name).Should(ContainSubstring(clusterId))
Expect(createdResourceOffer.Labels[discovery.ClusterIDLabel]).Should(Equal(createdResourceRequest.Spec.ClusterIdentity.ClusterID))

Expect(createdResourceOffer.Labels[crdreplicator.LocalLabelSelector]).Should(Equal("true"))
Expect(createdResourceOffer.Labels[crdreplicator.DestinationLabel]).Should(Equal(createdResourceRequest.Spec.ClusterIdentity.ClusterID))
By("Checking OwnerReference for Garbage Collector")
Expect(createdResourceOffer.GetOwnerReferences()).ShouldNot(HaveLen(0))
Expect(createdResourceOffer.GetOwnerReferences()).Should(ContainElement(MatchFields(IgnoreExtras, Fields{
Expand Down
5 changes: 4 additions & 1 deletion internal/resource-request-operator/utils.go
Expand Up @@ -11,6 +11,7 @@ import (

discoveryv1alpha1 "github.com/liqotech/liqo/apis/discovery/v1alpha1"
sharingv1alpha1 "github.com/liqotech/liqo/apis/sharing/v1alpha1"
crdreplicator "github.com/liqotech/liqo/internal/crdReplicator"
"github.com/liqotech/liqo/pkg/discovery"
)

Expand All @@ -30,7 +31,9 @@ func (r *ResourceRequestReconciler) generateResourceOffer(request *discoveryv1al

op, err := controllerutil.CreateOrUpdate(context.Background(), r.Client, offer, func() error {
offer.Labels = map[string]string{
discovery.ClusterIDLabel: request.Spec.ClusterIdentity.ClusterID,
discovery.ClusterIDLabel: request.Spec.ClusterIdentity.ClusterID,
crdreplicator.LocalLabelSelector: "true",
crdreplicator.DestinationLabel: request.Spec.ClusterIdentity.ClusterID,
}
creationTime := metav1.NewTime(time.Now())
spec := sharingv1alpha1.ResourceOfferSpec{
Expand Down

0 comments on commit 49c3163

Please sign in to comment.