@@ -61,6 +61,7 @@ func newAllocationListCommand(a *app) *cobra.Command {
6161 pool string
6262 purpose string
6363 unclaimed bool
64+ noLease bool
6465 scopeArgs []string
6566 )
6667 cmd := & cobra.Command {
@@ -70,16 +71,24 @@ func newAllocationListCommand(a *app) *cobra.Command {
7071 Long : `List the addresses handed out of pools.
7172
7273--unclaimed is the leak check: allocations with no claim bound. Under reclaim
73- policy Retain that is an address still held after its claim was deleted, and
74- nothing frees it until someone does so deliberately.
74+ policy Retain that is an address still held after its claim was deleted.
75+
76+ --no-lease narrows that to retained allocations with no lease deadline. The
77+ retention sweeper never releases these: each is held until it is released or
78+ a claim of the same name takes it back. Releasing one needs an IPAM Admin.
79+ It includes allocations whose lease is still to be worked out (LEASE
80+ "pending"), which may yet get a deadline. -o wide adds a LEASE column.
7581
7682` + scopeGrammarHelp (),
7783 Args : cobra .NoArgs ,
7884 Example : ` datumctl ipam allocation list
7985 datumctl ipam allocation list --pool us-central-1-tenant-v4 -o wide
8086
8187 # Addresses still held with no claim behind them — the Retain leak check
82- datumctl ipam allocation list --unclaimed` ,
88+ datumctl ipam allocation list --unclaimed
89+
90+ # Retained addresses nothing will release on a schedule
91+ datumctl ipam allocation list --no-lease -o wide` ,
8392 RunE : func (cmd * cobra.Command , args []string ) error {
8493 cs , ns , err := a .client ()
8594 if err != nil {
@@ -112,6 +121,9 @@ nothing frees it until someone does so deliberately.
112121 if unclaimed && al .Spec .ClaimRef != nil {
113122 continue
114123 }
124+ if noLease && ! retainedWithoutLease (al ) {
125+ continue
126+ }
115127 if ! scopeContains (al .Spec .Scope , wantScope ) {
116128 continue
117129 }
@@ -143,6 +155,7 @@ nothing frees it until someone does so deliberately.
143155 f .StringVar (& pool , "pool" , "" , "Only show allocations drawn from this pool" )
144156 f .StringVar (& purpose , "purpose" , "" , "Only show allocations of this purpose: Claim|Reservation|PoolCarve" )
145157 f .BoolVar (& unclaimed , "unclaimed" , false , "Only show allocations with no claim bound (retained or reserved)" )
158+ f .BoolVar (& noLease , "no-lease" , false , "Only show retained allocations with no lease deadline, including ones still to be evaluated" )
146159 f .StringArrayVar (& scopeArgs , "scope" , nil , scopeFlagUsage ("Only show allocations whose scope includes these references" ))
147160 return cmd
148161}
@@ -203,16 +216,17 @@ func (a *app) renderAllocationTable(allocs []ipamv1alpha1.IPAllocation) error {
203216 wide := a .opts .output == outputWide
204217 headers := []string {"NAME" , "ADDRESS" , "CLASS" , "POOL" , "CLAIM" , "PHASE" , "AGE" }
205218 if wide {
206- headers = []string {"NAME" , "ADDRESS" , "CLASS" , "POOL" , "CLAIM" , "PURPOSE" , "SCOPE" , "OWNER" , "RECLAIM" , "PHASE" , "AGE" }
219+ headers = []string {"NAME" , "ADDRESS" , "CLASS" , "POOL" , "CLAIM" , "PURPOSE" , "SCOPE" , "OWNER" , "RECLAIM" , "LEASE" , " PHASE" , "AGE" }
207220 }
221+ now := time .Now ()
208222 t := newTable (a .io .Out , headers )
209223 for i := range allocs {
210224 al := & allocs [i ]
211225 if wide {
212226 t .row (al .Name , orDash (allocationAddress (al )), orDash (al .Spec .ClassName ), al .Spec .PoolRef .Name ,
213227 allocationClaimName (al ), orDash (string (al .Spec .Purpose )), formatScope (al .Spec .Scope ),
214228 formatObjectRef (al .Spec .OwnerRef ), orDash (string (al .Spec .ReclaimPolicy )),
215- phaseText (string (al .Status .Phase )), humanDuration (al .CreationTimestamp ))
229+ leaseColumn ( al , now ), phaseText (string (al .Status .Phase )), humanDuration (al .CreationTimestamp ))
216230 } else {
217231 t .row (al .Name , orDash (allocationAddress (al )), orDash (al .Spec .ClassName ), al .Spec .PoolRef .Name ,
218232 allocationClaimName (al ), phaseText (string (al .Status .Phase )),
@@ -274,6 +288,45 @@ func (a *app) resolveAllocation(cs clientset.Interface, ns, arg string) ([]*ipam
274288 return []* ipamv1alpha1.IPAllocation {al }, nil
275289}
276290
291+ // retained reports whether al is a claim's address held after the claim was
292+ // deleted.
293+ func retained (al * ipamv1alpha1.IPAllocation ) bool {
294+ return al .Spec .Purpose == ipamv1alpha1 .PurposeClaim && al .Spec .ClaimRef == nil
295+ }
296+
297+ // leasePending reports whether the server has yet to work out al's lease.
298+ func leasePending (al * ipamv1alpha1.IPAllocation ) bool {
299+ c := meta .FindStatusCondition (al .Status .Conditions , ipamv1alpha1 .AllocationConditionRetained )
300+ return c != nil && c .Reason == ipamv1alpha1 .RetainedReasonLeasePending
301+ }
302+
303+ // retainedWithoutLease reports whether al is retained with no lease deadline,
304+ // as the server judges it when it decides who may release it: a lease still
305+ // to be worked out counts, and so does an allocation retained before
306+ // deadlines were recorded.
307+ func retainedWithoutLease (al * ipamv1alpha1.IPAllocation ) bool {
308+ return retained (al ) && al .Status .ExpiresAt == nil
309+ }
310+
311+ // leaseColumn is the LEASE cell of the wide list: when a retained
312+ // allocation's lease runs out, or why it has no deadline, in the words the
313+ // server's own table uses. An allocation that is not retained has no lease.
314+ func leaseColumn (al * ipamv1alpha1.IPAllocation , now time.Time ) string {
315+ switch {
316+ case ! retained (al ):
317+ return "—"
318+ case al .Status .ExpiresAt != nil :
319+ at := al .Status .ExpiresAt .Time
320+ if at .After (now ) {
321+ return "in " + shortDuration (at .Sub (now ))
322+ }
323+ return "expired " + shortDuration (now .Sub (at )) + " ago"
324+ case leasePending (al ):
325+ return "pending"
326+ }
327+ return "never"
328+ }
329+
277330// leaseText says when a retained allocation's lease runs out. It does not
278331// promise a release: the CLI cannot see whether the server's retention
279332// sweeper runs in enforce mode, which releases an expired allocation, or in
@@ -289,8 +342,7 @@ func leaseText(al *ipamv1alpha1.IPAllocation, now time.Time) string {
289342 return "ran out " + at .UTC ().Format (time .RFC3339 ) + " (" + shortDuration (now .Sub (at )) +
290343 " ago); released by the retention sweeper when it runs in enforce mode"
291344 }
292- if c := meta .FindStatusCondition (al .Status .Conditions , ipamv1alpha1 .AllocationConditionRetained ); c != nil &&
293- c .Reason == ipamv1alpha1 .RetainedReasonLeasePending {
345+ if leasePending (al ) {
294346 return "not yet evaluated"
295347 }
296348 return "none — held until released or reclaimed"
0 commit comments