mirror of
https://github.com/zalando/postgres-operator.git
synced 2026-10-18 14:37:32 +02:00
Extend diagnostic api with worker status info
This commit is contained in:
+25
-3
@@ -9,6 +9,7 @@ import (
|
||||
"reflect"
|
||||
"regexp"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/Sirupsen/logrus"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
@@ -71,6 +72,8 @@ type Cluster struct {
|
||||
|
||||
teamsAPIClient *teams.API
|
||||
KubeClient k8sutil.KubernetesClient //TODO: move clients to the better place?
|
||||
currentProcess spec.Process
|
||||
processMu sync.RWMutex
|
||||
}
|
||||
|
||||
type compareStatefulsetResult struct {
|
||||
@@ -122,6 +125,15 @@ func (c *Cluster) teamName() string {
|
||||
return c.Spec.TeamID
|
||||
}
|
||||
|
||||
func (c *Cluster) setProcessName(procName string, args ...interface{}) {
|
||||
c.processMu.Lock()
|
||||
defer c.processMu.Unlock()
|
||||
c.currentProcess = spec.Process{
|
||||
Name: fmt.Sprintf(procName, args...),
|
||||
StartTime: time.Now(),
|
||||
}
|
||||
}
|
||||
|
||||
func (c *Cluster) setStatus(status spec.PostgresStatus) {
|
||||
c.Status = status
|
||||
b, err := json.Marshal(status)
|
||||
@@ -149,6 +161,7 @@ func (c *Cluster) setStatus(status spec.PostgresStatus) {
|
||||
|
||||
// initUsers populates c.systemUsers and c.pgUsers maps.
|
||||
func (c *Cluster) initUsers() error {
|
||||
c.setProcessName("initializing users")
|
||||
c.initSystemUsers()
|
||||
|
||||
if err := c.initInfrastructureRoles(); err != nil {
|
||||
@@ -188,7 +201,7 @@ func (c *Cluster) Create() error {
|
||||
|
||||
c.setStatus(spec.ClusterStatusCreating)
|
||||
|
||||
//TODO: service will create endpoint implicitly
|
||||
//service will create endpoint implicitly
|
||||
ep, err = c.createEndpoint()
|
||||
if err != nil {
|
||||
return fmt.Errorf("could not create endpoint: %v", err)
|
||||
@@ -231,11 +244,11 @@ func (c *Cluster) Create() error {
|
||||
c.logger.Infof("pods are ready")
|
||||
|
||||
if !(c.masterLess || c.databaseAccessDisabled()) {
|
||||
if err := c.createRoles(); err != nil {
|
||||
if err = c.createRoles(); err != nil {
|
||||
return fmt.Errorf("could not create users: %v", err)
|
||||
}
|
||||
|
||||
if err := c.createDatabases(); err != nil {
|
||||
if err = c.createDatabases(); err != nil {
|
||||
return fmt.Errorf("could not create databases: %v", err)
|
||||
}
|
||||
|
||||
@@ -655,6 +668,14 @@ func (c *Cluster) initInfrastructureRoles() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetCurrentProcess provides name of the last process of the cluster
|
||||
func (c *Cluster) GetCurrentProcess() spec.Process {
|
||||
c.processMu.RLock()
|
||||
defer c.processMu.RUnlock()
|
||||
|
||||
return c.currentProcess
|
||||
}
|
||||
|
||||
// GetStatus provides status of the cluster
|
||||
func (c *Cluster) GetStatus() *spec.ClusterStatus {
|
||||
return &spec.ClusterStatus{
|
||||
@@ -667,6 +688,7 @@ func (c *Cluster) GetStatus() *spec.ClusterStatus {
|
||||
ReplicaService: c.GetServiceReplica(),
|
||||
Endpoint: c.GetEndpoint(),
|
||||
StatefulSet: c.GetStatefulSet(),
|
||||
CurrentProcess: c.GetCurrentProcess(),
|
||||
|
||||
Error: c.Error,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user