From c9e4c846e6b776aed7ab962595f67d75755b267b Mon Sep 17 00:00:00 2001 From: derekwaynecarr Date: Mon, 29 Feb 2016 17:06:32 -0500 Subject: [PATCH 1/2] Incorrect type passed into quota reflector --- .../resourcequota/replenishment_controller.go | 2 +- test/e2e/resource_quota.go | 51 +++++++++++++++++++ 2 files changed, 52 insertions(+), 1 deletion(-) diff --git a/pkg/controller/resourcequota/replenishment_controller.go b/pkg/controller/resourcequota/replenishment_controller.go index e8297dcfbd0..05907da79dc 100644 --- a/pkg/controller/resourcequota/replenishment_controller.go +++ b/pkg/controller/resourcequota/replenishment_controller.go @@ -181,7 +181,7 @@ func (r *replenishmentControllerFactory) NewController(options *ReplenishmentCon return r.kubeClient.Core().Secrets(api.NamespaceAll).Watch(options) }, }, - &api.PersistentVolumeClaim{}, + &api.Secret{}, options.ResyncPeriod(), framework.ResourceEventHandlerFuncs{ DeleteFunc: ObjectReplenishmentDeleteFunc(options), diff --git a/test/e2e/resource_quota.go b/test/e2e/resource_quota.go index 0ad7d252467..94d9b49205d 100644 --- a/test/e2e/resource_quota.go +++ b/test/e2e/resource_quota.go @@ -86,6 +86,43 @@ var _ = Describe("ResourceQuota", func() { Expect(err).NotTo(HaveOccurred()) }) + It("should create a ResourceQuota and capture the life of a secret.", func() { + By("Creating a ResourceQuota") + quotaName := "test-quota" + resourceQuota := newTestResourceQuota(quotaName) + resourceQuota, err := createResourceQuota(f.Client, f.Namespace.Name, resourceQuota) + Expect(err).NotTo(HaveOccurred()) + + By("Ensuring resource quota status is calculated") + usedResources := api.ResourceList{} + usedResources[api.ResourceQuotas] = resource.MustParse("1") + err = waitForResourceQuota(f.Client, f.Namespace.Name, quotaName, usedResources) + Expect(err).NotTo(HaveOccurred()) + + By("Creating a Secret") + secret := newTestSecretForQuota("test-secret") + secret, err = f.Client.Secrets(f.Namespace.Name).Create(secret) + Expect(err).NotTo(HaveOccurred()) + + By("Ensuring resource quota status captures secret creation") + usedResources = api.ResourceList{} + usedResources[api.ResourceQuotas] = resource.MustParse("1") + usedResources[api.ResourceSecrets] = resource.MustParse("2") + // we expect there to be two secrets because each namespace will receive + // a service account token secret by default + err = waitForResourceQuota(f.Client, f.Namespace.Name, quotaName, usedResources) + Expect(err).NotTo(HaveOccurred()) + + By("Deleting a secret") + err = f.Client.Secrets(f.Namespace.Name).Delete(secret.Name) + Expect(err).NotTo(HaveOccurred()) + + By("Ensuring resource quota status released usage") + usedResources[api.ResourceSecrets] = resource.MustParse("1") + err = waitForResourceQuota(f.Client, f.Namespace.Name, quotaName, usedResources) + Expect(err).NotTo(HaveOccurred()) + }) + It("should create a ResourceQuota and capture the life of a pod.", func() { By("Creating a ResourceQuota") quotaName := "test-quota" @@ -342,6 +379,7 @@ func newTestResourceQuota(name string) *api.ResourceQuota { hard[api.ResourceQuotas] = resource.MustParse("1") hard[api.ResourceCPU] = resource.MustParse("1") hard[api.ResourceMemory] = resource.MustParse("500Mi") + hard[api.ResourceSecrets] = resource.MustParse("2") return &api.ResourceQuota{ ObjectMeta: api.ObjectMeta{Name: name}, Spec: api.ResourceQuotaSpec{Hard: hard}, @@ -384,6 +422,19 @@ func newTestServiceForQuota(name string) *api.Service { } } +func newTestSecretForQuota(name string) *api.Secret { + return &api.Secret{ + ObjectMeta: api.ObjectMeta{ + Name: name, + }, + Data: map[string][]byte{ + "data-1": []byte("value-1\n"), + "data-2": []byte("value-2\n"), + "data-3": []byte("value-3\n"), + }, + } +} + // createResourceQuota in the specified namespace func createResourceQuota(c *client.Client, namespace string, resourceQuota *api.ResourceQuota) (*api.ResourceQuota, error) { return c.ResourceQuotas(namespace).Create(resourceQuota) From cb1f1d373e33f960536c1ada53263d4126a80f59 Mon Sep 17 00:00:00 2001 From: derekwaynecarr Date: Mon, 29 Feb 2016 18:52:35 -0500 Subject: [PATCH 2/2] ResourceQuota e2e should not assume 1 secret by default --- test/e2e/resource_quota.go | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/test/e2e/resource_quota.go b/test/e2e/resource_quota.go index 94d9b49205d..481cec9ea52 100644 --- a/test/e2e/resource_quota.go +++ b/test/e2e/resource_quota.go @@ -17,6 +17,7 @@ limitations under the License. package e2e import ( + "fmt" "time" "k8s.io/kubernetes/pkg/api" @@ -87,15 +88,23 @@ var _ = Describe("ResourceQuota", func() { }) It("should create a ResourceQuota and capture the life of a secret.", func() { + By("Discovering how many secrets are in namespace by default") + secrets, err := f.Client.Secrets(f.Namespace.Name).List(api.ListOptions{}) + Expect(err).NotTo(HaveOccurred()) + defaultSecrets := fmt.Sprintf("%d", len(secrets.Items)) + hardSecrets := fmt.Sprintf("%d", len(secrets.Items)+1) + By("Creating a ResourceQuota") quotaName := "test-quota" resourceQuota := newTestResourceQuota(quotaName) - resourceQuota, err := createResourceQuota(f.Client, f.Namespace.Name, resourceQuota) + resourceQuota.Spec.Hard[api.ResourceSecrets] = resource.MustParse(hardSecrets) + resourceQuota, err = createResourceQuota(f.Client, f.Namespace.Name, resourceQuota) Expect(err).NotTo(HaveOccurred()) By("Ensuring resource quota status is calculated") usedResources := api.ResourceList{} usedResources[api.ResourceQuotas] = resource.MustParse("1") + usedResources[api.ResourceSecrets] = resource.MustParse(defaultSecrets) err = waitForResourceQuota(f.Client, f.Namespace.Name, quotaName, usedResources) Expect(err).NotTo(HaveOccurred()) @@ -106,8 +115,7 @@ var _ = Describe("ResourceQuota", func() { By("Ensuring resource quota status captures secret creation") usedResources = api.ResourceList{} - usedResources[api.ResourceQuotas] = resource.MustParse("1") - usedResources[api.ResourceSecrets] = resource.MustParse("2") + usedResources[api.ResourceSecrets] = resource.MustParse(hardSecrets) // we expect there to be two secrets because each namespace will receive // a service account token secret by default err = waitForResourceQuota(f.Client, f.Namespace.Name, quotaName, usedResources) @@ -118,7 +126,7 @@ var _ = Describe("ResourceQuota", func() { Expect(err).NotTo(HaveOccurred()) By("Ensuring resource quota status released usage") - usedResources[api.ResourceSecrets] = resource.MustParse("1") + usedResources[api.ResourceSecrets] = resource.MustParse(defaultSecrets) err = waitForResourceQuota(f.Client, f.Namespace.Name, quotaName, usedResources) Expect(err).NotTo(HaveOccurred()) }) @@ -379,7 +387,6 @@ func newTestResourceQuota(name string) *api.ResourceQuota { hard[api.ResourceQuotas] = resource.MustParse("1") hard[api.ResourceCPU] = resource.MustParse("1") hard[api.ResourceMemory] = resource.MustParse("500Mi") - hard[api.ResourceSecrets] = resource.MustParse("2") return &api.ResourceQuota{ ObjectMeta: api.ObjectMeta{Name: name}, Spec: api.ResourceQuotaSpec{Hard: hard},