Skip to content

Commit

Permalink
Merge pull request #20 from dougbtv/fix-check-default-namespace-telem…
Browse files Browse the repository at this point in the history
…etry-backport

Bug 1770387: Fix check default namespace telemetry backport
  • Loading branch information
openshift-merge-robot committed Dec 6, 2019
2 parents bbb6856 + b6a59d9 commit ead10a3
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions pkg/controller/controller.go
Expand Up @@ -256,16 +256,18 @@ func (c *Controller) processItem(key string) error {
return fmt.Errorf("Error fetching object with key %s from store: %v", key, err)
}
if !exists {
return c.updateMetrics(key, "", Delete)

return c.updateMetrics(key, "", api_v1.NamespaceDefault, Delete)
}

pod, _ := obj.(*api_v1.Pod)
namespace := pod.ObjectMeta.Namespace
if pod.Status.Phase == api_v1.PodRunning {
glog.Infof("Pod found for net-attach-def metrics, processing %s under namespaces %s", key, namespace)
if name, ok := pod.GetAnnotations()[nadPodAnnotation]; ok {
return c.updateMetrics(key, name, Add)
return c.updateMetrics(key, name, namespace, Add)
}
//ok if annotation not found delete the metrics.
return c.updateMetrics(key, "", Delete)
return c.updateMetrics(key, "", namespace, Delete)
}

return nil
Expand Down Expand Up @@ -314,7 +316,7 @@ func (c *Controller) getConfigTypes(crd *networkv1.NetworkAttachmentDefinition)
return configTypes
}

func (c *Controller) updateMetrics(key string, configNames string, action metricAction) error {
func (c *Controller) updateMetrics(key string, configNames string, namespace string, action metricAction) error {
set := make(map[string]struct{})
var configTypes []string

Expand Down Expand Up @@ -342,10 +344,10 @@ func (c *Controller) updateMetrics(key string, configNames string, action metric
//clean up
oldConfigs := localmetrics.GetStoredValue(key)
if oldConfigs != "" {
c.updateMetrics(key, "", Delete)
c.updateMetrics(key, "", namespace, Delete)
}

networks, err := c.parsePodNetworkAnnotation(configNames, "default")
networks, err := c.parsePodNetworkAnnotation(configNames, namespace)
if err != nil {
return fmt.Errorf("Error reading pod annotation %v", err)
}
Expand Down Expand Up @@ -418,7 +420,6 @@ func (c *Controller) parsePodNetworkAnnotation(podNetworks, defaultNamespace str
net.Namespace = defaultNamespace
}
}

return networks, nil
}

Expand Down

0 comments on commit ead10a3

Please sign in to comment.