-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Prevent changes of DC name or both adding and removing a DC at the sa…
…me time. K8OP-263 (#1426) * Prevent changes of DC name or both adding and removing a DC at the same time.
- Loading branch information
1 parent
b34b80d
commit 7ddb755
Showing
7 changed files
with
136 additions
and
5 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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package k8ssandra | ||
|
||
import ( | ||
"fmt" | ||
|
||
api "github.com/k8ssandra/k8ssandra-operator/apis/k8ssandra/v1alpha1" | ||
"github.com/k8ssandra/k8ssandra-operator/pkg/utils" | ||
) | ||
|
||
func validateK8ssandraCluster(kc api.K8ssandraCluster) error { | ||
oldDCs := make([]string, 0) | ||
for dcName := range kc.Status.Datacenters { | ||
oldDCs = append(oldDCs, dcName) | ||
} | ||
newDcs := make([]string, 0) | ||
for _, dc := range kc.Spec.Cassandra.Datacenters { | ||
newDcs = append(newDcs, dc.Meta.Name) | ||
} | ||
wasAdded := false | ||
wasRemoved := false | ||
for _, dc := range kc.Spec.Cassandra.Datacenters { | ||
if !utils.SliceContains(oldDCs, dc.Meta.Name) { | ||
wasAdded = true | ||
break | ||
} | ||
} | ||
for dcName := range kc.Status.Datacenters { | ||
if !utils.SliceContains(newDcs, dcName) { | ||
wasRemoved = true | ||
break | ||
} | ||
} | ||
if wasAdded && wasRemoved { | ||
return fmt.Errorf("cannot add and remove datacenters at the same time") | ||
} | ||
return nil | ||
} |