Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename pause annotation #2783

Merged
merged 9 commits into from
Mar 31, 2020
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
13 changes: 6 additions & 7 deletions docs/operating-eck/troubleshooting.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Most common issues can be identified and resolved by following these instruction
- <<{p}-describe-failing-resources,Describe failing resources>>
- <<{p}-eck-debug-logs,Enable ECK debug logs>>
- <<{p}-view-logs>>
- <<{p}-pause-controllers,Pause ECK controllers>>
- <<{p}-exclude-resource,Exclude a resource from reconciliation>>
- <<{p}-get-k8s-events,Get Kubernetes events>>
- <<{p}-exec-into-containers,Exec into containers>>
- <<{p}-webhook-troubleshooting,Troubleshoot webhook>>
Expand Down Expand Up @@ -170,11 +170,10 @@ Due to link:https://github.com/eBay/Kubernetes/blob/master/docs/devel/api-conven
you can get errors reporting a conflict while updating a resource. You can ignore them, as the update goes through at the next reconciliation attempt, which will happen almost immediately.


[id="{p}-pause-controllers"]
== Pause ECK controllers
[id="{p}-exclude-resource"]
== Exclude resources from reconciliation

When debugging Elasticsearch, you night need to "pause" the operator reconciliations, so that no resource gets modified or created in the meantime.
To do this, set the annotation `common.k8s.elastic.co/pause` to `true` to any resource controlled by the operator:
For debugging purposes, you might want to temporarily prevent ECK from modifying Kubernetes resources belonging to a particular Elastic Stack resource. To do this, annotate the Elastic object with `eck.k8s.elastic.co/managed=false`. This annotation can be added to any of the following types of objects:

- Elasticsearch
- Kibana
Expand All @@ -184,14 +183,14 @@ To do this, set the annotation `common.k8s.elastic.co/pause` to `true` to any re
----
metadata:
annotations:
common.k8s.elastic.co/pause: "true"
eck.k8s.elastic.co/managed: "false"
----

Or in one line:

[source,sh]
----
kubectl annotate elasticsearch quickstart --overwrite common.k8s.elastic.co/pause=true
kubectl annotate elasticsearch quickstart --overwrite eck.k8s.elastic.co/managed=false
----

[id="{p}-get-k8s-events"]
Expand Down
6 changes: 3 additions & 3 deletions pkg/controller/apmserver/apmserver_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,9 +180,9 @@ func (r *ReconcileApmServer) Reconcile(request reconcile.Request) (reconcile.Res
return reconcile.Result{}, tracing.CaptureError(ctx, err)
}

