Skip to content

Commit

Permalink
Add cluster autoscaler annotation to allow safe eviction of collector…
Browse files Browse the repository at this point in the history
…s and rule evaluators (#237)
  • Loading branch information
xichen2020 committed Jun 9, 2022
1 parent e998f75 commit 78cd977
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 1 deletion.
4 changes: 4 additions & 0 deletions pkg/operator/collection.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,10 @@ func (r *collectionReconciler) makeCollectorDaemonSet(spec *monitoringv1.Collect

podAnnotations := map[string]string{
AnnotationMetricName: componentName,
// Allow cluster autoscaler to evict collector Pods even though the Pods
// have an emptyDir volume mounted. This is okay since the node where the
// Pod runs will be scaled down and therefore does not need metrics reporting.
ClusterAutoscalerSafeEvictionLabel: "true",
}

collectorArgs := []string{
Expand Down
21 changes: 20 additions & 1 deletion pkg/operator/e2e/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,15 @@ func testRuleEvaluatorDeployment(ctx context.Context, t *testContext) {
return false, nil
}

// Assert we have the expected annotations.
wantedAnnotations := map[string]string{
"components.gke.io/component-name": "managed_prometheus",
"cluster-autoscaler.kubernetes.io/safe-to-evict": "true",
}
if diff := cmp.Diff(wantedAnnotations, deploy.Spec.Template.Annotations); diff != "" {
return false, errors.Errorf("unexpected annotations (-want, +got): %s", diff)
}

for _, c := range deploy.Spec.Template.Spec.Containers {
if c.Name != "evaluator" {
continue
Expand Down Expand Up @@ -549,10 +558,21 @@ func testCollectorDeployed(ctx context.Context, t *testContext) {
return false, nil
}
}

// Assert we have the expected annotations.
wantedAnnotations := map[string]string{
"components.gke.io/component-name": "managed_prometheus",
"cluster-autoscaler.kubernetes.io/safe-to-evict": "true",
}
if diff := cmp.Diff(wantedAnnotations, ds.Spec.Template.Annotations); diff != "" {
return false, errors.Errorf("unexpected annotations (-want, +got): %s", diff)
}

for _, c := range ds.Spec.Template.Spec.Containers {
if c.Name != "prometheus" {
continue
}

// We're mainly interested in the dynamic flags but checking the entire set including
// the static ones is ultimately simpler.
wantArgs := []string{
Expand Down Expand Up @@ -583,7 +603,6 @@ func testCollectorDeployed(ctx context.Context, t *testContext) {
sort.Strings(c.Args)

if diff := cmp.Diff(wantArgs, c.Args); diff != "" {
t.Log(errors.Errorf("unexpected flags (-want, +got): %s", diff))
return false, errors.Errorf("unexpected flags (-want, +got): %s", diff)
}
return true, nil
Expand Down
4 changes: 4 additions & 0 deletions pkg/operator/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ const (
LabelAppName = "app.kubernetes.io/name"
// The component name, will be exposed as metric name.
AnnotationMetricName = "components.gke.io/component-name"
// ClusterAutoscalerSafeEvictionLabel is the annotation label that determines
// whether the cluster autoscaler can safely evict a Pod when the Pod doesn't
// satisfy certain eviction criteria.
ClusterAutoscalerSafeEvictionLabel = "cluster-autoscaler.kubernetes.io/safe-to-evict"

// The official images to be used with this version of the operator. For debugging
// and emergency use cases they may be overwritten through options.
Expand Down
4 changes: 4 additions & 0 deletions pkg/operator/operator_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ func rulesLabels() map[string]string {
func rulesAnnotations() map[string]string {
return map[string]string{
AnnotationMetricName: componentName,
// Allow cluster autoscaler to evict evaluator Pods even though the Pods
// have an emptyDir volume mounted. This is okay since the node where the
// Pod runs will be scaled down.
ClusterAutoscalerSafeEvictionLabel: "true",
}
}

Expand Down

0 comments on commit 78cd977

Please sign in to comment.