Code refactor

This commit is contained in:
Murat Kabilov
2017-05-12 11:37:09 +02:00
parent 0821990720
commit abb1173035
20 changed files with 788 additions and 701 deletions
+139
View File
@@ -0,0 +1,139 @@
package spec
import (
"encoding/json"
"k8s.io/client-go/pkg/api"
"k8s.io/client-go/pkg/api/meta"
"k8s.io/client-go/pkg/api/unversioned"
)
type MaintenanceWindow struct {
StartTime string
EndTime string
//StartTime time.Time // Start time
//StartWeekday time.Weekday // Start weekday
//
//EndTime time.Time // End time
//EndWeekday time.Weekday // End weekday
}
type Volume struct {
Size string `json:"size"`
StorageClass string `json:"storageClass"`
}
type PostgresqlParam struct {
Version string `json:"version"`
Parameters map[string]string `json:"parameters"`
}
type Resources struct {
Cpu string `json:"cpu"`
Memory string `json:"memory"`
}
type Patroni struct {
InitDB map[string]string `json:"initdb"`
PgHba []string `json:"pg_hba"`
TTL uint32 `json:"ttl"`
LoopWait uint32 `json:"loop_wait"`
RetryTimeout uint32 `json:"retry_timeout"`
MaximumLagOnFailover float32 `json:"maximum_lag_on_failover"` // float32 because https://github.com/kubernetes/kubernetes/issues/30213
}
type UserFlags []string
type PostgresSpec struct {
Resources `json:"resources,omitempty"`
Patroni `json:"patroni,omitempty"`
PostgresqlParam `json:"postgresql"`
Volume `json:"volume,omitempty"`
NumberOfInstances int32 `json:"numberOfInstances"`
Users map[string]UserFlags `json:"users"`
MaintenanceWindows []string `json:"maintenanceWindows,omitempty"`
EtcdHost string
DockerImage string
}
type PostgresStatus struct {
// Phase is the cluster running phase
Phase string `json:"phase"`
Reason string `json:"reason"`
// ControlPuased indicates the operator pauses the control of the cluster.
ControlPaused bool `json:"controlPaused"`
// Size is the current size of the cluster
Size int `json:"size"`
// CurrentVersion is the current cluster version
CurrentVersion string `json:"currentVersion"`
// TargetVersion is the version the cluster upgrading to.
// If the cluster is not upgrading, TargetVersion is empty.
TargetVersion string `json:"targetVersion"`
}
// PostgreSQL Third Party (resource) Object
type Postgresql struct {
unversioned.TypeMeta `json:",inline"`
Metadata api.ObjectMeta `json:"metadata"`
Spec *PostgresSpec `json:"spec"`
Status *PostgresStatus `json:"status"`
}
type PostgresqlList struct {
unversioned.TypeMeta `json:",inline"`
Metadata unversioned.ListMeta `json:"metadata"`
Items []Postgresql `json:"items"`
}
func (p *Postgresql) GetObjectKind() unversioned.ObjectKind {
return &p.TypeMeta
}
func (p *Postgresql) GetObjectMeta() meta.Object {
return &p.Metadata
}
func (pl *PostgresqlList) GetObjectKind() unversioned.ObjectKind {
return &pl.TypeMeta
}
func (pl *PostgresqlList) GetListMeta() unversioned.List {
return &pl.Metadata
}
// The code below is used only to work around a known problem with third-party
// resources and ugorji. If/when these issues are resolved, the code below
// should no longer be required.
//
type PostgresqlListCopy PostgresqlList
type PostgresqlCopy Postgresql
func (p *Postgresql) UnmarshalJSON(data []byte) error {
tmp := PostgresqlCopy{}
err := json.Unmarshal(data, &tmp)
if err != nil {
return err
}
tmp2 := Postgresql(tmp)
*p = tmp2
return nil
}
func (pl *PostgresqlList) UnmarshalJSON(data []byte) error {
tmp := PostgresqlListCopy{}
err := json.Unmarshal(data, &tmp)
if err != nil {
return err
}
tmp2 := PostgresqlList(tmp)
*pl = tmp2
return nil
}
-78
View File
@@ -1,78 +0,0 @@
package spec
import(
"encoding/json"
"k8s.io/client-go/pkg/api/meta"
"k8s.io/client-go/pkg/api/unversioned"
"k8s.io/client-go/pkg/api"
)
type Pgconf struct {
Parameter string `json:"param"`
Value string `json:"value"`
}
type SpiloSpec struct {
EtcdHost string `json:"etcd_host"`
VolumeSize int `json:"volume_size"`
NumberOfInstances int32 `json:"number_of_instances"`
DockerImage string `json:"docker_image"`
PostgresConfiguration []Pgconf `json:"postgres_configuration"`
ResourceCPU string `json:"resource_cpu"`
ResourceMemory string `json:"resource_memory"`
}
type Spilo struct {
unversioned.TypeMeta `json:",inline"`
Metadata api.ObjectMeta `json:"metadata"`
Spec SpiloSpec `json:"spec"`
}
type SpiloList struct {
unversioned.TypeMeta `json:",inline"`
Metadata unversioned.ListMeta `json:"metadata"`
Items []Spilo `json:"items"`
}
func (s *Spilo) GetObjectKind() unversioned.ObjectKind {
return &s.TypeMeta
}
func (s *Spilo) GetObjectMeta() meta.Object {
return &s.Metadata
}
func (sl *SpiloList) GetObjectKind() unversioned.ObjectKind {
return &sl.TypeMeta
}
func (sl *SpiloList) GetListMeta() unversioned.List {
return &sl.Metadata
}
type SpiloListCopy SpiloList
type SpiloCopy Spilo
func (e *Spilo) UnmarshalJSON(data []byte) error {
tmp := SpiloCopy{}
err := json.Unmarshal(data, &tmp)
if err != nil {
return err
}
tmp2 := Spilo(tmp)
*e = tmp2
return nil
}
func (el *SpiloList) UnmarshalJSON(data []byte) error {
tmp := SpiloListCopy{}
err := json.Unmarshal(data, &tmp)
if err != nil {
return err
}
tmp2 := SpiloList(tmp)
*el = tmp2
return nil
}