Skip to content

Commit

Permalink
metrics-adapter: preserve the resourceVersion of pods/nodes
Browse files Browse the repository at this point in the history
Signed-off-by: chaunceyjiang <chaunceyjiang@gmail.com>
  • Loading branch information
chaunceyjiang committed Apr 10, 2024
1 parent f369c55 commit c6c1033
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
22 changes: 12 additions & 10 deletions pkg/metricsadapter/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ func nodeTransformFunc(obj interface{}) (interface{}, error) {
Name: node.Name,
Namespace: node.Namespace,
Labels: node.Labels,
ResourceVersion: node.ResourceVersion,
DeletionTimestamp: node.DeletionTimestamp,
},
}
Expand All @@ -125,6 +126,7 @@ func podTransformFunc(obj interface{}) (interface{}, error) {
Name: pod.Name,
Namespace: pod.Namespace,
Labels: pod.Labels,
ResourceVersion: pod.ResourceVersion,
DeletionTimestamp: pod.DeletionTimestamp,
},
}
Expand Down Expand Up @@ -175,7 +177,7 @@ func (m *MetricsController) updateCluster(oldObj, curObj interface{}) {
if util.ClusterAccessCredentialChanged(curCluster.Spec, oldCluster.Spec) ||
util.IsClusterReady(&curCluster.Status) != util.IsClusterReady(&oldCluster.Status) {
// Cluster.Spec or Cluster health state is changed, rebuild informer.
m.InformerManager.Stop(curCluster.GetName())
m.stopInformerManager(curCluster.GetName())
m.queue.Add(curCluster.GetName())
}
}
Expand Down Expand Up @@ -213,27 +215,21 @@ func (m *MetricsController) handleClusters() bool {
if err != nil {
if apierrors.IsNotFound(err) {
klog.Infof("try to stop cluster informer %s", clusterName)
m.TypedInformerManager.Stop(clusterName)
m.InformerManager.Stop(clusterName)
m.MultiClusterDiscovery.Remove(clusterName)
m.stopInformerManager(clusterName)
return true
}
return false
}

if !cls.DeletionTimestamp.IsZero() {
klog.Infof("try to stop cluster informer %s", clusterName)
m.TypedInformerManager.Stop(clusterName)
m.InformerManager.Stop(clusterName)
m.MultiClusterDiscovery.Remove(clusterName)
m.stopInformerManager(clusterName)
return true
}

if !util.IsClusterReady(&cls.Status) {
klog.Warningf("cluster %s is notReady try to stop this cluster informer", clusterName)
m.TypedInformerManager.Stop(clusterName)
m.InformerManager.Stop(clusterName)
m.MultiClusterDiscovery.Remove(clusterName)
m.stopInformerManager(clusterName)
return false
}

Expand Down Expand Up @@ -276,3 +272,9 @@ func (m *MetricsController) handleClusters() bool {

return true
}

func (m *MetricsController) stopInformerManager(clusterName string) {
m.TypedInformerManager.Stop(clusterName)
m.InformerManager.Stop(clusterName)
m.MultiClusterDiscovery.Remove(clusterName)
}
4 changes: 3 additions & 1 deletion pkg/util/fedinformer/transform.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ func NodeTransformFunc(obj interface{}) (interface{}, error) {

aggregatedNode := &corev1.Node{
ObjectMeta: metav1.ObjectMeta{
Name: node.Name,
Name: node.Name,
ResourceVersion: node.ResourceVersion,
},
Status: corev1.NodeStatus{
Allocatable: node.Status.Allocatable,
Expand Down Expand Up @@ -101,6 +102,7 @@ func PodTransformFunc(obj interface{}) (interface{}, error) {
ObjectMeta: metav1.ObjectMeta{
Name: pod.Name,
Namespace: pod.Namespace,
ResourceVersion: pod.ResourceVersion,
Labels: pod.Labels,
DeletionTimestamp: pod.DeletionTimestamp,
},
Expand Down

0 comments on commit c6c1033

Please sign in to comment.