Use unified type for the namespaced object names

This commit is contained in:
Murat Kabilov
2017-05-12 11:41:34 +02:00
parent 79fdba4ac7
commit 08c0e3b6dd
10 changed files with 69 additions and 85 deletions
+4 -7
View File
@@ -59,7 +59,7 @@ type Cluster struct {
logger *logrus.Entry
pgUsers map[string]spec.PgUser
podEvents chan spec.PodEvent
podSubscribers map[spec.PodName]chan spec.PodEvent
podSubscribers map[spec.NamespacedName]chan spec.PodEvent
pgDb *sql.DB
mu sync.Mutex
}
@@ -74,18 +74,15 @@ func New(cfg Config, pgSpec spec.Postgresql, logger *logrus.Logger) *Cluster {
logger: lg,
pgUsers: make(map[string]spec.PgUser),
podEvents: make(chan spec.PodEvent),
podSubscribers: make(map[spec.PodName]chan spec.PodEvent),
podSubscribers: make(map[spec.NamespacedName]chan spec.PodEvent),
kubeResources: kubeResources,
}
return cluster
}
func (c *Cluster) ClusterName() spec.ClusterName {
return spec.ClusterName{
Name: c.Metadata.Name,
Namespace: c.Metadata.Namespace,
}
func (c *Cluster) ClusterName() spec.NamespacedName {
return util.NameFromMeta(c.Metadata)
}
func (c *Cluster) TeamName() string {
+4 -10
View File
@@ -84,10 +84,7 @@ func (c *Cluster) deletePersistenVolumeClaims() error {
}
func (c *Cluster) deletePod(pod *v1.Pod) error {
podName := spec.PodName{
Namespace: pod.Namespace,
Name: pod.Name,
}
podName := util.NameFromMeta(pod.ObjectMeta)
ch := make(chan spec.PodEvent)
if _, ok := c.podSubscribers[podName]; ok {
@@ -110,7 +107,7 @@ func (c *Cluster) deletePod(pod *v1.Pod) error {
return nil
}
func (c *Cluster) unregisterPodSubscriber(podName spec.PodName) {
func (c *Cluster) unregisterPodSubscriber(podName spec.NamespacedName) {
if _, ok := c.podSubscribers[podName]; !ok {
panic("Subscriber for Pod '" + podName.String() + "' is not found")
}
@@ -119,7 +116,7 @@ func (c *Cluster) unregisterPodSubscriber(podName spec.PodName) {
delete(c.podSubscribers, podName)
}
func (c *Cluster) registerPodSubscriber(podName spec.PodName) chan spec.PodEvent {
func (c *Cluster) registerPodSubscriber(podName spec.NamespacedName) chan spec.PodEvent {
ch := make(chan spec.PodEvent)
if _, ok := c.podSubscribers[podName]; ok {
panic("Pod '" + podName.String() + "' is already subscribed")
@@ -129,10 +126,7 @@ func (c *Cluster) registerPodSubscriber(podName spec.PodName) chan spec.PodEvent
}
func (c *Cluster) recreatePod(pod v1.Pod) error {
podName := spec.PodName{
Namespace: pod.Namespace,
Name: pod.Name,
}
podName := util.NameFromMeta(pod.ObjectMeta)
orphanDependents := false
deleteOptions := &v1.DeleteOptions{