Skip to content

Commit

Permalink
fix: Modify the code as suggested
Browse files Browse the repository at this point in the history
  • Loading branch information
wangwenchao7 committed May 29, 2023
1 parent ea1201e commit 5f868e5
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 18 deletions.
3 changes: 3 additions & 0 deletions pkg/control/sidecarcontrol/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (
"github.com/openkruise/kruise/pkg/util"
utilclient "github.com/openkruise/kruise/pkg/util/client"
"github.com/openkruise/kruise/pkg/util/configuration"
"github.com/openkruise/kruise/pkg/util/expectations"
utilfeature "github.com/openkruise/kruise/pkg/util/feature"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/meta"
Expand Down Expand Up @@ -67,6 +68,8 @@ var (
// SidecarIgnoredNamespaces = []string{"kube-system", "kube-public"}
// SubPathExprEnvReg format: $(ODD_NAME)、$(POD_NAME)...
SubPathExprEnvReg, _ = regexp.Compile(`\$\(([-._a-zA-Z][-._a-zA-Z0-9]*)\)`)

UpdateExpectations = expectations.NewUpdateExpectations(RevisionAdapterImpl)
)

type SidecarSetUpgradeSpec struct {
Expand Down
7 changes: 3 additions & 4 deletions pkg/controller/sidecarset/sidecarset_pod_event_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (

appsv1alpha1 "github.com/openkruise/kruise/apis/apps/v1alpha1"
"github.com/openkruise/kruise/pkg/control/sidecarcontrol"
sidecarsetutils "github.com/openkruise/kruise/pkg/controller/sidecarset/utils"

corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/errors"
Expand Down Expand Up @@ -56,7 +55,7 @@ func (p *enqueueRequestForPod) deletePod(obj runtime.Object) {
return
}
for _, sidecarSet := range sidecarSets {
sidecarsetutils.UpdateExpectations.DeleteObject(sidecarSet.Name, pod)
sidecarcontrol.UpdateExpectations.DeleteObject(sidecarSet.Name, pod)
}
}

Expand All @@ -76,7 +75,7 @@ func (p *enqueueRequestForPod) addPod(q workqueue.RateLimitingInterface, obj run

for _, sidecarSet := range sidecarSets {
if pod.DeletionTimestamp != nil {
sidecarsetutils.UpdateExpectations.DeleteObject(sidecarSet.Name, pod)
sidecarcontrol.UpdateExpectations.DeleteObject(sidecarSet.Name, pod)
}
klog.V(3).Infof("Create pod(%s/%s) and reconcile sidecarSet(%s)", pod.Namespace, pod.Name, sidecarSet.Name)
q.Add(reconcile.Request{
Expand Down Expand Up @@ -104,7 +103,7 @@ func (p *enqueueRequestForPod) updatePod(q workqueue.RateLimitingInterface, old,
continue
}
if newPod.DeletionTimestamp != nil {
sidecarsetutils.UpdateExpectations.DeleteObject(sidecarSet.Name, newPod)
sidecarcontrol.UpdateExpectations.DeleteObject(sidecarSet.Name, newPod)
}
var isChanged bool
var enqueueDelayTime time.Duration
Expand Down
7 changes: 3 additions & 4 deletions pkg/controller/sidecarset/sidecarset_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import (

appsv1alpha1 "github.com/openkruise/kruise/apis/apps/v1alpha1"
"github.com/openkruise/kruise/pkg/control/sidecarcontrol"
sidecarsetutils "github.com/openkruise/kruise/pkg/controller/sidecarset/utils"
"github.com/openkruise/kruise/pkg/util"
utilclient "github.com/openkruise/kruise/pkg/util/client"
historyutil "github.com/openkruise/kruise/pkg/util/history"
Expand Down Expand Up @@ -92,9 +91,9 @@ func (p *Processor) UpdateSidecarSet(sidecarSet *appsv1alpha1.SidecarSet) (recon

// in case of informer cache latency
for _, pod := range pods {
sidecarsetutils.UpdateExpectations.ObserveUpdated(sidecarSet.Name, sidecarcontrol.GetSidecarSetRevision(sidecarSet), pod)
sidecarcontrol.UpdateExpectations.ObserveUpdated(sidecarSet.Name, sidecarcontrol.GetSidecarSetRevision(sidecarSet), pod)
}
allUpdated, _, inflightPods := sidecarsetutils.UpdateExpectations.SatisfiedExpectations(sidecarSet.Name, sidecarcontrol.GetSidecarSetRevision(sidecarSet))
allUpdated, _, inflightPods := sidecarcontrol.UpdateExpectations.SatisfiedExpectations(sidecarSet.Name, sidecarcontrol.GetSidecarSetRevision(sidecarSet))
if !allUpdated {
klog.V(3).Infof("sidecarset %s matched pods has some update in flight: %v, will sync later", sidecarSet.Name, inflightPods)
return reconcile.Result{RequeueAfter: time.Second}, nil
Expand Down Expand Up @@ -168,7 +167,7 @@ func (p *Processor) updatePods(control sidecarcontrol.SidecarControl, pods []*co
klog.Errorf("updatePodSidecarAndHash error, s:%s, pod:%s, err:%v", sidecarset.Name, pod.Name, err)
return err
}
sidecarsetutils.UpdateExpectations.ExpectUpdated(sidecarset.Name, sidecarcontrol.GetSidecarSetRevision(sidecarset), pod)
sidecarcontrol.UpdateExpectations.ExpectUpdated(sidecarset.Name, sidecarcontrol.GetSidecarSetRevision(sidecarset), pod)
}

klog.V(3).Infof("sidecarSet(%s) updated pods(%s)", sidecarset.Name, strings.Join(podNames, ","))
Expand Down
10 changes: 0 additions & 10 deletions pkg/controller/sidecarset/utils/sidecarset_tuils.go

This file was deleted.

0 comments on commit 5f868e5

Please sign in to comment.