Skip to content

Commit 9526570

Browse files
committed
Rename annotations
see deislabs#49 (comment) no more `osiris.xxx/enabled` annotation, it's been replaced by: - `osiris.xxx/collectMetrics` for the pods - `osiris.xxx/enableScaling` for the workloads (deployments/statefulsets) - `osiris.xxx/manageEndpoints` for the services
1 parent 5f1e066 commit 9526570

9 files changed

Lines changed: 33 additions & 26 deletions

File tree

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ metadata:
127127
namespace: my-aoo
128128
name: my-app
129129
annotations:
130-
osiris.dm.gg/enabled: "true"
130+
osiris.dm.gg/enableScaling: "true"
131131
spec:
132132
replicas: 1
133133
selector:
@@ -163,7 +163,7 @@ metadata:
163163
namespace: my-namespace
164164
name: my-app
165165
annotations:
166-
osiris.dm.gg/enabled: "true"
166+
osiris.dm.gg/manageEndpoints: "true"
167167
osiris.dm.gg/deployment: my-app
168168
spec:
169169
selector:
@@ -181,7 +181,7 @@ The following table lists the supported annotations for Kubernetes `Deployments`
181181

182182
| Annotation | Description | Default |
183183
| ---------- | ----------- | ------- |
184-
| `osiris.dm.gg/enabled` | Enable the zeroscaler component to scrape and analyze metrics from the deployment's or statefulSet's pods and scale the deployment/statefulSet to zero when idle. Allowed values: `y`, `yes`, `true`, `on`, `1`. | _no value_ (= disabled) |
184+
| `osiris.dm.gg/enableScaling` | Enable the zeroscaler component to scrape and analyze metrics from the deployment's or statefulSet's pods and scale the deployment/statefulSet to zero when idle. Allowed values: `y`, `yes`, `true`, `on`, `1`. | _no value_ (= disabled) |
185185
| `osiris.dm.gg/minReplicas` | The minimum number of replicas to set on the deployment/statefulSet when Osiris will scale up. If you set `2`, Osiris will scale the deployment/statefulSet from `0` to `2` replicas directly. Osiris won't collect metrics from deployments/statefulSets which have more than `minReplicas` replicas - to avoid useless collections of metrics. | `1` |
186186
| `osiris.dm.gg/metricsCheckInterval` | The interval in which Osiris would repeatedly track the pod http request metrics. The value is the number of seconds of the interval. Note that this value override the global value defined by the `zeroscaler.metricsCheckInterval` Helm value. | _value of the `zeroscaler.metricsCheckInterval` Helm value_ |
187187
| `osiris.dm.gg/metricsCollector` | Configure the collection of metrics for a pod. The value is a JSON object with at least a `type` string, and an optional `implementation` object. See the *Metrics Scraping* section for more. | `{ "type": "osiris" }` |
@@ -201,7 +201,7 @@ The following table lists the supported annotations for Kubernetes `Services` an
201201

202202
| Annotation | Description | Default |
203203
| ---------- | ----------- | ------- |
204-
| `osiris.dm.gg/enabled` | Enable this service's endpoints to be managed by the Osiris endpoints controller. Allowed values: `y`, `yes`, `true`, `on`, `1`. | _no value_ (= disabled) |
204+
| `osiris.dm.gg/manageEndpoints` | Enable this service's endpoints to be managed by the Osiris endpoints controller. Allowed values: `y`, `yes`, `true`, `on`, `1`. | _no value_ (= disabled) |
205205
| `osiris.dm.gg/deployment` | Name of the deployment which is behind this service. This is _required_ to map the service with its deployment. | _no value_ |
206206
| `osiris.dm.gg/statefulset` | Name of the statefulSet which is behind this service. This is _required_ to map the service with its statefulSet. | _no value_ |
207207
| `osiris.dm.gg/loadBalancerHostname` | Map requests coming from a specific hostname to this service. Note that if you have multiple hostnames, you can set them with different annotations, using `osiris.dm.gg/loadBalancerHostname-1`, `osiris.dm.gg/loadBalancerHostname-2`, ... | _no value_ |

example/hello-osiris.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ metadata:
55
labels:
66
app: hello-osiris
77
annotations:
8-
osiris.dm.gg/enabled: "true"
8+
osiris.dm.gg/manageEndpoints: "true"
99
osiris.dm.gg/deployment: hello-osiris
1010
osiris.dm.gg/loadBalancerHostname: hello-osiris.contoso.io
1111
spec:
@@ -27,7 +27,7 @@ metadata:
2727
labels:
2828
app: hello-osiris
2929
annotations:
30-
osiris.dm.gg/enabled: "true"
30+
osiris.dm.gg/enableScaling: "true"
3131
osiris.dm.gg/minReplicas: "1"
3232
osiris.dm.gg/metricsCheckInterval: "120" # seconds
3333
spec:

pkg/deployments/activator/activator.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ func (a *activator) syncService(obj interface{}) {
107107
defer a.indicesLock.Unlock()
108108
svc := obj.(*corev1.Service)
109109
svcKey := getKey(svc.Namespace, "Service", svc.Name)
110-
if k8s.ResourceIsOsirisEnabled(svc.Annotations) {
110+
if k8s.ServiceIsEligibleForEndpointsManagement(svc.Annotations) {
111111
a.services[svcKey] = svc
112112
} else {
113113
delete(a.services, svcKey)

pkg/deployments/zeroscaler/zeroscaler.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ func (z *zeroscaler) Run(ctx context.Context) {
9393

9494
func (z *zeroscaler) syncDeployment(obj interface{}) {
9595
deployment := obj.(*appsv1.Deployment)
96-
if k8s.ResourceIsOsirisEnabled(deployment.Annotations) {
96+
if k8s.WorkloadIsEligibleForAutoScaling(deployment.Annotations) {
9797
glog.Infof(
9898
"Notified about new or updated Osiris-enabled deployment %s in "+
9999
"namespace %s",
@@ -147,7 +147,7 @@ func (z *zeroscaler) syncDeployment(obj interface{}) {
147147

148148
func (z *zeroscaler) syncStatefulSet(obj interface{}) {
149149
statefulSet := obj.(*appsv1.StatefulSet)
150-
if k8s.ResourceIsOsirisEnabled(statefulSet.Annotations) {
150+
if k8s.WorkloadIsEligibleForAutoScaling(statefulSet.Annotations) {
151151
glog.Infof(
152152
"Notified about new or updated Osiris-enabled statefulSet %s in "+
153153
"namespace %s",

pkg/endpoints/controller/controller.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ func (c *controller) Run(ctx context.Context) {
117117
// be prevented for non-Osiris-enabled services.
118118
func (c *controller) syncAppService(obj interface{}) {
119119
svc := obj.(*corev1.Service)
120-
if k8s.ResourceIsOsirisEnabled(svc.Annotations) {
120+
if k8s.ServiceIsEligibleForEndpointsManagement(svc.Annotations) {
121121
glog.Infof(
122122
"Notified about new or updated Osiris-enabled service %s in namespace %s",
123123
svc.Name,

pkg/endpoints/hijacker/hijacker.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ func (h *hijacker) handleRequest(w http.ResponseWriter, r *http.Request) {
213213
}
214214

215215
func validateService(svc *corev1.Service) error {
216-
if kubernetes.ResourceIsOsirisEnabled(svc.Annotations) {
216+
if kubernetes.ServiceIsEligibleForEndpointsManagement(svc.Annotations) {
217217
_, deploymentPresent := svc.Annotations["osiris.dm.gg/deployment"]
218218
_, statefulSetPresent := svc.Annotations["osiris.dm.gg/statefulset"]
219219
if !deploymentPresent && !statefulSetPresent {

pkg/endpoints/hijacker/service_patch.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ func getServicePatchOperations(
2727
patchOps := []kubernetes.PatchOperation{}
2828

2929
// Service is Osiris-enabled... make it so...
30-
if kubernetes.ResourceIsOsirisEnabled(svc.Annotations) {
30+
if kubernetes.ServiceIsEligibleForEndpointsManagement(svc.Annotations) {
3131

3232
glog.Infof("Hijacking service %s", svc.Name)
3333

pkg/kubernetes/osiris.go

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,15 @@ const (
99
IgnoredPathsAnnotationName = "osiris.dm.gg/ignoredPaths"
1010
MetricsCollectorAnnotationName = "osiris.dm.gg/metricsCollector"
1111
MetricsCheckIntervalAnnotationName = "osiris.dm.gg/metricsCheckInterval"
12-
osirisEnabledAnnotationName = "osiris.dm.gg/enabled"
12+
enableScalingAnnotationName = "osiris.dm.gg/enableScaling"
1313
collectMetricsAnnotationName = "osiris.dm.gg/collectMetrics"
14+
manageEndpointsAnnotationName = "osiris.dm.gg/manageEndpoints"
1415
)
1516

16-
// ResourceIsOsirisEnabled checks the annotations to see if the
17-
// kube resource is enabled for osiris or not.
18-
func ResourceIsOsirisEnabled(annotations map[string]string) bool {
19-
return annotationBooleanValue(annotations, osirisEnabledAnnotationName)
17+
// WorkloadIsEligibleForAutoScaling checks the annotations to see if the
18+
// workload (deployment or statefulset) is eligible for auto-scaling with osiris or not.
19+
func WorkloadIsEligibleForAutoScaling(annotations map[string]string) bool {
20+
return annotationBooleanValue(annotations, enableScalingAnnotationName)
2021
}
2122

2223
// PodIsEligibleForProxyInjection checks the annotations to see if the
@@ -25,6 +26,12 @@ func PodIsEligibleForProxyInjection(annotations map[string]string) bool {
2526
return annotationBooleanValue(annotations, collectMetricsAnnotationName)
2627
}
2728

29+
// ServiceIsEligibleForEndpointsManagement checks the annotations to see if the
30+
// service is eligible for management of its endpoints by osiris or not.
31+
func ServiceIsEligibleForEndpointsManagement(annotations map[string]string) bool {
32+
return annotationBooleanValue(annotations, manageEndpointsAnnotationName)
33+
}
34+
2835
func annotationBooleanValue(annotations map[string]string, key string) bool {
2936
enabled, ok := annotations[key]
3037
if !ok {

pkg/kubernetes/osiris_test.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import (
44
"testing"
55
)
66

7-
func TestResourceIsOsirisEnabled(t *testing.T) {
7+
func TestAnnotationBooleanValue(t *testing.T) {
88
testcases := []struct {
99
name string
1010
annotations map[string]string
@@ -13,35 +13,35 @@ func TestResourceIsOsirisEnabled(t *testing.T) {
1313
{
1414
name: "map with osiris enabled entry and value 1",
1515
annotations: map[string]string{
16-
osirisEnabledAnnotationName: "1",
16+
enableScalingAnnotationName: "1",
1717
},
1818
expectedResult: true,
1919
},
2020
{
2121
name: "map with osiris enabled entry and value true",
2222
annotations: map[string]string{
23-
osirisEnabledAnnotationName: "true",
23+
enableScalingAnnotationName: "true",
2424
},
2525
expectedResult: true,
2626
},
2727
{
2828
name: "map with osiris enabled entry and value on",
2929
annotations: map[string]string{
30-
osirisEnabledAnnotationName: "on",
30+
enableScalingAnnotationName: "on",
3131
},
3232
expectedResult: true,
3333
},
3434
{
3535
name: "map with osiris enabled entry and value y",
3636
annotations: map[string]string{
37-
osirisEnabledAnnotationName: "y",
37+
enableScalingAnnotationName: "y",
3838
},
3939
expectedResult: true,
4040
},
4141
{
4242
name: "map with osiris enabled entry and value yes",
4343
annotations: map[string]string{
44-
osirisEnabledAnnotationName: "yes",
44+
enableScalingAnnotationName: "yes",
4545
},
4646
expectedResult: true,
4747
},
@@ -54,18 +54,18 @@ func TestResourceIsOsirisEnabled(t *testing.T) {
5454
{
5555
name: "map with osiris enabled entry and invalid value",
5656
annotations: map[string]string{
57-
osirisEnabledAnnotationName: "yee",
57+
enableScalingAnnotationName: "yee",
5858
},
5959
expectedResult: false,
6060
},
6161
}
6262

6363
for _, test := range testcases {
6464
t.Run(test.name, func(t *testing.T) {
65-
actual := ResourceIsOsirisEnabled(test.annotations)
65+
actual := annotationBooleanValue(test.annotations, enableScalingAnnotationName)
6666
if actual != test.expectedResult {
6767
t.Errorf(
68-
"expected ResourceIsOsirisEnabled to return %t, but got %t",
68+
"expected annotationBooleanValue to return %t, but got %t",
6969
test.expectedResult, actual)
7070
}
7171
})

0 commit comments

Comments
 (0)