From 6ad585464a64efa377a8dcfe8b0783da3b0bcd07 Mon Sep 17 00:00:00 2001 From: LiZhenCheng9527 Date: Tue, 9 Jan 2024 19:08:44 +0800 Subject: [PATCH] fix by comment Signed-off-by: LiZhenCheng9527 --- pkg/fleet-manager/application/helper.go | 2 +- .../application/manifests/rollout_testloader.go | 17 +---------------- pkg/fleet-manager/application/rollout_helper.go | 9 +++------ .../application/rollout_helper_test.go | 3 ++- 4 files changed, 7 insertions(+), 24 deletions(-) diff --git a/pkg/fleet-manager/application/helper.go b/pkg/fleet-manager/application/helper.go index 9e5374731..a2d427b30 100644 --- a/pkg/fleet-manager/application/helper.go +++ b/pkg/fleet-manager/application/helper.go @@ -70,7 +70,7 @@ func (a *ApplicationManager) syncPolicyResource(ctx context.Context, app *applic } if result, err := a.syncRolloutPolicyForCluster(ctx, syncPolicy.Rollout, rolloutClusters, policyName); err != nil { - return result, errors.Wrapf(err, "failed to handleSyncPolicyByKind currentFleetCluster") + return result, errors.Wrapf(err, "failed to syncRolloutPolicy") } } diff --git a/pkg/fleet-manager/application/manifests/rollout_testloader.go b/pkg/fleet-manager/application/manifests/rollout_testloader.go index 1576c3cb4..8ca019681 100644 --- a/pkg/fleet-manager/application/manifests/rollout_testloader.go +++ b/pkg/fleet-manager/application/manifests/rollout_testloader.go @@ -17,9 +17,7 @@ import ( "bytes" "text/template" - "github.com/Masterminds/sprig/v3" "k8s.io/apimachinery/pkg/types" - "sigs.k8s.io/yaml" ) type TestloaderConfig struct { @@ -62,21 +60,8 @@ func renderTestloaderTemplateConfig(constTemplateName string, cfg TestloaderConf return b.Bytes(), nil } -// funMap returns a map of functions for use in the template. func funMap() template.FuncMap { - m := sprig.TxtFuncMap() - m["toYaml"] = toYaml - return m -} - -// toYaml converts a given value to its YAML representation. -func toYaml(value interface{}) string { - y, err := yaml.Marshal(value) - if err != nil { - return "" - } - - return string(y) + return nil } const TestlaoderDeployment = `apiVersion: apps/v1 diff --git a/pkg/fleet-manager/application/rollout_helper.go b/pkg/fleet-manager/application/rollout_helper.go index 7fb00733f..c66d8a2f0 100644 --- a/pkg/fleet-manager/application/rollout_helper.go +++ b/pkg/fleet-manager/application/rollout_helper.go @@ -222,13 +222,13 @@ func installPrivateTestloader(ctx context.Context, namespacedName types.Namespac func deleteResourceCreatedByKurator(ctx context.Context, namespaceName types.NamespacedName, kubeClient client.Client, obj client.Object) error { if err := kubeClient.Get(ctx, namespaceName, obj); err != nil { if !apierrors.IsNotFound(err) { - return errors.Wrapf(err, "get kubernetes resource error") + return errors.Wrapf(err, "falied to get resource %s in %s", namespaceName.Name, namespaceName.Namespace) } } else { // verify if the deployment were created by kurator annotations := obj.GetAnnotations() if _, exist := annotations[RolloutIdentifier]; exist { - if deleteErr := kubeClient.Delete(ctx, obj); deleteErr != nil { + if deleteErr := kubeClient.Delete(ctx, obj); deleteErr != nil && !apierrors.IsNotFound(deleteErr) { return errors.Wrapf(deleteErr, "failed to delete kubernetes resource") } } @@ -238,9 +238,6 @@ func deleteResourceCreatedByKurator(ctx context.Context, namespaceName types.Nam // create/update canary configuration func renderCanary(rolloutPolicy applicationapi.RolloutConfig, canaryInCluster *flaggerv1b1.Canary) *flaggerv1b1.Canary { - value := int32(*rolloutPolicy.RolloutPolicy.RolloutTimeoutSeconds) - ptrValue := &value - canaryInCluster.ObjectMeta.Namespace = rolloutPolicy.Workload.Namespace canaryInCluster.ObjectMeta.Name = rolloutPolicy.Workload.Name canaryInCluster.TypeMeta.Kind = "Canary" @@ -252,7 +249,7 @@ func renderCanary(rolloutPolicy applicationapi.RolloutConfig, canaryInCluster *f Kind: rolloutPolicy.Workload.Kind, Name: rolloutPolicy.Workload.Name, }, - ProgressDeadlineSeconds: ptrValue, + ProgressDeadlineSeconds: rolloutPolicy.RolloutPolicy.RolloutTimeoutSeconds, SkipAnalysis: rolloutPolicy.RolloutPolicy.SkipTrafficAnalysis, RevertOnDeletion: rolloutPolicy.RolloutPolicy.RevertOnDeletion, Suspend: rolloutPolicy.RolloutPolicy.Suspend, diff --git a/pkg/fleet-manager/application/rollout_helper_test.go b/pkg/fleet-manager/application/rollout_helper_test.go index 40d621e6f..4bf90e1f5 100644 --- a/pkg/fleet-manager/application/rollout_helper_test.go +++ b/pkg/fleet-manager/application/rollout_helper_test.go @@ -33,6 +33,7 @@ import ( func generateRolloutPloicy(installPrivateTestloader *bool) applicationapi.RolloutConfig { timeout := 50 + RolloutTimeoutSeconds := int32(50) min := 99.0 max := 500.0 @@ -128,7 +129,7 @@ func generateRolloutPloicy(installPrivateTestloader *bool) applicationapi.Rollou MaxAge: 24, }, }, - RolloutTimeoutSeconds: &timeout, + RolloutTimeoutSeconds: &RolloutTimeoutSeconds, SkipTrafficAnalysis: false, RevertOnDeletion: false, Suspend: false,