mirror of
https://github.com/zalando/postgres-operator.git
synced 2026-10-06 00:41:34 +02:00
PostgresTeamCRD for advanced team management
This commit is contained in:
@@ -12,6 +12,7 @@ import (
|
||||
"github.com/zalando/postgres-operator/pkg/apiserver"
|
||||
"github.com/zalando/postgres-operator/pkg/cluster"
|
||||
acidv1informer "github.com/zalando/postgres-operator/pkg/generated/informers/externalversions/acid.zalan.do/v1"
|
||||
"github.com/zalando/postgres-operator/pkg/postgresteams"
|
||||
"github.com/zalando/postgres-operator/pkg/spec"
|
||||
"github.com/zalando/postgres-operator/pkg/util"
|
||||
"github.com/zalando/postgres-operator/pkg/util/config"
|
||||
@@ -31,8 +32,9 @@ import (
|
||||
|
||||
// Controller represents operator controller
|
||||
type Controller struct {
|
||||
config spec.ControllerConfig
|
||||
opConfig *config.Config
|
||||
config spec.ControllerConfig
|
||||
opConfig *config.Config
|
||||
pgTeamMap *postgresteams.PostgresTeamMap
|
||||
|
||||
logger *logrus.Entry
|
||||
KubeClient k8sutil.KubernetesClient
|
||||
@@ -53,10 +55,11 @@ type Controller struct {
|
||||
clusterHistory map[spec.NamespacedName]ringlog.RingLogger // history of the cluster changes
|
||||
teamClusters map[string][]spec.NamespacedName
|
||||
|
||||
postgresqlInformer cache.SharedIndexInformer
|
||||
podInformer cache.SharedIndexInformer
|
||||
nodesInformer cache.SharedIndexInformer
|
||||
podCh chan cluster.PodEvent
|
||||
postgresqlInformer cache.SharedIndexInformer
|
||||
postgresTeamInformer cache.SharedIndexInformer
|
||||
podInformer cache.SharedIndexInformer
|
||||
nodesInformer cache.SharedIndexInformer
|
||||
podCh chan cluster.PodEvent
|
||||
|
||||
clusterEventQueues []*cache.FIFO // [workerID]Queue
|
||||
lastClusterSyncTime int64
|
||||
@@ -338,6 +341,17 @@ func (c *Controller) initSharedInformers() {
|
||||
DeleteFunc: c.postgresqlDelete,
|
||||
})
|
||||
|
||||
c.postgresTeamInformer = acidv1informer.NewPostgresTeamInformer(
|
||||
c.KubeClient.AcidV1ClientSet,
|
||||
c.opConfig.WatchedNamespace,
|
||||
constants.QueueResyncPeriodTPR,
|
||||
cache.Indexers{})
|
||||
|
||||
c.postgresTeamInformer.AddEventHandler(cache.ResourceEventHandlerFuncs{
|
||||
AddFunc: c.loadPostgresTeams,
|
||||
UpdateFunc: c.updatePostgresTeams,
|
||||
})
|
||||
|
||||
// Pods
|
||||
podLw := &cache.ListWatch{
|
||||
ListFunc: c.podListFunc,
|
||||
@@ -394,6 +408,7 @@ func (c *Controller) Run(stopCh <-chan struct{}, wg *sync.WaitGroup) {
|
||||
wg.Add(5)
|
||||
go c.runPodInformer(stopCh, wg)
|
||||
go c.runPostgresqlInformer(stopCh, wg)
|
||||
go c.runPostgresTeamInformer(stopCh, wg)
|
||||
go c.clusterResync(stopCh, wg)
|
||||
go c.apiserver.Run(stopCh, wg)
|
||||
go c.kubeNodesInformer(stopCh, wg)
|
||||
@@ -413,6 +428,12 @@ func (c *Controller) runPostgresqlInformer(stopCh <-chan struct{}, wg *sync.Wait
|
||||
c.postgresqlInformer.Run(stopCh)
|
||||
}
|
||||
|
||||
func (c *Controller) runPostgresTeamInformer(stopCh <-chan struct{}, wg *sync.WaitGroup) {
|
||||
defer wg.Done()
|
||||
|
||||
c.postgresTeamInformer.Run(stopCh)
|
||||
}
|
||||
|
||||
func queueClusterKey(eventType EventType, uid types.UID) string {
|
||||
return fmt.Sprintf("%s-%s", eventType, uid)
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@ import (
|
||||
|
||||
acidv1 "github.com/zalando/postgres-operator/pkg/apis/acid.zalan.do/v1"
|
||||
"github.com/zalando/postgres-operator/pkg/cluster"
|
||||
"github.com/zalando/postgres-operator/pkg/postgresteams"
|
||||
"github.com/zalando/postgres-operator/pkg/spec"
|
||||
"github.com/zalando/postgres-operator/pkg/util"
|
||||
"github.com/zalando/postgres-operator/pkg/util/config"
|
||||
@@ -394,6 +395,26 @@ func (c *Controller) getInfrastructureRole(
|
||||
return roles, nil
|
||||
}
|
||||
|
||||
func (c *Controller) loadPostgresTeams(obj interface{}) {
|
||||
var pgTeamMap postgresteams.PostgresTeamMap
|
||||
|
||||
pgTeam, ok := obj.(*acidv1.PostgresTeam)
|
||||
if !ok {
|
||||
c.logger.Errorf("could not cast to PostgresTeam spec")
|
||||
}
|
||||
|
||||
pgTeams, err := c.KubeClient.AcidV1ClientSet.AcidV1().PostgresTeams(pgTeam.Namespace).List(context.TODO(), metav1.ListOptions{})
|
||||
if err != nil {
|
||||
c.logger.Errorf("could not list postgres team objects: %v", err)
|
||||
}
|
||||
|
||||
pgTeamMap.Load(pgTeams)
|
||||
}
|
||||
|
||||
func (c *Controller) updatePostgresTeams(prev, obj interface{}) {
|
||||
c.loadPostgresTeams(obj)
|
||||
}
|
||||
|
||||
func (c *Controller) podClusterName(pod *v1.Pod) spec.NamespacedName {
|
||||
if name, ok := pod.Labels[c.opConfig.ClusterNameLabel]; ok {
|
||||
return spec.NamespacedName{
|
||||
|
||||
Reference in New Issue
Block a user