Skip to content

Commit

Permalink
feat: add log for enhancing quota managing
Browse files Browse the repository at this point in the history
  • Loading branch information
flyma authored and choujimmy committed Mar 6, 2020
1 parent 5cb0d1b commit e84bfaa
Show file tree
Hide file tree
Showing 8 changed files with 11 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ func recalculateProjectUsed(deleter *namespacedResourcesDeleter, namespace *v1.N
if project.Status.Clusters != nil {
clusterUsed, clusterUsedExist := project.Status.Clusters[namespace.Spec.ClusterName]
if clusterUsedExist {
release := namespace.Spec.Hard
release := namespace.Spec.Hard // For historic data that has no CachedSpecHard
if namespace.Status.CachedSpecHard != nil {
release = namespace.Status.CachedSpecHard
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/business/controller/namespace/namespace_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func (s *namespaceCache) getOrCreate(name string, self *v1.Namespace) *cachedNam
namespace.state = self.DeepCopy()
if self.Status.CachedSpecHard != nil {
namespace.state.Spec.Hard = self.Status.CachedSpecHard
} else {
} else { // For historic data that has no CachedSpecHard
namespace.state.Spec.Hard = self.Spec.Hard
}
}
Expand Down
4 changes: 4 additions & 0 deletions pkg/business/controller/namespace/namespace_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,7 @@ func (c *Controller) handlePhase(key string, cachedNamespace *cachedNamespace, n
// Since it's pending now, no need to set v1.NamespaceFailed.
return err
}
// Once project has been updated, try our best update namespace CachedSpecHard.
namespace.Status.CachedSpecHard = namespace.Spec.Hard
if err := c.ensureNamespaceOnCluster(namespace); err != nil {
namespace.Status.Phase = v1.NamespaceFailed
Expand All @@ -305,6 +306,7 @@ func (c *Controller) handlePhase(key string, cachedNamespace *cachedNamespace, n
namespace.Status.LastTransitionTime = metav1.Now()
return c.persistUpdate(namespace)
}
// Once project has been updated, try our best update namespace CachedSpecHard.
cachedHard := namespace.Status.CachedSpecHard
namespace.Status.CachedSpecHard = namespace.Spec.Hard
if err := c.ensureNamespaceOnCluster(namespace); err != nil {
Expand All @@ -331,6 +333,8 @@ func (c *Controller) calculateProjectUsed(cachedNamespace *cachedNamespace, name
return err
}
calculatedNamespaceNames := sets.NewString(project.Status.CalculatedNamespaces...)
// The following "if" clause is supposed to process "Pending" namespaces.
// The "else if" is for "Available" namespaces.
if !calculatedNamespaceNames.Has(namespace.ObjectMeta.Name) {
project.Status.CalculatedNamespaces = append(project.Status.CalculatedNamespaces, namespace.ObjectMeta.Name)
if project.Status.Clusters == nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ func recalculateParentProjectUsed(deleter *projectedResourcesDeleter, project *b
calculatedChildProjectNames.Delete(project.ObjectMeta.Name)
parentProject.Status.CalculatedChildProjects = calculatedChildProjectNames.List()
if parentProject.Status.Clusters != nil {
release := project.Spec.Clusters
release := project.Spec.Clusters // For historic data that has no CachedSpecClusters
if project.Status.CachedSpecClusters != nil {
release = project.Status.CachedSpecClusters
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/business/controller/project/project_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func (s *projectCache) getOrCreate(name string, self *v1.Project) *cachedProject
project.state = self.DeepCopy()
if self.Status.CachedSpecClusters != nil {
project.state.Spec.Clusters = self.Status.CachedSpecClusters
} else {
} else { // For historic data that has no CachedSpecClusters
project.state.Spec.Clusters = self.Spec.Clusters
}
}
Expand Down
1 change: 1 addition & 0 deletions pkg/business/controller/project/project_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,7 @@ func (c *Controller) handlePhase(key string, cachedProject *cachedProject, proje
return err
}
}
// Once parentProject has been updated, update project CachedSpecClusters immediately.
if project != nil && !reflect.DeepEqual(project.Spec.Clusters, project.Status.CachedSpecClusters) {
return c.updateCache(project, project.Spec.Clusters)
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/business/registry/namespace/strategy.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func (Strategy) PrepareForUpdate(ctx context.Context, obj, old runtime.Object) {
}
if oldNamespace.Status.CachedSpecHard != nil {
namespace.Status.CachedSpecHard = oldNamespace.Status.CachedSpecHard
} else {
} else { // For historic data that has no CachedSpecHard
namespace.Status.CachedSpecHard = oldNamespace.Spec.Hard
}
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/business/registry/project/strategy.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ func (Strategy) PrepareForUpdate(ctx context.Context, obj, old runtime.Object) {
}
if oldProject.Status.CachedSpecClusters != nil {
project.Status.CachedSpecClusters = oldProject.Status.CachedSpecClusters
} else {
} else { // For historic data that has no CachedSpecClusters
project.Status.CachedSpecClusters = oldProject.Spec.Clusters
}
}
Expand Down

0 comments on commit e84bfaa

Please sign in to comment.