mirror of https://github.com/k3s-io/k3s
fix golint failures of test/e2e_kubeadm/util.go
parent
18533fe84f
commit
270e27d4b7
|
@ -25,12 +25,13 @@ import (
|
||||||
clientset "k8s.io/client-go/kubernetes"
|
clientset "k8s.io/client-go/kubernetes"
|
||||||
"k8s.io/kubernetes/test/e2e/framework"
|
"k8s.io/kubernetes/test/e2e/framework"
|
||||||
|
|
||||||
. "github.com/onsi/gomega"
|
"github.com/onsi/gomega"
|
||||||
"github.com/onsi/gomega/gstruct"
|
"github.com/onsi/gomega/gstruct"
|
||||||
)
|
)
|
||||||
|
|
||||||
// ServiceAccounts utils
|
// ServiceAccounts utils
|
||||||
|
|
||||||
|
// ExpectServiceAccount expects to be able to get the ServiceAccount with specific name from the namespace
|
||||||
func ExpectServiceAccount(c clientset.Interface, namespace, name string) {
|
func ExpectServiceAccount(c clientset.Interface, namespace, name string) {
|
||||||
_, err := c.CoreV1().
|
_, err := c.CoreV1().
|
||||||
ServiceAccounts(namespace).
|
ServiceAccounts(namespace).
|
||||||
|
@ -40,6 +41,7 @@ func ExpectServiceAccount(c clientset.Interface, namespace, name string) {
|
||||||
|
|
||||||
// Secret utils
|
// Secret utils
|
||||||
|
|
||||||
|
// GetSecret gets Secret with specific name from the namespace
|
||||||
func GetSecret(c clientset.Interface, namespace, name string) *corev1.Secret {
|
func GetSecret(c clientset.Interface, namespace, name string) *corev1.Secret {
|
||||||
r, err := c.CoreV1().
|
r, err := c.CoreV1().
|
||||||
Secrets(namespace).
|
Secrets(namespace).
|
||||||
|
@ -50,6 +52,7 @@ func GetSecret(c clientset.Interface, namespace, name string) *corev1.Secret {
|
||||||
|
|
||||||
// ConfigMaps utils
|
// ConfigMaps utils
|
||||||
|
|
||||||
|
// GetConfigMap gets ConfigMap with specific name from the namespace
|
||||||
func GetConfigMap(c clientset.Interface, namespace, name string) *corev1.ConfigMap {
|
func GetConfigMap(c clientset.Interface, namespace, name string) *corev1.ConfigMap {
|
||||||
r, err := c.CoreV1().
|
r, err := c.CoreV1().
|
||||||
ConfigMaps(namespace).
|
ConfigMaps(namespace).
|
||||||
|
@ -60,6 +63,7 @@ func GetConfigMap(c clientset.Interface, namespace, name string) *corev1.ConfigM
|
||||||
|
|
||||||
// Service utils
|
// Service utils
|
||||||
|
|
||||||
|
// ExpectService expects to be able to get the Service with specific name from the namespace
|
||||||
func ExpectService(c clientset.Interface, namespace, name string) {
|
func ExpectService(c clientset.Interface, namespace, name string) {
|
||||||
_, err := c.CoreV1().
|
_, err := c.CoreV1().
|
||||||
Services(namespace).
|
Services(namespace).
|
||||||
|
@ -69,6 +73,7 @@ func ExpectService(c clientset.Interface, namespace, name string) {
|
||||||
|
|
||||||
// Deployments utils
|
// Deployments utils
|
||||||
|
|
||||||
|
// GetDeployment gets Deployment with specific name from the namespace
|
||||||
func GetDeployment(c clientset.Interface, namespace, name string) *appsv1.Deployment {
|
func GetDeployment(c clientset.Interface, namespace, name string) *appsv1.Deployment {
|
||||||
r, err := c.AppsV1().
|
r, err := c.AppsV1().
|
||||||
Deployments(namespace).
|
Deployments(namespace).
|
||||||
|
@ -79,6 +84,7 @@ func GetDeployment(c clientset.Interface, namespace, name string) *appsv1.Deploy
|
||||||
|
|
||||||
// DaemonSets utils
|
// DaemonSets utils
|
||||||
|
|
||||||
|
// GetDaemonSet gets DaemonSet with specific name from the namespace
|
||||||
func GetDaemonSet(c clientset.Interface, namespace, name string) *appsv1.DaemonSet {
|
func GetDaemonSet(c clientset.Interface, namespace, name string) *appsv1.DaemonSet {
|
||||||
r, err := c.AppsV1().
|
r, err := c.AppsV1().
|
||||||
DaemonSets(namespace).
|
DaemonSets(namespace).
|
||||||
|
@ -89,6 +95,7 @@ func GetDaemonSet(c clientset.Interface, namespace, name string) *appsv1.DaemonS
|
||||||
|
|
||||||
// RBAC utils
|
// RBAC utils
|
||||||
|
|
||||||
|
// ExpectRole expects to be able to get the Role with specific name from the namespace
|
||||||
func ExpectRole(c clientset.Interface, namespace, name string) {
|
func ExpectRole(c clientset.Interface, namespace, name string) {
|
||||||
_, err := c.RbacV1().
|
_, err := c.RbacV1().
|
||||||
Roles(namespace).
|
Roles(namespace).
|
||||||
|
@ -96,6 +103,7 @@ func ExpectRole(c clientset.Interface, namespace, name string) {
|
||||||
framework.ExpectNoError(err, "error getting Role %q from namespace %q", name, namespace)
|
framework.ExpectNoError(err, "error getting Role %q from namespace %q", name, namespace)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ExpectRoleBinding expects to be able to get the RoleBinding with specific name from the namespace
|
||||||
func ExpectRoleBinding(c clientset.Interface, namespace, name string) {
|
func ExpectRoleBinding(c clientset.Interface, namespace, name string) {
|
||||||
_, err := c.RbacV1().
|
_, err := c.RbacV1().
|
||||||
RoleBindings(namespace).
|
RoleBindings(namespace).
|
||||||
|
@ -103,6 +111,7 @@ func ExpectRoleBinding(c clientset.Interface, namespace, name string) {
|
||||||
framework.ExpectNoError(err, "error getting RoleBinding %q from namespace %q", name, namespace)
|
framework.ExpectNoError(err, "error getting RoleBinding %q from namespace %q", name, namespace)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ExpectClusterRole expects to be able to get the ClusterRole with specific name
|
||||||
func ExpectClusterRole(c clientset.Interface, name string) {
|
func ExpectClusterRole(c clientset.Interface, name string) {
|
||||||
_, err := c.RbacV1().
|
_, err := c.RbacV1().
|
||||||
ClusterRoles().
|
ClusterRoles().
|
||||||
|
@ -110,6 +119,7 @@ func ExpectClusterRole(c clientset.Interface, name string) {
|
||||||
framework.ExpectNoError(err, "error getting ClusterRole %q", name)
|
framework.ExpectNoError(err, "error getting ClusterRole %q", name)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ExpectClusterRoleBinding expects to be able to get the ClusterRoleBinding with specific name
|
||||||
func ExpectClusterRoleBinding(c clientset.Interface, name string) {
|
func ExpectClusterRoleBinding(c clientset.Interface, name string) {
|
||||||
_, err := c.RbacV1().
|
_, err := c.RbacV1().
|
||||||
ClusterRoleBindings().
|
ClusterRoleBindings().
|
||||||
|
@ -117,24 +127,26 @@ func ExpectClusterRoleBinding(c clientset.Interface, name string) {
|
||||||
framework.ExpectNoError(err, "error getting ClusterRoleBindings %q", name)
|
framework.ExpectNoError(err, "error getting ClusterRoleBindings %q", name)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ExpectClusterRoleBindingWithSubjectAndRole expects to be able to get the ClusterRoleBinding with specific name, subject and role
|
||||||
func ExpectClusterRoleBindingWithSubjectAndRole(c clientset.Interface, name, subjectKind, subject, role string) {
|
func ExpectClusterRoleBindingWithSubjectAndRole(c clientset.Interface, name, subjectKind, subject, role string) {
|
||||||
binding, err := c.RbacV1().
|
binding, err := c.RbacV1().
|
||||||
ClusterRoleBindings().
|
ClusterRoleBindings().
|
||||||
Get(name, metav1.GetOptions{})
|
Get(name, metav1.GetOptions{})
|
||||||
framework.ExpectNoError(err, "error getting ClusterRoleBindings %q", name)
|
framework.ExpectNoError(err, "error getting ClusterRoleBindings %q", name)
|
||||||
Expect(binding.Subjects).To(
|
gomega.Expect(binding.Subjects).To(
|
||||||
ContainElement(subjectMatcher(
|
gomega.ContainElement(subjectMatcher(
|
||||||
subject,
|
subject,
|
||||||
subjectKind,
|
subjectKind,
|
||||||
)),
|
)),
|
||||||
"ClusterRole %q does not have %s %q as subject", name, subjectKind, subject,
|
"ClusterRole %q does not have %s %q as subject", name, subjectKind, subject,
|
||||||
)
|
)
|
||||||
Expect(binding.RoleRef.Name).To(
|
gomega.Expect(binding.RoleRef.Name).To(
|
||||||
Equal(role),
|
gomega.Equal(role),
|
||||||
"ClusterRole %q does not have %q as role", name, role,
|
"ClusterRole %q does not have %q as role", name, role,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ExpectSubjectHasAccessToResource expects that the subject has access to the target resource
|
||||||
func ExpectSubjectHasAccessToResource(c clientset.Interface, subjectKind, subject string, resource *authv1.ResourceAttributes) {
|
func ExpectSubjectHasAccessToResource(c clientset.Interface, subjectKind, subject string, resource *authv1.ResourceAttributes) {
|
||||||
var sar *authv1.SubjectAccessReview
|
var sar *authv1.SubjectAccessReview
|
||||||
switch subjectKind {
|
switch subjectKind {
|
||||||
|
@ -161,14 +173,14 @@ func ExpectSubjectHasAccessToResource(c clientset.Interface, subjectKind, subjec
|
||||||
s, err := c.AuthorizationV1().SubjectAccessReviews().Create(sar)
|
s, err := c.AuthorizationV1().SubjectAccessReviews().Create(sar)
|
||||||
framework.ExpectNoError(err, "error getting SubjectAccessReview for %s %s to resource %+v", subjectKind, subject, *sar.Spec.ResourceAttributes)
|
framework.ExpectNoError(err, "error getting SubjectAccessReview for %s %s to resource %+v", subjectKind, subject, *sar.Spec.ResourceAttributes)
|
||||||
|
|
||||||
Expect(s.Status.Allowed).Should(BeTrue(), "%s %s has no access to resource %+v", subjectKind, subject, *sar.Spec.ResourceAttributes)
|
gomega.Expect(s.Status.Allowed).Should(gomega.BeTrue(), "%s %s has no access to resource %+v", subjectKind, subject, *sar.Spec.ResourceAttributes)
|
||||||
}
|
}
|
||||||
|
|
||||||
// matchers
|
// matchers
|
||||||
|
|
||||||
func subjectMatcher(name, kind string) OmegaMatcher {
|
func subjectMatcher(name, kind string) gomega.OmegaMatcher {
|
||||||
return gstruct.MatchFields(gstruct.IgnoreExtras, gstruct.Fields{
|
return gstruct.MatchFields(gstruct.IgnoreExtras, gstruct.Fields{
|
||||||
"Name": Equal(name),
|
"Name": gomega.Equal(name),
|
||||||
"Kind": Equal(kind),
|
"Kind": gomega.Equal(kind),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue