fix golint failures of test/e2e/auth
This commit is contained in:
@@ -30,13 +30,13 @@ import (
|
||||
e2elog "k8s.io/kubernetes/test/e2e/framework/log"
|
||||
imageutils "k8s.io/kubernetes/test/utils/image"
|
||||
|
||||
. "github.com/onsi/ginkgo"
|
||||
. "github.com/onsi/gomega"
|
||||
"github.com/onsi/ginkgo"
|
||||
"github.com/onsi/gomega"
|
||||
)
|
||||
|
||||
const (
|
||||
NodesGroup = "system:nodes"
|
||||
NodeNamePrefix = "system:node:"
|
||||
nodesGroup = "system:nodes"
|
||||
nodeNamePrefix = "system:node:"
|
||||
)
|
||||
|
||||
var _ = SIGDescribe("[Feature:NodeAuthorizer]", func() {
|
||||
@@ -48,47 +48,47 @@ var _ = SIGDescribe("[Feature:NodeAuthorizer]", func() {
|
||||
var asUser string
|
||||
var defaultSaSecret string
|
||||
var nodeName string
|
||||
BeforeEach(func() {
|
||||
ginkgo.BeforeEach(func() {
|
||||
ns = f.Namespace.Name
|
||||
|
||||
nodeList, err := f.ClientSet.CoreV1().Nodes().List(metav1.ListOptions{})
|
||||
framework.ExpectNoError(err, "failed to list nodes in namespace: %s", ns)
|
||||
Expect(len(nodeList.Items)).NotTo(Equal(0))
|
||||
gomega.Expect(len(nodeList.Items)).NotTo(gomega.Equal(0))
|
||||
nodeName = nodeList.Items[0].Name
|
||||
asUser = NodeNamePrefix + nodeName
|
||||
asUser = nodeNamePrefix + nodeName
|
||||
saName := "default"
|
||||
sa, err := f.ClientSet.CoreV1().ServiceAccounts(ns).Get(saName, metav1.GetOptions{})
|
||||
Expect(len(sa.Secrets)).NotTo(Equal(0))
|
||||
gomega.Expect(len(sa.Secrets)).NotTo(gomega.Equal(0))
|
||||
framework.ExpectNoError(err, "failed to retrieve service account (%s:%s)", ns, saName)
|
||||
defaultSaSecret = sa.Secrets[0].Name
|
||||
By("Creating a kubernetes client that impersonates a node")
|
||||
ginkgo.By("Creating a kubernetes client that impersonates a node")
|
||||
config, err := framework.LoadConfig()
|
||||
framework.ExpectNoError(err, "failed to load kubernetes client config")
|
||||
config.Impersonate = restclient.ImpersonationConfig{
|
||||
UserName: asUser,
|
||||
Groups: []string{NodesGroup},
|
||||
Groups: []string{nodesGroup},
|
||||
}
|
||||
c, err = clientset.NewForConfig(config)
|
||||
framework.ExpectNoError(err, "failed to create Clientset for the given config: %+v", *config)
|
||||
|
||||
})
|
||||
It("Getting a non-existent secret should exit with the Forbidden error, not a NotFound error", func() {
|
||||
ginkgo.It("Getting a non-existent secret should exit with the Forbidden error, not a NotFound error", func() {
|
||||
_, err := c.CoreV1().Secrets(ns).Get("foo", metav1.GetOptions{})
|
||||
Expect(apierrors.IsForbidden(err)).Should(Equal(true))
|
||||
gomega.Expect(apierrors.IsForbidden(err)).Should(gomega.Equal(true))
|
||||
})
|
||||
|
||||
It("Getting an existing secret should exit with the Forbidden error", func() {
|
||||
ginkgo.It("Getting an existing secret should exit with the Forbidden error", func() {
|
||||
_, err := c.CoreV1().Secrets(ns).Get(defaultSaSecret, metav1.GetOptions{})
|
||||
Expect(apierrors.IsForbidden(err)).Should(Equal(true))
|
||||
gomega.Expect(apierrors.IsForbidden(err)).Should(gomega.Equal(true))
|
||||
})
|
||||
|
||||
It("Getting a non-existent configmap should exit with the Forbidden error, not a NotFound error", func() {
|
||||
ginkgo.It("Getting a non-existent configmap should exit with the Forbidden error, not a NotFound error", func() {
|
||||
_, err := c.CoreV1().ConfigMaps(ns).Get("foo", metav1.GetOptions{})
|
||||
Expect(apierrors.IsForbidden(err)).Should(Equal(true))
|
||||
gomega.Expect(apierrors.IsForbidden(err)).Should(gomega.Equal(true))
|
||||
})
|
||||
|
||||
It("Getting an existing configmap should exit with the Forbidden error", func() {
|
||||
By("Create a configmap for testing")
|
||||
ginkgo.It("Getting an existing configmap should exit with the Forbidden error", func() {
|
||||
ginkgo.By("Create a configmap for testing")
|
||||
configmap := &v1.ConfigMap{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Namespace: ns,
|
||||
@@ -101,11 +101,11 @@ var _ = SIGDescribe("[Feature:NodeAuthorizer]", func() {
|
||||
_, err := f.ClientSet.CoreV1().ConfigMaps(ns).Create(configmap)
|
||||
framework.ExpectNoError(err, "failed to create configmap (%s:%s) %+v", ns, configmap.Name, *configmap)
|
||||
_, err = c.CoreV1().ConfigMaps(ns).Get(configmap.Name, metav1.GetOptions{})
|
||||
Expect(apierrors.IsForbidden(err)).Should(Equal(true))
|
||||
gomega.Expect(apierrors.IsForbidden(err)).Should(gomega.Equal(true))
|
||||
})
|
||||
|
||||
It("Getting a secret for a workload the node has access to should succeed", func() {
|
||||
By("Create a secret for testing")
|
||||
ginkgo.It("Getting a secret for a workload the node has access to should succeed", func() {
|
||||
ginkgo.By("Create a secret for testing")
|
||||
secret := &v1.Secret{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Namespace: ns,
|
||||
@@ -118,11 +118,11 @@ var _ = SIGDescribe("[Feature:NodeAuthorizer]", func() {
|
||||
_, err := f.ClientSet.CoreV1().Secrets(ns).Create(secret)
|
||||
framework.ExpectNoError(err, "failed to create secret (%s:%s)", ns, secret.Name)
|
||||
|
||||
By("Node should not get the secret")
|
||||
ginkgo.By("Node should not get the secret")
|
||||
_, err = c.CoreV1().Secrets(ns).Get(secret.Name, metav1.GetOptions{})
|
||||
Expect(apierrors.IsForbidden(err)).Should(Equal(true))
|
||||
gomega.Expect(apierrors.IsForbidden(err)).Should(gomega.Equal(true))
|
||||
|
||||
By("Create a pod that use the secret")
|
||||
ginkgo.By("Create a pod that use the secret")
|
||||
pod := &v1.Pod{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: "pause",
|
||||
@@ -151,7 +151,7 @@ var _ = SIGDescribe("[Feature:NodeAuthorizer]", func() {
|
||||
_, err = f.ClientSet.CoreV1().Pods(ns).Create(pod)
|
||||
framework.ExpectNoError(err, "failed to create pod (%s:%s)", ns, pod.Name)
|
||||
|
||||
By("The node should able to access the secret")
|
||||
ginkgo.By("The node should able to access the secret")
|
||||
itv := framework.Poll
|
||||
dur := 1 * time.Minute
|
||||
err = wait.Poll(itv, dur, func() (bool, error) {
|
||||
@@ -165,7 +165,7 @@ var _ = SIGDescribe("[Feature:NodeAuthorizer]", func() {
|
||||
framework.ExpectNoError(err, "failed to get secret after trying every %v for %v (%s:%s)", itv, dur, ns, secret.Name)
|
||||
})
|
||||
|
||||
It("A node shouldn't be able to create another node", func() {
|
||||
ginkgo.It("A node shouldn't be able to create another node", func() {
|
||||
node := &v1.Node{
|
||||
ObjectMeta: metav1.ObjectMeta{Name: "foo"},
|
||||
TypeMeta: metav1.TypeMeta{
|
||||
@@ -173,14 +173,14 @@ var _ = SIGDescribe("[Feature:NodeAuthorizer]", func() {
|
||||
APIVersion: "v1",
|
||||
},
|
||||
}
|
||||
By(fmt.Sprintf("Create node foo by user: %v", asUser))
|
||||
ginkgo.By(fmt.Sprintf("Create node foo by user: %v", asUser))
|
||||
_, err := c.CoreV1().Nodes().Create(node)
|
||||
Expect(apierrors.IsForbidden(err)).Should(Equal(true))
|
||||
gomega.Expect(apierrors.IsForbidden(err)).Should(gomega.Equal(true))
|
||||
})
|
||||
|
||||
It("A node shouldn't be able to delete another node", func() {
|
||||
By(fmt.Sprintf("Create node foo by user: %v", asUser))
|
||||
ginkgo.It("A node shouldn't be able to delete another node", func() {
|
||||
ginkgo.By(fmt.Sprintf("Create node foo by user: %v", asUser))
|
||||
err := c.CoreV1().Nodes().Delete("foo", &metav1.DeleteOptions{})
|
||||
Expect(apierrors.IsForbidden(err)).Should(Equal(true))
|
||||
gomega.Expect(apierrors.IsForbidden(err)).Should(gomega.Equal(true))
|
||||
})
|
||||
})
|
||||
|
Reference in New Issue
Block a user