add new parameter for Patroni API (PatroniAPICheckInterval, PatroniAPICheckTimeout) (#1803)
Co-authored-by: Jociele Padilha <jociele.padilha@zalando.de>
This commit is contained in:
		
							parent
							
								
									d032e4783e
								
							
						
					
					
						commit
						69254abeba
					
				| 
						 | 
					@ -349,6 +349,12 @@ spec:
 | 
				
			||||||
              timeouts:
 | 
					              timeouts:
 | 
				
			||||||
                type: object
 | 
					                type: object
 | 
				
			||||||
                properties:
 | 
					                properties:
 | 
				
			||||||
 | 
					                  patroni_api_check_interval:
 | 
				
			||||||
 | 
					                    type: string
 | 
				
			||||||
 | 
					                    default: "1s"
 | 
				
			||||||
 | 
					                  patroni_api_check_timeout:
 | 
				
			||||||
 | 
					                    type: string
 | 
				
			||||||
 | 
					                    default: "5s"
 | 
				
			||||||
                  pod_label_wait_timeout:
 | 
					                  pod_label_wait_timeout:
 | 
				
			||||||
                    type: string
 | 
					                    type: string
 | 
				
			||||||
                    default: "10m"
 | 
					                    default: "10m"
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -204,6 +204,10 @@ configPostgresPodResources:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# timeouts related to some operator actions
 | 
					# timeouts related to some operator actions
 | 
				
			||||||
configTimeouts:
 | 
					configTimeouts:
 | 
				
			||||||
 | 
					  # interval between consecutive attempts of operator calling the Patroni API
 | 
				
			||||||
 | 
					  patroni_api_check_interval: 1s
 | 
				
			||||||
 | 
					  # timeout when waiting for successful response from Patroni API
 | 
				
			||||||
 | 
					  patroni_api_check_timeout: 5s
 | 
				
			||||||
  # timeout when waiting for the Postgres pods to be deleted
 | 
					  # timeout when waiting for the Postgres pods to be deleted
 | 
				
			||||||
  pod_deletion_wait_timeout: 10m
 | 
					  pod_deletion_wait_timeout: 10m
 | 
				
			||||||
  # timeout when waiting for pod role and cluster labels
 | 
					  # timeout when waiting for pod role and cluster labels
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -498,6 +498,13 @@ configuration `resource_check_interval` and `resource_check_timeout` have no
 | 
				
			||||||
effect, and the parameters are grouped under the `timeouts` key in the
 | 
					effect, and the parameters are grouped under the `timeouts` key in the
 | 
				
			||||||
CRD-based configuration.
 | 
					CRD-based configuration.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					* **PatroniAPICheckInterval**
 | 
				
			||||||
 | 
					  the interval between consecutive attempts waiting for the return of 
 | 
				
			||||||
 | 
					  Patroni Api. The default is `1s`.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					* **PatroniAPICheckTimeout**
 | 
				
			||||||
 | 
					  the timeout for a response from Patroni Api. The default is `5s`.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
* **resource_check_interval**
 | 
					* **resource_check_interval**
 | 
				
			||||||
  interval to wait between consecutive attempts to check for the presence of
 | 
					  interval to wait between consecutive attempts to check for the presence of
 | 
				
			||||||
  some Kubernetes resource (i.e. `StatefulSet` or `PodDisruptionBudget`). The
 | 
					  some Kubernetes resource (i.e. `StatefulSet` or `PodDisruptionBudget`). The
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -96,6 +96,8 @@ data:
 | 
				
			||||||
  # pam_configuration: |
 | 
					  # pam_configuration: |
 | 
				
			||||||
  #  https://info.example.com/oauth2/tokeninfo?access_token= uid realm=/employees
 | 
					  #  https://info.example.com/oauth2/tokeninfo?access_token= uid realm=/employees
 | 
				
			||||||
  # pam_role_name: zalandos
 | 
					  # pam_role_name: zalandos
 | 
				
			||||||
 | 
					  patroni_api_check_interval: "1s"
 | 
				
			||||||
 | 
					  patroni_api_check_timeout: "5s"
 | 
				
			||||||
  # password_rotation_interval: "90"
 | 
					  # password_rotation_interval: "90"
 | 
				
			||||||
  # password_rotation_user_retention: "180"
 | 
					  # password_rotation_user_retention: "180"
 | 
				
			||||||
  pdb_name_format: "postgres-{cluster}-pdb"
 | 
					  pdb_name_format: "postgres-{cluster}-pdb"
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -347,6 +347,12 @@ spec:
 | 
				
			||||||
              timeouts:
 | 
					              timeouts:
 | 
				
			||||||
                type: object
 | 
					                type: object
 | 
				
			||||||
                properties:
 | 
					                properties:
 | 
				
			||||||
 | 
					                  patroni_api_check_interval:
 | 
				
			||||||
 | 
					                    type: string
 | 
				
			||||||
 | 
					                    default: "1s"
 | 
				
			||||||
 | 
					                  patroni_api_check_timeout:
 | 
				
			||||||
 | 
					                    type: string
 | 
				
			||||||
 | 
					                    default: "5s"
 | 
				
			||||||
                  pod_label_wait_timeout:
 | 
					                  pod_label_wait_timeout:
 | 
				
			||||||
                    type: string
 | 
					                    type: string
 | 
				
			||||||
                    default: "10m"
 | 
					                    default: "10m"
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -107,6 +107,8 @@ configuration:
 | 
				
			||||||
    # min_cpu_limit: 250m
 | 
					    # min_cpu_limit: 250m
 | 
				
			||||||
    # min_memory_limit: 250Mi
 | 
					    # min_memory_limit: 250Mi
 | 
				
			||||||
  timeouts:
 | 
					  timeouts:
 | 
				
			||||||
 | 
					    patroni_api_check_interval: 1s
 | 
				
			||||||
 | 
					    patroni_api_check_timeout: 5s
 | 
				
			||||||
    pod_label_wait_timeout: 10m
 | 
					    pod_label_wait_timeout: 10m
 | 
				
			||||||
    pod_deletion_wait_timeout: 10m
 | 
					    pod_deletion_wait_timeout: 10m
 | 
				
			||||||
    ready_wait_interval: 4s
 | 
					    ready_wait_interval: 4s
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1438,6 +1438,12 @@ var OperatorConfigCRDResourceValidation = apiextv1.CustomResourceValidation{
 | 
				
			||||||
					"timeouts": {
 | 
										"timeouts": {
 | 
				
			||||||
						Type: "object",
 | 
											Type: "object",
 | 
				
			||||||
						Properties: map[string]apiextv1.JSONSchemaProps{
 | 
											Properties: map[string]apiextv1.JSONSchemaProps{
 | 
				
			||||||
 | 
												"patroni_api_check_interval": {
 | 
				
			||||||
 | 
													Type: "string",
 | 
				
			||||||
 | 
												},
 | 
				
			||||||
 | 
												"patroni_api_check_timeout": {
 | 
				
			||||||
 | 
													Type: "string",
 | 
				
			||||||
 | 
												},
 | 
				
			||||||
							"pod_label_wait_timeout": {
 | 
												"pod_label_wait_timeout": {
 | 
				
			||||||
								Type: "string",
 | 
													Type: "string",
 | 
				
			||||||
							},
 | 
												},
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -111,12 +111,14 @@ type PostgresPodResourcesDefaults struct {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// OperatorTimeouts defines the timeout of ResourceCheck, PodWait, ReadyWait
 | 
					// OperatorTimeouts defines the timeout of ResourceCheck, PodWait, ReadyWait
 | 
				
			||||||
type OperatorTimeouts struct {
 | 
					type OperatorTimeouts struct {
 | 
				
			||||||
	ResourceCheckInterval  Duration `json:"resource_check_interval,omitempty"`
 | 
						ResourceCheckInterval   Duration `json:"resource_check_interval,omitempty"`
 | 
				
			||||||
	ResourceCheckTimeout   Duration `json:"resource_check_timeout,omitempty"`
 | 
						ResourceCheckTimeout    Duration `json:"resource_check_timeout,omitempty"`
 | 
				
			||||||
	PodLabelWaitTimeout    Duration `json:"pod_label_wait_timeout,omitempty"`
 | 
						PodLabelWaitTimeout     Duration `json:"pod_label_wait_timeout,omitempty"`
 | 
				
			||||||
	PodDeletionWaitTimeout Duration `json:"pod_deletion_wait_timeout,omitempty"`
 | 
						PodDeletionWaitTimeout  Duration `json:"pod_deletion_wait_timeout,omitempty"`
 | 
				
			||||||
	ReadyWaitInterval      Duration `json:"ready_wait_interval,omitempty"`
 | 
						ReadyWaitInterval       Duration `json:"ready_wait_interval,omitempty"`
 | 
				
			||||||
	ReadyWaitTimeout       Duration `json:"ready_wait_timeout,omitempty"`
 | 
						ReadyWaitTimeout        Duration `json:"ready_wait_timeout,omitempty"`
 | 
				
			||||||
 | 
						PatroniAPICheckInterval Duration `json:"patroni_api_check_interval,omitempty"`
 | 
				
			||||||
 | 
						PatroniAPICheckTimeout  Duration `json:"patroni_api_check_timeout,omitempty"`
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// LoadBalancerConfiguration defines the LB configuration
 | 
					// LoadBalancerConfiguration defines the LB configuration
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -67,7 +67,7 @@ func (c *Cluster) markRollingUpdateFlagForPod(pod *v1.Pod, msg string) error {
 | 
				
			||||||
		return fmt.Errorf("could not form patch for pod's rolling update flag: %v", err)
 | 
							return fmt.Errorf("could not form patch for pod's rolling update flag: %v", err)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	err = retryutil.Retry(1*time.Second, 5*time.Second,
 | 
						err = retryutil.Retry(c.OpConfig.PatroniAPICheckInterval, c.OpConfig.PatroniAPICheckTimeout,
 | 
				
			||||||
		func() (bool, error) {
 | 
							func() (bool, error) {
 | 
				
			||||||
			_, err2 := c.KubeClient.Pods(pod.Namespace).Patch(
 | 
								_, err2 := c.KubeClient.Pods(pod.Namespace).Patch(
 | 
				
			||||||
				context.TODO(),
 | 
									context.TODO(),
 | 
				
			||||||
| 
						 | 
					@ -356,7 +356,7 @@ func (c *Cluster) getPatroniConfig(pod *v1.Pod) (acidv1.Patroni, map[string]stri
 | 
				
			||||||
		pgParameters  map[string]string
 | 
							pgParameters  map[string]string
 | 
				
			||||||
	)
 | 
						)
 | 
				
			||||||
	podName := util.NameFromMeta(pod.ObjectMeta)
 | 
						podName := util.NameFromMeta(pod.ObjectMeta)
 | 
				
			||||||
	err := retryutil.Retry(1*time.Second, 5*time.Second,
 | 
						err := retryutil.Retry(c.OpConfig.PatroniAPICheckInterval, c.OpConfig.PatroniAPICheckTimeout,
 | 
				
			||||||
		func() (bool, error) {
 | 
							func() (bool, error) {
 | 
				
			||||||
			var err error
 | 
								var err error
 | 
				
			||||||
			patroniConfig, pgParameters, err = c.patroni.GetConfig(pod)
 | 
								patroniConfig, pgParameters, err = c.patroni.GetConfig(pod)
 | 
				
			||||||
| 
						 | 
					@ -377,7 +377,7 @@ func (c *Cluster) getPatroniConfig(pod *v1.Pod) (acidv1.Patroni, map[string]stri
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (c *Cluster) getPatroniMemberData(pod *v1.Pod) (patroni.MemberData, error) {
 | 
					func (c *Cluster) getPatroniMemberData(pod *v1.Pod) (patroni.MemberData, error) {
 | 
				
			||||||
	var memberData patroni.MemberData
 | 
						var memberData patroni.MemberData
 | 
				
			||||||
	err := retryutil.Retry(1*time.Second, 5*time.Second,
 | 
						err := retryutil.Retry(c.OpConfig.PatroniAPICheckInterval, c.OpConfig.PatroniAPICheckTimeout,
 | 
				
			||||||
		func() (bool, error) {
 | 
							func() (bool, error) {
 | 
				
			||||||
			var err error
 | 
								var err error
 | 
				
			||||||
			memberData, err = c.patroni.GetMemberData(pod)
 | 
								memberData, err = c.patroni.GetMemberData(pod)
 | 
				
			||||||
| 
						 | 
					@ -403,7 +403,7 @@ func (c *Cluster) recreatePod(podName spec.NamespacedName) (*v1.Pod, error) {
 | 
				
			||||||
	defer c.unregisterPodSubscriber(podName)
 | 
						defer c.unregisterPodSubscriber(podName)
 | 
				
			||||||
	stopChan := make(chan struct{})
 | 
						stopChan := make(chan struct{})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	err := retryutil.Retry(1*time.Second, 5*time.Second,
 | 
						err := retryutil.Retry(c.OpConfig.PatroniAPICheckInterval, c.OpConfig.PatroniAPICheckTimeout,
 | 
				
			||||||
		func() (bool, error) {
 | 
							func() (bool, error) {
 | 
				
			||||||
			err2 := c.KubeClient.Pods(podName.Namespace).Delete(
 | 
								err2 := c.KubeClient.Pods(podName.Namespace).Delete(
 | 
				
			||||||
				context.TODO(),
 | 
									context.TODO(),
 | 
				
			||||||
| 
						 | 
					@ -492,7 +492,7 @@ func (c *Cluster) getSwitchoverCandidate(master *v1.Pod) (spec.NamespacedName, e
 | 
				
			||||||
	candidates := make([]patroni.ClusterMember, 0)
 | 
						candidates := make([]patroni.ClusterMember, 0)
 | 
				
			||||||
	syncCandidates := make([]patroni.ClusterMember, 0)
 | 
						syncCandidates := make([]patroni.ClusterMember, 0)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	err := retryutil.Retry(1*time.Second, 5*time.Second,
 | 
						err := retryutil.Retry(c.OpConfig.PatroniAPICheckInterval, c.OpConfig.PatroniAPICheckTimeout,
 | 
				
			||||||
		func() (bool, error) {
 | 
							func() (bool, error) {
 | 
				
			||||||
			var err error
 | 
								var err error
 | 
				
			||||||
			members, err = c.patroni.GetClusterMembers(master)
 | 
								members, err = c.patroni.GetClusterMembers(master)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -6,11 +6,13 @@ import (
 | 
				
			||||||
	"io/ioutil"
 | 
						"io/ioutil"
 | 
				
			||||||
	"net/http"
 | 
						"net/http"
 | 
				
			||||||
	"testing"
 | 
						"testing"
 | 
				
			||||||
 | 
						"time"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	"github.com/golang/mock/gomock"
 | 
						"github.com/golang/mock/gomock"
 | 
				
			||||||
	"github.com/zalando/postgres-operator/mocks"
 | 
						"github.com/zalando/postgres-operator/mocks"
 | 
				
			||||||
	acidv1 "github.com/zalando/postgres-operator/pkg/apis/acid.zalan.do/v1"
 | 
						acidv1 "github.com/zalando/postgres-operator/pkg/apis/acid.zalan.do/v1"
 | 
				
			||||||
	"github.com/zalando/postgres-operator/pkg/spec"
 | 
						"github.com/zalando/postgres-operator/pkg/spec"
 | 
				
			||||||
 | 
						"github.com/zalando/postgres-operator/pkg/util/config"
 | 
				
			||||||
	"github.com/zalando/postgres-operator/pkg/util/k8sutil"
 | 
						"github.com/zalando/postgres-operator/pkg/util/k8sutil"
 | 
				
			||||||
	"github.com/zalando/postgres-operator/pkg/util/patroni"
 | 
						"github.com/zalando/postgres-operator/pkg/util/patroni"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
| 
						 | 
					@ -22,7 +24,13 @@ func TestGetSwitchoverCandidate(t *testing.T) {
 | 
				
			||||||
	ctrl := gomock.NewController(t)
 | 
						ctrl := gomock.NewController(t)
 | 
				
			||||||
	defer ctrl.Finish()
 | 
						defer ctrl.Finish()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	var cluster = New(Config{}, k8sutil.KubernetesClient{}, acidv1.Postgresql{}, logger, eventRecorder)
 | 
						var cluster = New(
 | 
				
			||||||
 | 
							Config{
 | 
				
			||||||
 | 
								OpConfig: config.Config{
 | 
				
			||||||
 | 
									PatroniAPICheckInterval: time.Duration(1),
 | 
				
			||||||
 | 
									PatroniAPICheckTimeout:  time.Duration(5),
 | 
				
			||||||
 | 
								},
 | 
				
			||||||
 | 
							}, k8sutil.KubernetesClient{}, acidv1.Postgresql{}, logger, eventRecorder)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// simulate different member scenarios
 | 
						// simulate different member scenarios
 | 
				
			||||||
	tests := []struct {
 | 
						tests := []struct {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -134,6 +134,8 @@ func (c *Controller) importConfigurationFromCRD(fromCRD *acidv1.OperatorConfigur
 | 
				
			||||||
	result.PodDeletionWaitTimeout = util.CoalesceDuration(time.Duration(fromCRD.Timeouts.PodDeletionWaitTimeout), "10m")
 | 
						result.PodDeletionWaitTimeout = util.CoalesceDuration(time.Duration(fromCRD.Timeouts.PodDeletionWaitTimeout), "10m")
 | 
				
			||||||
	result.ReadyWaitInterval = util.CoalesceDuration(time.Duration(fromCRD.Timeouts.ReadyWaitInterval), "4s")
 | 
						result.ReadyWaitInterval = util.CoalesceDuration(time.Duration(fromCRD.Timeouts.ReadyWaitInterval), "4s")
 | 
				
			||||||
	result.ReadyWaitTimeout = util.CoalesceDuration(time.Duration(fromCRD.Timeouts.ReadyWaitTimeout), "30s")
 | 
						result.ReadyWaitTimeout = util.CoalesceDuration(time.Duration(fromCRD.Timeouts.ReadyWaitTimeout), "30s")
 | 
				
			||||||
 | 
						result.PatroniAPICheckInterval = util.CoalesceDuration(time.Duration(fromCRD.Timeouts.PatroniAPICheckInterval), "1s")
 | 
				
			||||||
 | 
						result.PatroniAPICheckTimeout = util.CoalesceDuration(time.Duration(fromCRD.Timeouts.PatroniAPICheckTimeout), "5s")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// load balancer config
 | 
						// load balancer config
 | 
				
			||||||
	result.DbHostedZone = util.Coalesce(fromCRD.LoadBalancer.DbHostedZone, "db.example.com")
 | 
						result.DbHostedZone = util.Coalesce(fromCRD.LoadBalancer.DbHostedZone, "db.example.com")
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -224,6 +224,8 @@ type Config struct {
 | 
				
			||||||
	MajorVersionUpgradeTeamAllowList       []string          `name:"major_version_upgrade_team_allow_list" default:""`
 | 
						MajorVersionUpgradeTeamAllowList       []string          `name:"major_version_upgrade_team_allow_list" default:""`
 | 
				
			||||||
	MinimalMajorVersion                    string            `name:"minimal_major_version" default:"9.6"`
 | 
						MinimalMajorVersion                    string            `name:"minimal_major_version" default:"9.6"`
 | 
				
			||||||
	TargetMajorVersion                     string            `name:"target_major_version" default:"14"`
 | 
						TargetMajorVersion                     string            `name:"target_major_version" default:"14"`
 | 
				
			||||||
 | 
						PatroniAPICheckInterval                time.Duration     `name:"patroni_api_check_interval" default:"1s"`
 | 
				
			||||||
 | 
						PatroniAPICheckTimeout                 time.Duration     `name:"patroni_api_check_timeout" default:"5s"`
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// MustMarshal marshals the config or panics
 | 
					// MustMarshal marshals the config or panics
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue