From 64c00415abbe370a2feb98d241c42f65792fef3a Mon Sep 17 00:00:00 2001 From: Martin Schuppert Date: Mon, 11 Nov 2024 15:20:23 +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/cinder_controller.go | 10 ++++++++-- controllers/cinderapi_controller.go | 10 ++++++++-- controllers/cinderbackup_controller.go | 10 ++++++++-- controllers/cinderscheduler_controller.go | 10 ++++++++-- controllers/cindervolume_controller.go | 10 ++++++++-- go.mod | 2 +- go.sum | 4 ++-- 9 files changed, 46 insertions(+), 16 deletions(-) diff --git a/api/go.mod b/api/go.mod index 44f00adf..fef2267c 100644 --- a/api/go.mod +++ b/api/go.mod @@ -3,7 +3,7 @@ module github.com/openstack-k8s-operators/cinder-operator/api go 1.21 require ( - 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/storage v0.5.1-0.20241104140916-71a0e9d9766d golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56 k8s.io/api v0.29.10 diff --git a/api/go.sum b/api/go.sum index 01b4a75d..69a00b52 100644 --- a/api/go.sum +++ b/api/go.sum @@ -73,8 +73,8 @@ github.com/onsi/ginkgo/v2 v2.20.1 h1:YlVIbqct+ZmnEph770q9Q7NVAz4wwIiVNahee6JyUzo github.com/onsi/ginkgo/v2 v2.20.1/go.mod h1:lG9ey2Z29hR41WMVthyJBGUBcBhGOtoPF2VFMvBXFCI= github.com/onsi/gomega v1.34.1 h1:EUMJIKUjM8sKjYbtxQI9A4z2o+rruxnzNvpknOXie6k= github.com/onsi/gomega v1.34.1/go.mod h1:kU1QgUvBDLXBJq618Xvm2LUX6rSAfRaFRTcdOeDLwwY= -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/storage v0.5.1-0.20241104140916-71a0e9d9766d h1:6fA7kvhKRelVwNWxcMVe2d2lkN8MITY0OIudTBnmT+A= github.com/openstack-k8s-operators/lib-common/modules/storage v0.5.1-0.20241104140916-71a0e9d9766d/go.mod h1:tfgBeLRqmlH/NQkLPe7396rj+t0whv2wPuMb8Ttvh8w= github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= diff --git a/controllers/cinder_controller.go b/controllers/cinder_controller.go index 119da0c6..2a18d4d4 100644 --- a/controllers/cinder_controller.go +++ b/controllers/cinder_controller.go @@ -33,6 +33,7 @@ import ( "sigs.k8s.io/controller-runtime/pkg/reconcile" "github.com/go-logr/logr" + networkv1 "github.com/k8snetworkplumbingwg/network-attachment-definition-client/pkg/apis/k8s.cni.cncf.io/v1" cinderv1beta1 "github.com/openstack-k8s-operators/cinder-operator/api/v1beta1" "github.com/openstack-k8s-operators/cinder-operator/pkg/cinder" memcachedv1 "github.com/openstack-k8s-operators/infra-operator/apis/memcached/v1beta1" @@ -617,8 +618,9 @@ func (r *CinderReconciler) reconcileNormal(ctx context.Context, instance *cinder // Check networks that the DBSync job will use in reconcileInit. The ones from the API service are always enough, // it doesn't need the storage specific ones that volume or backup may have. + nadList := []networkv1.NetworkAttachmentDefinition{} for _, netAtt := range instance.Spec.CinderAPI.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)) @@ -638,11 +640,15 @@ func (r *CinderReconciler) reconcileNormal(ctx context.Context, instance *cinder err.Error())) return ctrl.Result{}, err } + + if nad != nil { + nadList = append(nadList, *nad) + } } instance.Status.Conditions.MarkTrue(condition.NetworkAttachmentsReadyCondition, condition.NetworkAttachmentsReadyMessage) - serviceAnnotations, err := nad.CreateNetworksAnnotation(instance.Namespace, instance.Spec.CinderAPI.NetworkAttachments) + serviceAnnotations, err := nad.EnsureNetworksAnnotation(nadList) if err != nil { return ctrl.Result{}, fmt.Errorf("failed create network annotation from %s: %w", instance.Spec.CinderAPI.NetworkAttachments, err) diff --git a/controllers/cinderapi_controller.go b/controllers/cinderapi_controller.go index 47790f7d..7f19504a 100644 --- a/controllers/cinderapi_controller.go +++ b/controllers/cinderapi_controller.go @@ -38,6 +38,7 @@ import ( "sigs.k8s.io/controller-runtime/pkg/reconcile" "github.com/go-logr/logr" + networkv1 "github.com/k8snetworkplumbingwg/network-attachment-definition-client/pkg/apis/k8s.cni.cncf.io/v1" cinderv1beta1 "github.com/openstack-k8s-operators/cinder-operator/api/v1beta1" "github.com/openstack-k8s-operators/cinder-operator/pkg/cinder" cinderapi "github.com/openstack-k8s-operators/cinder-operator/pkg/cinderapi" @@ -778,8 +779,9 @@ func (r *CinderAPIReconciler) reconcileNormal(ctx context.Context, instance *cin // // networks to attach to + nadList := []networkv1.NetworkAttachmentDefinition{} for _, netAtt := range instance.Spec.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)) @@ -799,9 +801,13 @@ func (r *CinderAPIReconciler) reconcileNormal(ctx context.Context, instance *cin err.Error())) return ctrl.Result{}, err } + + if nad != nil { + nadList = append(nadList, *nad) + } } - serviceAnnotations, err := nad.CreateNetworksAnnotation(instance.Namespace, instance.Spec.NetworkAttachments) + serviceAnnotations, err := nad.EnsureNetworksAnnotation(nadList) if err != nil { err = fmt.Errorf("failed create network annotation from %s: %w", instance.Spec.NetworkAttachments, err) instance.Status.Conditions.MarkFalse( diff --git a/controllers/cinderbackup_controller.go b/controllers/cinderbackup_controller.go index 39f06a56..dbc6803f 100644 --- a/controllers/cinderbackup_controller.go +++ b/controllers/cinderbackup_controller.go @@ -37,6 +37,7 @@ import ( "sigs.k8s.io/controller-runtime/pkg/reconcile" "github.com/go-logr/logr" + networkv1 "github.com/k8snetworkplumbingwg/network-attachment-definition-client/pkg/apis/k8s.cni.cncf.io/v1" cinderv1beta1 "github.com/openstack-k8s-operators/cinder-operator/api/v1beta1" "github.com/openstack-k8s-operators/cinder-operator/pkg/cinder" cinderbackup "github.com/openstack-k8s-operators/cinder-operator/pkg/cinderbackup" @@ -469,8 +470,9 @@ func (r *CinderBackupReconciler) reconcileNormal(ctx context.Context, instance * // // networks to attach to + nadList := []networkv1.NetworkAttachmentDefinition{} for _, netAtt := range instance.Spec.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)) @@ -490,9 +492,13 @@ func (r *CinderBackupReconciler) reconcileNormal(ctx context.Context, instance * err.Error())) return ctrl.Result{}, err } + + if nad != nil { + nadList = append(nadList, *nad) + } } - serviceAnnotations, err := nad.CreateNetworksAnnotation(instance.Namespace, instance.Spec.NetworkAttachments) + serviceAnnotations, err := nad.EnsureNetworksAnnotation(nadList) if err != nil { err = fmt.Errorf("failed create network annotation from %s: %w", instance.Spec.NetworkAttachments, err) instance.Status.Conditions.MarkFalse( diff --git a/controllers/cinderscheduler_controller.go b/controllers/cinderscheduler_controller.go index fbac5a06..31c6b013 100644 --- a/controllers/cinderscheduler_controller.go +++ b/controllers/cinderscheduler_controller.go @@ -37,6 +37,7 @@ import ( "sigs.k8s.io/controller-runtime/pkg/reconcile" "github.com/go-logr/logr" + networkv1 "github.com/k8snetworkplumbingwg/network-attachment-definition-client/pkg/apis/k8s.cni.cncf.io/v1" cinderv1beta1 "github.com/openstack-k8s-operators/cinder-operator/api/v1beta1" "github.com/openstack-k8s-operators/cinder-operator/pkg/cinder" cinderscheduler "github.com/openstack-k8s-operators/cinder-operator/pkg/cinderscheduler" @@ -468,8 +469,9 @@ func (r *CinderSchedulerReconciler) reconcileNormal(ctx context.Context, instanc // // networks to attach to + nadList := []networkv1.NetworkAttachmentDefinition{} for _, netAtt := range instance.Spec.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 +491,13 @@ func (r *CinderSchedulerReconciler) reconcileNormal(ctx context.Context, instanc err.Error())) return ctrl.Result{}, err } + + if nad != nil { + nadList = append(nadList, *nad) + } } - serviceAnnotations, err := nad.CreateNetworksAnnotation(instance.Namespace, instance.Spec.NetworkAttachments) + serviceAnnotations, err := nad.EnsureNetworksAnnotation(nadList) if err != nil { err = fmt.Errorf("failed create network annotation from %s: %w", instance.Spec.NetworkAttachments, err) instance.Status.Conditions.MarkFalse( diff --git a/controllers/cindervolume_controller.go b/controllers/cindervolume_controller.go index f00deedf..95145f06 100644 --- a/controllers/cindervolume_controller.go +++ b/controllers/cindervolume_controller.go @@ -38,6 +38,7 @@ import ( "sigs.k8s.io/controller-runtime/pkg/reconcile" "github.com/go-logr/logr" + networkv1 "github.com/k8snetworkplumbingwg/network-attachment-definition-client/pkg/apis/k8s.cni.cncf.io/v1" cinderv1beta1 "github.com/openstack-k8s-operators/cinder-operator/api/v1beta1" "github.com/openstack-k8s-operators/cinder-operator/pkg/cinder" "github.com/openstack-k8s-operators/cinder-operator/pkg/cindervolume" @@ -471,8 +472,9 @@ func (r *CinderVolumeReconciler) reconcileNormal(ctx context.Context, instance * // // networks to attach to + nadList := []networkv1.NetworkAttachmentDefinition{} for _, netAtt := range instance.Spec.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)) @@ -492,9 +494,13 @@ func (r *CinderVolumeReconciler) reconcileNormal(ctx context.Context, instance * err.Error())) return ctrl.Result{}, err } + + if nad != nil { + nadList = append(nadList, *nad) + } } - serviceAnnotations, err := nad.CreateNetworksAnnotation(instance.Namespace, instance.Spec.NetworkAttachments) + serviceAnnotations, err := nad.EnsureNetworksAnnotation(nadList) if err != nil { err = fmt.Errorf("failed create network annotation from %s: %w", instance.Spec.NetworkAttachments, err) instance.Status.Conditions.MarkFalse( diff --git a/go.mod b/go.mod index 7525d13d..77d77654 100644 --- a/go.mod +++ b/go.mod @@ -10,7 +10,7 @@ require ( 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/keystone-operator/api v0.5.1-0.20241106094500-2e94eb1e34a5 - 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/storage v0.5.1-0.20241104140916-71a0e9d9766d github.com/openstack-k8s-operators/lib-common/modules/test v0.5.1-0.20241104140916-71a0e9d9766d github.com/openstack-k8s-operators/mariadb-operator/api v0.5.1-0.20241106141725-340c4d78fef0 diff --git a/go.sum b/go.sum index c959b744..3a13e49e 100644 --- a/go.sum +++ b/go.sum @@ -82,8 +82,8 @@ github.com/openstack-k8s-operators/infra-operator/apis v0.5.1-0.20241106062833-6 github.com/openstack-k8s-operators/infra-operator/apis v0.5.1-0.20241106062833-6ba8f6c612c7/go.mod h1:1khEYHcLFRF0wBT7bFM7IHTmY7u3eTxwowOvNY/A3qo= github.com/openstack-k8s-operators/keystone-operator/api v0.5.1-0.20241106094500-2e94eb1e34a5 h1:KejIMvM/Mwb9/L3nRfCp9Zb9gZhnko3SJT4qnLEOsFI= github.com/openstack-k8s-operators/keystone-operator/api v0.5.1-0.20241106094500-2e94eb1e34a5/go.mod h1:3ZVAfShONGUZDenwtq8CHTf3p2CxcH1fN7J7Ff/ZSiQ= -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/openstack v0.5.1-0.20241104140916-71a0e9d9766d h1:Li5NFO947jH8Oe9jZVAhHYWqDaGjBBMx2n8QIIw22GI= github.com/openstack-k8s-operators/lib-common/modules/openstack v0.5.1-0.20241104140916-71a0e9d9766d/go.mod h1:IASoGvp5QM/tBJUd/8i8uIjj4DBnI+64Ydh4r7pmnvA= github.com/openstack-k8s-operators/lib-common/modules/storage v0.5.1-0.20241104140916-71a0e9d9766d h1:6fA7kvhKRelVwNWxcMVe2d2lkN8MITY0OIudTBnmT+A=