Skip to content

Commit

Permalink
chore: use Mod* pattern to set scaling in runtime
Browse files Browse the repository at this point in the history
  • Loading branch information
jvmakine committed Jan 17, 2025
1 parent 34b97dc commit 170431a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 13 deletions.
16 changes: 3 additions & 13 deletions backend/controller/state/deployments.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func (r *DeploymentReplicasUpdatedEvent) Handle(t SchemaState) (SchemaState, err
if !ok {
return t, fmt.Errorf("deployment %s not found", r.Key)
}
setMinReplicas(existing, r.Replicas)
existing.ModRuntime().ModScaling().MinReplicas = int32(r.Replicas)
return t, nil
}

Expand All @@ -98,7 +98,7 @@ func (r *DeploymentActivatedEvent) Handle(t SchemaState) (SchemaState, error) {

}
existing.ModRuntime().ModDeployment().ActivatedAt = r.ActivatedAt
setMinReplicas(existing, r.MinReplicas)
existing.ModRuntime().ModScaling().MinReplicas = int32(r.MinReplicas)
t.activeDeployments[r.Key] = true
return t, nil
}
Expand All @@ -114,17 +114,7 @@ func (r *DeploymentDeactivatedEvent) Handle(t SchemaState) (SchemaState, error)
return t, fmt.Errorf("deployment %s not found", r.Key)

}
setMinReplicas(existing, 0)
existing.ModRuntime().ModScaling().MinReplicas = 0
delete(t.activeDeployments, r.Key)
return t, nil
}

func setMinReplicas(s *schema.Module, minReplicas int) {
if s.Runtime == nil {
s.Runtime = &schema.ModuleRuntime{}
}
if s.Runtime.Scaling == nil {
s.Runtime.Scaling = &schema.ModuleRuntimeScaling{}
}
s.Runtime.Scaling.MinReplicas = int32(minReplicas)
}
7 changes: 7 additions & 0 deletions common/schema/moduleruntime.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,3 +114,10 @@ func (m *ModuleRuntimeDeployment) GetDeploymentKey() key.Deployment {
}
return m.DeploymentKey
}

func (m *ModuleRuntime) ModScaling() *ModuleRuntimeScaling {
if m.Scaling == nil {
m.Scaling = &ModuleRuntimeScaling{}
}
return m.Scaling
}

0 comments on commit 170431a

Please sign in to comment.