Skip to content

Commit 50ea316

Browse files
clarified delete events with update to the deployment spec
1 parent dd67b97 commit 50ea316

1 file changed

Lines changed: 18 additions & 6 deletions

File tree

internal/controller/controller.go

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ import (
2424
"k8s.io/client-go/util/workqueue"
2525
)
2626

27+
const (
28+
EventCreated = "CREATED"
29+
EventDeleted = "DELETED"
30+
)
31+
2732
// PodEvent represents a pod event to be processed.
2833
type PodEvent struct {
2934
Key string
@@ -111,7 +116,7 @@ func New(clientset kubernetes.Interface, namespace string, cfg *Config) (*Contro
111116
if err == nil {
112117
queue.Add(PodEvent{
113118
Key: key,
114-
EventType: "CREATED",
119+
EventType: EventCreated,
115120
})
116121
}
117122
}
@@ -153,7 +158,7 @@ func New(clientset kubernetes.Interface, namespace string, cfg *Config) (*Contro
153158
if err == nil {
154159
queue.Add(PodEvent{
155160
Key: key,
156-
EventType: "CREATED",
161+
EventType: EventCreated,
157162
})
158163
}
159164
}
@@ -184,7 +189,7 @@ func New(clientset kubernetes.Interface, namespace string, cfg *Config) (*Contro
184189
if err == nil {
185190
queue.Add(PodEvent{
186191
Key: key,
187-
EventType: "DELETED",
192+
EventType: EventDeleted,
188193
DeletedPod: pod,
189194
})
190195
}
@@ -272,7 +277,7 @@ func (c *Controller) processNextItem(ctx context.Context) bool {
272277
func (c *Controller) processEvent(ctx context.Context, event PodEvent) error {
273278
var pod *corev1.Pod
274279

275-
if event.EventType == "DELETED" {
280+
if event.EventType == EventDeleted {
276281
// For delete events, use the pod captured at deletion time
277282
pod = event.DeletedPod
278283
if pod == nil {
@@ -283,7 +288,14 @@ func (c *Controller) processEvent(ctx context.Context, event PodEvent) error {
283288
}
284289

285290
// Check if the parent deployment still exists
286-
// If it does, this is just a scale-down event, skip it
291+
// If it does, this is just a scale-down event, skip it.
292+
//
293+
// If a deployment changes image versions, this will not
294+
// fire delete/decommissioned events to the remote API.
295+
// This is as intended, as the server will keep track of
296+
// the (cluster unique) deployment name, and just update
297+
// the referenced image digest to the newly observed (via
298+
// the create event).
287299
deploymentName := getDeploymentName(pod)
288300
if deploymentName != "" && c.deploymentExists(ctx, pod.Namespace, deploymentName) {
289301
slog.Debug("Deployment still exists, skipping pod delete (scale down)",
@@ -319,7 +331,7 @@ func (c *Controller) processEvent(ctx context.Context, event PodEvent) error {
319331
}
320332

321333
status := deploymentrecord.StatusDeployed
322-
if event.EventType == "DELETED" {
334+
if event.EventType == EventDeleted {
323335
status = deploymentrecord.StatusDecommissioned
324336
}
325337

0 commit comments

Comments
 (0)