-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(oncall): reorganize Shift API underneath Schedules
- Loading branch information
1 parent
c035b6d
commit 347c034
Showing
3 changed files
with
89 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,36 +6,78 @@ local schedule = raw.oncall.v1alpha1.schedule; | |
local forProvider = schedule.spec.parameters.forProvider; | ||
|
||
{ | ||
local base = self, | ||
|
||
'#new':: d.func.new( | ||
'`new` creates a Schedule. The `name` is a display-friendly string.', | ||
[d.argument.new('name', d.T.string)] | ||
), | ||
new(name):: | ||
schedule.new(xtd.ascii.stringToRFC1123(name)) | ||
+ schedule.spec.parameters.forProvider.withName(name), | ||
|
||
'#withId':: d.func.new( | ||
'`withId` sets the resource name for a Schedule', | ||
[d.argument.new('id', d.T.string)] | ||
), | ||
withId(id):: schedule.metadata.withName(id), | ||
|
||
'#withShifts':: d.func.new( | ||
||| | ||
`withShifts` sets a Schedule to type `calendar` and configures shifts. | ||
Shifts are only applicable to `calendar` type Schedules. `shifts` is an | ||
array of Shift resource names. | ||
|||, | ||
[ | ||
d.argument.new('shifts', d.T.array), | ||
] | ||
), | ||
withShifts(shifts):: | ||
forProvider.withType('calendar') | ||
+ forProvider.withShiftsRef([ | ||
forProvider.shiftsRef.withName(shift) | ||
for shift in shifts | ||
]), | ||
calendar: { | ||
'#new':: d.func.new( | ||
||| | ||
`new` creates a Schedule with type `calendar`. It automatically | ||
includes references to Shift objects which are members of its `shifts` | ||
field. `shifts` is an object representing zero or more shifts. | ||
Shifts are unordered, and so are supplied as an object to allow for | ||
reuse. For example, a Primary/Secondary pair of Schedules could be | ||
declared like: | ||
local calendar = grafanaplane.oncall.schedule.calendar, | ||
local onCallUsers = [['[email protected]'], ['[email protected]']], | ||
primary: calendar.new('Primary', { | ||
weekday: // 24 hour daily shift | ||
calendar.shift.new('Weekday', '2025-01-01T12:00:00', 24 * 60 * 60) | ||
+ calendar.shift.withByDay(['MO', 'TU', 'WE', 'TH', 'FR']) | ||
+ calendar.shift.withRollingUsers('daily', onCallUsers), | ||
weekend: // 72 hour weekend shift | ||
calendar.shift.new('Weekend', '2025-01-01T12:00:00', 72 * 60 * 60) | ||
+ calendar.shift.withByDay(['FR', 'SA', 'SU', 'MO']) | ||
+ calendar.shift.withRollingUsers('weekly', onCallUsers), | ||
}), | ||
secondary: calendar.new('Secondary', { | ||
[shift.key]: | ||
shift.value | ||
// replace the resource ID | ||
+ calendar.shift.withId('secondary-' + shift.value.metadata.name) | ||
// start rotating from the second person | ||
+ calendar.shift.withStartRotationFromUserIndex(1) | ||
for shift in std.objectKeysValues(self.primary.shifts) | ||
}), | ||
|||, | ||
[ | ||
d.argument.new('name', d.T.string), | ||
d.argument.new('shifts', d.T.object, default='{}'), | ||
] | ||
), | ||
new(name, shifts={}): { | ||
scheduleName:: xtd.ascii.stringToRFC1123(name), | ||
schedule: | ||
schedule.new(self.scheduleName) | ||
+ forProvider.withName(name) | ||
+ forProvider.withType('calendar') | ||
+ forProvider.withShiftsRef([ | ||
forProvider.shiftsRef.withName(shift.metadata.name) | ||
for shift in std.objectValues(self.shifts) | ||
]), | ||
shifts: shifts, | ||
}, | ||
|
||
'#withId':: d.func.new( | ||
'`withId` sets the resource name for a Schedule', | ||
[d.argument.new('id', d.T.string)] | ||
), | ||
withId(id):: { | ||
scheduleName:: id, | ||
schedule+: schedule.metadata.withName(id), | ||
}, | ||
|
||
'#withShifts':: d.func.new( | ||
||| | ||
`withShifts` sets a map of Shifts on a calendar-type Schedule. | ||
|||, | ||
[d.argument.new('shifts', d.T.object)] | ||
), | ||
withShifts(shifts):: { | ||
shifts: shifts, | ||
}, | ||
|
||
shift: import './shift.libsonnet', | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters