Skip to content

Commit e18c808

Browse files
authored
Set event actions for all emitted events (#1560)
Define event action constants alongside the existing reasons and pass them to every Eventf call in schedulers, controllers and poollets. Also fix a few malformed event messages (missing format arguments). Signed-off-by: Maximilian Moehl <maximilian@moehl.eu>
1 parent a141648 commit e18c808

14 files changed

Lines changed: 61 additions & 23 deletions

File tree

internal/controllers/compute/machine_ephemeralvolume_controller.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ func (r *MachineEphemeralVolumeReconciler) reconcile(ctx context.Context, log lo
217217
r.addArchitectureIfNeeded(log, volume, arch)
218218
if err := r.handleCreateVolume(ctx, log, machine, volume); err != nil {
219219
if apierrors.IsForbidden(err) {
220-
r.Eventf(machine, volume, corev1.EventTypeNormal, events.VolumeNotReady, "Volume %s exceeded quota ", volume.Name)
220+
r.Eventf(machine, volume, corev1.EventTypeNormal, events.VolumeNotReady, events.CreatingEphemeralVolume, "Volume %s exceeded quota ", volume.Name)
221221
}
222222
errs = append(errs, err)
223223
}

internal/controllers/compute/machine_scheduler.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import (
2929

3030
const (
3131
outOfCapacity = "OutOfCapacity"
32+
scheduling = "Scheduling"
3233
)
3334

3435
type MachineScheduler struct {
@@ -101,7 +102,7 @@ func (s *MachineScheduler) reconcileExists(ctx context.Context, log logr.Logger,
101102

102103
nodes := s.snapshot.ListNodes()
103104
if len(nodes) == 0 {
104-
s.Eventf(machine, nil, corev1.EventTypeNormal, outOfCapacity, "No nodes available to schedule %s on", machine.Name)
105+
s.Eventf(machine, nil, corev1.EventTypeNormal, outOfCapacity, scheduling, "No nodes available to schedule %s on", machine.Name)
105106
return ctrl.Result{}, nil
106107
}
107108

@@ -128,7 +129,7 @@ func (s *MachineScheduler) reconcileExists(ctx context.Context, log logr.Logger,
128129
}
129130

130131
if len(filteredNodes) == 0 {
131-
s.Eventf(machine, nil, corev1.EventTypeNormal, outOfCapacity, "No nodes available after filtering to schedule %s on", machine.Name)
132+
s.Eventf(machine, nil, corev1.EventTypeNormal, outOfCapacity, scheduling, "No nodes available after filtering to schedule %s on", machine.Name)
132133
return ctrl.Result{}, nil
133134
}
134135

internal/controllers/ipam/prefixallocationscheduler_controller.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ import (
2323
"sigs.k8s.io/controller-runtime/pkg/manager"
2424
)
2525

26+
const (
27+
scheduling = "Scheduling"
28+
)
29+
2630
type PrefixAllocationScheduler struct {
2731
events.EventRecorder
2832
client.Client
@@ -149,7 +153,7 @@ func (s *PrefixAllocationScheduler) reconcile(ctx context.Context, log logr.Logg
149153
}
150154
if ref == "" {
151155
log.V(1).Info("No suitable prefix found")
152-
s.Eventf(allocation, nil, corev1.EventTypeNormal, "NoSuitablePrefix", "No suitable prefix for scheduling %s found.", allocation.Name)
156+
s.Eventf(allocation, nil, corev1.EventTypeNormal, "NoSuitablePrefix", scheduling, "No suitable prefix for scheduling %s found.", allocation.Name)
153157
return ctrl.Result{}, nil
154158
}
155159

internal/controllers/storage/bucket_scheduler.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ func (s *BucketScheduler) schedule(ctx context.Context, log logr.Logger, bucket
7373
}
7474
if len(available) == 0 {
7575
log.Info("No bucket pool available for bucket class", "BucketClass", bucket.Spec.BucketClassRef.Name)
76-
s.Eventf(bucket, nil, corev1.EventTypeNormal, "CannotSchedule", "No BucketPoolRef found for BucketClass %s", bucket.Spec.BucketClassRef.Name)
76+
s.Eventf(bucket, nil, corev1.EventTypeNormal, "CannotSchedule", scheduling, "No BucketPoolRef found for BucketClass %s", bucket.Spec.BucketClassRef.Name)
7777
return ctrl.Result{}, nil
7878
}
7979

@@ -86,7 +86,7 @@ func (s *BucketScheduler) schedule(ctx context.Context, log logr.Logger, bucket
8686
}
8787
if len(filtered) == 0 {
8888
log.Info("No bucket pool tolerated by the bucket", "Tolerations", bucket.Spec.Tolerations)
89-
s.Eventf(bucket, nil, corev1.EventTypeNormal, "CannotSchedule", "No BucketPoolRef tolerated by the %s", bucket.Name)
89+
s.Eventf(bucket, nil, corev1.EventTypeNormal, "CannotSchedule", scheduling, "No BucketPoolRef tolerated by the %s", bucket.Name)
9090
return ctrl.Result{}, nil
9191
}
9292
available = filtered

internal/controllers/storage/volume_scheduler.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import (
2929

3030
const (
3131
outOfCapacity = "OutOfCapacity"
32+
scheduling = "Scheduling"
3233
)
3334

3435
type VolumeScheduler struct {
@@ -142,7 +143,7 @@ func (s *VolumeScheduler) reconcileExists(ctx context.Context, log logr.Logger,
142143

143144
nodes := s.snapshot.ListNodes()
144145
if len(nodes) == 0 {
145-
s.Eventf(volume, nil, corev1.EventTypeNormal, outOfCapacity, "No nodes available to schedule %s on", volume.Name)
146+
s.Eventf(volume, nil, corev1.EventTypeNormal, outOfCapacity, scheduling, "No nodes available to schedule %s on", volume.Name)
146147
return ctrl.Result{}, nil
147148
}
148149

@@ -165,7 +166,7 @@ func (s *VolumeScheduler) reconcileExists(ctx context.Context, log logr.Logger,
165166
}
166167

167168
if len(filteredNodes) == 0 {
168-
s.Eventf(volume, nil, corev1.EventTypeNormal, outOfCapacity, "No nodes available after filtering to schedule %s on", volume.Name)
169+
s.Eventf(volume, nil, corev1.EventTypeNormal, outOfCapacity, scheduling, "No nodes available after filtering to schedule %s on", volume.Name)
169170
return ctrl.Result{}, nil
170171
}
171172

poollet/bucketpoollet/controllers/bucket_controller.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ func (r *BucketReconciler) prepareIRIBucketClass(ctx context.Context, bucket *st
257257
return "", false, fmt.Errorf("error getting bucket class %s: %w", bucketClassName, err)
258258
}
259259

260-
r.Eventf(bucket, nil, corev1.EventTypeNormal, bucketpoolletevents.BucketClassNotReady, "Bucket class %s not found", bucketClassName)
260+
r.Eventf(bucket, nil, corev1.EventTypeNormal, bucketpoolletevents.BucketClassNotReady, bucketpoolletevents.ResolvingBucketClass, "Bucket class %s not found", bucketClassName)
261261
return "", false, nil
262262
}
263263

poollet/bucketpoollet/controllers/events/events.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@
33

44
package events
55

6+
// Event reasons.
67
const (
78
BucketClassNotReady = "BucketClassNotReady"
89
)
10+
11+
// Event actions.
12+
const (
13+
ResolvingBucketClass = "ResolvingBucketClass"
14+
)

poollet/machinepoollet/controllers/events/events.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,19 @@
33

44
package events
55

6+
// Event reasons.
67
const (
78
MachineClassNotReady = "MachineClassNotReady"
89
NetworkInterfaceNotReady = "NetworkInterfaceNotReady"
910
VolumeNotReady = "VolumeNotReady"
1011
IgnitionNotReady = "IgnitionNotReady"
1112
)
13+
14+
// Event actions.
15+
const (
16+
ResolvingMachineClass = "ResolvingMachineClass"
17+
ResolvingIgnition = "ResolvingIgnition"
18+
AttachingNetworkInterface = "AttachingNetworkInterface"
19+
AttachingVolume = "AttachingVolume"
20+
CreatingEphemeralVolume = "CreatingEphemeralVolume"
21+
)

poollet/machinepoollet/controllers/machine_controller.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -710,7 +710,7 @@ func (r *MachineReconciler) prepareIRIMachineClass(ctx context.Context, machine
710710
return "", false, fmt.Errorf("error getting machine class: %w", err)
711711
}
712712

713-
r.Eventf(machine, nil, corev1.EventTypeNormal, machinepoolletEvents.MachineClassNotReady, "Machine class %s is not ready: %v", machineClassName, err)
713+
r.Eventf(machine, nil, corev1.EventTypeNormal, machinepoolletEvents.MachineClassNotReady, machinepoolletEvents.ResolvingMachineClass, "Machine class %s is not ready: %v", machineClassName, err)
714714
return "", false, nil
715715
}
716716

@@ -744,7 +744,7 @@ func (r *MachineReconciler) prepareIRIIgnitionData(ctx context.Context, machine
744744
return nil, false, err
745745
}
746746

747-
r.Eventf(machine, nil, corev1.EventTypeNormal, machinepoolletEvents.IgnitionNotReady, "Ignition not ready: %v", ignitionSecret.GetName(), err)
747+
r.Eventf(machine, nil, corev1.EventTypeNormal, machinepoolletEvents.IgnitionNotReady, machinepoolletEvents.ResolvingIgnition, "Ignition %s not ready: %v", ignitionSecret.GetName(), err)
748748
return nil, false, nil
749749
}
750750

@@ -755,7 +755,7 @@ func (r *MachineReconciler) prepareIRIIgnitionData(ctx context.Context, machine
755755

756756
data, ok := ignitionSecret.Data[ignitionKey]
757757
if !ok {
758-
r.Eventf(machine, nil, corev1.EventTypeNormal, machinepoolletEvents.IgnitionNotReady, "Ignition has no data at key %s", ignitionKey)
758+
r.Eventf(machine, nil, corev1.EventTypeNormal, machinepoolletEvents.IgnitionNotReady, machinepoolletEvents.ResolvingIgnition, "Ignition has no data at key %s", ignitionKey)
759759
return nil, false, nil
760760
}
761761

poollet/machinepoollet/controllers/machine_controller_networkinterface.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ func (r *MachineReconciler) prepareIRINetworkInterfacesForMachine(
125125
expectedNicNames := utilslices.ToSetFunc(machine.Spec.NetworkInterfaces, func(v computev1alpha1.NetworkInterface) string { return v.Name })
126126
actualNicNames := utilslices.ToSetFunc(iriNics, (*iri.NetworkInterface).GetName)
127127
missingNicNames := sets.List(expectedNicNames.Difference(actualNicNames))
128-
r.Eventf(machine, nil, corev1.EventTypeNormal, events.NetworkInterfaceNotReady, "Machine network interfaces are not ready: %s", strings.Join(missingNicNames, ", "))
128+
r.Eventf(machine, nil, corev1.EventTypeNormal, events.NetworkInterfaceNotReady, events.AttachingNetworkInterface, "Machine network interfaces are not ready: %s", strings.Join(missingNicNames, ", "))
129129
return nil, nil, false, nil
130130
}
131131

@@ -183,17 +183,17 @@ func (r *MachineReconciler) getNetworkInterfaceIP(
183183
return commonv1alpha1.IP{}, false, fmt.Errorf("error getting prefix %s: %w", prefixName, err)
184184
}
185185

186-
r.Eventf(machine, nil, corev1.EventTypeNormal, events.NetworkInterfaceNotReady, "Network interface prefix %s not found", prefixName)
186+
r.Eventf(machine, nil, corev1.EventTypeNormal, events.NetworkInterfaceNotReady, events.AttachingNetworkInterface, "Network interface prefix %s not found", prefixName)
187187
return commonv1alpha1.IP{}, false, nil
188188
}
189189

190190
if !metav1.IsControlledBy(prefix, nic) {
191-
r.Eventf(machine, nil, corev1.EventTypeNormal, events.NetworkInterfaceNotReady, "Network interface prefix %s not controlled by network interface", prefixName, nic.Name)
191+
r.Eventf(machine, nil, corev1.EventTypeNormal, events.NetworkInterfaceNotReady, events.AttachingNetworkInterface, "Network interface prefix %s not controlled by network interface %s", prefixName, nic.Name)
192192
return commonv1alpha1.IP{}, false, nil
193193
}
194194

195195
if prefix.Status.Phase != ipamv1alpha1.PrefixPhaseAllocated {
196-
r.Eventf(machine, nil, corev1.EventTypeNormal, events.NetworkInterfaceNotReady, "Network interface prefix %s is not yet allocated", prefixName)
196+
r.Eventf(machine, nil, corev1.EventTypeNormal, events.NetworkInterfaceNotReady, events.AttachingNetworkInterface, "Network interface prefix %s is not yet allocated", prefixName)
197197
return commonv1alpha1.IP{}, false, nil
198198
}
199199

@@ -260,7 +260,7 @@ func (r *MachineReconciler) prepareIRINetworkInterface(
260260
if !apierrors.IsNotFound(err) {
261261
return nil, false, fmt.Errorf("error getting network %s: %w", networkKey.Name, err)
262262
}
263-
r.Eventf(machine, nil, corev1.EventTypeNormal, events.NetworkInterfaceNotReady, "Network interface %s network %s not found", nic.Name, networkKey.Name)
263+
r.Eventf(machine, nil, corev1.EventTypeNormal, events.NetworkInterfaceNotReady, events.AttachingNetworkInterface, "Network interface %s network %s not found", nic.Name, networkKey.Name)
264264
return nil, false, nil
265265
}
266266
nicLabels, err := r.iriNetworkInterfaceLabels(nic)

0 commit comments

Comments
 (0)