Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support config maxunavaliable in deployment #504

Merged
merged 1 commit into from
Sep 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func (g *appConfigurationGenerator) Generate(spec *models.Spec) error {
gfs := []appconfiguration.NewGeneratorFunc{
NewNamespaceGeneratorFunc(g.project.Name),
accessories.NewDatabaseGeneratorFunc(g.project, g.stack, g.appName, g.app.Workload, g.app.Database),
workload.NewWorkloadGeneratorFunc(g.project, g.stack, g.appName, g.app.Workload, g.app.Monitoring),
workload.NewWorkloadGeneratorFunc(g.project, g.stack, g.appName, g.app.Workload, g.app.Monitoring, g.app.OpsRule),
NewMonitoringGeneratorFunc(g.project, g.app.Monitoring, g.appName),
// The OrderedResourcesGenerator should be executed after all resources are generated.
NewOrderedResourcesGeneratorFunc(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"kusionstack.io/kube-api/apps/v1alpha1"

"k8s.io/apimachinery/pkg/util/intstr"
"kusionstack.io/kusion/pkg/generator/appconfiguration"
"kusionstack.io/kusion/pkg/generator/appconfiguration/generator/workload/network"
"kusionstack.io/kusion/pkg/models"
"kusionstack.io/kusion/pkg/models/appconfiguration/monitoring"
"kusionstack.io/kusion/pkg/models/appconfiguration/trait"
"kusionstack.io/kusion/pkg/models/appconfiguration/workload"
"kusionstack.io/kusion/pkg/projectstack"
)
Expand All @@ -23,6 +25,7 @@ type workloadServiceGenerator struct {
appName string
service *workload.Service
monitoring *monitoring.Monitor
opsRule *trait.OpsRule
}

// NewWorkloadServiceGenerator returns a new workloadServiceGenerator instance.
Expand All @@ -32,6 +35,7 @@ func NewWorkloadServiceGenerator(
appName string,
service *workload.Service,
monitoring *monitoring.Monitor,
opsRule *trait.OpsRule,
) (appconfiguration.Generator, error) {
if len(project.Name) == 0 {
return nil, fmt.Errorf("project name must not be empty")
Expand All @@ -51,6 +55,7 @@ func NewWorkloadServiceGenerator(
appName: appName,
service: service,
monitoring: monitoring,
opsRule: opsRule,
}, nil
}

Expand All @@ -61,9 +66,10 @@ func NewWorkloadServiceGeneratorFunc(
appName string,
service *workload.Service,
monitoring *monitoring.Monitor,
opsRule *trait.OpsRule,
) appconfiguration.NewGeneratorFunc {
return func() (appconfiguration.Generator, error) {
return NewWorkloadServiceGenerator(project, stack, appName, service, monitoring)
return NewWorkloadServiceGenerator(project, stack, appName, service, monitoring, opsRule)
}
}

Expand Down Expand Up @@ -162,14 +168,24 @@ func (g *workloadServiceGenerator) Generate(spec *models.Spec) error {
APIVersion: appsv1.SchemeGroupVersion.String(),
Kind: workload.TypeDeploy,
}
spec := appsv1.DeploymentSpec{
Replicas: appconfiguration.GenericPtr(int32(service.Replicas)),
Selector: &metav1.LabelSelector{MatchLabels: selector},
Template: podTemplateSpec,
}
if g.opsRule != nil && g.opsRule.MaxUnavailable != "" {
maxUnavailable := intstr.Parse(g.opsRule.MaxUnavailable)
spec.Strategy = appsv1.DeploymentStrategy{
Type: appsv1.RollingUpdateDeploymentStrategyType,
RollingUpdate: &appsv1.RollingUpdateDeployment{
MaxUnavailable: &maxUnavailable,
},
}
}
resource = &appsv1.Deployment{
TypeMeta: typeMeta,
ObjectMeta: objectMeta,
Spec: appsv1.DeploymentSpec{
Replicas: appconfiguration.GenericPtr(int32(service.Replicas)),
Selector: &metav1.LabelSelector{MatchLabels: selector},
Template: podTemplateSpec,
},
Spec: spec,
}
case workload.TypeCollaset:
typeMeta = metav1.TypeMeta{
Expand Down
Loading
Loading