mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-09 20:17:41 +00:00
Merge pull request #22211 from derekwaynecarr/quota_fix
Auto commit by PR queue bot
This commit is contained in:
commit
94a2319804
@ -181,7 +181,7 @@ func (r *replenishmentControllerFactory) NewController(options *ReplenishmentCon
|
|||||||
return r.kubeClient.Core().Secrets(api.NamespaceAll).Watch(options)
|
return r.kubeClient.Core().Secrets(api.NamespaceAll).Watch(options)
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
&api.PersistentVolumeClaim{},
|
&api.Secret{},
|
||||||
options.ResyncPeriod(),
|
options.ResyncPeriod(),
|
||||||
framework.ResourceEventHandlerFuncs{
|
framework.ResourceEventHandlerFuncs{
|
||||||
DeleteFunc: ObjectReplenishmentDeleteFunc(options),
|
DeleteFunc: ObjectReplenishmentDeleteFunc(options),
|
||||||
|
@ -17,6 +17,7 @@ limitations under the License.
|
|||||||
package e2e
|
package e2e
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"k8s.io/kubernetes/pkg/api"
|
"k8s.io/kubernetes/pkg/api"
|
||||||
@ -86,6 +87,50 @@ var _ = Describe("ResourceQuota", func() {
|
|||||||
Expect(err).NotTo(HaveOccurred())
|
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() {
|
It("should create a ResourceQuota and capture the life of a pod.", func() {
|
||||||
By("Creating a ResourceQuota")
|
By("Creating a ResourceQuota")
|
||||||
quotaName := "test-quota"
|
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
|
// createResourceQuota in the specified namespace
|
||||||
func createResourceQuota(c *client.Client, namespace string, resourceQuota *api.ResourceQuota) (*api.ResourceQuota, error) {
|
func createResourceQuota(c *client.Client, namespace string, resourceQuota *api.ResourceQuota) (*api.ResourceQuota, error) {
|
||||||
return c.ResourceQuotas(namespace).Create(resourceQuota)
|
return c.ResourceQuotas(namespace).Create(resourceQuota)
|
||||||
|
Loading…
Reference in New Issue
Block a user