-
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.
- Loading branch information
1 parent
a98e2c9
commit a6adb65
Showing
5 changed files
with
90 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
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 := true | ||
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 | ||
} |