mirror of
https://github.com/kubevela/kubevela.git
synced 2026-02-23 14:23:54 +00:00
Compare commits
4 Commits
v1.4.7-pat
...
v1.4.9
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
766c5852c6 | ||
|
|
4cb9a14b18 | ||
|
|
9a1e75cf48 | ||
|
|
192dc8966d |
@@ -136,7 +136,7 @@ func (r *Reconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Resu
|
||||
if annotations := app.GetAnnotations(); annotations == nil || annotations[oam.AnnotationKubeVelaVersion] == "" {
|
||||
metav1.SetMetaDataAnnotation(&app.ObjectMeta, oam.AnnotationKubeVelaVersion, version.VelaVersion)
|
||||
}
|
||||
logCtx.AddTag("publish_version", app.GetAnnotations()[oam.AnnotationKubeVelaVersion])
|
||||
logCtx.AddTag("publish_version", app.GetAnnotations()[oam.AnnotationPublishVersion])
|
||||
|
||||
appParser := appfile.NewApplicationParser(r.Client, r.dm, r.pd)
|
||||
handler, err := NewAppHandler(logCtx, r, app, appParser)
|
||||
|
||||
@@ -81,3 +81,14 @@ func TestParseApplyOncePolicy(t *testing.T) {
|
||||
r.NoError(err)
|
||||
r.Equal(policySpec, spec)
|
||||
}
|
||||
|
||||
func TestParsePolicy(t *testing.T) {
|
||||
r := require.New(t)
|
||||
// Test skipping empty policy
|
||||
app := &v1beta1.Application{Spec: v1beta1.ApplicationSpec{
|
||||
Policies: []v1beta1.AppPolicy{{Type: "example", Name: "s", Properties: nil}},
|
||||
}}
|
||||
exists, err := parsePolicy(app, "example", nil)
|
||||
r.False(exists, "empty policy should not be included")
|
||||
r.NoError(err)
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ const (
|
||||
// GetEnvBindingPolicy extract env-binding policy with given policy name, if policy name is empty, the first env-binding policy will be used
|
||||
func GetEnvBindingPolicy(app *v1beta1.Application, policyName string) (*v1alpha1.EnvBindingSpec, error) {
|
||||
for _, policy := range app.Spec.Policies {
|
||||
if (policy.Name == policyName || policyName == "") && policy.Type == v1alpha1.EnvBindingPolicyType {
|
||||
if (policy.Name == policyName || policyName == "") && policy.Type == v1alpha1.EnvBindingPolicyType && policy.Properties != nil {
|
||||
envBindingSpec := &v1alpha1.EnvBindingSpec{}
|
||||
err := json.Unmarshal(policy.Properties.Raw, envBindingSpec)
|
||||
return envBindingSpec, err
|
||||
|
||||
@@ -19,6 +19,7 @@ package policy
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
errors2 "k8s.io/apimachinery/pkg/api/errors"
|
||||
@@ -32,6 +33,9 @@ import (
|
||||
|
||||
// ParseOverridePolicyRelatedDefinitions get definitions inside override policy
|
||||
func ParseOverridePolicyRelatedDefinitions(ctx context.Context, cli client.Client, app *v1beta1.Application, policy v1beta1.AppPolicy) (compDefs []*v1beta1.ComponentDefinition, traitDefs []*v1beta1.TraitDefinition, err error) {
|
||||
if policy.Properties == nil {
|
||||
return compDefs, traitDefs, fmt.Errorf("override policy %s must not have empty properties", policy.Name)
|
||||
}
|
||||
spec := &v1alpha1.OverridePolicySpec{}
|
||||
if err = json.Unmarshal(policy.Properties.Raw, spec); err != nil {
|
||||
return nil, nil, errors.Wrapf(err, "invalid override policy spec")
|
||||
|
||||
@@ -62,6 +62,12 @@ func TestParseOverridePolicyRelatedDefinitions(t *testing.T) {
|
||||
Policy: v1beta1.AppPolicy{Properties: &runtime.RawExtension{Raw: []byte(`{"components":[{"type":"comp","traits":[{"type":"trait-404"}]}]}`)}},
|
||||
Error: "failed to get trait definition",
|
||||
},
|
||||
"empty-policy": {
|
||||
Policy: v1beta1.AppPolicy{Properties: nil},
|
||||
ComponentDefs: nil,
|
||||
TraitDefs: nil,
|
||||
Error: "have empty properties",
|
||||
},
|
||||
}
|
||||
for name, tt := range testCases {
|
||||
t.Run(name, func(t *testing.T) {
|
||||
|
||||
@@ -18,6 +18,7 @@ package policy
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
utilfeature "k8s.io/apiserver/pkg/util/feature"
|
||||
@@ -65,6 +66,9 @@ func GetPlacementsFromTopologyPolicies(ctx context.Context, cli client.Client, a
|
||||
hasTopologyPolicy := false
|
||||
for _, policy := range policies {
|
||||
if policy.Type == v1alpha1.TopologyPolicyType {
|
||||
if policy.Properties == nil {
|
||||
return nil, fmt.Errorf("topology policy %s must not have empty properties", policy.Name)
|
||||
}
|
||||
hasTopologyPolicy = true
|
||||
topologySpec := &v1alpha1.TopologyPolicySpec{}
|
||||
if err := utils.StrictUnmarshal(policy.Properties.Raw, topologySpec); err != nil {
|
||||
|
||||
@@ -146,6 +146,10 @@ func TestGetClusterLabelSelectorInTopology(t *testing.T) {
|
||||
Inputs: []v1beta1.AppPolicy{},
|
||||
Outputs: []v1alpha1.PlacementDecision{{Cluster: "local", Namespace: ""}},
|
||||
},
|
||||
"empty-topology-policy": {
|
||||
Inputs: []v1beta1.AppPolicy{{Type: "topology", Name: "some-name", Properties: nil}},
|
||||
Error: "have empty properties",
|
||||
},
|
||||
}
|
||||
for name, tt := range testCases {
|
||||
t.Run(name, func(t *testing.T) {
|
||||
|
||||
@@ -437,7 +437,7 @@ func (h *gcHandler) GarbageCollectLegacyResourceTrackers(ctx context.Context) er
|
||||
}
|
||||
}
|
||||
for _, policy := range h.app.Spec.Policies {
|
||||
if policy.Type == v1alpha1.EnvBindingPolicyType {
|
||||
if policy.Type == v1alpha1.EnvBindingPolicyType && policy.Properties != nil {
|
||||
spec := &v1alpha1.EnvBindingSpec{}
|
||||
if err = json.Unmarshal(policy.Properties.Raw, &spec); err == nil {
|
||||
for _, env := range spec.Envs {
|
||||
|
||||
@@ -134,7 +134,7 @@ func (h *provider) ApplyInParallel(ctx wfContext.Context, v *value.Value, act ty
|
||||
deployCtx := multicluster.ContextWithClusterName(context.Background(), cluster)
|
||||
deployCtx = auth.ContextWithUserInfo(deployCtx, h.app)
|
||||
if err = h.apply(deployCtx, cluster, common.WorkflowResourceCreator, workloads...); err != nil {
|
||||
return v.FillObject(err, "err")
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -126,6 +126,9 @@ func overrideConfiguration(policies []v1beta1.AppPolicy, components []common.App
|
||||
var err error
|
||||
for _, policy := range policies {
|
||||
if policy.Type == v1alpha1.OverridePolicyType {
|
||||
if policy.Properties == nil {
|
||||
return nil, fmt.Errorf("override policy %s must not have empty properties", policy.Name)
|
||||
}
|
||||
overrideSpec := &v1alpha1.OverridePolicySpec{}
|
||||
if err := utils.StrictUnmarshal(policy.Properties.Raw, overrideSpec); err != nil {
|
||||
return nil, errors.Wrapf(err, "failed to parse override policy %s", policy.Name)
|
||||
|
||||
@@ -48,6 +48,14 @@ func TestOverrideConfiguration(t *testing.T) {
|
||||
}},
|
||||
Error: "failed to parse override policy",
|
||||
},
|
||||
"empty-policy": {
|
||||
Policies: []v1beta1.AppPolicy{{
|
||||
Name: "override-policy",
|
||||
Type: "override",
|
||||
Properties: nil,
|
||||
}},
|
||||
Error: "empty properties",
|
||||
},
|
||||
"normal": {
|
||||
Policies: []v1beta1.AppPolicy{{
|
||||
Name: "override-policy",
|
||||
|
||||
@@ -403,14 +403,14 @@ func (w *workflow) setMetadataToContext(wfCtx wfContext.Context) error {
|
||||
return wfCtx.SetVar(metadata, wfTypes.ContextKeyMetadata)
|
||||
}
|
||||
|
||||
func (e *engine) getBackoffTimes(stepID string) (success bool, backoffTimes int) {
|
||||
func (e *engine) getBackoffTimes(stepID string) int {
|
||||
if v, ok := e.wfCtx.GetValueInMemory(wfTypes.ContextPrefixBackoffTimes, stepID); ok {
|
||||
times, ok := v.(int)
|
||||
if ok {
|
||||
return true, times
|
||||
return times
|
||||
}
|
||||
}
|
||||
return false, 0
|
||||
return -1
|
||||
}
|
||||
|
||||
func (e *engine) getBackoffWaitTime() int {
|
||||
@@ -418,17 +418,19 @@ func (e *engine) getBackoffWaitTime() int {
|
||||
minTimes := 15
|
||||
found := false
|
||||
for _, step := range e.status.Steps {
|
||||
success, backoffTimes := e.getBackoffTimes(step.ID)
|
||||
if success && backoffTimes < minTimes {
|
||||
minTimes = backoffTimes
|
||||
if backoffTimes := e.getBackoffTimes(step.ID); backoffTimes > 0 {
|
||||
found = true
|
||||
if backoffTimes < minTimes {
|
||||
minTimes = backoffTimes
|
||||
}
|
||||
}
|
||||
if step.SubStepsStatus != nil {
|
||||
for _, subStep := range step.SubStepsStatus {
|
||||
success, backoffTimes := e.getBackoffTimes(subStep.ID)
|
||||
if success && backoffTimes < minTimes {
|
||||
minTimes = backoffTimes
|
||||
if backoffTimes := e.getBackoffTimes(subStep.ID); backoffTimes > 0 {
|
||||
found = true
|
||||
if backoffTimes < minTimes {
|
||||
minTimes = backoffTimes
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -912,10 +912,12 @@ var _ = Describe("Test Workflow", func() {
|
||||
Expect(interval).Should(BeEquivalentTo(int(0.05 * math.Pow(2, float64(i+5)))))
|
||||
}
|
||||
|
||||
_, err = wf.ExecuteSteps(ctx, revision, runners)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
interval = e.getBackoffWaitTime()
|
||||
Expect(interval).Should(BeEquivalentTo(MaxWorkflowWaitBackoffTime))
|
||||
for i := 0; i < 10; i++ {
|
||||
_, err = wf.ExecuteSteps(ctx, revision, runners)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
interval = e.getBackoffWaitTime()
|
||||
Expect(interval).Should(BeEquivalentTo(MaxWorkflowWaitBackoffTime))
|
||||
}
|
||||
|
||||
By("Test get backoff time after clean")
|
||||
wfContext.CleanupMemoryStore(app.Name, app.Namespace)
|
||||
|
||||
Reference in New Issue
Block a user