func formatImageStreamQuota(out *tabwriter.Writer, c client.Interface, kc kclient.Interface, stream *imageapi.ImageStream) { quotas, err := kc.ResourceQuotas(stream.Namespace).List(api.ListOptions{}) if err != nil { return } var limit *resource.Quantity for _, item := range quotas.Items { // search for smallest ImageStream quota if value, ok := item.Spec.Hard[imageapi.ResourceImageStreamSize]; ok { if limit == nil || limit.Cmp(value) > 0 { limit = &value } } } if limit != nil { quantity := imagequota.GetImageStreamSize(c, stream, make(map[string]*imageapi.Image)) scale := mega if quantity.Value() >= (1<<giga.scale) || limit.Value() >= (1<<giga.scale) { scale = giga } formatString(out, "Quota Usage", fmt.Sprintf("%s / %s", formatQuantity(quantity, scale), formatQuantity(limit, scale))) } }
func deleteResourceQuotas(kubeClient client.Interface, ns string) error { resourceQuotas, err := kubeClient.ResourceQuotas(ns).List(unversioned.ListOptions{}) if err != nil { return err } for i := range resourceQuotas.Items { err := kubeClient.ResourceQuotas(ns).Delete(resourceQuotas.Items[i].Name) if err != nil && !errors.IsNotFound(err) { return err } } return nil }
func deleteResourceQuotas(kubeClient client.Interface, ns string) error { resourceQuotas, err := kubeClient.ResourceQuotas(ns).List(labels.Everything(), fields.Everything()) if err != nil { return err } for i := range resourceQuotas.Items { err := kubeClient.ResourceQuotas(ns).Delete(resourceQuotas.Items[i].Name) if err != nil && !errors.IsNotFound(err) { return err } } return nil }
// NewResourceQuota creates a new resource quota admission control handler func NewResourceQuota(client client.Interface) admission.Interface { lw := &cache.ListWatch{ ListFunc: func() (runtime.Object, error) { return client.ResourceQuotas(api.NamespaceAll).List(labels.Everything(), fields.Everything()) }, WatchFunc: func(resourceVersion string) (watch.Interface, error) { return client.ResourceQuotas(api.NamespaceAll).Watch(labels.Everything(), fields.Everything(), resourceVersion) }, } indexer, reflector := cache.NewNamespaceKeyedIndexerAndReflector(lw, &api.ResourceQuota{}, 0) reflector.Run() return createResourceQuota(client, indexer) }
// NewResourceQuota creates a new resource quota admission control handler func NewResourceQuota(client client.Interface) admission.Interface { lw := &cache.ListWatch{ ListFunc: func() (runtime.Object, error) { return client.ResourceQuotas(api.NamespaceAll).List(unversioned.ListOptions{}) }, WatchFunc: func(options unversioned.ListOptions) (watch.Interface, error) { return client.ResourceQuotas(api.NamespaceAll).Watch(options) }, } indexer, reflector := cache.NewNamespaceKeyedIndexerAndReflector(lw, &api.ResourceQuota{}, 0) reflector.Run() return createResourceQuota(client, indexer) }