diff --git a/README.md b/README.md index 628750b7..1555f6a4 100644 --- a/README.md +++ b/README.md @@ -141,7 +141,7 @@ spec: labels: app: nginx annotations: - osiris.deislabs.io/enabled: "true" + osiris.deislabs.io/collectMetrics: "true" # ... # ... ``` @@ -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 diff --git a/example/hello-osiris.yaml b/example/hello-osiris.yaml index eab33bcf..3beb45e4 100644 --- a/example/hello-osiris.yaml +++ b/example/hello-osiris.yaml @@ -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: diff --git a/pkg/kubernetes/osiris.go b/pkg/kubernetes/osiris.go index 2cab7ac7..823124a5 100644 --- a/pkg/kubernetes/osiris.go +++ b/pkg/kubernetes/osiris.go @@ -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 } diff --git a/pkg/metrics/proxy/injector/pod_patch.go b/pkg/metrics/proxy/injector/pod_patch.go index 51db0db2..c7965c49 100644 --- a/pkg/metrics/proxy/injector/pod_patch.go +++ b/pkg/metrics/proxy/injector/pod_patch.go @@ -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 }