Merge pull request #22211 from derekwaynecarr/quota_fix

Auto commit by PR queue bot
This commit is contained in:
k8s-merge-robot 2016-03-01 10:13:44 -08:00
commit 94a2319804
2 changed files with 59 additions and 1 deletions

View File

@ -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),

View File

@ -17,6 +17,7 @@ limitations under the License.
package e2e
import (
"fmt"
"time"
"k8s.io/kubernetes/pkg/api"
@ -86,6 +87,50 @@ var _ = Describe("ResourceQuota", func() {
Expect(err).NotTo(HaveOccurred())
})
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.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())
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.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)
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(defaultSecrets)
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"
@ -384,6 +429,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)