Skip to content

Commit

Permalink
resume progress
Browse files Browse the repository at this point in the history
  • Loading branch information
enshi.wzh committed Dec 14, 2023
1 parent e590adf commit 63e6d2c
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 4 deletions.
Binary file modified .DS_Store
Binary file not shown.
4 changes: 2 additions & 2 deletions certs/csr_details.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ distinguished_name = dn
C=CN
ST=Hangzhou
L=Hangzhou
O=Alibaba
OU=Alibaba Cloud
O=TraasStack
OU=Alipay
CN=altershield

[ req_ext ]
Expand Down
1 change: 1 addition & 0 deletions pkg/constants/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const (
)

const (
LabelContinue = "altershield.io/continue"
LabelChangeDefense = "altershield.io/change-defense"
LabelCurrentExecutionID = "altershield.io/current-execution-id"
)
Expand Down
16 changes: 16 additions & 0 deletions pkg/controllers/changedefenseexecution_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"fmt"
v1alpha1 "github.com/traas-stack/altershield-operator/apis/app.ops.cloud.alipay.com/v1alpha1"
ac "github.com/traas-stack/altershield-operator/pkg/altershield/client"
"github.com/traas-stack/altershield-operator/pkg/constants"
"github.com/traas-stack/altershield-operator/pkg/types"
"github.com/traas-stack/altershield-operator/pkg/utils"
apps "k8s.io/api/apps/v1"
Expand All @@ -34,6 +35,7 @@ import (
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/controller"
"sigs.k8s.io/controller-runtime/pkg/source"
"strconv"
"time"
)

Expand Down Expand Up @@ -147,6 +149,12 @@ func (r *ChangeDefenseExecutionReconciler) processInitial(changeDefenseExec *v1a
currentBatch := newStatus.DefenseStatus.CurrentBatch
steps := changeDefenseExec.Spec.DefenseStrategy.Workload.Steps

// label target object to resume
if err := r.resumeProgress(info.Obj); err != nil {
klog.Errorf("failed to resume change progress: %v", err)
return ctrl.Result{Requeue: true}, err
}

request := ac.NewSubmitChangeExecBatchStartNotifyRequest(changeDefenseExec.Spec.ID, currentBatch, len(steps), info)
response, err := r.AsClient.SubmitChangeExecBatchStartNotify(request)
if err != nil {
Expand All @@ -159,6 +167,14 @@ func (r *ChangeDefenseExecutionReconciler) processInitial(changeDefenseExec *v1a
return ctrl.Result{}, nil
}

func (r *ChangeDefenseExecutionReconciler) resumeProgress(in client.Object) error {
if in.GetLabels() == nil {
in.SetLabels(make(map[string]string))
}
in.GetLabels()[constants.LabelContinue] = strconv.FormatInt(time.Now().UnixMilli(), 10)
return r.Update(context.TODO(), in)
}

func (r *ChangeDefenseExecutionReconciler) processProgressing(changeDefenseExec *v1alpha1.ChangeDefenseExecution,
newStatus *v1alpha1.ChangeDefenseExecutionStatus, workloadInfo *types.WorkloadInfo) (ctrl.Result, error) {
currentBatch := newStatus.DefenseStatus.CurrentBatch
Expand Down
3 changes: 1 addition & 2 deletions pkg/metric/provider/prometheus/object_series_registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package prometheus

import (
"fmt"
"k8s.io/klog/v2"
"sync"

apimeta "k8s.io/apimachinery/pkg/api/meta"
Expand Down Expand Up @@ -80,7 +79,7 @@ func (r *objectSeriesRegistry) SetSeries(newSeriesSlices [][]promadapterclient.S
for i, newSeries := range newSeriesSlices {
namer := namers[i]
addedSeries := make(map[string]struct{})
for index, series := range newSeries {
for _, series := range newSeries {
if _, ok := addedSeries[series.Name]; ok {
continue
}
Expand Down

0 comments on commit 63e6d2c

Please sign in to comment.