forked from elastic/cloud-on-k8s
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Avoid updating the association status when no association (elastic#4986)
This fixes a bug where the association status of the Elasticsearch resource is updated by the EsMonitoring association controller when there is no association and therefore no changes to be made. The `oldStatus` and the `newStatus` appeared to be different because one was nil and the other was empty. The equality tests now supports this situation.
- Loading branch information
1 parent
c746726
commit 8cd5190
Showing
3 changed files
with
80 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
pkg/controller/association/controller/es_monitoring_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
// or more contributor license agreements. Licensed under the Elastic License 2.0; | ||
// you may not use this file except in compliance with the Elastic License 2.0. | ||
|
||
package controller | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"sigs.k8s.io/controller-runtime/pkg/reconcile" | ||
|
||
esv1 "github.com/elastic/cloud-on-k8s/pkg/apis/elasticsearch/v1" | ||
"github.com/elastic/cloud-on-k8s/pkg/controller/association" | ||
"github.com/elastic/cloud-on-k8s/pkg/controller/common/annotation" | ||
"github.com/elastic/cloud-on-k8s/pkg/utils/k8s" | ||
) | ||
|
||
var ( | ||
sampleES = esv1.Elasticsearch{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Namespace: "esns", | ||
Name: "esname", | ||
Annotations: map[string]string{ | ||
annotation.ControllerVersionAnnotation: "1.5.0", | ||
}, | ||
ResourceVersion: "42"}, | ||
Status: esv1.ElasticsearchStatus{Version: "7.15.0"}, | ||
} | ||
) | ||
|
||
// Test_EsMonitoringReconciler_NoAssociation tests that an Elasticsearch resource is not updated by the EsMonitoring | ||
// reconciler when there is no EsMonitoring association. Covers the bug https://github.com/elastic/cloud-on-k8s/issues/4985. | ||
func Test_EsMonitoringReconciler_NoAssociation(t *testing.T) { | ||
es := sampleES | ||
resourceVersion := es.ResourceVersion | ||
r := association.NewTestAssociationReconciler(esMonitoringAssociationInfo(), &es) | ||
_, err := r.Reconcile(context.Background(), reconcile.Request{NamespacedName: k8s.ExtractNamespacedName(&es)}) | ||
require.NoError(t, err) | ||
// should not update the Elasticsearch resource | ||
var updatedEs esv1.Elasticsearch | ||
err = r.Get(context.Background(), k8s.ExtractNamespacedName(&es), &updatedEs) | ||
require.NoError(t, err) | ||
// resource version should not have changed | ||
require.Equal(t, resourceVersion, updatedEs.ResourceVersion) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters