Skip to content

Commit

Permalink
Make replicas configurable in scalable DeploymentConfigs
Browse files Browse the repository at this point in the history
  • Loading branch information
miguelsorianod committed Sep 9, 2019
1 parent eb52579 commit 6b1c068
Showing 1 changed file with 184 additions and 1 deletion.
185 changes: 184 additions & 1 deletion pkg/apis/apps/v1alpha1/apimanager_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,14 +111,48 @@ type ApicastSpec struct {
RegistryURL *string `json:"registryURL,omitempty"`
// +optional
Image *string `json:"image,omitempty"`
// +optional
ApicastProductionSpec *ApicastProductionSpec `json:"apicastProductionSpec,omitempty"`
// +optional
ApicastStagingSpec *ApicastStagingSpec `json:"apicastStagingSpec,omitempty"`
}

type ApicastProductionSpec struct {
// +optional
Replicas *int64 `json:"replicas,omitempty"`
}

type ApicastStagingSpec struct {
// +optional
Replicas *int64 `json:"replicas,omitempty"`
}

type BackendSpec struct {
// +optional
Image *string `json:"image,omitempty"`

// +optional
RedisImage *string `json:"redisImage,omitempty"`
// +optional
BackendListenerSpec *BackendListenerSpec `json:"backendListenerSpec,omitempty"`
// +optional
BackendWorkerSpec *BackendWorkerSpec `json:"backendWorkerSpec,omitempty"`
// +optional
BackendCronSpec *BackendCronSpec `json:"backendCronSpec,omitempty"`
}

type BackendListenerSpec struct {
// +optional
Replicas *int64 `json:"replicas,omitempty"`
}

type BackendWorkerSpec struct {
// +optional
Replicas *int64 `json:"replicas,omitempty"`
}

type BackendCronSpec struct {
// +optional
Replicas *int64 `json:"replicas,omitempty"`
}

