-
Notifications
You must be signed in to change notification settings - Fork 719
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
542 additions
and
61 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// 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 driver | ||
|
||
import ( | ||
"github.com/elastic/cloud-on-k8s/pkg/controller/elasticsearch/sset" | ||
) | ||
|
||
func (d *defaultDriver) expectationsMet(actualStatefulSets sset.StatefulSetList) (bool, error) { | ||
if !d.Expectations.GenerationExpected(actualStatefulSets.ObjectMetas()...) { | ||
// Our cache of StatefulSets is out of date compared to previous reconciliation operations. | ||
// Continuing with the reconciliation at this point may lead to: | ||
// - errors on rejected sset updates (conflict since cached resource out of date): that's ok | ||
// - calling ES orchestration settings (zen1/zen2/allocation excludes) with wrong assumptions: that's not ok | ||
// Hence we choose to abort the reconciliation early: will run again later with an updated cache. | ||
log.V(1).Info("StatefulSet cache out-of-date, re-queueing", "namespace", d.ES.Namespace, "es_name", d.ES.Name) | ||
return false, nil | ||
} | ||
|
||
podsReconciled, err := actualStatefulSets.PodReconciliationDone(d.Client) | ||
if err != nil { | ||
return false, err | ||
} | ||
if !podsReconciled { | ||
// Pods we have in the cache do not match StatefulSets we have in the cache. | ||
// This can happen if some pods have been scheduled for creation/deletion/upgrade | ||
// but the operation has not happened or been observed yet. | ||
// Continuing with nodes reconciliation at this point would be dangerous, since | ||
// we may update ES orchestration settings (zen1/zen2/allocation excludes) with | ||
// wrong assumptions (especially on master-eligible and ES version mismatches). | ||
return false, nil | ||
} | ||
return true, nil | ||
} |
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,61 @@ | ||
// 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 driver | ||
|
||
import ( | ||
"testing" | ||
|
||
"sigs.k8s.io/controller-runtime/pkg/client/fake" | ||
|
||
"github.com/elastic/cloud-on-k8s/pkg/controller/common" | ||
"github.com/elastic/cloud-on-k8s/pkg/controller/common/reconciler" | ||
"github.com/elastic/cloud-on-k8s/pkg/controller/elasticsearch/sset" | ||
"github.com/elastic/cloud-on-k8s/pkg/utils/k8s" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func Test_defaultDriver_expectationsMet(t *testing.T) { | ||
d := &defaultDriver{DefaultDriverParameters{ | ||
Expectations: reconciler.NewExpectations(), | ||
Client: k8s.WrapClient(fake.NewFakeClient()), | ||
}} | ||
|
||
// no expectations set | ||
met, err := d.expectationsMet(sset.StatefulSetList{}) | ||
require.NoError(t, err) | ||
require.True(t, met) | ||
|
||
// a sset generation is expected | ||
statefulSet := sset.TestSset{Name: "sset"}.Build() | ||
statefulSet.Generation = 123 | ||
d.Expectations.ExpectGeneration(statefulSet.ObjectMeta) | ||
// but not met yet | ||
statefulSet.Generation = 122 | ||
met, err = d.expectationsMet(sset.StatefulSetList{statefulSet}) | ||
require.NoError(t, err) | ||
require.False(t, met) | ||
// met now | ||
statefulSet.Generation = 123 | ||
met, err = d.expectationsMet(sset.StatefulSetList{statefulSet}) | ||
require.NoError(t, err) | ||
require.True(t, met) | ||
|
||
// we expect some sset replicas to exist | ||
// but corresponding pod does not exist | ||
statefulSet.Spec.Replicas = common.Int32(1) | ||
// expectations should not be met: we miss a pod | ||
met, err = d.expectationsMet(sset.StatefulSetList{statefulSet}) | ||
require.NoError(t, err) | ||
require.False(t, met) | ||
|
||
// add the missing pod | ||
pod := sset.TestPod{Name: "sset-0", StatefulSetName: statefulSet.Name}.Build() | ||
d.Client = k8s.WrapClient(fake.NewFakeClient(&pod)) | ||
// expectations should be met | ||
met, err = d.expectationsMet(sset.StatefulSetList{statefulSet}) | ||
require.NoError(t, err) | ||
require.True(t, met) | ||
} |
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
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
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
Oops, something went wrong.