Skip to content

Commit

Permalink
One more test
Browse files Browse the repository at this point in the history
  • Loading branch information
videlov committed Jan 23, 2025
1 parent dbae26a commit e7b5925
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
4 changes: 2 additions & 2 deletions pkg/lib/sidecars/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,13 @@ func (p *ProxyRestart) RestartProxies(ctx context.Context, expectedImage predica
func (p *ProxyRestart) RestartWithPredicates(ctx context.Context, preds []predicates.SidecarProxyPredicate, limits *pods.PodsRestartLimits, failOnError bool) ([]restart.RestartWarning, bool, error) {
podsToRestart, err := p.podsLister.GetPodsToRestart(ctx, preds, limits)
if err != nil {
p.logger.Error(err, "Getting Kyma pods to restart failed")
p.logger.Error(err, "Getting pods to restart failed")
return nil, false, err
}

warnings, err := restart.Restart(ctx, p.k8sClient, podsToRestart, p.logger, failOnError)
if err != nil {
p.logger.Error(err, "Restarting Kyma pods failed")
p.logger.Error(err, "Restarting pods failed")
return nil, false, err
}

Expand Down
26 changes: 26 additions & 0 deletions pkg/lib/sidecars/proxy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"github.com/kyma-project/istio/operator/pkg/labels"
"github.com/kyma-project/istio/operator/pkg/lib/sidecars"
"github.com/kyma-project/istio/operator/pkg/lib/sidecars/pods"
"github.com/kyma-project/istio/operator/pkg/lib/sidecars/restart"
"github.com/kyma-project/istio/operator/pkg/lib/sidecars/test/helpers"
. "github.com/onsi/ginkgo/v2"
ginkgotypes "github.com/onsi/ginkgo/v2/types"
Expand Down Expand Up @@ -346,6 +347,31 @@ var _ = Describe("RestartWithPredicates", func() {

Expect(err.Error()).To(Equal("running pod restart action failed: intentionally failing client on client.Patch"))
})

It("should not return error if restarting pods fails but failOnError is false", func() {
// given
pod := getPod("test-pod", "test-namespace", "podOwner", "ReplicaSet")
rsOwner := getReplicaSet("podOwner", "test-namespace", "rsOwner", "ReplicaSet")
rsOwnerRS := getReplicaSet("rsOwner", "test-namespace", "base", "ReplicaSet")
c := fakeClient(pod, rsOwner, rsOwnerRS)

preds := []predicates.SidecarProxyPredicate{
predicates.NewImageResourcesPredicate(predicates.SidecarImage{Repository: "istio", Tag: "1.1.0"}, helpers.DefaultSidecarResources),
}
limits := pods.NewPodsRestartLimits(2, 2)

// when
failClient := &shouldFailClient{c, false, true}

podsLister := pods.NewPods(failClient, &logger)
proxyRestarter := sidecars.NewProxyRestarter(failClient, podsLister, &logger)
warnings, hasMorePods, err := proxyRestarter.RestartWithPredicates(ctx, preds, limits, false)

// then
Expect(err).ToNot(HaveOccurred())
Expect(warnings).To(Equal([]restart.RestartWarning{}))
Expect(hasMorePods).To(BeFalse())
})
})

func getPod(name, namespace, ownerName, ownerKind string) *v1.Pod {
Expand Down

0 comments on commit e7b5925

Please sign in to comment.