Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/e2e.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
- ubuntu-24.04-arm
runs-on: ${{ matrix.os }}
steps:
- uses: jumpstarter-dev/jumpstarter-e2e@main
- uses: jumpstarter-dev/jumpstarter-e2e@lease-selector
with:
controller-ref: ${{ github.ref }}
# use the matching branch on the jumpstarter repo
Expand Down
5 changes: 4 additions & 1 deletion internal/controller/exporter_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/meta"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/apimachinery/pkg/runtime"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
Expand Down Expand Up @@ -117,7 +118,9 @@ func (r *ExporterReconciler) reconcileStatusLeaseRef(
ctx,
&leases,
client.InNamespace(exporter.Namespace),
MatchingActiveLeases(),
client.MatchingLabelsSelector{
Selector: MatchingActiveLeases(labels.Everything()),
},
); err != nil {
return fmt.Errorf("reconcileStatusLeaseRef: failed to list active leases: %w", err)
}
Expand Down
7 changes: 2 additions & 5 deletions internal/controller/lease.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@ import (
"k8s.io/apimachinery/pkg/labels"
"k8s.io/apimachinery/pkg/selection"
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
"sigs.k8s.io/controller-runtime/pkg/client"

jumpstarterdevv1alpha1 "github.com/jumpstarter-dev/jumpstarter-controller/api/v1alpha1"
)

func MatchingActiveLeases() client.ListOption {
func MatchingActiveLeases(prev labels.Selector) labels.Selector {
// TODO: use field selector once KEP-4358 is stabilized
// Reference: https://github.com/kubernetes/kubernetes/pull/122717
requirement, err := labels.NewRequirement(
Expand All @@ -20,7 +19,5 @@ func MatchingActiveLeases() client.ListOption {

utilruntime.Must(err)

return client.MatchingLabelsSelector{
Selector: labels.Everything().Add(*requirement),
}
return prev.Add(*requirement)
}
4 changes: 3 additions & 1 deletion internal/controller/lease_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,9 @@ func (r *LeaseReconciler) ListActiveLeases(ctx context.Context, namespace string
ctx,
&activeLeases,
client.InNamespace(namespace),
MatchingActiveLeases(),
client.MatchingLabelsSelector{
Selector: MatchingActiveLeases(labels.Everything()),
},
); err != nil {
return nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions internal/service/client/v1/client_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,10 @@ func (s *ClientService) ListLeases(ctx context.Context, req *cpb.ListLeasesReque
var jleases jumpstarterdevv1alpha1.LeaseList
if err := s.List(ctx, &jleases, &kclient.ListOptions{
Namespace: namespace,
LabelSelector: selector,
LabelSelector: controller.MatchingActiveLeases(selector),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but isn't this going to filter on the labels of the lease itself? should we label the leases with our selector too?

Limit: int64(req.PageSize),
Continue: req.PageToken,
}, controller.MatchingActiveLeases()); err != nil {
}); err != nil {
return nil, err
}

Expand Down
5 changes: 4 additions & 1 deletion internal/service/controller_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ import (
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/fields"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/types"
k8suuid "k8s.io/apimachinery/pkg/util/uuid"
Expand Down Expand Up @@ -670,7 +671,9 @@ func (s *ControllerService) ListLeases(
ctx,
&leases,
client.InNamespace(jclient.Namespace),
controller.MatchingActiveLeases(),
client.MatchingLabelsSelector{
Selector: controller.MatchingActiveLeases(labels.Everything()),
},
); err != nil {
return nil, err
}
Expand Down
Loading