Skip to content
Merged
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
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ metadata:
namespace: my-aoo
name: my-app
annotations:
osiris.dm.gg/enabled: "true"
osiris.dm.gg/enableScaling: "true"
spec:
replicas: 1
selector:
Expand Down Expand Up @@ -163,7 +163,7 @@ metadata:
namespace: my-namespace
name: my-app
annotations:
osiris.dm.gg/enabled: "true"
osiris.dm.gg/manageEndpoints: "true"
osiris.dm.gg/deployment: my-app
spec:
selector:
Expand All @@ -181,7 +181,7 @@ The following table lists the supported annotations for Kubernetes `Deployments`

| Annotation | Description | Default |
| ---------- | ----------- | ------- |
| `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) |
| `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) |
| `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` |
| `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_ |
| `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" }` |
Expand All @@ -201,7 +201,7 @@ The following table lists the supported annotations for Kubernetes `Services` an

| Annotation | Description | Default |
| ---------- | ----------- | ------- |
| `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) |
| `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) |
| `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_ |
| `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_ |
| `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_ |
Expand Down
4 changes: 2 additions & 2 deletions example/hello-osiris.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ metadata:
labels:
app: hello-osiris
annotations:
osiris.dm.gg/enabled: "true"
osiris.dm.gg/manageEndpoints: "true"
osiris.dm.gg/deployment: hello-osiris
osiris.dm.gg/loadBalancerHostname: hello-osiris.contoso.io
spec:
Expand All @@ -27,7 +27,7 @@ metadata:
labels:
app: hello-osiris
annotations:
osiris.dm.gg/enabled: "true"
osiris.dm.gg/enableScaling: "true"
osiris.dm.gg/minReplicas: "1"
osiris.dm.gg/metricsCheckInterval: "120" # seconds
spec:
Expand Down
2 changes: 1 addition & 1 deletion pkg/deployments/activator/activator.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ func (a *activator) syncService(obj interface{}) {
defer a.indicesLock.Unlock()
svc := obj.(*corev1.Service)
svcKey := getKey(svc.Namespace, "Service", svc.Name)
if k8s.ResourceIsOsirisEnabled(svc.Annotations) {
if k8s.ServiceIsEligibleForEndpointsManagement(svc.Annotations) {
a.services[svcKey] = svc
} else {
delete(a.services, svcKey)
Expand Down
4 changes: 2 additions & 2 deletions pkg/deployments/zeroscaler/zeroscaler.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ func (z *zeroscaler) Run(ctx context.Context) {

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

func (z *zeroscaler) syncStatefulSet(obj interface{}) {
statefulSet := obj.(*appsv1.StatefulSet)
if k8s.ResourceIsOsirisEnabled(statefulSet.Annotations) {
if k8s.WorkloadIsEligibleForAutoScaling(statefulSet.Annotations) {
glog.Infof(
"Notified about new or updated Osiris-enabled statefulSet %s in "+
"namespace %s",
Expand Down
2 changes: 1 addition & 1 deletion pkg/endpoints/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ func (c *controller) Run(ctx context.Context) {
// be prevented for non-Osiris-enabled services.
func (c *controller) syncAppService(obj interface{}) {
svc := obj.(*corev1.Service)
if k8s.ResourceIsOsirisEnabled(svc.Annotations) {
if k8s.ServiceIsEligibleForEndpointsManagement(svc.Annotations) {
glog.Infof(
"Notified about new or updated Osiris-enabled service %s in namespace %s",
svc.Name,
Expand Down
2 changes: 1 addition & 1 deletion pkg/endpoints/hijacker/hijacker.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ func (h *hijacker) handleRequest(w http.ResponseWriter, r *http.Request) {
}

func validateService(svc *corev1.Service) error {
if kubernetes.ResourceIsOsirisEnabled(svc.Annotations) {
if kubernetes.ServiceIsEligibleForEndpointsManagement(svc.Annotations) {
_, deploymentPresent := svc.Annotations["osiris.dm.gg/deployment"]
_, statefulSetPresent := svc.Annotations["osiris.dm.gg/statefulset"]
if !deploymentPresent && !statefulSetPresent {
Expand Down
2 changes: 1 addition & 1 deletion pkg/endpoints/hijacker/service_patch.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func getServicePatchOperations(
patchOps := []kubernetes.PatchOperation{}

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

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

Expand Down
17 changes: 12 additions & 5 deletions pkg/kubernetes/osiris.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,15 @@ const (
IgnoredPathsAnnotationName = "osiris.dm.gg/ignoredPaths"
MetricsCollectorAnnotationName = "osiris.dm.gg/metricsCollector"
MetricsCheckIntervalAnnotationName = "osiris.dm.gg/metricsCheckInterval"
osirisEnabledAnnotationName = "osiris.dm.gg/enabled"
enableScalingAnnotationName = "osiris.dm.gg/enableScaling"
collectMetricsAnnotationName = "osiris.dm.gg/collectMetrics"
manageEndpointsAnnotationName = "osiris.dm.gg/manageEndpoints"
)

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

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

// ServiceIsEligibleForEndpointsManagement checks the annotations to see if the
// service is eligible for management of its endpoints by osiris or not.
func ServiceIsEligibleForEndpointsManagement(annotations map[string]string) bool {
return annotationBooleanValue(annotations, manageEndpointsAnnotationName)
}

func annotationBooleanValue(annotations map[string]string, key string) bool {
enabled, ok := annotations[key]
if !ok {
Expand Down
18 changes: 9 additions & 9 deletions pkg/kubernetes/osiris_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"testing"
)

func TestResourceIsOsirisEnabled(t *testing.T) {
func TestAnnotationBooleanValue(t *testing.T) {
testcases := []struct {
name string
annotations map[string]string
Expand All @@ -13,35 +13,35 @@ func TestResourceIsOsirisEnabled(t *testing.T) {
{
name: "map with osiris enabled entry and value 1",
annotations: map[string]string{
osirisEnabledAnnotationName: "1",
enableScalingAnnotationName: "1",
},
expectedResult: true,
},
{
name: "map with osiris enabled entry and value true",
annotations: map[string]string{
osirisEnabledAnnotationName: "true",
enableScalingAnnotationName: "true",
},
expectedResult: true,
},
{
name: "map with osiris enabled entry and value on",
annotations: map[string]string{
osirisEnabledAnnotationName: "on",
enableScalingAnnotationName: "on",
},
expectedResult: true,
},
{
name: "map with osiris enabled entry and value y",
annotations: map[string]string{
osirisEnabledAnnotationName: "y",
enableScalingAnnotationName: "y",
},
expectedResult: true,
},
{
name: "map with osiris enabled entry and value yes",
annotations: map[string]string{
osirisEnabledAnnotationName: "yes",
enableScalingAnnotationName: "yes",
},
expectedResult: true,
},
Expand All @@ -54,18 +54,18 @@ func TestResourceIsOsirisEnabled(t *testing.T) {
{
name: "map with osiris enabled entry and invalid value",
annotations: map[string]string{
osirisEnabledAnnotationName: "yee",
enableScalingAnnotationName: "yee",
},
expectedResult: false,
},
}

for _, test := range testcases {
t.Run(test.name, func(t *testing.T) {
actual := ResourceIsOsirisEnabled(test.annotations)
actual := annotationBooleanValue(test.annotations, enableScalingAnnotationName)
if actual != test.expectedResult {
t.Errorf(
"expected ResourceIsOsirisEnabled to return %t, but got %t",
"expected annotationBooleanValue to return %t, but got %t",
test.expectedResult, actual)
}
})
Expand Down