Skip to content

Commit

Permalink
fix(oncall): use selectors for OnCallShift membership in Schedules
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-bauer committed Jan 10, 2025
1 parent b3c1e31 commit 3049366
Showing 1 changed file with 19 additions and 7 deletions.
26 changes: 19 additions & 7 deletions grafanaplane/oncall/schedule.libsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ local xtd = import 'github.com/jsonnet-libs/xtd/main.libsonnet';

local raw = import '../zz/main.libsonnet';
local schedule = raw.oncall.v1alpha1.schedule;
local onCallShift = raw.oncall.v1alpha1.onCallShift;
local forProvider = schedule.spec.parameters.forProvider;

{
Expand Down Expand Up @@ -47,17 +48,28 @@ local forProvider = schedule.spec.parameters.forProvider;
d.argument.new('shifts', d.T.object, default='{}'),
]
),
new(name, shifts={}): {
new(name, shifts=[]): {
local this = self,

// For this schedule to refer to all of its related shifts, we must
// supply a single matchLabel selector. To do this, we construct a label
// to be applied to all child shifts, and match using that.
local shiftLabels = {
'oncall.grafana.net.namespaced/schedule-claim-name': this.scheduleName,
},

scheduleName:: xtd.ascii.stringToRFC1123(name),
schedule:
schedule.new(self.scheduleName)
schedule.new(this.scheduleName)
+ forProvider.withName(name)
+ forProvider.withType('calendar')
+ forProvider.withShiftsRef([
forProvider.shiftsRef.withName(shift.metadata.name)
for shift in self.shifts
]),
shifts: shifts,
+ forProvider.shiftsSelector.withMatchLabels(shiftLabels),
shifts: [
// label each shift with the schedule-claim-name
onCallShift.metadata.withLabels(shiftLabels)
+ shift
for shift in shifts
],
},

'#withId':: d.func.new(
Expand Down

0 comments on commit 3049366

Please sign in to comment.