Skip to content
This repository was archived by the owner on Jan 27, 2021. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ spec:
labels:
app: nginx
annotations:
osiris.deislabs.io/enabled: "true"
osiris.deislabs.io/collectMetrics: "true"
# ...
# ...
```
Expand Down Expand Up @@ -194,7 +194,7 @@ The following table lists the supported annotations for Kubernetes `Pods` and th

| Annotation | Description | Default |
| ---------- | ----------- | ------- |
| `osiris.deislabs.io/enabled` | Enable the metrics collecting proxy sidecar container to be injected into this pod. Allowed values: `y`, `yes`, `true`, `on`, `1`. | _no value_ (= disabled) |
| `osiris.deislabs.io/collectMetrics` | Enable the metrics collecting proxy to be injected as a sidecar container into this pod. This is _required_ for metrics collection. Allowed values: `y`, `yes`, `true`, `on`, `1`. | _no value_ (= disabled) |
| `osiris.deislabs.io/ignoredPaths` | The list of (url) paths that should be "ignored" by Osiris. Requests to such paths won't be "counted" by the proxy. Format: comma-separated string. | _no value_ |

#### Service Annotations
Expand Down
2 changes: 1 addition & 1 deletion example/hello-osiris.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ spec:
labels:
app: hello-osiris
annotations:
osiris.deislabs.io/enabled: "true"
osiris.deislabs.io/collectMetrics: "true"
osiris.deislabs.io/ignoredPaths: "/first/path,/second-path"
spec:
containers:
Expand Down
13 changes: 12 additions & 1 deletion pkg/kubernetes/osiris.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,24 @@ import (
const (
IgnoredPathsAnnotationName = "osiris.deislabs.io/ignoredPaths"
osirisEnabledAnnotationName = "osiris.deislabs.io/enabled"
collectMetricsAnnotationName = "osiris.deislabs.io/collectMetrics"
metricsCheckIntervalAnnotationName = "osiris.deislabs.io/metricsCheckInterval"
)

// ResourceIsOsirisEnabled checks the annotations to see if the
// kube resource is enabled for osiris or not.
func ResourceIsOsirisEnabled(annotations map[string]string) bool {
enabled, ok := annotations[osirisEnabledAnnotationName]
return annotationBooleanValue(annotations, osirisEnabledAnnotationName)
}

// PodIsEligibleForProxyInjection checks the annotations to see if the
// pod is eligible for proxy injection or not.
func PodIsEligibleForProxyInjection(annotations map[string]string) bool {
return annotationBooleanValue(annotations, collectMetricsAnnotationName)
}

func annotationBooleanValue(annotations map[string]string, key string) bool {
enabled, ok := annotations[key]
if !ok {
return false
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/metrics/proxy/injector/pod_patch.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func (i *injector) getPodPatchOperations(
req.UserInfo,
)

if !kubernetes.ResourceIsOsirisEnabled(pod.Annotations) ||
if !kubernetes.PodIsEligibleForProxyInjection(pod.Annotations) ||
(podContainsProxyInitContainer(&pod) && podContainsProxyContainer(&pod)) {
return nil, nil
}
Expand Down