mirror of
https://github.com/zalando/postgres-operator.git
synced 2026-10-08 23:06:45 +02:00
api server
This commit is contained in:
@@ -15,10 +15,11 @@ import (
|
||||
"github.com/zalando-incubator/postgres-operator/pkg/util/config"
|
||||
"github.com/zalando-incubator/postgres-operator/pkg/util/constants"
|
||||
"github.com/zalando-incubator/postgres-operator/pkg/util/k8sutil"
|
||||
"github.com/zalando-incubator/postgres-operator/pkg/apiserver"
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
RestConfig *rest.Config
|
||||
RestConfig *rest.Config `json:"-"`
|
||||
InfrastructureRoles map[string]spec.PgUser
|
||||
|
||||
NoDatabaseAccess bool
|
||||
@@ -34,6 +35,7 @@ type Controller struct {
|
||||
logger *logrus.Entry
|
||||
KubeClient k8sutil.KubernetesClient
|
||||
RestClient rest.Interface // kubernetes API group REST client
|
||||
apiserver *apiserver.Server
|
||||
|
||||
clustersMu sync.RWMutex
|
||||
clusters map[spec.NamespacedName]*cluster.Cluster
|
||||
@@ -166,6 +168,8 @@ func (c *Controller) initController() {
|
||||
return fmt.Sprintf("%s-%s", e.EventType, e.UID), nil
|
||||
})
|
||||
}
|
||||
|
||||
c.apiserver = apiserver.New(c, c.opConfig.APIPort, c.logger.Logger)
|
||||
}
|
||||
|
||||
func (c *Controller) Run(stopCh <-chan struct{}, wg *sync.WaitGroup) {
|
||||
@@ -176,7 +180,7 @@ func (c *Controller) Run(stopCh <-chan struct{}, wg *sync.WaitGroup) {
|
||||
go c.runPostgresqlInformer(stopCh, wg)
|
||||
go c.podEventsDispatcher(stopCh, wg)
|
||||
go c.clusterResync(stopCh, wg)
|
||||
go c.RunAPIServer(stopCh, wg)
|
||||
go c.apiserver.Run(stopCh, wg)
|
||||
|
||||
for i := range c.clusterEventQueues {
|
||||
wg.Add(1)
|
||||
|
||||
@@ -1,43 +0,0 @@
|
||||
package controller
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/http/pprof"
|
||||
"sync"
|
||||
)
|
||||
|
||||
func (c *Controller) RunAPIServer(stopCh <-chan struct{}, wg *sync.WaitGroup) {
|
||||
defer wg.Done()
|
||||
|
||||
mux := http.NewServeMux()
|
||||
|
||||
mux.Handle("/debug/pprof/", http.HandlerFunc(pprof.Index))
|
||||
mux.Handle("/debug/pprof/cmdline", http.HandlerFunc(pprof.Cmdline))
|
||||
mux.Handle("/debug/pprof/profile", http.HandlerFunc(pprof.Profile))
|
||||
mux.Handle("/debug/pprof/symbol", http.HandlerFunc(pprof.Symbol))
|
||||
mux.Handle("/debug/pprof/trace", http.HandlerFunc(pprof.Trace))
|
||||
|
||||
server := http.Server{
|
||||
Addr: fmt.Sprintf(":%d", c.opConfig.APIPort),
|
||||
Handler: mux,
|
||||
}
|
||||
|
||||
go func() {
|
||||
err := server.ListenAndServe()
|
||||
if err != http.ErrServerClosed {
|
||||
c.logger.Fatalf("could not start http server: %v", err)
|
||||
}
|
||||
}()
|
||||
c.logger.Infof("listening on %s", server.Addr)
|
||||
|
||||
<-stopCh
|
||||
|
||||
ctx, _ := context.WithCancel(context.Background())
|
||||
server.Shutdown(ctx)
|
||||
}
|
||||
|
||||
func (c *Controller) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
fmt.Printf("Request: %+v\n", r.URL.String())
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
package controller
|
||||
|
||||
import (
|
||||
"github.com/zalando-incubator/postgres-operator/pkg/util/config"
|
||||
"github.com/zalando-incubator/postgres-operator/pkg/spec"
|
||||
"github.com/zalando-incubator/postgres-operator/pkg/cluster"
|
||||
)
|
||||
|
||||
type controllerStatus struct {
|
||||
ControllerConfig Config
|
||||
OperatorConfig config.Config
|
||||
LastSyncTime int64
|
||||
}
|
||||
|
||||
type clusterStatus struct {
|
||||
Team string
|
||||
Cluster string
|
||||
|
||||
Config cluster.Config
|
||||
Status spec.PostgresStatus
|
||||
Resources cluster.KubeResources
|
||||
Spec spec.PostgresSpec
|
||||
}
|
||||
|
||||
func (c *Controller) ClusterStatus(team, cluster string) interface{} {
|
||||
clusterName := spec.NamespacedName{
|
||||
Namespace: c.opConfig.Namespace,
|
||||
Name: team + "-" + cluster,
|
||||
}
|
||||
|
||||
cl, ok := c.clusters[clusterName]
|
||||
if !ok {
|
||||
return struct{}{}
|
||||
}
|
||||
|
||||
return clusterStatus{
|
||||
Config: cl.Config,
|
||||
Cluster: cl.Spec.ClusterName,
|
||||
Team: cl.Spec.TeamID,
|
||||
Status: cl.Status,
|
||||
Resources: cl.KubeResources,
|
||||
Spec: cl.Spec,
|
||||
}
|
||||
}
|
||||
|
||||
func (c *Controller) Status() interface{} {
|
||||
return controllerStatus{
|
||||
ControllerConfig: c.config,
|
||||
OperatorConfig: *c.opConfig,
|
||||
LastSyncTime: c.lastClusterSyncTime,
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user