Skip to content

Commit

Permalink
Fixes needed after e2e deps update
Browse files Browse the repository at this point in the history
  • Loading branch information
bskiba committed Jun 15, 2020
1 parent 9a76a7a commit 03227c2
Show file tree
Hide file tree
Showing 19 changed files with 853 additions and 204 deletions.
51 changes: 26 additions & 25 deletions vertical-pod-autoscaler/e2e/utils/webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ limitations under the License.
package utils

import (
"context"
"fmt"
"strings"
"time"
Expand Down Expand Up @@ -55,32 +56,32 @@ func LabelNamespace(f *framework.Framework, namespace string) {
client := f.ClientSet

// Add a unique label to the namespace
ns, err := client.CoreV1().Namespaces().Get(namespace, metav1.GetOptions{})
ns, err := client.CoreV1().Namespaces().Get(context.TODO(), namespace, metav1.GetOptions{})
framework.ExpectNoError(err, "error getting namespace %s", namespace)
if ns.Labels == nil {
ns.Labels = map[string]string{}
}
ns.Labels[f.UniqueName] = "true"
_, err = client.CoreV1().Namespaces().Update(ns)
_, err = client.CoreV1().Namespaces().Update(context.TODO(), ns, metav1.UpdateOptions{})
framework.ExpectNoError(err, "error labeling namespace %s", namespace)
}

// CreateWebhookConfigurationReadyNamespace creates a separate namespace for webhook configuration ready markers to
// prevent cross-talk with webhook configurations being tested.
func CreateWebhookConfigurationReadyNamespace(f *framework.Framework) {
ns, err := f.ClientSet.CoreV1().Namespaces().Create(&v1.Namespace{
ns, err := f.ClientSet.CoreV1().Namespaces().Create(context.TODO(), &v1.Namespace{
ObjectMeta: metav1.ObjectMeta{
Name: f.Namespace.Name + "-markers",
Labels: map[string]string{f.UniqueName + "-markers": "true"},
},
})
}, metav1.CreateOptions{})
framework.ExpectNoError(err, "creating namespace for webhook configuration ready markers")
f.AddNamespacesToDelete(ns)
}

// RegisterMutatingWebhookForPod creates mutation webhook configuration
// and applies it to the cluster.
func RegisterMutatingWebhookForPod(f *framework.Framework, configName string, context *certContext, servicePort int32) func() {
func RegisterMutatingWebhookForPod(f *framework.Framework, configName string, certContext *certContext, servicePort int32) func() {
client := f.ClientSet
ginkgo.By("Registering the mutating pod webhook via the AdmissionRegistration API")

Expand Down Expand Up @@ -109,7 +110,7 @@ func RegisterMutatingWebhookForPod(f *framework.Framework, configName string, co
Path: strPtr("/mutating-pods-sidecar"),
Port: pointer.Int32Ptr(servicePort),
},
CABundle: context.signingCert,
CABundle: certContext.signingCert,
},
SideEffects: &sideEffectsNone,
AdmissionReviewVersions: []string{"v1", "v1beta1"},
Expand All @@ -119,7 +120,7 @@ func RegisterMutatingWebhookForPod(f *framework.Framework, configName string, co
},
},
// Register a webhook that can be probed by marker requests to detect when the configuration is ready.
newMutatingIsReadyWebhookFixture(f, context, servicePort),
newMutatingIsReadyWebhookFixture(f, certContext, servicePort),
},
})
framework.ExpectNoError(err, "registering mutating webhook config %s with namespace %s", configName, namespace)
Expand All @@ -128,7 +129,7 @@ func RegisterMutatingWebhookForPod(f *framework.Framework, configName string, co
framework.ExpectNoError(err, "waiting for webhook configuration to be ready")

return func() {
client.AdmissionregistrationV1beta1().MutatingWebhookConfigurations().Delete(configName, nil)
client.AdmissionregistrationV1beta1().MutatingWebhookConfigurations().Delete(context.TODO(), configName, metav1.DeleteOptions{})
}
}

