core: clean up ApplyMultus()

In pkg/operator/k8sutil/network.go:ApplyMultus(), be more explicit about
the intended behavior in both var names, code comments, and unit tests.
Additionally fix a logic bug that could cause errors in the future if
more "cluster network apps" are identified in the future.

Signed-off-by: Blaine Gardner <blaine.gardner@redhat.com>
This commit is contained in:
Blaine Gardner committed 2021-06-23 11:50:39 -06:00
1 parent 077ed3f444
commit edb94fd349
1 file changed
+14 -5
+14 -5
View File
@@ -81,13 +81,22 @@ func ApplyMultus(net cephv1.NetworkSpec, objectMeta *metav1.ObjectMeta) error {
shortSyntax = true
}
var isExcluded bool
for _, clusterNetworkApps := range getClusterNetworkApps() {
isExcluded = strings.Contains(objectMeta.Labels["app"], clusterNetworkApps)
app, ok := objectMeta.Labels["app"]
if !ok {
app = "" // unknown app
}
if isExcluded {
isClusterNetApp := false
for _, clusterNetworkApp := range getClusterNetworkApps() {
if app == clusterNetworkApp {
isClusterNetApp = true
break
}
}
if isClusterNetApp {
// append all networks to apps that are cluster network apps
v = append(v, string(ns))
} else {
// only append public networks to apps that are not cluster network apps
if k == publicNetworkSelectorKeyName {
v = append(v, string(ns))
}
@@ -116,7 +125,7 @@ func ApplyMultus(net cephv1.NetworkSpec, objectMeta *metav1.ObjectMeta) error {
// getClusterNetworkApps returns the list of ceph apps that utilize cluster network
func getClusterNetworkApps() []string {
return []string{"osd"}
return []string{"rook-ceph-osd"}
}
// GetNetworkAttachmentConfig returns the NetworkAttachmentDefinitions configuration