type SystemSpec struct {
Expand All @@ -145,8 +179,23 @@ type SystemSpec struct {

// +optional
DatabaseSpec *SystemDatabaseSpec `json:"database,omitempty"`

SystemAppSpec *SystemAppSpec `json:"systemAppSpec,omitempty"`
SystemSidekiqSpec *SystemSidekiqSpec `json:"systemSidekiqSpec,omitempty"`
}

type SystemAppSpec struct {
// +optional
Replicas *int64 `json:"replicas,omitempty"`
}

type SystemSidekiqSpec struct {
// +optional
Replicas *int64 `json:"replicas,omitempty"`
}

// TODO could memcached replicas be configurable?

type SystemFileStorageSpec struct {
// Union type. Only one of the fields can be set.
// +optional
Expand Down Expand Up @@ -189,6 +238,14 @@ type ZyncSpec struct {
Image *string `json:"image,omitempty"`
// +optional
PostgreSQLImage *string `json:"postgreSQLImage,omitempty"`

// +optional
ZyncAppSpec *ZyncAppSpec `json:"zyncAppSpec,omitempty"`
}

type ZyncAppSpec struct {
// +optional
Replicas *int64 `json:"replicas,omitempty"`
}

type HighAvailabilitySpec struct {
Expand All @@ -207,15 +264,29 @@ func (apimanager *APIManager) SetDefaults() (bool, error) {
tmpChanged := apimanager.setAPIManagerCommonSpecDefaults()
changed = changed || tmpChanged

tmpChanged = apimanager.setBackendSpecDefaults()
changed = changed || tmpChanged

tmpChanged = apimanager.setApicastSpecDefaults()
changed = changed || tmpChanged

tmpChanged, err = apimanager.setSystemSpecDefaults()
changed = changed || tmpChanged
if err != nil {
return changed, err
}

tmpChanged = apimanager.setZyncDefaults()
changed = changed || tmpChanged

return changed, err
}

const (
MinReplicas = 1
MinHAReplicas = 2
)

func (apimanager *APIManager) setApicastSpecDefaults() bool {
changed := false
spec := &apimanager.Spec
Expand Down Expand Up @@ -246,6 +317,76 @@ func (apimanager *APIManager) setApicastSpecDefaults() bool {
changed = true
}

if spec.Apicast.ApicastStagingSpec != nil {
spec.Apicast.ApicastStagingSpec = &ApicastStagingSpec{}
changed = true
}

if spec.Apicast.ApicastProductionSpec != nil {
spec.Apicast.ApicastProductionSpec = &ApicastProductionSpec{}
changed = true
}

if spec.Apicast.ApicastStagingSpec.Replicas == nil {
spec.Apicast.ApicastStagingSpec.Replicas = apimanager.defaultReplicas()
changed = true
}

if spec.Apicast.ApicastProductionSpec.Replicas == nil {
spec.Apicast.ApicastProductionSpec.Replicas = apimanager.defaultReplicas()
changed = true
}

return changed
}

func (apimanager *APIManager) defaultReplicas() *int64 {
var defaultReplicas int64 = 1
if apimanager.Spec.HighAvailability != nil && apimanager.Spec.HighAvailability.Enabled {
defaultReplicas = 2
}
return &defaultReplicas
}

func (apimanager *APIManager) setBackendSpecDefaults() bool {
changed := false
spec := &apimanager.Spec

if spec.Backend != nil {
spec.Backend = &BackendSpec{}
changed = true
}

if spec.Backend.BackendListenerSpec != nil {
spec.Backend.BackendListenerSpec = &BackendListenerSpec{}
changed = true
}

if spec.Backend.BackendCronSpec != nil {
spec.Backend.BackendCronSpec = &BackendCronSpec{}
changed = true
}

if spec.Backend.BackendWorkerSpec != nil {
spec.Backend.BackendWorkerSpec = &BackendWorkerSpec{}
changed = true
}

if spec.Backend.BackendListenerSpec.Replicas == nil {
spec.Backend.BackendListenerSpec.Replicas = apimanager.defaultReplicas()
changed = true
}

if spec.Backend.BackendCronSpec.Replicas == nil {
spec.Backend.BackendListenerSpec.Replicas = apimanager.defaultReplicas()
changed = true
}

if spec.Backend.BackendWorkerSpec.Replicas == nil {
spec.Backend.BackendWorkerSpec.Replicas = apimanager.defaultReplicas()
changed = true
}

return changed
}

Expand Down Expand Up @@ -306,6 +447,26 @@ func (apimanager *APIManager) setSystemSpecDefaults() (bool, error) {
return changed, err
}

if spec.System.SystemAppSpec == nil {
spec.System.SystemAppSpec = &SystemAppSpec{}
changed = true
}

if spec.System.SystemSidekiqSpec == nil {
spec.System.SystemSidekiqSpec = &SystemSidekiqSpec{}
changed = true
}

if spec.System.SystemAppSpec.Replicas == nil {
spec.System.SystemAppSpec.Replicas = apimanager.defaultReplicas()
changed = true
}

if spec.System.SystemSidekiqSpec.Replicas == nil {
spec.System.SystemSidekiqSpec.Replicas = apimanager.defaultReplicas()
changed = true
}

return changed, nil
}

Expand Down Expand Up @@ -363,3 +524,25 @@ func (apimanager *APIManager) setSystemDatabaseSpecDefaults() (bool, error) {

return changed, nil
}

func (apimanager *APIManager) setZyncDefaults() bool {
changed := false
spec := &apimanager.Spec

if spec.Zync == nil {
spec.Zync = &ZyncSpec{}
changed = true
}

if spec.Zync.ZyncAppSpec == nil {
spec.Zync.ZyncAppSpec = &ZyncAppSpec{}
changed = true
}

if spec.Zync.ZyncAppSpec.Replicas == nil {
spec.Zync.ZyncAppSpec.Replicas = apimanager.defaultReplicas()
changed = true
}

return changed
}

0 comments on commit 6b1c068

Please sign in to comment.