Skip to content

Commit

Permalink
Make exclusions not block in sub reconciler (#974)
Browse files Browse the repository at this point in the history
* Make exclusions not block in sub reconciler

* Fix test cases and make CanSafelyRemove in mock check state
  • Loading branch information
johscheuer committed Nov 17, 2021
1 parent eaacef7 commit 2ee69ec
Show file tree
Hide file tree
Showing 6 changed files with 331 additions and 41 deletions.
34 changes: 33 additions & 1 deletion controllers/admin_client_mock.go
Expand Up @@ -375,7 +375,39 @@ func (client *mockAdminClient) IncludeProcesses(addresses []fdbtypes.ProcessAddr
// The list returned by this method will be the addresses that are *not*
// safe to remove.
func (client *mockAdminClient) CanSafelyRemove(addresses []fdbtypes.ProcessAddress) ([]fdbtypes.ProcessAddress, error) {
return nil, nil
skipExclude := map[string]internal.None{}

// Check which process groups have the skip exclusion flag or are already
// excluded
for _, pg := range client.Cluster.Status.ProcessGroups {
if !(pg.ExclusionSkipped || pg.Excluded) {
continue
}

for _, addr := range pg.Addresses {
skipExclude[addr] = internal.None{}
}
}

// Add all process groups that are excluded in the client
for _, addr := range client.ExcludedAddresses {
skipExclude[addr] = internal.None{}
}

// Filter out all excluded process groups and also all process groups
// that skip exclusion
remaining := make([]fdbtypes.ProcessAddress, 0, len(addresses))

for _, addr := range addresses {
// Is already excluded or skipped
if _, ok := skipExclude[addr.String()]; ok {
continue
}

remaining = append(remaining, addr)
}

return remaining, nil
}

// GetExclusions gets a list of the addresses currently excluded from the
Expand Down
180 changes: 180 additions & 0 deletions controllers/admin_client_mock_test.go
@@ -0,0 +1,180 @@
/*
* admin_client_mock_test.go
*
* This source file is part of the FoundationDB open source project
*
* Copyright 2020-2021 Apple Inc. and the FoundationDB project authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package controllers

import (
"net"

. "github.com/onsi/ginkgo"
. "github.com/onsi/ginkgo/extensions/table"
. "github.com/onsi/gomega"

fdbtypes "github.com/FoundationDB/fdb-kubernetes-operator/api/v1beta1"
)

var _ = Describe("mock_client", func() {
When("checking if it's safe to delete a process group", func() {
type testCase struct {
cluster *fdbtypes.FoundationDBCluster
removals []fdbtypes.ProcessAddress
exclusions []fdbtypes.ProcessAddress
remaining []fdbtypes.ProcessAddress
}

DescribeTable("should return the correct image",
func(input testCase) {
admin, err := newMockAdminClient(input.cluster, nil)
Expect(err).NotTo(HaveOccurred())

err = admin.ExcludeProcesses(input.exclusions)
Expect(err).NotTo(HaveOccurred())

remaining, err := admin.CanSafelyRemove(input.removals)
Expect(err).NotTo(HaveOccurred())

Expect(remaining).To(ContainElements(input.remaining))
Expect(len(remaining)).To(Equal(len(input.remaining)))
},
Entry("Empty list of removals",
testCase{
cluster: &fdbtypes.FoundationDBCluster{},
removals: []fdbtypes.ProcessAddress{},
exclusions: []fdbtypes.ProcessAddress{},
remaining: []fdbtypes.ProcessAddress{},
}),
Entry("Process group that skips exclusion",
testCase{
cluster: &fdbtypes.FoundationDBCluster{
Status: fdbtypes.FoundationDBClusterStatus{
ProcessGroups: []*fdbtypes.ProcessGroupStatus{
{
Addresses: []string{
"1.1.1.1:4500",
},
ExclusionSkipped: true,
},
{
Addresses: []string{
"1.1.1.2:4500",
},
},
},
},
},
removals: []fdbtypes.ProcessAddress{
{
IPAddress: net.ParseIP("1.1.1.1"),
Port: 4500,
},
{
IPAddress: net.ParseIP("1.1.1.2"),
Port: 4500,
},
},
exclusions: []fdbtypes.ProcessAddress{},
remaining: []fdbtypes.ProcessAddress{
{
IPAddress: net.ParseIP("1.1.1.2"),
Port: 4500,
},
},
}),
Entry("Process group that is excluded by the client",
testCase{
cluster: &fdbtypes.FoundationDBCluster{
Status: fdbtypes.FoundationDBClusterStatus{
ProcessGroups: []*fdbtypes.ProcessGroupStatus{
{
Addresses: []string{
"1.1.1.1:4500",
},
},
{
Addresses: []string{
"1.1.1.2:4500",
},
},
},
},
},
removals: []fdbtypes.ProcessAddress{
{
IPAddress: net.ParseIP("1.1.1.1"),
Port: 4500,
},
{
IPAddress: net.ParseIP("1.1.1.2"),
Port: 4500,
},
},
exclusions: []fdbtypes.ProcessAddress{
{
IPAddress: net.ParseIP("1.1.1.1"),
Port: 4500,
},
},
remaining: []fdbtypes.ProcessAddress{
{
IPAddress: net.ParseIP("1.1.1.2"),
Port: 4500,
},
},
}),
Entry("Process group that is excluded in the cluster status",
testCase{
cluster: &fdbtypes.FoundationDBCluster{
Status: fdbtypes.FoundationDBClusterStatus{
ProcessGroups: []*fdbtypes.ProcessGroupStatus{
{
Addresses: []string{
"1.1.1.1:4500",
},
Excluded: true,
},
{
Addresses: []string{
"1.1.1.2:4500",
},
},
},
},
},
removals: []fdbtypes.ProcessAddress{
{
IPAddress: net.ParseIP("1.1.1.1"),
Port: 4500,
},
{
IPAddress: net.ParseIP("1.1.1.2"),
Port: 4500,
},
},
exclusions: []fdbtypes.ProcessAddress{},
remaining: []fdbtypes.ProcessAddress{
{
IPAddress: net.ParseIP("1.1.1.2"),
Port: 4500,
},
},
}),
)
})
})

0 comments on commit 2ee69ec

Please sign in to comment.