From edb94fd3498bbf73d4d203e0302f1fe60d4bf73e Mon Sep 17 00:00:00 2001 From: Blaine Gardner Date: Mon, 21 Jun 2021 16:28:14 -0600 Subject: [PATCH] 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 --- pkg/operator/k8sutil/network.go | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/pkg/operator/k8sutil/network.go b/pkg/operator/k8sutil/network.go index 7c7c53ccd..a5b111f14 100644 --- a/pkg/operator/k8sutil/network.go +++ b/pkg/operator/k8sutil/network.go @@ -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