Skip to content

Commit

Permalink
fix: opsRule doesn't work in CollaSet (#706)
Browse files Browse the repository at this point in the history
* fix: ops rule generator

* fix: opsRule doesn't work in CollaSet
  • Loading branch information
SparkYuan committed Dec 19, 2023
1 parent 089068e commit 816225b
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 33 deletions.
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ require (
kcl-lang.io/kcl-go v0.7.0
kcl-lang.io/kcl-plugin v0.5.0
kcl-lang.io/kpm v0.4.2
kusionstack.io/kube-api v0.0.0-20230817144216-4714955f3801
kusionstack.io/kube-api v0.1.1
sigs.k8s.io/controller-runtime v0.15.1
)

Expand Down Expand Up @@ -238,7 +238,7 @@ require (
github.com/skeema/knownhosts v1.2.0 // indirect
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d // indirect
github.com/smartystreets/goconvey v1.6.4 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/spf13/pflag v1.0.5
github.com/thoas/go-funk v0.9.3 // indirect
github.com/tidwall/match v1.1.1 // indirect
github.com/tidwall/pretty v1.2.0 // indirect
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -950,8 +950,8 @@ kcl-lang.io/kcl-plugin v0.5.0 h1:eoh6y4l81rwA8yhJXU4hN7YmJeTUNB1nfYCP9OffSxc=
kcl-lang.io/kcl-plugin v0.5.0/go.mod h1:QnZ5OLcyBw5nOnHpChRHtvBq8wvjwiHu/ZZ8j1dfz48=
kcl-lang.io/kpm v0.4.2 h1:rEjfUdX+2kmwwuBaYvsNURQ5D97C3qLNBYAd+XT+DbU=
kcl-lang.io/kpm v0.4.2/go.mod h1:9C/Q9RhRDinbhN7HzQxEexw00HVWUYwWbarMuC1E4xM=
kusionstack.io/kube-api v0.0.0-20230817144216-4714955f3801 h1:rWNki+bYgDqEgia/t8Vfk681NqTV0EbTXc8+JnkvZyM=
kusionstack.io/kube-api v0.0.0-20230817144216-4714955f3801/go.mod h1:QIQrH+MK9xuV+mXCAkk6DN8z6b8oyf4XN0VRccmHH/k=
kusionstack.io/kube-api v0.1.1 h1:ieoZhaUfK78hsyQ7GsU6ZuxBAcVU+ZuKs7vedGkO8sI=
kusionstack.io/kube-api v0.1.1/go.mod h1:QIQrH+MK9xuV+mXCAkk6DN8z6b8oyf4XN0VRccmHH/k=
lukechampine.com/frand v1.4.2 h1:RzFIpOvkMXuPMBb9maa4ND4wjBn71E1Jpf8BzJHMaVw=
lukechampine.com/frand v1.4.2/go.mod h1:4S/TM2ZgrKejMcKMbeLjISpJMO+/eZ1zu3vYX9dtj3s=
oras.land/oras-go v1.2.3 h1:v8PJl+gEAntI1pJ/LCrDgsuk+1PKVavVEPsYIHFE5uY=
Expand Down
52 changes: 26 additions & 26 deletions pkg/modules/generators/trait/ops_rule_generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,39 +50,39 @@ func (g *opsRuleGenerator) Generate(spec *intent.Intent) error {
return nil
}

if g.app.Workload.Header.Type != workload.TypeService {
// Job does not support maxUnavailable
if g.app.Workload.Header.Type == workload.TypeJob {
return nil
}

if g.app.Workload.Service.Type != workload.TypeCollaset {
return nil
}

maxUnavailable := intstr.Parse(g.app.OpsRule.MaxUnavailable)
resource := &v1alpha1.RuleSet{
TypeMeta: metav1.TypeMeta{
APIVersion: v1alpha1.GroupVersion.String(),
Kind: "RuleSet",
},
ObjectMeta: metav1.ObjectMeta{
Name: modules.UniqueAppName(g.project.Name, g.stack.Name, g.appName),
Namespace: g.project.Name,
},
Spec: v1alpha1.RuleSetSpec{
Selector: metav1.LabelSelector{
MatchLabels: modules.UniqueAppLabels(g.project.Name, g.appName),
if g.app.Workload.Service.Type == workload.TypeCollaset {
maxUnavailable := intstr.Parse(g.app.OpsRule.MaxUnavailable)
resource := &v1alpha1.PodTransitionRule{
TypeMeta: metav1.TypeMeta{
APIVersion: v1alpha1.GroupVersion.String(),
Kind: "PodTransitionRule",
},
Rules: []v1alpha1.RuleSetRule{
{
Name: "maxUnavailable",
RuleSetRuleDefinition: v1alpha1.RuleSetRuleDefinition{
AvailablePolicy: &v1alpha1.AvailableRule{
MaxUnavailableValue: &maxUnavailable,
ObjectMeta: metav1.ObjectMeta{
Name: modules.UniqueAppName(g.project.Name, g.stack.Name, g.appName),
Namespace: g.project.Name,
},
Spec: v1alpha1.PodTransitionRuleSpec{
Selector: &metav1.LabelSelector{
MatchLabels: modules.UniqueAppLabels(g.project.Name, g.appName),
},
Rules: []v1alpha1.TransitionRule{
{
Name: "maxUnavailable",
TransitionRuleDefinition: v1alpha1.TransitionRuleDefinition{
AvailablePolicy: &v1alpha1.AvailableRule{
MaxUnavailableValue: &maxUnavailable,
},
},
},
},
},
},
}
return modules.AppendToIntent(intent.Kubernetes, modules.KubernetesResourceID(resource.TypeMeta, resource.ObjectMeta), spec, resource)
}
return modules.AppendToIntent(intent.Kubernetes, modules.KubernetesResourceID(resource.TypeMeta, resource.ObjectMeta), spec, resource)
return nil
}
6 changes: 3 additions & 3 deletions pkg/modules/generators/trait/ops_rule_generator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,11 @@ func Test_opsRuleGenerator_Generate(t *testing.T) {
exp: &intent.Intent{
Resources: intent.Resources{
intent.Resource{
ID: "apps.kusionstack.io/v1alpha1:RuleSet:default:default-dev-foo",
ID: "apps.kusionstack.io/v1alpha1:PodTransitionRule:default:default-dev-foo",
Type: "Kubernetes",
Attributes: map[string]interface{}{
"apiVersion": "apps.kusionstack.io/v1alpha1",
"kind": "RuleSet",
"kind": "PodTransitionRule",
"metadata": map[string]interface{}{
"creationTimestamp": interface{}(nil),
"name": "default-dev-foo",
Expand All @@ -115,7 +115,7 @@ func Test_opsRuleGenerator_Generate(t *testing.T) {
},
DependsOn: []string(nil),
Extensions: map[string]interface{}{
"GVK": "apps.kusionstack.io/v1alpha1, Kind=RuleSet",
"GVK": "apps.kusionstack.io/v1alpha1, Kind=PodTransitionRule",
},
},
},
Expand Down

0 comments on commit 816225b

Please sign in to comment.