Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 81 additions & 0 deletions test/extended/operators/leases.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
package operators

import (

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we want to start from exclude list so the test will be green?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we want to start from exclude list so the test will be green?

given how far off we are, let's close a few and then add the list. Many ought to be easy.

"context"
"encoding/json"
"fmt"
"strings"

"k8s.io/client-go/tools/leaderelection/resourcelock"

g "github.com/onsi/ginkgo"
o "github.com/onsi/gomega"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
e2e "k8s.io/kubernetes/test/e2e/framework"
)

var _ = g.Describe("[sig-arch] Leases", func() {
defer g.GinkgoRecover()

g.It("should be able to span 60s kube-apiserver disruption", func() {
ctx := context.Background()

kubeClient, err := e2e.LoadClientset()
o.Expect(err).NotTo(o.HaveOccurred())

shortLeases := []string{}

configMaps, err := kubeClient.CoreV1().ConfigMaps("").List(ctx, metav1.ListOptions{})

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how about using a paginated list instead?

o.Expect(err).NotTo(o.HaveOccurred())
for _, configmap := range configMaps.Items {
leaderElection, ok := configmap.Annotations[resourcelock.LeaderElectionRecordAnnotationKey]
if !ok {
continue
}
leaderElectionRecord := &resourcelock.LeaderElectionRecord{}
if err := json.Unmarshal([]byte(leaderElection), leaderElectionRecord); err != nil {
o.Expect(err).NotTo(o.HaveOccurred())
}
if leaderElectionRecord.LeaseDurationSeconds < 107 {
shortLeases = append(shortLeases, fmt.Sprintf("configmap/%s used by %q, has too short a lease (%d) to span 60s kube-apiserver disruption. Try 107s leaseDuration with 13s retryPeriod and a 85s renewDeadline. Be sure you have the graceful release properly wired.", configmap.Name, leaderElectionRecord.HolderIdentity, leaderElectionRecord.LeaseDurationSeconds))
}
}

endpoints, err := kubeClient.CoreV1().Endpoints("").List(ctx, metav1.ListOptions{})
o.Expect(err).NotTo(o.HaveOccurred())
for _, endpoint := range endpoints.Items {
leaderElection, ok := endpoint.Annotations[resourcelock.LeaderElectionRecordAnnotationKey]

@romfreiman romfreiman Jun 9, 2021

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe to have this as an function and call it both for cm and endpoints?

if !ok {
continue
}
leaderElectionRecord := &resourcelock.LeaderElectionRecord{}
if err := json.Unmarshal([]byte(leaderElection), leaderElectionRecord); err != nil {
o.Expect(err).NotTo(o.HaveOccurred())
}
if leaderElectionRecord.LeaseDurationSeconds < 107 {
shortLeases = append(shortLeases, fmt.Sprintf("endpoint/%s used by %q, has too short a lease (%d) to span 60s kube-apiserver disruption. Try 107s leaseDuration with 13s retryPeriod and a 85s renewDeadline. Be sure you have the graceful release properly wired.", endpoint.Name, leaderElectionRecord.HolderIdentity, leaderElectionRecord.LeaseDurationSeconds))
}
}

leases, err := kubeClient.CoordinationV1().Leases("").List(ctx, metav1.ListOptions{})

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it looks like kube-apiservers use the lease, we could filter them out

o.Expect(err).NotTo(o.HaveOccurred())
for _, lease := range leases.Items {
if lease.Spec.LeaseDurationSeconds != nil && *lease.Spec.LeaseDurationSeconds < 107 {
identity := "MISSING"
if lease.Spec.HolderIdentity != nil {
identity = *lease.Spec.HolderIdentity
}
shortLeases = append(shortLeases, fmt.Sprintf("lease/%s used by %q, has too short a lease (%d) to span 60s kube-apiserver disruption. Try 107s leaseDuration with 13s retryPeriod and a 85s renewDeadline. Be sure you have the graceful release properly wired.", lease.Name, identity, *lease.Spec.LeaseDurationSeconds))
}
}

if len(shortLeases) > 0 {
//if suppressPreTestFailure {
// result.Flakef("pre-test environment had disruption and limited this test, suppressing failure: %s", failMessage)
//} else {
g.Fail(strings.Join(shortLeases, "\n"))
//}
}
})
})

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.