Skip to content

Commit 80ae2db

Browse files
committed
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: openstack-k8s-operators/lib-common#579 Signed-off-by: Martin Schuppert <[email protected]>
1 parent 336a127 commit 80ae2db

File tree

8 files changed

+38
-15
lines changed

8 files changed

+38
-15
lines changed

api/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ go 1.21
55
require (
66
github.com/onsi/ginkgo/v2 v2.20.1
77
github.com/onsi/gomega v1.34.1
8-
github.com/openstack-k8s-operators/lib-common/modules/common v0.5.1-0.20241029151503-4878b3fa3333
8+
github.com/openstack-k8s-operators/lib-common/modules/common v0.5.1-0.20241113144931-ff1fd2dcd04a
99
k8s.io/api v0.29.10
1010
k8s.io/apimachinery v0.29.10
1111
k8s.io/client-go v0.29.10

api/go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@ github.com/onsi/ginkgo/v2 v2.20.1 h1:YlVIbqct+ZmnEph770q9Q7NVAz4wwIiVNahee6JyUzo
7171
github.com/onsi/ginkgo/v2 v2.20.1/go.mod h1:lG9ey2Z29hR41WMVthyJBGUBcBhGOtoPF2VFMvBXFCI=
7272
github.com/onsi/gomega v1.34.1 h1:EUMJIKUjM8sKjYbtxQI9A4z2o+rruxnzNvpknOXie6k=
7373
github.com/onsi/gomega v1.34.1/go.mod h1:kU1QgUvBDLXBJq618Xvm2LUX6rSAfRaFRTcdOeDLwwY=
74-
github.com/openstack-k8s-operators/lib-common/modules/common v0.5.1-0.20241029151503-4878b3fa3333 h1:yejekTWudX5af3mCJQ1MUPLEa0X6sIsklf07o9KilRk=
75-
github.com/openstack-k8s-operators/lib-common/modules/common v0.5.1-0.20241029151503-4878b3fa3333/go.mod h1:YpNTuJhDWhbXM50O3qBkhO7M+OOyRmWkNVmJ4y3cyFs=
74+
github.com/openstack-k8s-operators/lib-common/modules/common v0.5.1-0.20241113144931-ff1fd2dcd04a h1:izLb1IVe6pXuQ6Y49CIAkN7yS9qe2fDptRlhxMHSYv4=
75+
github.com/openstack-k8s-operators/lib-common/modules/common v0.5.1-0.20241113144931-ff1fd2dcd04a/go.mod h1:YpNTuJhDWhbXM50O3qBkhO7M+OOyRmWkNVmJ4y3cyFs=
7676
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
7777
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
7878
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=

controllers/barbican_controller.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import (
3030
"sigs.k8s.io/controller-runtime/pkg/log"
3131

3232
"github.com/go-logr/logr"
33+
networkv1 "github.com/k8snetworkplumbingwg/network-attachment-definition-client/pkg/apis/k8s.cni.cncf.io/v1"
3334
barbicanv1beta1 "github.com/openstack-k8s-operators/barbican-operator/api/v1beta1"
3435
"github.com/openstack-k8s-operators/barbican-operator/pkg/barbican"
3536
rabbitmqv1 "github.com/openstack-k8s-operators/infra-operator/apis/rabbitmq/v1beta1"
@@ -315,8 +316,9 @@ func (r *BarbicanReconciler) reconcileNormal(ctx context.Context, instance *barb
315316
instance.Status.Conditions.MarkTrue(condition.ServiceConfigReadyCondition, condition.ServiceConfigReadyMessage)
316317

317318
// networks to attach to
319+
nadList := []networkv1.NetworkAttachmentDefinition{}
318320
for _, netAtt := range instance.Spec.BarbicanAPI.NetworkAttachments {
319-
_, err := nad.GetNADWithName(ctx, helper, netAtt, instance.Namespace)
321+
nad, err := nad.GetNADWithName(ctx, helper, netAtt, instance.Namespace)
320322
if err != nil {
321323
if k8s_errors.IsNotFound(err) {
322324
Log.Info(fmt.Sprintf("network-attachment-definition %s not found", netAtt))
@@ -336,10 +338,14 @@ func (r *BarbicanReconciler) reconcileNormal(ctx context.Context, instance *barb
336338
err.Error()))
337339
return ctrl.Result{}, err
338340
}
341+
342+
if nad != nil {
343+
nadList = append(nadList, *nad)
344+
}
339345
}
340346

341347
// TODO: _ should be serviceAnnotations
342-
serviceAnnotations, err := nad.CreateNetworksAnnotation(instance.Namespace, instance.Spec.BarbicanAPI.NetworkAttachments)
348+
serviceAnnotations, err := nad.EnsureNetworksAnnotation(nadList)
343349
if err != nil {
344350
return ctrl.Result{}, fmt.Errorf("failed create network annotation from %s: %w",
345351
instance.Spec.BarbicanAPI.NetworkAttachments, err)

controllers/barbicanapi_controller.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"time"
2323

2424
"github.com/go-logr/logr"
25+
networkv1 "github.com/k8snetworkplumbingwg/network-attachment-definition-client/pkg/apis/k8s.cni.cncf.io/v1"
2526
barbicanv1beta1 "github.com/openstack-k8s-operators/barbican-operator/api/v1beta1"
2627
"github.com/openstack-k8s-operators/barbican-operator/pkg/barbican"
2728
"github.com/openstack-k8s-operators/barbican-operator/pkg/barbicanapi"
@@ -682,8 +683,9 @@ func (r *BarbicanAPIReconciler) reconcileNormal(ctx context.Context, instance *b
682683

683684
Log.Info(fmt.Sprintf("[API] Getting networks '%s'", instance.Name))
684685
// networks to attach to
686+
nadList := []networkv1.NetworkAttachmentDefinition{}
685687
for _, netAtt := range instance.Spec.NetworkAttachments {
686-
_, err := nad.GetNADWithName(ctx, helper, netAtt, instance.Namespace)
688+
nad, err := nad.GetNADWithName(ctx, helper, netAtt, instance.Namespace)
687689
if err != nil {
688690
if k8s_errors.IsNotFound(err) {
689691
Log.Info(fmt.Sprintf("network-attachment-definition %s not found", netAtt))
@@ -703,10 +705,14 @@ func (r *BarbicanAPIReconciler) reconcileNormal(ctx context.Context, instance *b
703705
err.Error()))
704706
return ctrl.Result{}, err
705707
}
708+
709+
if nad != nil {
710+
nadList = append(nadList, *nad)
711+
}
706712
}
707713

708714
Log.Info(fmt.Sprintf("[API] Getting service annotations '%s'", instance.Name))
709-
serviceAnnotations, err := nad.CreateNetworksAnnotation(instance.Namespace, instance.Spec.NetworkAttachments)
715+
serviceAnnotations, err := nad.EnsureNetworksAnnotation(nadList)
710716
if err != nil {
711717
return ctrl.Result{}, fmt.Errorf("failed create network annotation from %s: %w",
712718
instance.Spec.NetworkAttachments, err)

controllers/barbicankeystonelistener_controller.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import (
2222
"time"
2323

2424
"github.com/go-logr/logr"
25-
// routev1 "github.com/openshift/api/route/v1"
25+
networkv1 "github.com/k8snetworkplumbingwg/network-attachment-definition-client/pkg/apis/k8s.cni.cncf.io/v1"
2626
barbicanv1beta1 "github.com/openstack-k8s-operators/barbican-operator/api/v1beta1"
2727
"github.com/openstack-k8s-operators/barbican-operator/pkg/barbican"
2828
"github.com/openstack-k8s-operators/barbican-operator/pkg/barbicankeystonelistener"
@@ -478,8 +478,9 @@ func (r *BarbicanKeystoneListenerReconciler) reconcileNormal(ctx context.Context
478478

479479
Log.Info(fmt.Sprintf("[KeystoneListener] Getting networks '%s'", instance.Name))
480480
// networks to attach to
481+
nadList := []networkv1.NetworkAttachmentDefinition{}
481482
for _, netAtt := range instance.Spec.NetworkAttachments {
482-
_, err := nad.GetNADWithName(ctx, helper, netAtt, instance.Namespace)
483+
nad, err := nad.GetNADWithName(ctx, helper, netAtt, instance.Namespace)
483484
if err != nil {
484485
if k8s_errors.IsNotFound(err) {
485486
Log.Info(fmt.Sprintf("network-attachment-definition %s not found", netAtt))
@@ -499,10 +500,14 @@ func (r *BarbicanKeystoneListenerReconciler) reconcileNormal(ctx context.Context
499500
err.Error()))
500501
return ctrl.Result{}, err
501502
}
503+
504+
if nad != nil {
505+
nadList = append(nadList, *nad)
506+
}
502507
}
503508

504509
Log.Info(fmt.Sprintf("[KeystoneListener] Getting service annotations '%s'", instance.Name))
505-
serviceAnnotations, err := nad.CreateNetworksAnnotation(instance.Namespace, instance.Spec.NetworkAttachments)
510+
serviceAnnotations, err := nad.EnsureNetworksAnnotation(nadList)
506511
if err != nil {
507512
return ctrl.Result{}, fmt.Errorf("failed create network annotation from %s: %w",
508513
instance.Spec.NetworkAttachments, err)

controllers/barbicanworker_controller.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"time"
2323

2424
"github.com/go-logr/logr"
25+
networkv1 "github.com/k8snetworkplumbingwg/network-attachment-definition-client/pkg/apis/k8s.cni.cncf.io/v1"
2526
barbicanv1beta1 "github.com/openstack-k8s-operators/barbican-operator/api/v1beta1"
2627
"github.com/openstack-k8s-operators/barbican-operator/pkg/barbican"
2728
"github.com/openstack-k8s-operators/barbican-operator/pkg/barbicanworker"
@@ -440,8 +441,9 @@ func (r *BarbicanWorkerReconciler) reconcileNormal(ctx context.Context, instance
440441

441442
Log.Info(fmt.Sprintf("[Worker] Getting networks '%s'", instance.Name))
442443
// networks to attach to
444+
nadList := []networkv1.NetworkAttachmentDefinition{}
443445
for _, netAtt := range instance.Spec.NetworkAttachments {
444-
_, err := nad.GetNADWithName(ctx, helper, netAtt, instance.Namespace)
446+
nad, err := nad.GetNADWithName(ctx, helper, netAtt, instance.Namespace)
445447
if err != nil {
446448
if k8s_errors.IsNotFound(err) {
447449
Log.Info(fmt.Sprintf("network-attachment-definition %s not found", netAtt))
@@ -461,10 +463,14 @@ func (r *BarbicanWorkerReconciler) reconcileNormal(ctx context.Context, instance
461463
err.Error()))
462464
return ctrl.Result{}, err
463465
}
466+
467+
if nad != nil {
468+
nadList = append(nadList, *nad)
469+
}
464470
}
465471

466472
Log.Info(fmt.Sprintf("[Worker] Getting service annotations '%s'", instance.Name))
467-
serviceAnnotations, err := nad.CreateNetworksAnnotation(instance.Namespace, instance.Spec.NetworkAttachments)
473+
serviceAnnotations, err := nad.EnsureNetworksAnnotation(nadList)
468474
if err != nil {
469475
return ctrl.Result{}, fmt.Errorf("failed create network annotation from %s: %w",
470476
instance.Spec.NetworkAttachments, err)

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ require (
1111
github.com/openstack-k8s-operators/barbican-operator/api v0.0.0-00010101000000-000000000000
1212
github.com/openstack-k8s-operators/infra-operator/apis v0.5.1-0.20241024081600-3e23dc62002c
1313
github.com/openstack-k8s-operators/keystone-operator/api v0.5.1-0.20241023160107-bd8e671350e1
14-
github.com/openstack-k8s-operators/lib-common/modules/common v0.5.1-0.20241029151503-4878b3fa3333
14+
github.com/openstack-k8s-operators/lib-common/modules/common v0.5.1-0.20241113144931-ff1fd2dcd04a
1515
github.com/openstack-k8s-operators/lib-common/modules/storage v0.5.1-0.20241025164019-30baa23bf6f1
1616
github.com/openstack-k8s-operators/lib-common/modules/test v0.5.1-0.20241025164019-30baa23bf6f1
1717
github.com/openstack-k8s-operators/mariadb-operator/api v0.5.0

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,8 @@ github.com/openstack-k8s-operators/infra-operator/apis v0.5.1-0.20241024081600-3
8181
github.com/openstack-k8s-operators/infra-operator/apis v0.5.1-0.20241024081600-3e23dc62002c/go.mod h1:J9oUh3eGBvAFfyUMiPxPRBSxAcO8rnwITN4RTh/It+8=
8282
github.com/openstack-k8s-operators/keystone-operator/api v0.5.1-0.20241023160107-bd8e671350e1 h1:he0/o7mLKhXa16QlwajRHtAOjot84Emvgl4jdl3esgU=
8383
github.com/openstack-k8s-operators/keystone-operator/api v0.5.1-0.20241023160107-bd8e671350e1/go.mod h1:saoorrsPo3DzDPGM6PJ8sQJBNuNRGCHjRHChRQmkoQ0=
84-
github.com/openstack-k8s-operators/lib-common/modules/common v0.5.1-0.20241029151503-4878b3fa3333 h1:yejekTWudX5af3mCJQ1MUPLEa0X6sIsklf07o9KilRk=
85-
github.com/openstack-k8s-operators/lib-common/modules/common v0.5.1-0.20241029151503-4878b3fa3333/go.mod h1:YpNTuJhDWhbXM50O3qBkhO7M+OOyRmWkNVmJ4y3cyFs=
84+
github.com/openstack-k8s-operators/lib-common/modules/common v0.5.1-0.20241113144931-ff1fd2dcd04a h1:izLb1IVe6pXuQ6Y49CIAkN7yS9qe2fDptRlhxMHSYv4=
85+
github.com/openstack-k8s-operators/lib-common/modules/common v0.5.1-0.20241113144931-ff1fd2dcd04a/go.mod h1:YpNTuJhDWhbXM50O3qBkhO7M+OOyRmWkNVmJ4y3cyFs=
8686
github.com/openstack-k8s-operators/lib-common/modules/openstack v0.5.1-0.20241025164019-30baa23bf6f1 h1:k5aZEt+xNGZXvEYs02FC2nL0I6QLgsWOsDOGwgiQh2E=
8787
github.com/openstack-k8s-operators/lib-common/modules/openstack v0.5.1-0.20241025164019-30baa23bf6f1/go.mod h1:djfljx3jfHqywhY3oDvPg/GLKwiFVkds6v7P7/Yg+8g=
8888
github.com/openstack-k8s-operators/lib-common/modules/storage v0.5.1-0.20241025164019-30baa23bf6f1 h1:3ga7BSlbuXypDeuV6mpG1AvgxWLeYTKYzCb9J/UyU5c=

0 commit comments

Comments
 (0)