Skip to content

Commit f16cd14

Browse files
committed
feat: use generateName for leases to allow alias reuse after deletion
Leases created with --lease-id now use K8s generateName instead of a fixed Name. The user-provided alias is stored as a label and resolved transparently in Get/Delete/Update via a name-or-alias lookup. This prevents the "already exists" error when re-creating a lease with the same --lease-id after deletion (since deletion is a soft-delete that leaves the K8s object in etcd). Signed-off-by: Benny Zlotnik <bzlotnik@redhat.com> Assisted-by: claude-opus-4.6
1 parent fbf73a6 commit f16cd14

30 files changed

Lines changed: 1101 additions & 521 deletions

File tree

controller/api/v1alpha1/lease_helpers.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,9 @@ func (l *Lease) ToProtobuf() *cpb.Lease {
320320
Name: l.Status.ExporterRef.Name,
321321
}))
322322
}
323+
if alias, ok := l.Labels[string(LeaseLabelName)]; ok {
324+
lease.Alias = ptr.To(alias)
325+
}
323326

324327
return &lease
325328
}

controller/api/v1alpha1/lease_helpers_test.go

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -521,4 +521,44 @@ var _ = Describe("Lease.ToProtobuf", func() {
521521

522522
Expect(pb.Tags).To(BeEmpty())
523523
})
524+
525+
It("should populate alias from lease-name label", func() {
526+
lease := &Lease{
527+
ObjectMeta: metav1.ObjectMeta{
528+
Name: "demo-x7k2q",
529+
Namespace: "default",
530+
Labels: map[string]string{
531+
string(LeaseLabelName): "demo",
532+
},
533+
},
534+
Spec: LeaseSpec{
535+
ClientRef: corev1.LocalObjectReference{Name: "test-client"},
536+
Duration: &metav1.Duration{Duration: time.Hour},
537+
Selector: metav1.LabelSelector{MatchLabels: map[string]string{"board": "rpi4"}},
538+
},
539+
}
540+
541+
pb := lease.ToProtobuf()
542+
543+
Expect(pb.Alias).NotTo(BeNil())
544+
Expect(*pb.Alias).To(Equal("demo"))
545+
})
546+
547+
It("should not set alias when lease-name label is absent", func() {
548+
lease := &Lease{
549+
ObjectMeta: metav1.ObjectMeta{
550+
Name: "lease-m9p3r",
551+
Namespace: "default",
552+
},
553+
Spec: LeaseSpec{
554+
ClientRef: corev1.LocalObjectReference{Name: "test-client"},
555+
Duration: &metav1.Duration{Duration: time.Hour},
556+
Selector: metav1.LabelSelector{MatchLabels: map[string]string{"board": "rpi4"}},
557+
},
558+
}
559+
560+
pb := lease.ToProtobuf()
561+
562+
Expect(pb.Alias).To(BeNil())
563+
})
524564
})

controller/api/v1alpha1/lease_types.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ type LeaseLabel string
8282
const (
8383
LeaseLabelEnded LeaseLabel = "jumpstarter.dev/lease-ended"
8484
LeaseLabelEndedValue string = "true"
85+
LeaseLabelName LeaseLabel = "jumpstarter.dev/lease-name"
8586
LeaseTagMetadataPrefix string = "metadata.jumpstarter.dev/"
8687
)
8788

controller/internal/protocol/jumpstarter/client/v1/client.pb.go

Lines changed: 126 additions & 58 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

controller/internal/protocol/jumpstarter/client/v1/client_grpc.pb.go

Lines changed: 20 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

controller/internal/protocol/jumpstarter/v1/common.pb.go

Lines changed: 15 additions & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)