From b635cfca355a8abeba37c4c122aefde5041ab970 Mon Sep 17 00:00:00 2001 From: Martin Schuppert Date: Mon, 11 Nov 2024 15:43:20 +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/ironicapi_controller.go | 10 ++++++++-- controllers/ironicconductor_controller.go | 10 ++++++++-- controllers/ironicinspector_controller.go | 10 ++++++++-- go.mod | 2 ++ go.sum | 4 ++-- 7 files changed, 32 insertions(+), 10 deletions(-) diff --git a/api/go.mod b/api/go.mod index 8460ab19..ff214390 100644 --- a/api/go.mod +++ b/api/go.mod @@ -77,3 +77,5 @@ require ( // mschuppert: map to latest commit from release-4.13 tag // must consistent within modules and service operators replace github.com/openshift/api => github.com/openshift/api v0.0.0-20240830023148-b7d0481c9094 //allow-merging + +replace github.com/openstack-k8s-operators/lib-common/modules/common => github.com/stuggi/lib-common/modules/common v0.0.0-20241111135421-92a34fe4cb1c diff --git a/api/go.sum b/api/go.sum index 6142e971..18c0d4af 100644 --- a/api/go.sum +++ b/api/go.sum @@ -74,8 +74,6 @@ 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.20241029151503-4878b3fa3333 h1:yejekTWudX5af3mCJQ1MUPLEa0X6sIsklf07o9KilRk= -github.com/openstack-k8s-operators/lib-common/modules/common v0.5.1-0.20241029151503-4878b3fa3333/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= @@ -96,6 +94,8 @@ github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+ github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= +github.com/stuggi/lib-common/modules/common v0.0.0-20241111135421-92a34fe4cb1c h1:dC5OUlwOjXzI4EDuomP65sqP6B/h8KJN9P8DTZThB7w= +github.com/stuggi/lib-common/modules/common v0.0.0-20241111135421-92a34fe4cb1c/go.mod h1:YpNTuJhDWhbXM50O3qBkhO7M+OOyRmWkNVmJ4y3cyFs= github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= diff --git a/controllers/ironicapi_controller.go b/controllers/ironicapi_controller.go index e591158b..ff39a846 100644 --- a/controllers/ironicapi_controller.go +++ b/controllers/ironicapi_controller.go @@ -40,6 +40,7 @@ import ( "sigs.k8s.io/controller-runtime/pkg/predicate" "sigs.k8s.io/controller-runtime/pkg/reconcile" + networkv1 "github.com/k8snetworkplumbingwg/network-attachment-definition-client/pkg/apis/k8s.cni.cncf.io/v1" ironicv1 "github.com/openstack-k8s-operators/ironic-operator/api/v1beta1" ironic "github.com/openstack-k8s-operators/ironic-operator/pkg/ironic" ironicapi "github.com/openstack-k8s-operators/ironic-operator/pkg/ironicapi" @@ -786,8 +787,9 @@ func (r *IronicAPIReconciler) reconcileNormal(ctx context.Context, instance *iro } // 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)) @@ -807,9 +809,13 @@ func (r *IronicAPIReconciler) reconcileNormal(ctx context.Context, instance *iro 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 { return ctrl.Result{}, fmt.Errorf("failed create network annotation from %s: %w", instance.Spec.NetworkAttachments, err) diff --git a/controllers/ironicconductor_controller.go b/controllers/ironicconductor_controller.go index 846c43e5..5ef70677 100644 --- a/controllers/ironicconductor_controller.go +++ b/controllers/ironicconductor_controller.go @@ -26,6 +26,7 @@ import ( k8s_types "k8s.io/apimachinery/pkg/types" "github.com/go-logr/logr" + networkv1 "github.com/k8snetworkplumbingwg/network-attachment-definition-client/pkg/apis/k8s.cni.cncf.io/v1" routev1 "github.com/openshift/api/route/v1" appsv1 "k8s.io/api/apps/v1" corev1 "k8s.io/api/core/v1" @@ -625,8 +626,9 @@ func (r *IronicConductorReconciler) 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)) @@ -646,9 +648,13 @@ func (r *IronicConductorReconciler) 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 { return ctrl.Result{}, fmt.Errorf("failed create network annotation from %s: %w", instance.Spec.NetworkAttachments, err) diff --git a/controllers/ironicinspector_controller.go b/controllers/ironicinspector_controller.go index 5ed1b64d..84297200 100644 --- a/controllers/ironicinspector_controller.go +++ b/controllers/ironicinspector_controller.go @@ -22,6 +22,7 @@ import ( "time" "github.com/go-logr/logr" + networkv1 "github.com/k8snetworkplumbingwg/network-attachment-definition-client/pkg/apis/k8s.cni.cncf.io/v1" ironic "github.com/openstack-k8s-operators/ironic-operator/pkg/ironic" ironicinspector "github.com/openstack-k8s-operators/ironic-operator/pkg/ironicinspector" mariadbv1 "github.com/openstack-k8s-operators/mariadb-operator/api/v1beta1" @@ -762,8 +763,9 @@ func (r *IronicInspectorReconciler) reconcileNormal( // // 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)) @@ -783,9 +785,13 @@ func (r *IronicInspectorReconciler) reconcileNormal( 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 { return ctrl.Result{}, fmt.Errorf("failed create network annotation from %s: %w", instance.Spec.NetworkAttachments, err) diff --git a/go.mod b/go.mod index a3ab2410..e7be45df 100644 --- a/go.mod +++ b/go.mod @@ -90,3 +90,5 @@ replace github.com/openstack-k8s-operators/ironic-operator/api => ./api // mschuppert: map to latest commit from release-4.13 tag // must consistent within modules and service operators replace github.com/openshift/api => github.com/openshift/api v0.0.0-20240830023148-b7d0481c9094 //allow-merging + +replace github.com/openstack-k8s-operators/lib-common/modules/common => github.com/stuggi/lib-common/modules/common v0.0.0-20241111135421-92a34fe4cb1c diff --git a/go.sum b/go.sum index 44546914..0e05afaa 100644 --- a/go.sum +++ b/go.sum @@ -82,8 +82,6 @@ github.com/openstack-k8s-operators/infra-operator/apis v0.5.1-0.20241030094454-1 github.com/openstack-k8s-operators/infra-operator/apis v0.5.1-0.20241030094454-1ea50ac03c59/go.mod h1:1khEYHcLFRF0wBT7bFM7IHTmY7u3eTxwowOvNY/A3qo= github.com/openstack-k8s-operators/keystone-operator/api v0.5.1-0.20241030161253-ca1668251700 h1:J1wC1E2seCIedpwpnVbfjR70e99V4siHHKgs8SV7qjc= github.com/openstack-k8s-operators/keystone-operator/api v0.5.1-0.20241030161253-ca1668251700/go.mod h1:uJ1wM1Y0VlOUAxVoSyvko+tny3enIoTfc7srS8Lrzts= -github.com/openstack-k8s-operators/lib-common/modules/common v0.5.1-0.20241029151503-4878b3fa3333 h1:yejekTWudX5af3mCJQ1MUPLEa0X6sIsklf07o9KilRk= -github.com/openstack-k8s-operators/lib-common/modules/common v0.5.1-0.20241029151503-4878b3fa3333/go.mod h1:YpNTuJhDWhbXM50O3qBkhO7M+OOyRmWkNVmJ4y3cyFs= github.com/openstack-k8s-operators/lib-common/modules/openstack v0.5.1-0.20241029151503-4878b3fa3333 h1:XWxFOmOYPC6V5KUDkzU20vQOsha1PPNQzzqkNv926mg= github.com/openstack-k8s-operators/lib-common/modules/openstack v0.5.1-0.20241029151503-4878b3fa3333/go.mod h1:IASoGvp5QM/tBJUd/8i8uIjj4DBnI+64Ydh4r7pmnvA= github.com/openstack-k8s-operators/lib-common/modules/test v0.5.1-0.20241029151503-4878b3fa3333 h1:zUlxLqucrLMNDp6dc3I7eYWZyGVE7tLrPyWR/n+VD9w= @@ -110,6 +108,8 @@ github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+ github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= +github.com/stuggi/lib-common/modules/common v0.0.0-20241111135421-92a34fe4cb1c h1:dC5OUlwOjXzI4EDuomP65sqP6B/h8KJN9P8DTZThB7w= +github.com/stuggi/lib-common/modules/common v0.0.0-20241111135421-92a34fe4cb1c/go.mod h1:YpNTuJhDWhbXM50O3qBkhO7M+OOyRmWkNVmJ4y3cyFs= github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=