Skip to content
Snippets Groups Projects
Select Git revision
  • f9e14d25170f26cf12367e29a2496c3767f5f839
  • master default protected
  • spilo-wale-removal
  • dependabot/go_modules/golang.org/x/oauth2-0.27.0
  • bug-upgrade
  • gh-pages
  • patroni-4-integration
  • remove-zappr
  • ignore-auto-upgrade
  • arm-pooler
  • update-go-and-deps
  • pluralsh-liveness-probe
  • silenium-dev-master
  • bump-v1.9.1
  • enable-query-logging
  • bump-v1.7.1
  • resize-mixed-mode
  • instance-annotation
  • bump-v1.8.2
  • clone-bucket-prefix
  • bump-v1.8.1
  • v1.14.0
  • v1.13.0
  • v1.12.2
  • v1.12.1
  • v1.12.0
  • v1.11.0
  • v1.10.1
  • v1.10.0
  • v1.9.0
  • v1.8.2
  • v1.8.1
  • v1.8.0
  • v1.7.1
  • v1.7.0
  • v1.6.3
  • v1.6.2
  • v1.6.1
  • v1.6.0
  • v1.5.0
  • v1.4.0
41 results

config.go

Blame
  • user avatar
    Oleksii Kliukin authored
    Previously, the operator started to move the pods off the nodes to be
    decomissioned by watching the eol_node_label value. Every new postgres
    pod has been created with the anti-affinity to that label, making sure
    that the pods being moved won't land on another to be decomissioned
    node.
    
    The changes introduce another label that indicates the ready node.  The
    new pod affinity will esnure that the pod is only scheduled to the node
    marked as ready, discarding the previous anti-affinity.  That way the
    nodes can transition from the pending-decomission to the other statuses
    (drained, terminating) without having pods suddently scaled to them.
    
    In addition, rename the label that triggers the start of the upgrade
    process to node_eol_label (for consistency with node_readiness_label)
    and set its default vvalue to lifecycle-status:pending-decomission.
    f9e14d25
    History
    config.go 5.83 KiB
    package config
    
    import (
    	"encoding/json"
    	"strings"
    	"time"
    
    	"github.com/zalando-incubator/postgres-operator/pkg/spec"
    )
    
    // CRD describes CustomResourceDefinition specific configuration parameters
    type CRD struct {
    	ReadyWaitInterval time.Duration `name:"ready_wait_interval" default:"4s"`
    	ReadyWaitTimeout  time.Duration `name:"ready_wait_timeout" default:"30s"`
    	ResyncPeriod      time.Duration `name:"resync_period" default:"5m"`
    }
    
    // Resources describes kubernetes resource specific configuration parameters
    type Resources struct {
    	ResourceCheckInterval   time.Duration     `name:"resource_check_interval" default:"3s"`
    	ResourceCheckTimeout    time.Duration     `name:"resource_check_timeout" default:"10m"`
    	PodLabelWaitTimeout     time.Duration     `name:"pod_label_wait_timeout" default:"10m"`
    	PodDeletionWaitTimeout  time.Duration     `name:"pod_deletion_wait_timeout" default:"10m"`
    	PodTerminateGracePeriod time.Duration     `name:"pod_terminate_grace_period" default:"5m"`
    	ClusterLabels           map[string]string `name:"cluster_labels" default:"application:spilo"`
    	ClusterNameLabel        string            `name:"cluster_name_label" default:"cluster-name"`
    	PodRoleLabel            string            `name:"pod_role_label" default:"spilo-role"`
    	PodToleration           map[string]string `name:"toleration" default:""`
    	DefaultCPURequest       string            `name:"default_cpu_request" default:"100m"`
    	DefaultMemoryRequest    string            `name:"default_memory_request" default:"100Mi"`
    	DefaultCPULimit         string            `name:"default_cpu_limit" default:"3"`
    	DefaultMemoryLimit      string            `name:"default_memory_limit" default:"1Gi"`
    	NodeEOLLabel            map[string]string `name:"node_eol_label" default:"lifecycle-status:pending-decommission"`
    	NodeReadinessLabel      map[string]string `name:"node_readiness_label" default:"lifecycle-status:ready"`
    }
    
    // Auth describes authentication specific configuration parameters
    type Auth struct {
    	SecretNameTemplate            stringTemplate      `name:"secret_name_template" default:"{username}.{cluster}.credentials.{tprkind}.{tprgroup}"`
    	PamRoleName                   string              `name:"pam_role_name" default:"zalandos"`
    	PamConfiguration              string              `name:"pam_configuration" default:"https://info.example.com/oauth2/tokeninfo?access_token= uid realm=/employees"`
    	TeamsAPIUrl                   string              `name:"teams_api_url" default:"https://teams.example.com/api/"`
    	OAuthTokenSecretName          spec.NamespacedName `name:"oauth_token_secret_name" default:"postgresql-operator"`
    	InfrastructureRolesSecretName spec.NamespacedName `name:"infrastructure_roles_secret_name"`
    	SuperUsername                 string              `name:"super_username" default:"postgres"`
    	ReplicationUsername           string              `name:"replication_username" default:"standby"`
    }
    
    // Config describes operator config
    type Config struct {
    	CRD
    	Resources
    	Auth
    	Namespace                string            `name:"namespace"`
    	EtcdHost                 string            `name:"etcd_host" default:"etcd-client.default.svc.cluster.local:2379"`
    	DockerImage              string            `name:"docker_image" default:"registry.opensource.zalan.do/acid/spiloprivate-9.6:1.2-p4"`
    	ServiceAccountName       string            `name:"service_account_name" default:"operator"`
    	DbHostedZone             string            `name:"db_hosted_zone" default:"db.example.com"`
    	EtcdScope                string            `name:"etcd_scope" default:"service"`
    	WALES3Bucket             string            `name:"wal_s3_bucket"`
    	KubeIAMRole              string            `name:"kube_iam_role"`
    	DebugLogging             bool              `name:"debug_logging" default:"true"`
    	EnableDBAccess           bool              `name:"enable_database_access" default:"true"`
    	EnableTeamsAPI           bool              `name:"enable_teams_api" default:"true"`
    	EnableTeamSuperuser      bool              `name:"enable_team_superuser" default:"false"`
    	TeamAdminRole            string            `name:"team_admin_role" default:"admin"`
    	EnableLoadBalancer       bool              `name:"enable_load_balancer" default:"true"`
    	MasterDNSNameFormat      stringTemplate    `name:"master_dns_name_format" default:"{cluster}.{team}.{hostedzone}"`
    	ReplicaDNSNameFormat     stringTemplate    `name:"replica_dns_name_format" default:"{cluster}-repl.{team}.{hostedzone}"`
    	PDBNameFormat            stringTemplate    `name:"pdb_name_format" default:"postgres-{cluster}-pdb"`
    	Workers                  uint32            `name:"workers" default:"4"`
    	APIPort                  int               `name:"api_port" default:"8080"`
    	RingLogLines             int               `name:"ring_log_lines" default:"100"`
    	ClusterHistoryEntries    int               `name:"cluster_history_entries" default:"1000"`
    	TeamAPIRoleConfiguration map[string]string `name:"team_api_role_configuration" default:"log_statement:all"`
    	PodTerminateGracePeriod  time.Duration     `name:"pod_terminate_grace_period" default:"5m"`
    }
    
    // MustMarshal marshals the config or panics
    func (c Config) MustMarshal() string {
    	b, err := json.MarshalIndent(c, "", "\t")
    	if err != nil {
    		panic(err)
    	}
    
    	return string(b)
    }
    
    // NewFromMap creates Config from the map
    func NewFromMap(m map[string]string) *Config {
    	cfg := Config{}
    	fields, _ := structFields(&cfg)
    
    	for _, structField := range fields {
    		key := strings.ToLower(structField.Name)
    		value, ok := m[key]
    		if !ok && structField.Default != "" {
    			value = structField.Default
    		}
    
    		if value == "" {
    			continue
    		}
    		err := processField(value, structField.Field)
    		if err != nil {
    			panic(err)
    		}
    	}
    
    	return &cfg
    }
    
    // Copy creates a copy of the config
    func Copy(c *Config) Config {
    	cfg := *c
    
    	cfg.ClusterLabels = make(map[string]string, len(c.ClusterLabels))
    	for k, v := range c.ClusterLabels {
    		cfg.ClusterLabels[k] = v
    	}
    
    	return cfg
    }