Merge pull request #2113 from calvin0327/cleanup-federated-resourcequota
cleanup federated resource quota
This commit is contained in:
commit
d0cb708e7e
|
@ -6,7 +6,6 @@ import (
|
||||||
corev1 "k8s.io/api/core/v1"
|
corev1 "k8s.io/api/core/v1"
|
||||||
apierrors "k8s.io/apimachinery/pkg/api/errors"
|
apierrors "k8s.io/apimachinery/pkg/api/errors"
|
||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
"k8s.io/apimachinery/pkg/labels"
|
|
||||||
"k8s.io/apimachinery/pkg/types"
|
"k8s.io/apimachinery/pkg/types"
|
||||||
"k8s.io/apimachinery/pkg/util/errors"
|
"k8s.io/apimachinery/pkg/util/errors"
|
||||||
"k8s.io/client-go/tools/record"
|
"k8s.io/client-go/tools/record"
|
||||||
|
@ -120,12 +119,9 @@ func (c *SyncController) SetupWithManager(mgr controllerruntime.Manager) error {
|
||||||
func (c *SyncController) cleanUpWorks(namespace, name string) error {
|
func (c *SyncController) cleanUpWorks(namespace, name string) error {
|
||||||
var errs []error
|
var errs []error
|
||||||
workList := &workv1alpha1.WorkList{}
|
workList := &workv1alpha1.WorkList{}
|
||||||
if err := c.List(context.TODO(), workList, &client.ListOptions{
|
if err := c.List(context.TODO(), workList, client.MatchingLabels{
|
||||||
LabelSelector: labels.SelectorFromSet(
|
|
||||||
labels.Set{
|
|
||||||
util.FederatedResourceQuotaNamespaceLabel: namespace,
|
util.FederatedResourceQuotaNamespaceLabel: namespace,
|
||||||
util.FederatedResourceQuotaNameLabel: name,
|
util.FederatedResourceQuotaNameLabel: name,
|
||||||
}),
|
|
||||||
}); err != nil {
|
}); err != nil {
|
||||||
klog.Errorf("Failed to list works, err: %v", err)
|
klog.Errorf("Failed to list works, err: %v", err)
|
||||||
return err
|
return err
|
||||||
|
@ -139,11 +135,8 @@ func (c *SyncController) cleanUpWorks(namespace, name string) error {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(errs) > 0 {
|
|
||||||
return errors.NewAggregate(errs)
|
return errors.NewAggregate(errs)
|
||||||
}
|
}
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *SyncController) buildWorks(quota *policyv1alpha1.FederatedResourceQuota, clusters []clusterv1alpha1.Cluster) error {
|
func (c *SyncController) buildWorks(quota *policyv1alpha1.FederatedResourceQuota, clusters []clusterv1alpha1.Cluster) error {
|
||||||
var errs []error
|
var errs []error
|
||||||
|
@ -190,11 +183,8 @@ func (c *SyncController) buildWorks(quota *policyv1alpha1.FederatedResourceQuota
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(errs) > 0 {
|
|
||||||
return errors.NewAggregate(errs)
|
return errors.NewAggregate(errs)
|
||||||
}
|
}
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func extractClusterHardResourceList(spec policyv1alpha1.FederatedResourceQuotaSpec, cluster string) corev1.ResourceList {
|
func extractClusterHardResourceList(spec policyv1alpha1.FederatedResourceQuotaSpec, cluster string) corev1.ResourceList {
|
||||||
for index := range spec.StaticAssignments {
|
for index := range spec.StaticAssignments {
|
||||||
|
|
|
@ -173,8 +173,5 @@ func (c *HorizontalPodAutoscalerController) deleteWorks(workName string) error {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if len(errs) > 0 {
|
|
||||||
return utilerrors.NewAggregate(errs)
|
return utilerrors.NewAggregate(errs)
|
||||||
}
|
}
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
|
@ -354,14 +354,9 @@ func (c *ServiceExportController) reportEndpointSliceWithServiceExportCreate(ser
|
||||||
errs = append(errs, err)
|
errs = append(errs, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(errs) > 0 {
|
|
||||||
return utilerrors.NewAggregate(errs)
|
return utilerrors.NewAggregate(errs)
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// reportEndpointSliceWithEndpointSliceCreateOrUpdate reports the EndpointSlice when referencing service has been exported.
|
// reportEndpointSliceWithEndpointSliceCreateOrUpdate reports the EndpointSlice when referencing service has been exported.
|
||||||
func (c *ServiceExportController) reportEndpointSliceWithEndpointSliceCreateOrUpdate(clusterName string, endpointSlice *unstructured.Unstructured) error {
|
func (c *ServiceExportController) reportEndpointSliceWithEndpointSliceCreateOrUpdate(clusterName string, endpointSlice *unstructured.Unstructured) error {
|
||||||
relatedServiceName := endpointSlice.GetLabels()[discoveryv1.LabelServiceName]
|
relatedServiceName := endpointSlice.GetLabels()[discoveryv1.LabelServiceName]
|
||||||
|
@ -436,13 +431,9 @@ func cleanupWorkWithServiceExportDelete(c client.Client, serviceExportKey keys.F
|
||||||
errs = append(errs, err)
|
errs = append(errs, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if len(errs) > 0 {
|
|
||||||
return utilerrors.NewAggregate(errs)
|
return utilerrors.NewAggregate(errs)
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func cleanupWorkWithEndpointSliceDelete(c client.Client, endpointSliceKey keys.FederatedKey) error {
|
func cleanupWorkWithEndpointSliceDelete(c client.Client, endpointSliceKey keys.FederatedKey) error {
|
||||||
executionSpace, err := names.GenerateExecutionSpaceName(endpointSliceKey.Cluster)
|
executionSpace, err := names.GenerateExecutionSpaceName(endpointSliceKey.Cluster)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -546,13 +546,9 @@ func (d *DependenciesDistributor) removeScheduleResultFromAttachedBindings(bindi
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(errs) > 0 {
|
|
||||||
return utilerrors.NewAggregate(errs)
|
return utilerrors.NewAggregate(errs)
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func buildAttachedBinding(binding *workv1alpha2.ResourceBinding, object *unstructured.Unstructured) *workv1alpha2.ResourceBinding {
|
func buildAttachedBinding(binding *workv1alpha2.ResourceBinding, object *unstructured.Unstructured) *workv1alpha2.ResourceBinding {
|
||||||
labels := generateBindingDependedByLabel(binding.Namespace, binding.Name)
|
labels := generateBindingDependedByLabel(binding.Namespace, binding.Name)
|
||||||
|
|
||||||
|
|
|
@ -973,14 +973,9 @@ func (d *ResourceDetector) HandleClusterPropagationPolicyDeletion(policyName str
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(errs) > 0 {
|
|
||||||
return errors.NewAggregate(errs)
|
return errors.NewAggregate(errs)
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// HandlePropagationPolicyCreation handles PropagationPolicy add event.
|
// HandlePropagationPolicyCreation handles PropagationPolicy add event.
|
||||||
// When a new policy arrives, should check if object in waiting list matches the policy, if yes remove the object
|
// When a new policy arrives, should check if object in waiting list matches the policy, if yes remove the object
|
||||||
// from waiting list and throw the object to it's reconcile queue. If not, do nothing.
|
// from waiting list and throw the object to it's reconcile queue. If not, do nothing.
|
||||||
|
|
|
@ -132,11 +132,8 @@ func RemoveOrphanWorks(c client.Client, works []workv1alpha1.Work) error {
|
||||||
}
|
}
|
||||||
klog.Infof("Delete orphan work %s/%s successfully.", work.GetNamespace(), work.GetName())
|
klog.Infof("Delete orphan work %s/%s successfully.", work.GetNamespace(), work.GetName())
|
||||||
}
|
}
|
||||||
if len(errs) > 0 {
|
|
||||||
return errors.NewAggregate(errs)
|
return errors.NewAggregate(errs)
|
||||||
}
|
}
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// FetchWorkload fetches the kubernetes resource to be propagated.
|
// FetchWorkload fetches the kubernetes resource to be propagated.
|
||||||
func FetchWorkload(dynamicClient dynamic.Interface, informerManager informermanager.SingleClusterInformerManager,
|
func FetchWorkload(dynamicClient dynamic.Interface, informerManager informermanager.SingleClusterInformerManager,
|
||||||
|
@ -223,14 +220,9 @@ func DeleteWorks(c client.Client, namespace, name string) error {
|
||||||
errs = append(errs, err)
|
errs = append(errs, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(errs) > 0 {
|
|
||||||
return errors.NewAggregate(errs)
|
return errors.NewAggregate(errs)
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// GenerateNodeClaimByPodSpec will return a NodeClaim from PodSpec.
|
// GenerateNodeClaimByPodSpec will return a NodeClaim from PodSpec.
|
||||||
func GenerateNodeClaimByPodSpec(podSpec *corev1.PodSpec) *workv1alpha2.NodeClaim {
|
func GenerateNodeClaimByPodSpec(podSpec *corev1.PodSpec) *workv1alpha2.NodeClaim {
|
||||||
nodeClaim := &workv1alpha2.NodeClaim{
|
nodeClaim := &workv1alpha2.NodeClaim{
|
||||||
|
|
|
@ -73,9 +73,5 @@ func DeleteEndpointSlice(c client.Client, selector labels.Set) error {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(errs) > 0 {
|
|
||||||
return errors.NewAggregate(errs)
|
return errors.NewAggregate(errs)
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in New Issue