Skip to content
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
31 changes: 25 additions & 6 deletions test/extended/apiserver/kubeconfigs.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@ package apiserver
import (
"context"
"fmt"
"regexp"

g "github.com/onsi/ginkgo"
o "github.com/onsi/gomega"
exutil "github.com/openshift/origin/test/extended/util"

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

exutil "github.com/openshift/origin/test/extended/util"
)

var _ = g.Describe("[Conformance][sig-api-machinery][Feature:APIServer] local kubeconfig", func() {
Expand All @@ -29,13 +32,29 @@ 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 {
g.By("Testing master node " + master.Name)
kubeconfigPath := "/etc/kubernetes/static-pod-resources/kube-apiserver-certs/secrets/node-kubeconfigs/" + kubeconfig
framework.Logf("Verifying kubeconfig %q on master %s", master.Name)
out, err := oc.AsAdmin().Run("debug").Args("node/"+master.Name, "--", "chroot", "/host", "/bin/bash", "-euxo", "pipefail", "-c", fmt.Sprintf(`oc --kubeconfig "%s" get namespace kube-system`, kubeconfigPath)).Output()
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)
}
o.Expect(err).NotTo(o.HaveOccurred())
framework.Logf(out)
}
})
}
})

func testNode(oc *exutil.CLI, kubeconfig, masterName string) (bool, 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
Copy link

Choose a reason for hiding this comment

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

the message you've linked ends with a quesiton tag, but the regex work fine
https://play.golang.org/p/aBGVR3_3YsQ

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 didn't want to be that precise 😉

Copy link

Choose a reason for hiding this comment

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

those symbols on regexps 😬
🤣

matched, _ := regexp.MatchString("The connection to the server .+ was refused - did you specify the right host or port", out)
return !matched, err
}