if common.IsPaused(as.ObjectMeta) {
log.Info("Object is paused. Skipping reconciliation", "namespace", as.Namespace, "as_name", as.Name)
return common.PauseRequeue, nil
if common.IsUnmanaged(as.ObjectMeta) {
log.Info("Object currently not managed by this controller. Skipping reconciliation", "namespace", as.Namespace, "as_name", as.Name)
return reconcile.Result{}, nil
}

if compatible, err := r.isCompatible(ctx, &as); err != nil || !compatible {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,9 @@ func (r *ReconcileApmServerElasticsearchAssociation) Reconcile(request reconcile
return reconcile.Result{}, tracing.CaptureError(ctx, err)
}

if common.IsPaused(apmServer.ObjectMeta) {
log.Info("Object is paused. Skipping reconciliation", "namespace", apmServer.Namespace, "as_name", apmServer.Name)
return common.PauseRequeue, nil
if common.IsUnmanaged(apmServer.ObjectMeta) {
log.Info("Object is currently not managed by this controller. Skipping reconciliation", "namespace", apmServer.Namespace, "as_name", apmServer.Name)
return reconcile.Result{}, nil
}

// ApmServer is being deleted, short-circuit reconciliation and remove artifacts related to the association.
Expand Down
50 changes: 0 additions & 50 deletions pkg/controller/common/pause.go

This file was deleted.

73 changes: 0 additions & 73 deletions pkg/controller/common/pause_test.go

This file was deleted.

31 changes: 31 additions & 0 deletions pkg/controller/common/unmanaged.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
// or more contributor license agreements. Licensed under the Elastic License;
// you may not use this file except in compliance with the Elastic License.

package common

import (
"fmt"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

const (
// ManagedAnnotation annotation
LegacyPauseAnnoation = "common.k8s.elastic.co/pause"
ManagedAnnotation = "eck.k8s.elastic.co/managed"
)

// IsUnmanaged checks if a given resource is currently unmanaged.
func IsUnmanaged(meta metav1.ObjectMeta) bool {
managed, exists := meta.Annotations[ManagedAnnotation]
if exists && managed == "false" {
return true
}

paused, exists := meta.Annotations[LegacyPauseAnnoation]
if exists {
log.Info(fmt.Sprintf("%s is deprecated, please use %s", LegacyPauseAnnoation, ManagedAnnotation), "namespace", meta.Namespace, "name", meta.Name)
}
return exists && paused == "true"
}
pebrc marked this conversation as resolved.
Show resolved Hide resolved
89 changes: 89 additions & 0 deletions pkg/controller/common/unmanaged_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
// or more contributor license agreements. Licensed under the Elastic License;
// you may not use this file except in compliance with the Elastic License.

package common

import (
"testing"

"github.com/stretchr/testify/assert"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

type testcase struct {
name string

// annotationSequence is list of annotations that are simulated.
annotationSequence []map[string]string

// Expected (un)managed state.
expectedState []bool
}

func TestUnmanagedCondition(t *testing.T) {
var tests = []testcase{
{
name: "Simple unmanaged/managed simulation (a.k.a the Happy Path)",
annotationSequence: []map[string]string{
{ManagedAnnotation: "true"},
{ManagedAnnotation: "false"},
{ManagedAnnotation: "true"},
{ManagedAnnotation: "false"},
},
expectedState: []bool{
false,
true,
false,
true,
},
},
{
name: "Anything but 'false' means managed",
annotationSequence: []map[string]string{
{ManagedAnnotation: ""}, // empty annotation
{ManagedAnnotation: "false"},
{ManagedAnnotation: "XXXX"}, // unable to parse these
{ManagedAnnotation: "1"},
{ManagedAnnotation: "0"},
},
expectedState: []bool{
false,
true,
false,
false,
false,
},
},
{
name: "Still support legacy annotation",
annotationSequence: []map[string]string{
{LegacyPauseAnnoation: "true"}, // still support legacy for backwards compatibility
{LegacyPauseAnnoation: "false"},
{LegacyPauseAnnoation: "foo"},
{LegacyPauseAnnoation: "false", ManagedAnnotation: "false"}, // new one takes precedence
{LegacyPauseAnnoation: "true", ManagedAnnotation: "true"}, // but legacy is respected if true
},
expectedState: []bool{
true,
false,
false,
true,
true,
},
},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
for i, expectedState := range test.expectedState {
meta := v1.ObjectMeta{
Name: "bar",
Namespace: "foo",
Annotations: test.annotationSequence[i],
}
actualPauseState := IsUnmanaged(meta)
assert.Equal(t, expectedState, actualPauseState, test.annotationSequence[i])
}
})
}
}
6 changes: 3 additions & 3 deletions pkg/controller/elasticsearch/elasticsearch_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,9 +184,9 @@ func (r *ReconcileElasticsearch) Reconcile(request reconcile.Request) (reconcile
return reconcile.Result{}, tracing.CaptureError(ctx, err)
}

if common.IsPaused(es.ObjectMeta) {
log.Info("Object is paused. Skipping reconciliation", "namespace", es.Namespace, "es_name", es.Name)
return common.PauseRequeue, nil
if common.IsUnmanaged(es.ObjectMeta) {
log.Info("Object is currently not managed by this controller. Skipping reconciliation", "namespace", es.Namespace, "es_name", es.Name)
return reconcile.Result{}, nil
}

selector := map[string]string{label.ClusterNameLabelName: es.Name}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,9 @@ func (r *ReconcileRemoteCa) Reconcile(request reconcile.Request) (reconcile.Resu
return reconcile.Result{}, err
}

if common.IsPaused(es.ObjectMeta) {
log.Info("Object is paused. Skipping reconciliation", "namespace", es.Namespace, "es_name", es.Name)
return common.PauseRequeue, nil
if common.IsUnmanaged(es.ObjectMeta) {
log.Info("Object is currently not managed by this controller. Skipping reconciliation", "namespace", es.Namespace, "es_name", es.Name)
return reconcile.Result{}, nil
}

return doReconcile(ctx, r, &es)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,9 @@ func (r *ReconcileEnterpriseSearch) Reconcile(request reconcile.Request) (reconc
return reconcile.Result{}, tracing.CaptureError(ctx, err)
}

if common.IsPaused(ents.ObjectMeta) {
log.Info("Object is paused. Skipping reconciliation", "namespace", ents.Namespace, "ents_name", ents.Name)
return common.PauseRequeue, nil
if common.IsUnmanaged(ents.ObjectMeta) {
log.Info("Object is currently not managed by this controller. Skipping reconciliation", "namespace", ents.Namespace, "ents_name", ents.Name)
return reconcile.Result{}, nil
}

if compatible, err := r.isCompatible(ctx, &ents); err != nil || !compatible {
Expand Down
6 changes: 3 additions & 3 deletions pkg/controller/entsearchassociation/association_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,9 @@ func (r *ReconcileEnterpriseSearchElasticsearchAssociation) Reconcile(request re
return reconcile.Result{}, tracing.CaptureError(ctx, err)
}

if common.IsPaused(entSearch.ObjectMeta) {
log.Info("Object is paused. Skipping reconciliation", "namespace", entSearch.Namespace, "ents_name", entSearch.Name)
return common.PauseRequeue, nil
if common.IsUnmanaged(entSearch.ObjectMeta) {
log.Info("Object is currently not managed by this controller. Skipping reconciliation", "namespace", entSearch.Namespace, "ents_name", entSearch.Name)
return reconcile.Result{}, nil
}

// EnterpriseSearch is being deleted, short-circuit reconciliation and remove artifacts related to the association.
Expand Down
7 changes: 3 additions & 4 deletions pkg/controller/kibana/kibana_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,10 +137,9 @@ func (r *ReconcileKibana) Reconcile(request reconcile.Request) (reconcile.Result
return reconcile.Result{}, tracing.CaptureError(ctx, err)
}

// skip reconciliation if paused
if common.IsPaused(kb.ObjectMeta) {
log.Info("Object is paused. Skipping reconciliation", "namespace", kb.Namespace, "kibana_name", kb.Name)
return common.PauseRequeue, nil
if common.IsUnmanaged(kb.ObjectMeta) {
log.Info("Object is currently not managed by this controller. Skipping reconciliation", "namespace", kb.Namespace, "kibana_name", kb.Name)
return reconcile.Result{}, nil
}

// check for compatibility with the operator version
Expand Down
6 changes: 3 additions & 3 deletions pkg/controller/kibanaassociation/association_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,9 @@ func (r *ReconcileAssociation) Reconcile(request reconcile.Request) (reconcile.R
return reconcile.Result{}, tracing.CaptureError(ctx, r.onDelete(kbName))
}

if common.IsPaused(kibana.ObjectMeta) {
log.Info("Object is paused. Skipping reconciliation", "namespace", kibana.Namespace, "kibana_name", kibana.Name)
return common.PauseRequeue, nil
if common.IsUnmanaged(kibana.ObjectMeta) {
log.Info("Object is currently not managed by this controller. Skipping reconciliation", "namespace", kibana.Namespace, "kibana_name", kibana.Name)
return reconcile.Result{}, nil
}

compatible, err := r.isCompatible(ctx, &kibana)
Expand Down
Loading