Expand All @@ -144,12 +145,12 @@ func createMutatingWebhookConfiguration(f *framework.Framework, config *admissio
}
framework.Failf(`webhook %s in config %s has no namespace or object selector with %s="true", and can interfere with other tests`, webhook.Name, config.Name, f.UniqueName)
}
return f.ClientSet.AdmissionregistrationV1beta1().MutatingWebhookConfigurations().Create(config)
return f.ClientSet.AdmissionregistrationV1beta1().MutatingWebhookConfigurations().Create(context.TODO(), config, metav1.CreateOptions{})
}

// newMutatingIsReadyWebhookFixture creates a mutating webhook that can be added to a webhook configuration and then probed
// with "marker" requests via waitWebhookConfigurationReady to wait for a webhook configuration to be ready.
func newMutatingIsReadyWebhookFixture(f *framework.Framework, context *certContext, servicePort int32) admissionregistrationv1beta1.MutatingWebhook {
func newMutatingIsReadyWebhookFixture(f *framework.Framework, certContext *certContext, servicePort int32) admissionregistrationv1beta1.MutatingWebhook {
sideEffectsNone := admissionregistrationv1beta1.SideEffectClassNone
failOpen := admissionregistrationv1beta1.Ignore
return admissionregistrationv1beta1.MutatingWebhook{
Expand All @@ -169,7 +170,7 @@ func newMutatingIsReadyWebhookFixture(f *framework.Framework, context *certConte
Path: strPtr("/always-deny"),
Port: pointer.Int32Ptr(servicePort),
},
CABundle: context.signingCert,
CABundle: certContext.signingCert,
},
// network failures while the service network routing is being set up should be ignored by the marker
FailurePolicy: &failOpen,
Expand Down Expand Up @@ -200,7 +201,7 @@ func waitWebhookConfigurationReady(f *framework.Framework) error {
},
},
}
_, err := cmClient.Create(marker)
_, err := cmClient.Create(context.TODO(), marker, metav1.CreateOptions{})
if err != nil {
// The always-deny webhook does not provide a reason, so check for the error string we expect
if strings.Contains(err.Error(), "denied") {
Expand All @@ -209,7 +210,7 @@ func waitWebhookConfigurationReady(f *framework.Framework) error {
return false, err
}
// best effort cleanup of markers that are no longer needed
_ = cmClient.Delete(marker.GetName(), nil)
_ = cmClient.Delete(context.TODO(), marker.GetName(), metav1.DeleteOptions{})
framework.Logf("Waiting for webhook configuration to be ready...")
return false, nil
})
Expand All @@ -220,7 +221,7 @@ func waitWebhookConfigurationReady(f *framework.Framework) error {
func CreateAuthReaderRoleBinding(f *framework.Framework, namespace string) {
ginkgo.By("Create role binding to let webhook read extension-apiserver-authentication")
client := f.ClientSet
_, err := client.RbacV1().RoleBindings("kube-system").Create(&rbacv1.RoleBinding{
_, err := client.RbacV1().RoleBindings("kube-system").Create(context.TODO(), &rbacv1.RoleBinding{
ObjectMeta: metav1.ObjectMeta{
Name: roleBindingName,
Annotations: map[string]string{
Expand All @@ -240,7 +241,7 @@ func CreateAuthReaderRoleBinding(f *framework.Framework, namespace string) {
Namespace: namespace,
},
},
})
}, metav1.CreateOptions{})
if err != nil && apierrors.IsAlreadyExists(err) {
framework.Logf("role binding %s already exists", roleBindingName)
} else {
Expand All @@ -249,7 +250,7 @@ func CreateAuthReaderRoleBinding(f *framework.Framework, namespace string) {
}

// DeployWebhookAndService creates a webhook with a corresponding service.
func DeployWebhookAndService(f *framework.Framework, image string, context *certContext, servicePort int32,
func DeployWebhookAndService(f *framework.Framework, image string, certContext *certContext, servicePort int32,
containerPort int32, params ...string) {
ginkgo.By("Deploying the webhook pod")
client := f.ClientSet
Expand All @@ -261,12 +262,12 @@ func DeployWebhookAndService(f *framework.Framework, image string, context *cert
},
Type: v1.SecretTypeOpaque,
Data: map[string][]byte{
"tls.crt": context.cert,
"tls.key": context.key,
"tls.crt": certContext.cert,
"tls.key": certContext.key,
},
}
namespace := f.Namespace.Name
_, err := client.CoreV1().Secrets(namespace).Create(secret)
_, err := client.CoreV1().Secrets(namespace).Create(context.TODO(), secret, metav1.CreateOptions{})
framework.ExpectNoError(err, "creating secret %q in namespace %q", secretName, namespace)

// Create the deployment of the webhook
Expand Down Expand Up @@ -342,7 +343,7 @@ func DeployWebhookAndService(f *framework.Framework, image string, context *cert
},
},
}
deployment, err := client.AppsV1().Deployments(namespace).Create(d)
deployment, err := client.AppsV1().Deployments(namespace).Create(context.TODO(), d, metav1.CreateOptions{})
framework.ExpectNoError(err, "creating deployment %s in namespace %s", deploymentName, namespace)
ginkgo.By("Wait for the deployment to be ready")
err = e2edeploy.WaitForDeploymentRevisionAndImage(client, namespace, deploymentName, "1", image)
Expand Down Expand Up @@ -370,7 +371,7 @@ func DeployWebhookAndService(f *framework.Framework, image string, context *cert
},
},
}
_, err = client.CoreV1().Services(namespace).Create(service)
_, err = client.CoreV1().Services(namespace).Create(context.TODO(), service, metav1.CreateOptions{})
framework.ExpectNoError(err, "creating service %s in namespace %s", WebhookServiceName, namespace)

ginkgo.By("Verifying the service has paired with the endpoint")
Expand All @@ -380,8 +381,8 @@ func DeployWebhookAndService(f *framework.Framework, image string, context *cert

// CleanWebhookTest cleans after a webhook test.
func CleanWebhookTest(client clientset.Interface, namespaceName string) {
_ = client.CoreV1().Services(namespaceName).Delete(WebhookServiceName, nil)
_ = client.AppsV1().Deployments(namespaceName).Delete(deploymentName, nil)
_ = client.CoreV1().Secrets(namespaceName).Delete(WebhookServiceName, nil)
_ = client.RbacV1().RoleBindings("kube-system").Delete(roleBindingName, nil)
_ = client.CoreV1().Services(namespaceName).Delete(context.TODO(), WebhookServiceName, metav1.DeleteOptions{})
_ = client.AppsV1().Deployments(namespaceName).Delete(context.TODO(), deploymentName, metav1.DeleteOptions{})
_ = client.CoreV1().Secrets(namespaceName).Delete(context.TODO(), WebhookServiceName, metav1.DeleteOptions{})
_ = client.RbacV1().RoleBindings("kube-system").Delete(context.TODO(), roleBindingName, metav1.DeleteOptions{})
}
52 changes: 43 additions & 9 deletions vertical-pod-autoscaler/e2e/v1/actuation.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ limitations under the License.
package autoscaling

import (
"context"
"fmt"
"time"

Expand All @@ -36,6 +37,7 @@ import (
"k8s.io/kubernetes/test/e2e/framework"
framework_deployment "k8s.io/kubernetes/test/e2e/framework/deployment"
framework_job "k8s.io/kubernetes/test/e2e/framework/job"
framework_rc "k8s.io/kubernetes/test/e2e/framework/rc"
framework_rs "k8s.io/kubernetes/test/e2e/framework/replicaset"
framework_ss "k8s.io/kubernetes/test/e2e/framework/statefulset"
testutils "k8s.io/kubernetes/test/utils"
Expand Down Expand Up @@ -188,7 +190,7 @@ var _ = ActuationSuiteE2eDescribe("Actuation", func() {
permissiveMaxUnavailable := 7
// Creating new PDB and removing old one, since PDBs are immutable at the moment
setupPDB(f, "hamster-pdb-2", permissiveMaxUnavailable)
err = c.PolicyV1beta1().PodDisruptionBudgets(ns).Delete(pdb.Name, &metav1.DeleteOptions{})
err = c.PolicyV1beta1().PodDisruptionBudgets(ns).Delete(context.TODO(), pdb.Name, metav1.DeleteOptions{})
gomega.Expect(err).NotTo(gomega.HaveOccurred())

ginkgo.By(fmt.Sprintf("Waiting for pods to be evicted, sleep for %s", VpaEvictionTimeout.String()))
Expand Down Expand Up @@ -365,7 +367,7 @@ func getCPURequest(podSpec apiv1.PodSpec) resource.Quantity {
}

func killPod(f *framework.Framework, podList *apiv1.PodList) {
f.ClientSet.CoreV1().Pods(f.Namespace.Name).Delete(podList.Items[0].Name, &metav1.DeleteOptions{})
f.ClientSet.CoreV1().Pods(f.Namespace.Name).Delete(context.TODO(), podList.Items[0].Name, metav1.DeleteOptions{})
err := WaitForPodsRestarted(f, podList)
gomega.Expect(err).NotTo(gomega.HaveOccurred())
}
Expand Down Expand Up @@ -468,8 +470,7 @@ func setupHamsterController(f *framework.Framework, controllerKind, cpu, memory

func setupHamsterReplicationController(f *framework.Framework, cpu, memory string, replicas int32) {
hamsterContainer := SetupHamsterContainer(cpu, memory)
rc := framework.RcByNameContainer("hamster-rc", replicas, "k8s.gcr.io/ubuntu-slim:0.1",
hamsterLabels, hamsterContainer, nil)
rc := framework_rc.ByNameContainer("hamster-rc", replicas, hamsterLabels, hamsterContainer, nil)

rc.Namespace = f.Namespace.Name
err := testutils.CreateRCWithRetries(f.ClientSet, f.Namespace.Name, rc)
Expand Down Expand Up @@ -509,8 +510,7 @@ func setupHamsterJob(f *framework.Framework, cpu, memory string, replicas int32)
}

func setupHamsterRS(f *framework.Framework, cpu, memory string, replicas int32) {
rs := framework_rs.NewReplicaSet("hamster-rs", f.Namespace.Name, replicas,
hamsterLabels, "", "")
rs := newReplicaSet("hamster-rs", f.Namespace.Name, replicas, hamsterLabels, "", "")
rs.Spec.Template.Spec.Containers[0] = SetupHamsterContainer(cpu, memory)
err := createReplicaSetWithRetries(f.ClientSet, f.Namespace.Name, rs)
gomega.Expect(err).NotTo(gomega.HaveOccurred())
Expand Down Expand Up @@ -541,7 +541,7 @@ func setupPDB(f *framework.Framework, name string, maxUnavailable int) *policyv1
},
},
}
_, err := f.ClientSet.PolicyV1beta1().PodDisruptionBudgets(f.Namespace.Name).Create(pdb)
_, err := f.ClientSet.PolicyV1beta1().PodDisruptionBudgets(f.Namespace.Name).Create(context.TODO(), pdb, metav1.CreateOptions{})
gomega.Expect(err).NotTo(gomega.HaveOccurred())
return pdb
}
Expand All @@ -557,7 +557,7 @@ func createReplicaSetWithRetries(c clientset.Interface, namespace string, obj *a
return fmt.Errorf("object provided to create is empty")
}
createFunc := func() (bool, error) {
_, err := c.AppsV1().ReplicaSets(namespace).Create(obj)
_, err := c.AppsV1().ReplicaSets(namespace).Create(context.TODO(), obj, metav1.CreateOptions{})
if err == nil || apierrs.IsAlreadyExists(err) {
return true, nil
}
Expand All @@ -574,7 +574,7 @@ func createStatefulSetSetWithRetries(c clientset.Interface, namespace string, ob
return fmt.Errorf("object provided to create is empty")
}
createFunc := func() (bool, error) {
_, err := c.AppsV1().StatefulSets(namespace).Create(obj)
_, err := c.AppsV1().StatefulSets(namespace).Create(context.TODO(), obj, metav1.CreateOptions{})
if err == nil || apierrs.IsAlreadyExists(err) {
return true, nil
}
Expand All @@ -585,3 +585,37 @@ func createStatefulSetSetWithRetries(c clientset.Interface, namespace string, ob
}
return testutils.RetryWithExponentialBackOff(createFunc)
}

// newReplicaSet returns a new ReplicaSet.
func newReplicaSet(name, namespace string, replicas int32, podLabels map[string]string, imageName, image string) *appsv1.ReplicaSet {
return &appsv1.ReplicaSet{
TypeMeta: metav1.TypeMeta{
Kind: "ReplicaSet",
APIVersion: "apps/v1",
},
ObjectMeta: metav1.ObjectMeta{
Namespace: namespace,
Name: name,
},
Spec: appsv1.ReplicaSetSpec{
Selector: &metav1.LabelSelector{
MatchLabels: podLabels,
},
Replicas: &replicas,
Template: apiv1.PodTemplateSpec{
ObjectMeta: metav1.ObjectMeta{
Labels: podLabels,
},
Spec: apiv1.PodSpec{
Containers: []apiv1.Container{
{
Name: imageName,
Image: image,
SecurityContext: &apiv1.SecurityContext{},
},
},
},
},
},
}
}
7 changes: 4 additions & 3 deletions vertical-pod-autoscaler/e2e/v1/admission_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ limitations under the License.
package autoscaling

import (
"context"
"fmt"
"time"

Expand Down Expand Up @@ -531,7 +532,7 @@ func startDeploymentPods(f *framework.Framework, deployment *appsv1.Deployment)
zero := int32(0)
deployment.Spec.Replicas = &zero
c, ns := f.ClientSet, f.Namespace.Name
deployment, err := c.AppsV1().Deployments(ns).Create(deployment)
deployment, err := c.AppsV1().Deployments(ns).Create(context.TODO(), deployment, metav1.CreateOptions{})
gomega.Expect(err).NotTo(gomega.HaveOccurred(), "when creating deployment with size 0")

err = framework_deployment.WaitForDeploymentComplete(c, deployment)
Expand All @@ -555,12 +556,12 @@ func startDeploymentPods(f *framework.Framework, deployment *appsv1.Deployment)
Replicas: desiredPodCount,
},
}
afterScale, err := c.AppsV1().Deployments(ns).UpdateScale(deployment.Name, &scale)
afterScale, err := c.AppsV1().Deployments(ns).UpdateScale(context.TODO(), deployment.Name, &scale, metav1.UpdateOptions{})
gomega.Expect(err).NotTo(gomega.HaveOccurred())
gomega.Expect(afterScale.Spec.Replicas).To(gomega.Equal(desiredPodCount), fmt.Sprintf("expected %d replicas after scaling", desiredPodCount))

// After scaling deployment we need to retrieve current version with updated replicas count.
deployment, err = c.AppsV1().Deployments(ns).Get(deployment.Name, metav1.GetOptions{})
deployment, err = c.AppsV1().Deployments(ns).Get(context.TODO(), deployment.Name, metav1.GetOptions{})
gomega.Expect(err).NotTo(gomega.HaveOccurred(), "when getting scaled deployment")
err = framework_deployment.WaitForDeploymentComplete(c, deployment)
gomega.Expect(err).NotTo(gomega.HaveOccurred(), "when waiting for deployment to resize")
Expand Down
Loading

0 comments on commit 03227c2

Please sign in to comment.