Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automated backport of #2769: Improve calico CNI detection #2795

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 42 additions & 11 deletions pkg/discovery/network/calico.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,30 +23,27 @@ import (

"github.com/pkg/errors"
"github.com/submariner-io/submariner/pkg/cni"
v1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
controllerClient "sigs.k8s.io/controller-runtime/pkg/client"
)

//nolint:nilnil // Intentional as the purpose is to discover.
func discoverCalicoNetwork(ctx context.Context, client controllerClient.Client) (*ClusterNetwork, error) {
cmList := &corev1.ConfigMapList{}

err := client.List(ctx, cmList, controllerClient.InNamespace(metav1.NamespaceAll))
found, err := calicoConfigMapExists(ctx, client)
if err != nil {
return nil, errors.Wrapf(err, "error listing ConfigMaps")
return nil, err
}

findCalicoConfigMap := false

for i := range cmList.Items {
if cmList.Items[i].Name == "calico-config" {
findCalicoConfigMap = true
break
if !found {
found, err = calicoDaemonSetExists(ctx, client)
if err != nil {
return nil, err
}
}

if !findCalicoConfigMap {
if !found {
return nil, nil
}

Expand All @@ -62,3 +59,37 @@ func discoverCalicoNetwork(ctx context.Context, client controllerClient.Client)

return nil, nil
}

func calicoConfigMapExists(ctx context.Context, client controllerClient.Client) (bool, error) {
cmList := &corev1.ConfigMapList{}

err := client.List(ctx, cmList, controllerClient.InNamespace(metav1.NamespaceAll))
if err != nil {
return false, errors.Wrapf(err, "error listing ConfigMaps")
}

for i := range cmList.Items {
if cmList.Items[i].Name == "calico-config" {
return true, nil
}
}

return false, nil
}

func calicoDaemonSetExists(ctx context.Context, client controllerClient.Client) (bool, error) {
dsList := &v1.DaemonSetList{}

err := client.List(ctx, dsList, controllerClient.InNamespace(metav1.NamespaceAll))
if err != nil {
return false, errors.Wrapf(err, "error listing DaemonSets")
}

for i := range dsList.Items {
if dsList.Items[i].Name == "calico-node" {
return true, nil
}
}

return false, nil
}
Loading