Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug 1986003: Switch kubeconfig retries to use backoff #26407

Merged
merged 1 commit into from
Aug 19, 2021
Merged
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
37 changes: 24 additions & 13 deletions test/extended/apiserver/kubeconfigs.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@ import (
"context"
"fmt"
"regexp"
"time"

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

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/wait"
"k8s.io/client-go/util/retry"
"k8s.io/kubernetes/test/e2e/framework"

exutil "github.com/openshift/origin/test/extended/util"
Expand All @@ -32,29 +35,37 @@ var _ = g.Describe("[Conformance][sig-api-machinery][Feature:APIServer] local ku
framework.Logf("Discovered %d master nodes.", len(masterNodes.Items))
o.Expect(masterNodes.Items).NotTo(o.HaveLen(0))
for _, master := range masterNodes.Items {
retry, err := testNode(oc, kubeconfig, master.Name)
for retries := 2; retries > 0; retries-- {
if !retry {
break
}
g.By("There was a retryable error for " + fmt.Sprintf("%s/%s", master.Name, kubeconfig))
retry, err = testNode(oc, kubeconfig, master.Name)
}
err := retry.OnError(
wait.Backoff{
Duration: 2 * time.Second,
Steps: 3,
Factor: 5.0,
Jitter: 0.1,
},
func(err error) bool {
// retry error when kube-apiserver was temporarily unavailable, this matches oc error coming from:
// https://github.com/kubernetes/kubernetes/blob/cbb5ea8210596ada1efce7e7a271ca4217ae598e/staging/src/k8s.io/kubectl/pkg/cmd/util/helpers.go#L237-L243
matched, _ := regexp.MatchString("The connection to the server .+ was refused - did you specify the right host or port", err.Error())
return !matched
},
func() error {
return testNode(oc, kubeconfig, master.Name)
})
o.Expect(err).NotTo(o.HaveOccurred())
}
})
}
})

func testNode(oc *exutil.CLI, kubeconfig, masterName string) (bool, error) {
func testNode(oc *exutil.CLI, kubeconfig, masterName string) error {
g.By("Testing master node " + masterName)
kubeconfigPath := "/etc/kubernetes/static-pod-resources/kube-apiserver-certs/secrets/node-kubeconfigs/" + kubeconfig
framework.Logf("Verifying kubeconfig %q on master %q", kubeconfig, masterName)
out, err := oc.AsAdmin().Run("debug").Args("node/"+masterName, "--", "chroot", "/host", "/bin/bash", "-euxo", "pipefail", "-c",
fmt.Sprintf(`oc --kubeconfig "%s" get namespace kube-system`, kubeconfigPath)).Output()
framework.Logf(out)
// retry error when kube-apiserver was temporarily unavailable, this matches oc error coming from:
// https://github.com/kubernetes/kubernetes/blob/cbb5ea8210596ada1efce7e7a271ca4217ae598e/staging/src/k8s.io/kubectl/pkg/cmd/util/helpers.go#L237-L243
matched, _ := regexp.MatchString("The connection to the server .+ was refused - did you specify the right host or port", out)
return !matched, err
if err != nil {
return fmt.Errorf(out)
Copy link
Contributor

Choose a reason for hiding this comment

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

is The connection to the server .+ was refused - did you specify the right host or port reported in out?

Copy link
Contributor

Choose a reason for hiding this comment

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

ah, I see it was

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, I had to switch from using err to out due to how wait.Retry uses 2 separate functions for action and decision about retry.

}
return nil
}