Apply the configuration from CRD.

This commit is contained in:
Oleksii Kliukin 2018-06-13 12:59:10 +02:00
parent 5a6aa9b6d9
commit e558240fdf
8 changed files with 209 additions and 121 deletions

View File

@ -7,6 +7,7 @@ import (
"os/signal" "os/signal"
"sync" "sync"
"syscall" "syscall"
"time"
"github.com/zalando-incubator/postgres-operator/pkg/controller" "github.com/zalando-incubator/postgres-operator/pkg/controller"
"github.com/zalando-incubator/postgres-operator/pkg/spec" "github.com/zalando-incubator/postgres-operator/pkg/spec"
@ -20,6 +21,14 @@ var (
config spec.ControllerConfig config spec.ControllerConfig
) )
func mustParseDuration(d string) time.Duration {
duration, err := time.ParseDuration(d)
if err != nil {
panic(err)
}
return duration
}
func init() { func init() {
flag.StringVar(&kubeConfigFile, "kubeconfig", "", "Path to kubeconfig file with authorization and master location information.") flag.StringVar(&kubeConfigFile, "kubeconfig", "", "Path to kubeconfig file with authorization and master location information.")
flag.BoolVar(&outOfCluster, "outofcluster", false, "Whether the operator runs in- our outside of the Kubernetes cluster.") flag.BoolVar(&outOfCluster, "outofcluster", false, "Whether the operator runs in- our outside of the Kubernetes cluster.")
@ -38,6 +47,17 @@ func init() {
log.Printf("Fully qualified configmap name: %v", config.ConfigMapName) log.Printf("Fully qualified configmap name: %v", config.ConfigMapName)
} }
if crd_interval := os.Getenv("CRD_READY_WAIT_INTERVAL"); crd_interval != "" {
config.CRDReadyWaitInterval = mustParseDuration(crd_interval)
} else {
config.CRDReadyWaitInterval = 4 * time.Second
}
if crd_timeout := os.Getenv("CRD_READY_WAIT_TIMEOUT"); crd_timeout != "" {
config.CRDReadyWaitTimeout = mustParseDuration(crd_timeout)
} else {
config.CRDReadyWaitTimeout = 30 * time.Second
}
} }
func main() { func main() {

View File

@ -101,23 +101,24 @@ func (c *Controller) initOperatorConfig() {
c.logger.Infoln("no ConfigMap specified. Loading default values") c.logger.Infoln("no ConfigMap specified. Loading default values")
} }
configMapData["watched_namespace"] = c.getEffectiveNamespace(os.Getenv("WATCHED_NAMESPACE"), configMapData["watched_namespace"])
if c.config.NoDatabaseAccess {
configMapData["enable_database_access"] = "false"
}
if c.config.NoTeamsAPI {
configMapData["enable_teams_api"] = "false"
}
c.opConfig = config.NewFromMap(configMapData) c.opConfig = config.NewFromMap(configMapData)
c.warnOnDeprecatedOperatorParameters() c.warnOnDeprecatedOperatorParameters()
}
func (c *Controller) modifyConfigFromEnvironment() {
c.opConfig.WatchedNamespace = c.getEffectiveNamespace(os.Getenv("WATCHED_NAMESPACE"), c.opConfig.WatchedNamespace)
if c.config.NoDatabaseAccess {
c.opConfig.EnableDBAccess = c.config.NoDatabaseAccess
}
if c.config.NoTeamsAPI {
c.opConfig.EnableTeamsAPI = c.config.NoTeamsAPI
}
scalyrAPIKey := os.Getenv("SCALYR_API_KEY") scalyrAPIKey := os.Getenv("SCALYR_API_KEY")
if scalyrAPIKey != "" { if scalyrAPIKey != "" {
c.opConfig.ScalyrAPIKey = scalyrAPIKey c.opConfig.ScalyrAPIKey = scalyrAPIKey
} }
} }
// warningOnDeprecatedParameters emits warnings upon finding deprecated parmaters // warningOnDeprecatedParameters emits warnings upon finding deprecated parmaters
@ -163,33 +164,34 @@ func (c *Controller) initPodServiceAccount() {
func (c *Controller) initController() { func (c *Controller) initController() {
c.initClients() c.initClients()
c.initOperatorConfig()
c.initPodServiceAccount()
c.initSharedInformers() if configObjectName := os.Getenv("POSTGRES_OPERATOR_CONFIGURATION_OBJECT"); configObjectName != "" {
if err := c.createOperatorCRD(); err != nil {
c.logger.Infof("config: %s", c.opConfig.MustMarshal()) c.logger.Fatalf("could not register Operator Configuration CustomResourceDefinition: %v", err)
}
if c.opConfig.DebugLogging { if cfg, err := c.readOperatorConfigurationFromCRD(configObjectName); err != nil {
c.logger.Logger.Level = logrus.DebugLevel c.logger.Fatalf("unable to read operator configuration: %v", err)
} else {
c.opConfig = c.importConfigurationFromCRD(&cfg.Configuration)
}
} else {
c.initOperatorConfig()
} }
c.modifyConfigFromEnvironment()
if err := c.createPostgresCRD(); err != nil { if err := c.createPostgresCRD(); err != nil {
c.logger.Fatalf("could not register Postgres CustomResourceDefinition: %v", err) c.logger.Fatalf("could not register Postgres CustomResourceDefinition: %v", err)
} }
if err := c.createOperatorCRD(); err != nil { c.initPodServiceAccount()
c.logger.Fatalf("could not register Operator Configuration CustomResourceDefinition: %v", err) c.initSharedInformers()
if c.opConfig.DebugLogging {
c.logger.Logger.Level = logrus.DebugLevel
} }
if configObjectName := os.Getenv("POSTGRES_OPERATOR_CONFIGURATION_OBJECT"); configObjectName != "" { c.logger.Infof("config: %s", c.opConfig.MustMarshal())
if config, err := c.readOperatorConfigurationFromCRD(configObjectName); err != nil {
c.logger.Fatalf("unable to read operator configuration: %v", err)
} else {
c.logger.Fatalf("operator configuration: %#v", config)
}
}
if infraRoles, err := c.getInfrastructureRoles(&c.opConfig.InfrastructureRolesSecretName); err != nil { if infraRoles, err := c.getInfrastructureRoles(&c.opConfig.InfrastructureRolesSecretName); err != nil {
c.logger.Warningf("could not get infrastructure roles: %v", err) c.logger.Warningf("could not get infrastructure roles: %v", err)

View File

@ -4,14 +4,12 @@ import (
"encoding/json" "encoding/json"
"fmt" "fmt"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"github.com/zalando-incubator/postgres-operator/pkg/util/constants"
"github.com/zalando-incubator/postgres-operator/pkg/util/config" "github.com/zalando-incubator/postgres-operator/pkg/util/config"
"github.com/zalando-incubator/postgres-operator/pkg/util/constants"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
) )
func (c *Controller) readOperatorConfigurationFromCRD(configObjectName string) (*config.OperatorConfiguration, error) {
func (c *Controller) readOperatorConfigurationFromCRD(configObjectName string) (*config.OperatorConfiguration, error){
var ( var (
config config.OperatorConfiguration config config.OperatorConfiguration
) )
@ -22,7 +20,7 @@ func (c *Controller) readOperatorConfigurationFromCRD(configObjectName string) (
Resource(constants.OperatorConfigCRDResource). Resource(constants.OperatorConfigCRDResource).
VersionedParams(&metav1.ListOptions{ResourceVersion: "0"}, metav1.ParameterCodec) VersionedParams(&metav1.ListOptions{ResourceVersion: "0"}, metav1.ParameterCodec)
data, err := req.DoRaw(); data, err := req.DoRaw()
if err != nil { if err != nil {
return nil, fmt.Errorf("could not get operator configuration object %s: %v", configObjectName, err) return nil, fmt.Errorf("could not get operator configuration object %s: %v", configObjectName, err)
} }
@ -31,4 +29,77 @@ func (c *Controller) readOperatorConfigurationFromCRD(configObjectName string) (
} }
return &config, nil return &config, nil
} }
// importConfigurationFromCRD is a transitional function that converts CRD configuration to the one based on the configmap
func (c *Controller) importConfigurationFromCRD(fromCRD *config.OperatorConfigurationData) *config.Config {
result := &config.Config{}
result.EtcdHost = fromCRD.EtcdHost
result.DockerImage = fromCRD.DockerImage
result.Workers = fromCRD.Workers
result.MinInstances = fromCRD.MinInstances
result.MaxInstances = fromCRD.MaxInstances
result.ResyncPeriod = fromCRD.ResyncPeriod
result.SuperUsername = fromCRD.PostgresUsersConfiguration.SuperUsername
result.ReplicationUsername = fromCRD.PostgresUsersConfiguration.ReplicationUsername
result.PodServiceAccountName = fromCRD.Kubernetes.PodServiceAccountName
result.PodServiceAccountDefinition = fromCRD.Kubernetes.PodServiceAccountDefinition
result.PodTerminateGracePeriod = fromCRD.Kubernetes.PodTerminateGracePeriod
result.WatchedNamespace = fromCRD.Kubernetes.WatchedNamespace
result.PDBNameFormat = fromCRD.Kubernetes.PDBNameFormat
result.SecretNameTemplate = fromCRD.Kubernetes.SecretNameTemplate
result.OAuthTokenSecretName = fromCRD.Kubernetes.OAuthTokenSecretName
result.InfrastructureRolesSecretName = fromCRD.Kubernetes.InfrastructureRolesSecretName
result.PodRoleLabel = fromCRD.Kubernetes.PodRoleLabel
result.ClusterLabels = fromCRD.Kubernetes.ClusterLabels
result.ClusterNameLabel = fromCRD.Kubernetes.ClusterNameLabel
result.NodeReadinessLabel = fromCRD.Kubernetes.NodeReadinessLabel
result.DefaultCPURequest = fromCRD.PostgresPodResources.DefaultCPURequest
result.DefaultMemoryRequest = fromCRD.PostgresPodResources.DefaultMemoryRequest
result.DefaultCPULimit = fromCRD.PostgresPodResources.DefaultCPULimit
result.DefaultMemoryLimit = fromCRD.PostgresPodResources.DefaultMemoryLimit
result.ResourceCheckInterval = fromCRD.Timeouts.ResourceCheckInterval
result.ResourceCheckTimeout = fromCRD.Timeouts.ResourceCheckTimeout
result.PodLabelWaitTimeout = fromCRD.Timeouts.PodLabelWaitTimeout
result.PodDeletionWaitTimeout = fromCRD.Timeouts.PodDeletionWaitTimeout
result.ReadyWaitInterval = fromCRD.Timeouts.ReadyWaitInterval
result.ReadyWaitTimeout = fromCRD.Timeouts.ReadyWaitTimeout
result.DbHostedZone = fromCRD.LoadBalancer.DbHostedZone
result.EnableMasterLoadBalancer = fromCRD.LoadBalancer.EnableMasterLoadBalancer
result.EnableReplicaLoadBalancer = fromCRD.LoadBalancer.EnableReplicaLoadBalancer
result.MasterDNSNameFormat = fromCRD.LoadBalancer.MasterDNSNameFormat
result.ReplicaDNSNameFormat = fromCRD.LoadBalancer.ReplicaDNSNameFormat
result.WALES3Bucket = fromCRD.AWSGCP.WALES3Bucket
result.LogS3Bucket = fromCRD.AWSGCP.LogS3Bucket
result.KubeIAMRole = fromCRD.AWSGCP.KubeIAMRole
result.DebugLogging = fromCRD.OperatorDebug.DebugLogging
result.EnableDBAccess = fromCRD.OperatorDebug.EnableDBAccess
result.EnableTeamsAPI = fromCRD.TeamsAPI.EnableTeamsAPI
result.TeamsAPIUrl = fromCRD.TeamsAPI.TeamsAPIUrl
result.TeamAPIRoleConfiguration = fromCRD.TeamsAPI.TeamAPIRoleConfiguration
result.EnableTeamSuperuser = fromCRD.TeamsAPI.EnableTeamSuperuser
result.TeamAdminRole = fromCRD.TeamsAPI.TeamAdminRole
result.PamRoleName = fromCRD.TeamsAPI.PamRoleName
result.APIPort = fromCRD.LoggingRESTAPI.APIPort
result.RingLogLines = fromCRD.LoggingRESTAPI.RingLogLines
result.ClusterHistoryEntries = fromCRD.LoggingRESTAPI.ClusterHistoryEntries
result.ScalyrAPIKey = fromCRD.Scalyr.ScalyrAPIKey
result.ScalyrImage = fromCRD.Scalyr.ScalyrImage
result.ScalyrServerURL = fromCRD.Scalyr.ScalyrServerURL
result.ScalyrCPURequest = fromCRD.Scalyr.ScalyrCPURequest
result.ScalyrMemoryRequest = fromCRD.Scalyr.ScalyrMemoryRequest
result.ScalyrCPULimit = fromCRD.Scalyr.ScalyrCPULimit
result.ScalyrMemoryLimit = fromCRD.Scalyr.ScalyrMemoryLimit
return result
}

View File

@ -75,7 +75,7 @@ func (c *Controller) createZalandoCRD(plural, singular, short string) error {
c.logger.Infof("customResourceDefinition %q has been registered", crd.Name) c.logger.Infof("customResourceDefinition %q has been registered", crd.Name)
} }
return wait.Poll(c.opConfig.CRD.ReadyWaitInterval, c.opConfig.CRD.ReadyWaitTimeout, func() (bool, error) { return wait.Poll(c.config.CRDReadyWaitInterval, c.config.CRDReadyWaitTimeout, func() (bool, error) {
c, err := c.KubeClient.CustomResourceDefinitions().Get(crd.Name, metav1.GetOptions{}) c, err := c.KubeClient.CustomResourceDefinitions().Get(crd.Name, metav1.GetOptions{})
if err != nil { if err != nil {
return false, err return false, err

View File

@ -162,10 +162,12 @@ type ControllerConfig struct {
RestConfig *rest.Config `json:"-"` RestConfig *rest.Config `json:"-"`
InfrastructureRoles map[string]PgUser InfrastructureRoles map[string]PgUser
NoDatabaseAccess bool NoDatabaseAccess bool
NoTeamsAPI bool NoTeamsAPI bool
ConfigMapName NamespacedName CRDReadyWaitInterval time.Duration
Namespace string CRDReadyWaitTimeout time.Duration
ConfigMapName NamespacedName
Namespace string
} }
// cached value for the GetOperatorNamespace // cached value for the GetOperatorNamespace

View File

@ -40,11 +40,11 @@ type Resources struct {
// Auth describes authentication specific configuration parameters // Auth describes authentication specific configuration parameters
type Auth struct { type Auth struct {
SecretNameTemplate StringTemplate `name:"secret_name_template" default:"{username}.{cluster}.credentials.{tprkind}.{tprgroup}"` SecretNameTemplate StringTemplate `name:"secret_name_template" default:"{username}.{cluster}.credentials.{tprkind}.{tprgroup}"`
PamRoleName string `name:"pam_role_name" default:"zalandos"` 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"` 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/"` TeamsAPIUrl string `name:"teams_api_url" default:"https://teams.example.com/api/"`
OAuthTokenSecretName spec.NamespacedName `name:"oauth_token_secret_name" default:"postgresql-operator"` OAuthTokenSecretName spec.NamespacedName `name:"oauth_token_secret_name" default:"postgresql-operator"`
InfrastructureRolesSecretName spec.NamespacedName `name:"infrastructure_roles_secret_name"` InfrastructureRolesSecretName spec.NamespacedName `name:"infrastructure_roles_secret_name"`
SuperUsername string `name:"super_username" default:"postgres"` SuperUsername string `name:"super_username" default:"postgres"`
ReplicationUsername string `name:"replication_username" default:"standby"` ReplicationUsername string `name:"replication_username" default:"standby"`

View File

@ -1,7 +1,6 @@
package config package config
import ( import (
"encoding/json" "encoding/json"
"time" "time"
@ -15,93 +14,91 @@ type OperatorConfiguration struct {
metav1.ObjectMeta `json:"metadata"` metav1.ObjectMeta `json:"metadata"`
Configuration OperatorConfigurationData `json:"configuration"` Configuration OperatorConfigurationData `json:"configuration"`
Error error `json:"-"` Error error `json:"-"`
} }
type OperatorConfigurationList struct { type OperatorConfigurationList struct {
metav1.TypeMeta `json:",inline"` metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata"` metav1.ListMeta `json:"metadata"`
Items []OperatorConfiguration `json:"items"` Items []OperatorConfiguration `json:"items"`
} }
type PostgresUsersConfiguration struct { type PostgresUsersConfiguration struct {
SuperUsername string `json:"super_username,omitempty"` SuperUsername string `json:"super_username,omitempty"`
ReplicationUsername string `json:"replication_username,omitempty"` ReplicationUsername string `json:"replication_username,omitempty"`
} }
type KubernetesMetaConfiguration struct { type KubernetesMetaConfiguration struct {
PodServiceAccountName string `json:"pod_service_account_name,omitempty"` PodServiceAccountName string `json:"pod_service_account_name,omitempty"`
// TODO: change it to the proper json // TODO: change it to the proper json
PodServiceAccountDefinition string `json:"pod_service_account_definition,omitempty"` PodServiceAccountDefinition string `json:"pod_service_account_definition,omitempty"`
PodTerminateGracePeriod time.Duration `json:"pod_terminate_grace_period,omitempty"` PodTerminateGracePeriod time.Duration `json:"pod_terminate_grace_period,omitempty"`
WatchedNamespace string `json:"watched_namespace,omitempty"` WatchedNamespace string `json:"watched_namespace,omitempty"`
PDBNameFormat StringTemplate `json:"pdb_name_format,omitempty"` PDBNameFormat StringTemplate `json:"pdb_name_format,omitempty"`
SecretNameTemplate StringTemplate `json:"secret_name_template,omitempty"` SecretNameTemplate StringTemplate `json:"secret_name_template,omitempty"`
OAuthTokenSecretName spec.NamespacedName `json:"oauth_token_secret_name,omitempty"` OAuthTokenSecretName spec.NamespacedName `json:"oauth_token_secret_name,omitempty"`
InfrastructureRolesSecretName spec.NamespacedName `json:"infrastructure_roles_secret_name,omitempty"` InfrastructureRolesSecretName spec.NamespacedName `json:"infrastructure_roles_secret_name,omitempty"`
PodRoleLabel string `json:"pod_role_label,omitempty"` PodRoleLabel string `json:"pod_role_label,omitempty"`
ClusterLabels map[string]string `json:"cluster_labels,omitempty"` ClusterLabels map[string]string `json:"cluster_labels,omitempty"`
ClusterNameLabel string `json:"cluster_name_label,omitempty"` ClusterNameLabel string `json:"cluster_name_label,omitempty"`
NodeReadinessLabel map[string]string `json:"node_readiness_label,omitempty"` NodeReadinessLabel map[string]string `json:"node_readiness_label,omitempty"`
// TODO: use a proper toleration structure? // TODO: use a proper toleration structure?
PodToleration map[string]string `json:"toleration,omitempty"` PodToleration map[string]string `json:"toleration,omitempty"`
// TODO: use namespacedname // TODO: use namespacedname
PodEnvironmentConfigMap string `json:"pod_environment_configmap,omitempty"` PodEnvironmentConfigMap string `json:"pod_environment_configmap,omitempty"`
} }
type PostgresPodResourcesDefaults struct { type PostgresPodResourcesDefaults struct {
DefaultCPURequest string `json:"default_cpu_request,omitempty"` DefaultCPURequest string `json:"default_cpu_request,omitempty"`
DefaultMemoryRequest string `json:"default_memory_request,omitempty"` DefaultMemoryRequest string `json:"default_memory_request,omitempty"`
DefaultCPULimit string `json:"default_cpu_limit,omitempty"` DefaultCPULimit string `json:"default_cpu_limit,omitempty"`
DefaultMemoryLimit string `json:"default_memory_limit,omitempty"` DefaultMemoryLimit string `json:"default_memory_limit,omitempty"`
} }
type OperatorTimeouts struct { type OperatorTimeouts struct {
ResourceCheckInterval time.Duration `json:"resource_check_interval,omitempty"` ResourceCheckInterval time.Duration `json:"resource_check_interval,omitempty"`
ResourceCheckTimeout time.Duration `json:"resource_check_timeout,omitempty"` ResourceCheckTimeout time.Duration `json:"resource_check_timeout,omitempty"`
PodLabelWaitTimeout time.Duration `json:"pod_label_wait_timeout,omitempty"` PodLabelWaitTimeout time.Duration `json:"pod_label_wait_timeout,omitempty"`
PodDeletionWaitTimeout time.Duration `json:"pod_deletion_wait_timeout,omitempty"` PodDeletionWaitTimeout time.Duration `json:"pod_deletion_wait_timeout,omitempty"`
ReadyWaitInterval time.Duration `json:"ready_wait_interval,omitempty"` ReadyWaitInterval time.Duration `json:"ready_wait_interval,omitempty"`
ReadyWaitTimeout time.Duration `json:"ready_wait_timeout,omitempty"` ReadyWaitTimeout time.Duration `json:"ready_wait_timeout,omitempty"`
} }
type LoadBalancerConfiguration struct { type LoadBalancerConfiguration struct {
DbHostedZone string `json:"db_hosted_zone,omitempty"` DbHostedZone string `json:"db_hosted_zone,omitempty"`
EnableMasterLoadBalancer bool `json:"enable_master_load_balancer,omitempty"` EnableMasterLoadBalancer bool `json:"enable_master_load_balancer,omitempty"`
EnableReplicaLoadBalancer bool `json:"enable_replica_load_balancer,omitempty"` EnableReplicaLoadBalancer bool `json:"enable_replica_load_balancer,omitempty"`
MasterDNSNameFormat StringTemplate `json:"master_dns_name_format,omitempty"` MasterDNSNameFormat StringTemplate `json:"master_dns_name_format,omitempty"`
ReplicaDNSNameFormat StringTemplate `json:"replica_dns_name_format,omitempty"` ReplicaDNSNameFormat StringTemplate `json:"replica_dns_name_format,omitempty"`
} }
type AWSGCPConfiguration struct { type AWSGCPConfiguration struct {
WALES3Bucket string `json:"wal_s3_bucket,omitempty"` WALES3Bucket string `json:"wal_s3_bucket,omitempty"`
LogS3Bucket string `json:"log_s3_bucket,omitempty"` LogS3Bucket string `json:"log_s3_bucket,omitempty"`
KubeIAMRole string `json:"kube_iam_role,omitempty"` KubeIAMRole string `json:"kube_iam_role,omitempty"`
} }
type OperatorDebugConfiguration struct { type OperatorDebugConfiguration struct {
DebugLogging bool `json:"debug_logging,omitempty"` DebugLogging bool `json:"debug_logging,omitempty"`
EnableDBAccess bool `json:"enable_database_access,omitempty"` EnableDBAccess bool `json:"enable_database_access,omitempty"`
} }
type TeamsAPIConfiguration struct { type TeamsAPIConfiguration struct {
EnableTeamsAPI bool `json:"enable_teams_api,omitempty"` EnableTeamsAPI bool `json:"enable_teams_api,omitempty"`
TeamsAPIUrl string `json:"teams_api_url,omitempty"` TeamsAPIUrl string `json:"teams_api_url,omitempty"`
TeamAPIRoleConfiguration map[string]string `json:"team_api_role_configuration,omitempty"` TeamAPIRoleConfiguration map[string]string `json:"team_api_role_configuration,omitempty"`
EnableTeamSuperuser bool `json:"enable_team_superuser,omitempty"` EnableTeamSuperuser bool `json:"enable_team_superuser,omitempty"`
TeamAdminRole string `json:"team_admin_role,omitempty"` TeamAdminRole string `json:"team_admin_role,omitempty"`
PamRoleName string `json:"pam_role_name,omitempty"` PamRoleName string `json:"pam_role_name,omitempty"`
PamConfiguration string `json:"pam_configuration,omitempty"` PamConfiguration string `json:"pam_configuration,omitempty"`
ProtectedRoles []string `json:"protected_role_names,omitempty"` ProtectedRoles []string `json:"protected_role_names,omitempty"`
} }
type LoggingRESTAPIConfiguration struct { type LoggingRESTAPIConfiguration struct {
APIPort int `json:"api_port,omitempty"` APIPort int `json:"api_port,omitempty"`
RingLogLines int `json:"ring_log_lines,omitempty"` RingLogLines int `json:"ring_log_lines,omitempty"`
ClusterHistoryEntries int `json:"cluster_history_entries,omitempty"` ClusterHistoryEntries int `json:"cluster_history_entries,omitempty"`
} }
type ScalyrConfiguration struct { type ScalyrConfiguration struct {
@ -115,36 +112,34 @@ type ScalyrConfiguration struct {
} }
type OperatorConfigurationData struct { type OperatorConfigurationData struct {
EtcdHost string `json:"etcd_host,omitempty"` EtcdHost string `json:"etcd_host,omitempty"`
DockerImage string `json:"docker_image,omitempty"` DockerImage string `json:"docker_image,omitempty"`
Workers int `json:"workers,omitempty"` Workers uint32 `json:"workers,omitempty"`
MinInstances int32 `json:"min_instances,omitempty"` MinInstances int32 `json:"min_instances,omitempty"`
MaxInstances int32 `json:"max_instances,omitempty"` MaxInstances int32 `json:"max_instances,omitempty"`
ResyncPeriod time.Duration `json:"resync_period,omitempty"` ResyncPeriod time.Duration `json:"resync_period,omitempty"`
PostgresUsersConfiguration PostgresUsersConfiguration `json:"users"` PostgresUsersConfiguration PostgresUsersConfiguration `json:"users"`
Kubernetes KubernetesMetaConfiguration `json:"kubernetes"` Kubernetes KubernetesMetaConfiguration `json:"kubernetes"`
PostgresPodResources PostgresPodResourcesDefaults `json:"postgres_pod_resources"` PostgresPodResources PostgresPodResourcesDefaults `json:"postgres_pod_resources"`
Timeouts OperatorTimeouts `json:"timeouts"` Timeouts OperatorTimeouts `json:"timeouts"`
LoadBalancer LoadBalancerConfiguration `json:"load_balancer"` LoadBalancer LoadBalancerConfiguration `json:"load_balancer"`
AWSGCP AWSGCPConfiguration `json:"aws_or_gcp"` AWSGCP AWSGCPConfiguration `json:"aws_or_gcp"`
OperatorDebug OperatorDebugConfiguration `json:"debug"` OperatorDebug OperatorDebugConfiguration `json:"debug"`
TeamsAPI TeamsAPIConfiguration `json:"teams_api"` TeamsAPI TeamsAPIConfiguration `json:"teams_api"`
LoggingRESTAPI LoggingRESTAPIConfiguration `json:"logging_rest_api"` LoggingRESTAPI LoggingRESTAPIConfiguration `json:"logging_rest_api"`
Scalyr ScalyrConfiguration `json:"scalyr"` Scalyr ScalyrConfiguration `json:"scalyr"`
} }
type OperatorConfigurationUsers struct { type OperatorConfigurationUsers struct {
SuperUserName string `json:"superuser_name,omitempty"` SuperUserName string `json:"superuser_name,omitempty"`
Replication string `json:"replication_user_name,omitempty"` Replication string `json:"replication_user_name,omitempty"`
ProtectedRoles []string `json:"protected_roles,omitempty"` ProtectedRoles []string `json:"protected_roles,omitempty"`
TeamAPIRoleConfiguration map[string]string `json:"team_api_role_configuration,omitempty"` TeamAPIRoleConfiguration map[string]string `json:"team_api_role_configuration,omitempty"`
} }
type OperatorConfigurationCopy OperatorConfiguration type OperatorConfigurationCopy OperatorConfiguration
type OperatorConfigurationListCopy OperatorConfigurationList type OperatorConfigurationListCopy OperatorConfigurationList
func (opc *OperatorConfiguration) UnmarshalJSON(data []byte) error { func (opc *OperatorConfiguration) UnmarshalJSON(data []byte) error {
var ref OperatorConfigurationCopy var ref OperatorConfigurationCopy
if err := json.Unmarshal(data, &ref); err != nil { if err := json.Unmarshal(data, &ref); err != nil {
@ -162,4 +157,3 @@ func (opcl *OperatorConfigurationList) UnmarshalJSON(data []byte) error {
*opcl = OperatorConfigurationList(ref) *opcl = OperatorConfigurationList(ref)
return nil return nil
} }

View File

@ -2,13 +2,12 @@ package constants
// Different properties of the PostgreSQL Custom Resource Definition // Different properties of the PostgreSQL Custom Resource Definition
const ( const (
PostgresCRDKind = "postgresql" PostgresCRDKind = "postgresql"
PostgresCRDResource = "postgresqls" PostgresCRDResource = "postgresqls"
PostgresCRDShort = "pg" PostgresCRDShort = "pg"
CRDGroup = "acid.zalan.do" CRDGroup = "acid.zalan.do"
CRDApiVersion = "v1" CRDApiVersion = "v1"
OperatorConfigCRDKind = "postgresql-operator-configuration" OperatorConfigCRDKind = "postgresql-operator-configuration"
OperatorConfigCRDResource = "postgresql-operator-configurations" OperatorConfigCRDResource = "postgresql-operator-configurations"
OperatorConfigCRDShort = "pgopconfig" OperatorConfigCRDShort = "pgopconfig"
) )