From 0823d992f39cd57f4d2960d434d11b174cd8ee29 Mon Sep 17 00:00:00 2001 From: Martin Schuppert Date: Mon, 11 Nov 2024 16:13:03 +0100 Subject: [PATCH] Use new nad.EnsureNetworksAnnotation() func to get NAD annotations For BGP setup there is the need to set the default gateway to the additional interface defined via the multus annotations. To allow this a user can configure `ipam.gateway` in the NAD. EnsureNetworksAnnotation() will override the pod network default route by reading the NAD. If `ipam.gateway` is defined and not "", it gets set on the networks annotation as the `default-route`. Jira: https://issues.redhat.com/browse/OSPRH-8680 Depends-On: https://github.com/openstack-k8s-operators/lib-common/pull/579 Signed-off-by: Martin Schuppert --- api/go.mod | 2 +- api/go.sum | 4 ++-- controllers/ovncontroller_controller.go | 9 +++++++-- controllers/ovndbcluster_controller.go | 10 ++++++++-- go.mod | 2 +- go.sum | 4 ++-- 6 files changed, 21 insertions(+), 10 deletions(-) diff --git a/api/go.mod b/api/go.mod index 1b21ad76..f5fd05f9 100644 --- a/api/go.mod +++ b/api/go.mod @@ -6,7 +6,7 @@ require ( github.com/go-logr/logr v1.4.2 github.com/google/uuid v1.6.0 github.com/onsi/gomega v1.34.1 - github.com/openstack-k8s-operators/lib-common/modules/common v0.5.1-0.20241104140916-71a0e9d9766d + github.com/openstack-k8s-operators/lib-common/modules/common v0.5.1-0.20241113144931-ff1fd2dcd04a k8s.io/api v0.29.10 k8s.io/apimachinery v0.29.10 sigs.k8s.io/controller-runtime v0.17.6 diff --git a/api/go.sum b/api/go.sum index 88ff23b9..325fcf0d 100644 --- a/api/go.sum +++ b/api/go.sum @@ -82,8 +82,8 @@ github.com/onsi/gomega v1.34.1 h1:EUMJIKUjM8sKjYbtxQI9A4z2o+rruxnzNvpknOXie6k= github.com/onsi/gomega v1.34.1/go.mod h1:kU1QgUvBDLXBJq618Xvm2LUX6rSAfRaFRTcdOeDLwwY= github.com/openshift/api v0.0.0-20240830023148-b7d0481c9094 h1:J1wuGhVxpsHykZBa6Beb1gQ96Ptej9AE/BvwCBiRj1E= github.com/openshift/api v0.0.0-20240830023148-b7d0481c9094/go.mod h1:CxgbWAlvu2iQB0UmKTtRu1YfepRg1/vJ64n2DlIEVz4= -github.com/openstack-k8s-operators/lib-common/modules/common v0.5.1-0.20241104140916-71a0e9d9766d h1:4rZOEft7IFZSzPx+QVuaRq1KEfM8MT+qBILnoa3Kf00= -github.com/openstack-k8s-operators/lib-common/modules/common v0.5.1-0.20241104140916-71a0e9d9766d/go.mod h1:YpNTuJhDWhbXM50O3qBkhO7M+OOyRmWkNVmJ4y3cyFs= +github.com/openstack-k8s-operators/lib-common/modules/common v0.5.1-0.20241113144931-ff1fd2dcd04a h1:izLb1IVe6pXuQ6Y49CIAkN7yS9qe2fDptRlhxMHSYv4= +github.com/openstack-k8s-operators/lib-common/modules/common v0.5.1-0.20241113144931-ff1fd2dcd04a/go.mod h1:YpNTuJhDWhbXM50O3qBkhO7M+OOyRmWkNVmJ4y3cyFs= github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= diff --git a/controllers/ovncontroller_controller.go b/controllers/ovncontroller_controller.go index 5c0a819a..caae0bd4 100644 --- a/controllers/ovncontroller_controller.go +++ b/controllers/ovncontroller_controller.go @@ -468,8 +468,9 @@ func (r *OVNControllerReconciler) reconcileNormal(ctx context.Context, instance } sort.Strings(networkAttachments) + nadList := []netattdefv1.NetworkAttachmentDefinition{} for _, netAtt := range networkAttachments { - _, err = nad.GetNADWithName(ctx, helper, netAtt, instance.Namespace) + nad, err := nad.GetNADWithName(ctx, helper, netAtt, instance.Namespace) if err != nil { if k8s_errors.IsNotFound(err) { Log.Info(fmt.Sprintf("network-attachment-definition %s not found", netAtt)) @@ -489,9 +490,13 @@ func (r *OVNControllerReconciler) reconcileNormal(ctx context.Context, instance err.Error())) return ctrl.Result{}, err } + + if nad != nil { + nadList = append(nadList, *nad) + } } - serviceAnnotations, err := nad.CreateNetworksAnnotation(instance.Namespace, networkAttachments) + serviceAnnotations, err := nad.EnsureNetworksAnnotation(nadList) if err != nil { return ctrl.Result{}, fmt.Errorf("failed to create network annotation from %s: %w", networkAttachments, err) diff --git a/controllers/ovndbcluster_controller.go b/controllers/ovndbcluster_controller.go index 4a21566a..24d0fc68 100644 --- a/controllers/ovndbcluster_controller.go +++ b/controllers/ovndbcluster_controller.go @@ -23,6 +23,7 @@ import ( "time" "github.com/go-logr/logr" + netattdefv1 "github.com/k8snetworkplumbingwg/network-attachment-definition-client/pkg/apis/k8s.cni.cncf.io/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/fields" "k8s.io/apimachinery/pkg/runtime" @@ -356,10 +357,11 @@ func (r *OVNDBClusterReconciler) reconcileNormal(ctx context.Context, instance * // network to attach to networkAttachments := []string{} + nadList := []netattdefv1.NetworkAttachmentDefinition{} if instance.Spec.NetworkAttachment != "" { networkAttachments = append(networkAttachments, instance.Spec.NetworkAttachment) - _, err := nad.GetNADWithName(ctx, helper, instance.Spec.NetworkAttachment, instance.Namespace) + nad, err := nad.GetNADWithName(ctx, helper, instance.Spec.NetworkAttachment, instance.Namespace) if err != nil { if k8s_errors.IsNotFound(err) { Log.Info(fmt.Sprintf("network-attachment-definition %s not found", instance.Spec.NetworkAttachment)) @@ -379,6 +381,10 @@ func (r *OVNDBClusterReconciler) reconcileNormal(ctx context.Context, instance * err.Error())) return ctrl.Result{}, err } + + if nad != nil { + nadList = append(nadList, *nad) + } } else if instance.Spec.DBType == ovnv1.SBDBType { // This config map was created by the SB and it only needs to be deleted once // since this reconcile loop can be done by the SB and the NB, filtering so only @@ -390,7 +396,7 @@ func (r *OVNDBClusterReconciler) reconcileNormal(ctx context.Context, instance * } } - serviceAnnotations, err := nad.CreateNetworksAnnotation(instance.Namespace, networkAttachments) + serviceAnnotations, err := nad.EnsureNetworksAnnotation(nadList) if err != nil { return ctrl.Result{}, fmt.Errorf("failed create network annotation from %s: %w", instance.Spec.NetworkAttachment, err) diff --git a/go.mod b/go.mod index 157f708d..cf62436d 100644 --- a/go.mod +++ b/go.mod @@ -9,7 +9,7 @@ require ( github.com/onsi/ginkgo/v2 v2.20.1 github.com/onsi/gomega v1.34.1 github.com/openstack-k8s-operators/infra-operator/apis v0.5.1-0.20241106062833-6ba8f6c612c7 - github.com/openstack-k8s-operators/lib-common/modules/common v0.5.1-0.20241104140916-71a0e9d9766d + github.com/openstack-k8s-operators/lib-common/modules/common v0.5.1-0.20241113144931-ff1fd2dcd04a github.com/openstack-k8s-operators/lib-common/modules/test v0.5.1-0.20241104140916-71a0e9d9766d github.com/openstack-k8s-operators/ovn-operator/api v0.0.0-20230418071801-b5843d9e05fb go.uber.org/zap v1.27.0 diff --git a/go.sum b/go.sum index b029b1ed..a7573981 100644 --- a/go.sum +++ b/go.sum @@ -78,8 +78,8 @@ github.com/openshift/api v0.0.0-20240830023148-b7d0481c9094 h1:J1wuGhVxpsHykZBa6 github.com/openshift/api v0.0.0-20240830023148-b7d0481c9094/go.mod h1:CxgbWAlvu2iQB0UmKTtRu1YfepRg1/vJ64n2DlIEVz4= github.com/openstack-k8s-operators/infra-operator/apis v0.5.1-0.20241106062833-6ba8f6c612c7 h1:2NCYi2y2n/JvpFcOCo3Lnwoy7zOl6WCMDKc82+0Acvw= github.com/openstack-k8s-operators/infra-operator/apis v0.5.1-0.20241106062833-6ba8f6c612c7/go.mod h1:1khEYHcLFRF0wBT7bFM7IHTmY7u3eTxwowOvNY/A3qo= -github.com/openstack-k8s-operators/lib-common/modules/common v0.5.1-0.20241104140916-71a0e9d9766d h1:4rZOEft7IFZSzPx+QVuaRq1KEfM8MT+qBILnoa3Kf00= -github.com/openstack-k8s-operators/lib-common/modules/common v0.5.1-0.20241104140916-71a0e9d9766d/go.mod h1:YpNTuJhDWhbXM50O3qBkhO7M+OOyRmWkNVmJ4y3cyFs= +github.com/openstack-k8s-operators/lib-common/modules/common v0.5.1-0.20241113144931-ff1fd2dcd04a h1:izLb1IVe6pXuQ6Y49CIAkN7yS9qe2fDptRlhxMHSYv4= +github.com/openstack-k8s-operators/lib-common/modules/common v0.5.1-0.20241113144931-ff1fd2dcd04a/go.mod h1:YpNTuJhDWhbXM50O3qBkhO7M+OOyRmWkNVmJ4y3cyFs= github.com/openstack-k8s-operators/lib-common/modules/test v0.5.1-0.20241104140916-71a0e9d9766d h1:6tQArLsL+R8dNAp0Ye+fdw1KHo2c8OQwqwG7pU2bTTw= github.com/openstack-k8s-operators/lib-common/modules/test v0.5.1-0.20241104140916-71a0e9d9766d/go.mod h1:LV0jo5etIsGyINpmB37i4oWR8zU6ApIuh7fsqGGA41o= github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=