on service change recreate service before endpoint

This commit is contained in:
Felix Kunde 2020-02-11 17:31:01 +01:00
parent be6c8cd573
commit d09eb7b259
1 changed files with 9 additions and 7 deletions

View File

@ -417,6 +417,15 @@ func (c *Cluster) updateService(role PostgresRole, newService *v1.Service) error
// make sure we clear the stored service and endpoint status if the subsequent create fails.
c.Services[role] = nil
c.Endpoints[role] = nil
// create new service
svc, err := c.KubeClient.Services(serviceName.Namespace).Create(newService)
if err != nil {
return fmt.Errorf("could not create service %q: %v", serviceName, err)
}
c.Services[role] = svc
if role == Master {
// create the new endpoint using the addresses obtained from the previous one
endpointSpec := c.generateEndpoint(role, currentEndpoint.Subsets)
@ -428,13 +437,6 @@ func (c *Cluster) updateService(role PostgresRole, newService *v1.Service) error
c.Endpoints[role] = ep
}
svc, err := c.KubeClient.Services(serviceName.Namespace).Create(newService)
if err != nil {
return fmt.Errorf("could not create service %q: %v", serviceName, err)
}
c.Services[role] = svc
return nil
}