Documentation ¶
Index ¶
- Constants
- Variables
- func ByteMap(m *map[string][]byte)
- func IsBiggerPostgresVersion(old string, new string) bool
- func PointerEqualsValue[T comparable](ptr *T, v T) bool
- type Certificate
- type Cluster
- func (c *Cluster) AnnotationsToPropagate(annotations map[string]string) map[string]string
- func (c *Cluster) Create() (err error)
- func (c *Cluster) Delete()
- func (c *Cluster) ExecCommand(podName *spec.NamespacedName, command ...string) (string, error)
- func (c *Cluster) GetCurrentProcess() Process
- func (c *Cluster) GetDesiredMajorVersion() string
- func (c *Cluster) GetDesiredMajorVersionAsInt() int
- func (c *Cluster) GetEndpointMaster() *v1.Endpoints
- func (c *Cluster) GetEndpointReplica() *v1.Endpoints
- func (c *Cluster) GetPodDisruptionBudget() *policyv1.PodDisruptionBudget
- func (c *Cluster) GetReference() *v1.ObjectReference
- func (c *Cluster) GetServiceMaster() *v1.Service
- func (c *Cluster) GetServiceReplica() *v1.Service
- func (c *Cluster) GetSpec() (*cpov1.Postgresql, error)
- func (c *Cluster) GetStatefulSet() *appsv1.StatefulSet
- func (c *Cluster) GetStatus() *ClusterStatus
- func (c *Cluster) Lock()
- func (c *Cluster) MigrateMasterPod(podName spec.NamespacedName) error
- func (c *Cluster) MigrateReplicaPod(podName spec.NamespacedName, fromNodeName string) error
- func (c *Cluster) NeedsRepair() (bool, cpov1.PostgresStatus)
- func (c *Cluster) ReceivePodEvent(event PodEvent)
- func (c *Cluster) Run(stopCh <-chan struct{})
- func (c *Cluster) Switchover(curMaster *v1.Pod, candidate spec.NamespacedName) error
- func (c *Cluster) Sync(newSpec *cpov1.Postgresql) error
- func (c *Cluster) Unlock()
- func (c *Cluster) Update(oldSpec, newSpec *cpov1.Postgresql) error
- type ClusterStatus
- type Config
- type ConnectionPoolerObjects
- type InstallFunction
- type LeafCertificate
- type OAuthTokenGetter
- type PodEvent
- type PodEventType
- type PodType
- type PostgresRole
- type PrivateKey
- type Process
- type RootCertificateAuthority
- type SecretOauthTokenGetter
- type SyncReason
- type TemplateParams
- type WorkerStatus
Constants ¶
const ( TYPE_POSTGRESQL = PodType("postgresql") TYPE_REPOSITORY = PodType("repo-host") TYPE_BACKUP_JOB = PodType("backup-job") TYPE_LOGICAL_BACKUP = PodType("logical-backup") TYPE_POOLER = PodType("pooler") )
const (
CPOmonitoring = `` /* 1453-byte string literal not displayed */
)
Variables ¶
var VersionMap = map[string]int{
"10": 100000,
"11": 110000,
"12": 120000,
"13": 130000,
"14": 140000,
"15": 150000,
"16": 160000,
"17": 170000,
}
VersionMap Map of version numbers
Functions ¶
func IsBiggerPostgresVersion ¶
IsBiggerPostgresVersion Compare two Postgres version numbers
func PointerEqualsValue ¶
func PointerEqualsValue[T comparable](ptr *T, v T) bool
Types ¶
type Certificate ¶
type Certificate struct {
// contains filtered or unexported fields
}
Certificate represents an X.509 certificate that conforms to the Internet PKI Profile, RFC 5280.
func (Certificate) Equal ¶
func (c Certificate) Equal(other Certificate) bool
Equal reports whether c and other have the same value.
func (Certificate) MarshalText ¶
func (c Certificate) MarshalText() ([]byte, error)
MarshalText returns a PEM encoding of c that OpenSSL understands.
func (*Certificate) UnmarshalText ¶
func (c *Certificate) UnmarshalText(data []byte) error
UnmarshalText populates c from its PEM encoding.
type Cluster ¶
type Cluster struct { cpov1.Postgresql Config KubeClient k8sutil.KubernetesClient //TODO: move clients to the better place? ConnectionPooler map[PostgresRole]*ConnectionPoolerObjects EBSVolumes map[string]volumes.VolumeProperties VolumeResizer volumes.VolumeResizer // contains filtered or unexported fields }
Cluster describes postgresql cluster
func New ¶
func New(cfg Config, kubeClient k8sutil.KubernetesClient, pgSpec cpov1.Postgresql, logger *logrus.Entry, eventRecorder record.EventRecorder) *Cluster
New creates a new cluster. This function should be called from a controller.
func (*Cluster) AnnotationsToPropagate ¶
AnnotationsToPropagate get the annotations to update if required based on the annotations in postgres CRD
func (*Cluster) Delete ¶
func (c *Cluster) Delete()
Delete deletes the cluster and cleans up all objects associated with it (including statefulsets). The deletion order here is somewhat significant, because Patroni, when running with the Kubernetes DCS, reuses the master's endpoint to store the leader related metadata. If we remove the endpoint before the pods, it will be re-created by the current master pod and will remain, obstructing the creation of the new cluster with the same name. Therefore, the endpoints should be deleted last.
func (*Cluster) ExecCommand ¶
ExecCommand executes arbitrary command inside the pod
func (*Cluster) GetCurrentProcess ¶
GetCurrentProcess provides name of the last process of the cluster
func (*Cluster) GetDesiredMajorVersion ¶
GetDesiredMajorVersion returns major version to use, incl. potential auto upgrade
func (*Cluster) GetDesiredMajorVersionAsInt ¶
GetDesiredMajorVersionAsInt Convert string to comparable integer of PG version
func (*Cluster) GetEndpointMaster ¶
GetEndpointMaster returns cluster's kubernetes master Endpoint
func (*Cluster) GetEndpointReplica ¶
GetEndpointReplica returns cluster's kubernetes replica Endpoint
func (*Cluster) GetPodDisruptionBudget ¶
func (c *Cluster) GetPodDisruptionBudget() *policyv1.PodDisruptionBudget
GetPodDisruptionBudget returns cluster's kubernetes PodDisruptionBudget
func (*Cluster) GetReference ¶
func (c *Cluster) GetReference() *v1.ObjectReference
GetReference of Postgres CR object i.e. required to emit events to this resource
func (*Cluster) GetServiceMaster ¶
GetServiceMaster returns cluster's kubernetes master Service
func (*Cluster) GetServiceReplica ¶
GetServiceReplica returns cluster's kubernetes replica Service
func (*Cluster) GetSpec ¶
func (c *Cluster) GetSpec() (*cpov1.Postgresql, error)
GetSpec returns a copy of the operator-side spec of a Postgres cluster in a thread-safe manner
func (*Cluster) GetStatefulSet ¶
func (c *Cluster) GetStatefulSet() *appsv1.StatefulSet
GetStatefulSet returns cluster's kubernetes StatefulSet
func (*Cluster) GetStatus ¶
func (c *Cluster) GetStatus() *ClusterStatus
GetStatus provides status of the cluster
func (*Cluster) MigrateMasterPod ¶
func (c *Cluster) MigrateMasterPod(podName spec.NamespacedName) error
MigrateMasterPod migrates master pod via failover to a replica
func (*Cluster) MigrateReplicaPod ¶
func (c *Cluster) MigrateReplicaPod(podName spec.NamespacedName, fromNodeName string) error
MigrateReplicaPod recreates pod on a new node
func (*Cluster) NeedsRepair ¶
func (c *Cluster) NeedsRepair() (bool, cpov1.PostgresStatus)
NeedsRepair returns true if the cluster should be included in the repair scan (based on its in-memory status).
func (*Cluster) ReceivePodEvent ¶
ReceivePodEvent is called back by the controller in order to add the cluster's pod event to the queue.
func (*Cluster) Run ¶
func (c *Cluster) Run(stopCh <-chan struct{})
Run starts the pod event dispatching for the given cluster.
func (*Cluster) Switchover ¶
Switchover does a switchover (via Patroni) to a candidate pod
func (*Cluster) Sync ¶
func (c *Cluster) Sync(newSpec *cpov1.Postgresql) error
Sync syncs the cluster, making sure the actual Kubernetes objects correspond to what is defined in the manifest. Unlike the update, sync does not error out if some objects do not exist and takes care of creating them.
func (*Cluster) Update ¶
func (c *Cluster) Update(oldSpec, newSpec *cpov1.Postgresql) error
Update changes Kubernetes objects according to the new specification. Unlike the sync case, the missing object (i.e. service) is treated as an error logical backup cron jobs are an exception: a user-initiated Update can enable a logical backup job for a cluster that had no such job before. In this case a missing job is not an error.
type ClusterStatus ¶
type ClusterStatus struct { Team string Cluster string Namespace string MasterService *v1.Service ReplicaService *v1.Service ClusterPodsService *v1.Service MasterEndpoint *v1.Endpoints ReplicaEndpoint *v1.Endpoints StatefulSet *appsv1.StatefulSet PodDisruptionBudget *policyv1.PodDisruptionBudget CurrentProcess Process Worker uint32 Status cpov1.PostgresStatus Spec cpov1.PostgresSpec Error error }
ClusterStatus describes status of the cluster
type Config ¶
type Config struct { OpConfig config.Config RestConfig *rest.Config PgTeamMap *pgteams.PostgresTeamMap InfrastructureRoles map[string]spec.PgUser // inherited from the controller PodServiceAccount *v1.ServiceAccount PodServiceAccountRoleBinding *rbacv1.RoleBinding }
Config contains operator-wide clients and configuration used from a cluster. TODO: remove struct duplication.
type ConnectionPoolerObjects ¶
type ConnectionPoolerObjects struct { Deployment *appsv1.Deployment Service *v1.Service Name string ClusterName string Namespace string Role PostgresRole // It could happen that a connection pooler was enabled, but the operator // was not able to properly process a corresponding event or was restarted. // In this case we will miss missing/require situation and a lookup function // will not be installed. To avoid synchronizing it all the time to prevent // this, we can remember the result in memory at least until the next // restart. LookupFunction bool }
ConnectionPoolerObjects K8s objects that are belong to connection pooler
type InstallFunction ¶
type LeafCertificate ¶
type LeafCertificate struct { Certificate Certificate PrivateKey PrivateKey }
LeafCertificate is a certificate and private key pair that can be validated by RootCertificateAuthority.
type OAuthTokenGetter ¶
type OAuthTokenGetter interface {
// contains filtered or unexported methods
}
OAuthTokenGetter provides the method for fetching OAuth tokens
type PodEvent ¶
type PodEvent struct { ResourceVersion string PodName types.NamespacedName PrevPod *v1.Pod CurPod *v1.Pod EventType PodEventType }
PodEvent describes the event for a single Pod
type PodEventType ¶
type PodEventType string
PodEventType represents the type of a pod-related event
const ( PodEventAdd PodEventType = "ADD" PodEventUpdate PodEventType = "UPDATE" PodEventDelete PodEventType = "DELETE" )
Possible values for the EventType
type PostgresRole ¶
type PostgresRole string
PostgresRole describes role of the node
const ( // spilo roles Master PostgresRole = "master" Replica PostgresRole = "replica" // roles returned by Patroni cluster endpoint Leader PostgresRole = "leader" StandbyLeader PostgresRole = "standby_leader" SyncStandby PostgresRole = "sync_standby" // clusterrole for service ClusterPods PostgresRole = "clusterpods" )
type PrivateKey ¶
type PrivateKey struct {
// contains filtered or unexported fields
}
PrivateKey represents the private key of a Certificate.
func (PrivateKey) MarshalText ¶
func (k PrivateKey) MarshalText() ([]byte, error)
MarshalText returns a PEM encoding of k that OpenSSL understands.
func (*PrivateKey) UnmarshalText ¶
func (k *PrivateKey) UnmarshalText(data []byte) error
UnmarshalText populates k from its PEM encoding.
type RootCertificateAuthority ¶
type RootCertificateAuthority struct { Certificate Certificate PrivateKey PrivateKey }
func NewRootCertificateAuthority ¶
func NewRootCertificateAuthority() (*RootCertificateAuthority, error)
NewRootCertificateAuthority generates a new key and self-signed certificate for issuing other certificates.
func (*RootCertificateAuthority) GenerateLeafCertificate ¶
func (root *RootCertificateAuthority) GenerateLeafCertificate( commonName string, dnsNames []string, server bool, ) (*LeafCertificate, error)
GenerateLeafCertificate generates a new key and certificate signed by root.
type SecretOauthTokenGetter ¶
type SecretOauthTokenGetter struct { OAuthTokenSecretName spec.NamespacedName // contains filtered or unexported fields }
SecretOauthTokenGetter enables fetching OAuth tokens by reading Kubernetes secrets
type SyncReason ¶
type SyncReason []string
var NoSync SyncReason = []string{}
no sync happened, empty value
type TemplateParams ¶
type TemplateParams map[string]interface{}
type WorkerStatus ¶
type WorkerStatus struct { CurrentCluster types.NamespacedName CurrentProcess Process }
WorkerStatus describes status of the worker