Update the sample configuratin, fix most unmarshaling issues.
This commit is contained in:
parent
6bebb87d8f
commit
144c08695b
|
|
@ -70,7 +70,7 @@ configuration:
|
|||
scalyr:
|
||||
scalyr_cpu_request: 100m
|
||||
scalyr_memory_request: 50Mi
|
||||
scalyr_cpu_limit: 1
|
||||
scalyr_cpu_limit: "1"
|
||||
scalyr_memory_limit: 1Gi
|
||||
# scalyr_api_key: ""
|
||||
# scalyr_image: ""
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ import (
|
|||
"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"
|
||||
"time"
|
||||
)
|
||||
|
||||
func (c *Controller) readOperatorConfigurationFromCRD(configObjectNamespace, configObjectName string) (*config.OperatorConfiguration, error) {
|
||||
|
|
@ -40,14 +41,14 @@ func (c *Controller) importConfigurationFromCRD(fromCRD *config.OperatorConfigur
|
|||
result.Workers = fromCRD.Workers
|
||||
result.MinInstances = fromCRD.MinInstances
|
||||
result.MaxInstances = fromCRD.MaxInstances
|
||||
result.ResyncPeriod = fromCRD.ResyncPeriod
|
||||
result.ResyncPeriod = time.Duration(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.PodTerminateGracePeriod = time.Duration(fromCRD.Kubernetes.PodTerminateGracePeriod)
|
||||
result.WatchedNamespace = fromCRD.Kubernetes.WatchedNamespace
|
||||
result.PDBNameFormat = fromCRD.Kubernetes.PDBNameFormat
|
||||
result.SecretNameTemplate = fromCRD.Kubernetes.SecretNameTemplate
|
||||
|
|
@ -63,12 +64,12 @@ func (c *Controller) importConfigurationFromCRD(fromCRD *config.OperatorConfigur
|
|||
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.ResourceCheckInterval = time.Duration(fromCRD.Timeouts.ResourceCheckInterval)
|
||||
result.ResourceCheckTimeout = time.Duration(fromCRD.Timeouts.ResourceCheckTimeout)
|
||||
result.PodLabelWaitTimeout = time.Duration(fromCRD.Timeouts.PodLabelWaitTimeout)
|
||||
result.PodDeletionWaitTimeout = time.Duration(fromCRD.Timeouts.PodDeletionWaitTimeout)
|
||||
result.ReadyWaitInterval = time.Duration(fromCRD.Timeouts.ReadyWaitInterval)
|
||||
result.ReadyWaitTimeout = time.Duration(fromCRD.Timeouts.ReadyWaitTimeout)
|
||||
|
||||
result.DbHostedZone = fromCRD.LoadBalancer.DbHostedZone
|
||||
result.EnableMasterLoadBalancer = fromCRD.LoadBalancer.EnableMasterLoadBalancer
|
||||
|
|
|
|||
|
|
@ -190,7 +190,7 @@ func (m *MaintenanceWindow) MarshalJSON() ([]byte, error) {
|
|||
m.EndTime.Format("15:04"))), nil
|
||||
}
|
||||
|
||||
// UnmarshalJSON convets a JSON to the maintenance window definition.
|
||||
// UnmarshalJSON converts a JSON to the maintenance window definition.
|
||||
func (m *MaintenanceWindow) UnmarshalJSON(data []byte) error {
|
||||
var (
|
||||
got MaintenanceWindow
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ import (
|
|||
"k8s.io/client-go/pkg/apis/apps/v1beta1"
|
||||
policyv1beta1 "k8s.io/client-go/pkg/apis/policy/v1beta1"
|
||||
"k8s.io/client-go/rest"
|
||||
"encoding/json"
|
||||
)
|
||||
|
||||
// EventType contains type of the events for the TPRs and Pods received from Kubernetes
|
||||
|
|
@ -187,6 +188,15 @@ func (n *NamespacedName) Decode(value string) error {
|
|||
return n.DecodeWorker(value, GetOperatorNamespace())
|
||||
}
|
||||
|
||||
func (n *NamespacedName) UnmarshalJSON(data []byte) error {
|
||||
result := NamespacedName{}
|
||||
if err := result.Decode(string(data)); err != nil {
|
||||
return err
|
||||
}
|
||||
*n = result
|
||||
return nil
|
||||
}
|
||||
|
||||
// DecodeWorker separates the decode logic to (unit) test
|
||||
// from obtaining the operator namespace that depends on k8s mounting files at runtime
|
||||
func (n *NamespacedName) DecodeWorker(value, operatorNamespace string) error {
|
||||
|
|
@ -237,3 +247,31 @@ func GetOperatorNamespace() string {
|
|||
}
|
||||
return operatorNamespace
|
||||
}
|
||||
|
||||
type Duration time.Duration
|
||||
|
||||
func (d *Duration) UnmarshalJSON(b []byte) error {
|
||||
var (
|
||||
v interface{}
|
||||
err error
|
||||
)
|
||||
if err = json.Unmarshal(b, &v); err != nil {
|
||||
return err
|
||||
}
|
||||
switch val := v.(type) {
|
||||
case string:
|
||||
t, err := time.ParseDuration(val);
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
*d = Duration(t)
|
||||
return nil
|
||||
case float64:
|
||||
t := time.Duration(val)
|
||||
*d = Duration(t)
|
||||
return nil
|
||||
default:
|
||||
return fmt.Errorf("could not recognize type %T as a valid type to unmarshal to Duration", val)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
@ -2,8 +2,6 @@ package config
|
|||
|
||||
import (
|
||||
"encoding/json"
|
||||
"time"
|
||||
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
|
||||
"github.com/zalando-incubator/postgres-operator/pkg/spec"
|
||||
|
|
@ -33,7 +31,7 @@ type KubernetesMetaConfiguration struct {
|
|||
PodServiceAccountName string `json:"pod_service_account_name,omitempty"`
|
||||
// TODO: change it to the proper json
|
||||
PodServiceAccountDefinition string `json:"pod_service_account_definition,omitempty"`
|
||||
PodTerminateGracePeriod time.Duration `json:"pod_terminate_grace_period,omitempty"`
|
||||
PodTerminateGracePeriod spec.Duration `json:"pod_terminate_grace_period,omitempty"`
|
||||
WatchedNamespace string `json:"watched_namespace,omitempty"`
|
||||
PDBNameFormat StringTemplate `json:"pdb_name_format,omitempty"`
|
||||
SecretNameTemplate StringTemplate `json:"secret_name_template,omitempty"`
|
||||
|
|
@ -57,12 +55,12 @@ type PostgresPodResourcesDefaults struct {
|
|||
}
|
||||
|
||||
type OperatorTimeouts struct {
|
||||
ResourceCheckInterval time.Duration `json:"resource_check_interval,omitempty"`
|
||||
ResourceCheckTimeout time.Duration `json:"resource_check_timeout,omitempty"`
|
||||
PodLabelWaitTimeout time.Duration `json:"pod_label_wait_timeout,omitempty"`
|
||||
PodDeletionWaitTimeout time.Duration `json:"pod_deletion_wait_timeout,omitempty"`
|
||||
ReadyWaitInterval time.Duration `json:"ready_wait_interval,omitempty"`
|
||||
ReadyWaitTimeout time.Duration `json:"ready_wait_timeout,omitempty"`
|
||||
ResourceCheckInterval spec.Duration `json:"resource_check_interval,omitempty"`
|
||||
ResourceCheckTimeout spec.Duration `json:"resource_check_timeout,omitempty"`
|
||||
PodLabelWaitTimeout spec.Duration `json:"pod_label_wait_timeout,omitempty"`
|
||||
PodDeletionWaitTimeout spec.Duration `json:"pod_deletion_wait_timeout,omitempty"`
|
||||
ReadyWaitInterval spec.Duration `json:"ready_wait_interval,omitempty"`
|
||||
ReadyWaitTimeout spec.Duration `json:"ready_wait_timeout,omitempty"`
|
||||
}
|
||||
|
||||
type LoadBalancerConfiguration struct {
|
||||
|
|
@ -117,7 +115,7 @@ type OperatorConfigurationData struct {
|
|||
Workers uint32 `json:"workers,omitempty"`
|
||||
MinInstances int32 `json:"min_instances,omitempty"`
|
||||
MaxInstances int32 `json:"max_instances,omitempty"`
|
||||
ResyncPeriod time.Duration `json:"resync_period,omitempty"`
|
||||
ResyncPeriod spec.Duration `json:"resync_period,omitempty"`
|
||||
PostgresUsersConfiguration PostgresUsersConfiguration `json:"users"`
|
||||
Kubernetes KubernetesMetaConfiguration `json:"kubernetes"`
|
||||
PostgresPodResources PostgresPodResourcesDefaults `json:"postgres_pod_resources"`
|
||||
|
|
|
|||
Loading…
Reference in New Issue