mirror of
https://github.com/zalando/postgres-operator.git
synced 2026-09-30 20:02:14 +02:00
* fix: rename module to github.com/zalando/postgres-operator/v2 Upgrade performed using https://github.com/icholy/gomajor ``` gomajor path -version v2 ``` Signed-off-by: Benjamin Ritter <benjamin.ritter@x-cellent.com> * fix: make fmt Signed-off-by: Benjamin Ritter <benjamin.ritter@x-cellent.com> * fix: adjust codegen module name Signed-off-by: Benjamin Ritter <benjamin.ritter@x-cellent.com> --------- Signed-off-by: Benjamin Ritter <benjamin.ritter@x-cellent.com> Co-authored-by: Felix Kunde <felix-kunde@gmx.de>
59 lines
1.4 KiB
Go
59 lines
1.4 KiB
Go
package controller
|
|
|
|
import (
|
|
v1 "k8s.io/api/core/v1"
|
|
|
|
"github.com/zalando/postgres-operator/v2/pkg/cluster"
|
|
"github.com/zalando/postgres-operator/v2/pkg/spec"
|
|
"github.com/zalando/postgres-operator/v2/pkg/util"
|
|
"k8s.io/apimachinery/pkg/types"
|
|
)
|
|
|
|
func (c *Controller) dispatchPodEvent(clusterName spec.NamespacedName, event cluster.PodEvent) {
|
|
c.clustersMu.RLock()
|
|
cluster, ok := c.clusters[clusterName]
|
|
c.clustersMu.RUnlock()
|
|
if ok {
|
|
cluster.ReceivePodEvent(event)
|
|
}
|
|
}
|
|
|
|
func (c *Controller) podAdd(obj interface{}) {
|
|
if pod, ok := obj.(*v1.Pod); ok {
|
|
c.preparePodEventForDispatch(pod, nil, cluster.PodEventAdd)
|
|
}
|
|
}
|
|
|
|
func (c *Controller) podUpdate(prev, cur interface{}) {
|
|
prevPod, ok := prev.(*v1.Pod)
|
|
if !ok {
|
|
return
|
|
}
|
|
|
|
curPod, ok := cur.(*v1.Pod)
|
|
if !ok {
|
|
return
|
|
}
|
|
|
|
c.preparePodEventForDispatch(curPod, prevPod, cluster.PodEventUpdate)
|
|
}
|
|
|
|
func (c *Controller) podDelete(obj interface{}) {
|
|
|
|
if pod, ok := obj.(*v1.Pod); ok {
|
|
c.preparePodEventForDispatch(pod, nil, cluster.PodEventDelete)
|
|
}
|
|
}
|
|
|
|
func (c *Controller) preparePodEventForDispatch(curPod, prevPod *v1.Pod, event cluster.PodEventType) {
|
|
podEvent := cluster.PodEvent{
|
|
PodName: types.NamespacedName(util.NameFromMeta(curPod.ObjectMeta)),
|
|
CurPod: curPod,
|
|
PrevPod: prevPod,
|
|
EventType: event,
|
|
ResourceVersion: curPod.ResourceVersion,
|
|
}
|
|
|
|
c.dispatchPodEvent(c.podClusterName(curPod), podEvent)
|
|
}
|