From f1c73fa1535fcfa00b8d195cf8135ecdf875f924 Mon Sep 17 00:00:00 2001 From: Martin Schuppert Date: Mon, 11 Nov 2024 15:29:00 +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/designate_controller.go | 10 ++++++++-- controllers/designateapi_controller.go | 9 +++++++-- controllers/designatebackendbind9_controller.go | 10 ++++++++-- controllers/designatecentral_controller.go | 10 ++++++++-- controllers/designatemdns_controller.go | 10 ++++++++-- controllers/designateproducer_controller.go | 10 ++++++++-- controllers/designateunbound_controller.go | 10 ++++++++-- controllers/designateworker_controller.go | 10 ++++++++-- go.mod | 2 +- go.sum | 4 ++-- 12 files changed, 69 insertions(+), 22 deletions(-) diff --git a/api/go.mod b/api/go.mod index e2c5656b..ce8e6514 100644 --- a/api/go.mod +++ b/api/go.mod @@ -4,7 +4,7 @@ go 1.21 require ( github.com/onsi/ginkgo/v2 v2.20.1 - github.com/openstack-k8s-operators/lib-common/modules/common v0.5.1-0.20241029151503-4878b3fa3333 + 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.4.1-0.20241014140317-e5c35d28f3af k8s.io/api v0.29.10 k8s.io/apimachinery v0.29.10 diff --git a/api/go.sum b/api/go.sum index 0d8670e0..25097336 100644 --- a/api/go.sum +++ b/api/go.sum @@ -71,8 +71,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.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/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.4.1-0.20241014140317-e5c35d28f3af h1:l8GXJhv4P/fy7Amz9XPEi8sn+hvxrQf1gICpmOaqOuE= github.com/openstack-k8s-operators/lib-common/modules/storage v0.4.1-0.20241014140317-e5c35d28f3af/go.mod h1:cGynoLGY9NfyIeWXI3zZ+hgZdHF3SUi8ht5ygZ8CmhI= github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= diff --git a/controllers/designate_controller.go b/controllers/designate_controller.go index 0df6d0d6..b342fde2 100644 --- a/controllers/designate_controller.go +++ b/controllers/designate_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" designatev1beta1 "github.com/openstack-k8s-operators/designate-operator/api/v1beta1" "github.com/openstack-k8s-operators/designate-operator/pkg/designate" rabbitmqv1 "github.com/openstack-k8s-operators/infra-operator/apis/rabbitmq/v1beta1" @@ -603,8 +604,9 @@ func (r *DesignateReconciler) reconcileNormal(ctx context.Context, instance *des // Note: Dkehn - this will remain in the code base until determination of DNS server connections are determined. // networks to attach to + nadList := []networkv1.NetworkAttachmentDefinition{} for _, netAtt := range instance.Spec.DesignateAPI.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)) @@ -624,9 +626,13 @@ func (r *DesignateReconciler) reconcileNormal(ctx context.Context, instance *des err.Error())) return ctrl.Result{}, err } + + if nad != nil { + nadList = append(nadList, *nad) + } } - serviceAnnotations, err := nad.CreateNetworksAnnotation(instance.Namespace, instance.Spec.DesignateAPI.NetworkAttachments) + serviceAnnotations, err := nad.EnsureNetworksAnnotation(nadList) if err != nil { return ctrl.Result{}, fmt.Errorf("failed create network annotation from %s: %w", instance.Spec.DesignateAPI.NetworkAttachments, err) diff --git a/controllers/designateapi_controller.go b/controllers/designateapi_controller.go index e1681950..0339f53e 100644 --- a/controllers/designateapi_controller.go +++ b/controllers/designateapi_controller.go @@ -813,8 +813,9 @@ func (r *DesignateAPIReconciler) reconcileNormal(ctx context.Context, instance * // TODO check when/if Init, Update, or Upgrade should/could be skipped // // 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)) @@ -834,9 +835,13 @@ func (r *DesignateAPIReconciler) 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 { return ctrl.Result{}, fmt.Errorf("failed create network annotation from %s: %w", instance.Spec.NetworkAttachments, err) diff --git a/controllers/designatebackendbind9_controller.go b/controllers/designatebackendbind9_controller.go index a0c10051..5ac47819 100644 --- a/controllers/designatebackendbind9_controller.go +++ b/controllers/designatebackendbind9_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" designatev1beta1 "github.com/openstack-k8s-operators/designate-operator/api/v1beta1" "github.com/openstack-k8s-operators/designate-operator/pkg/designate" designatebackendbind9 "github.com/openstack-k8s-operators/designate-operator/pkg/designatebackendbind9" @@ -395,8 +396,9 @@ func (r *DesignateBackendbind9Reconciler) reconcileNormal(ctx context.Context, i // TODO check when/if Init, Update, or Upgrade should/could be skipped // // 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) { r.Log.Info(fmt.Sprintf("network-attachment-definition %s not found", netAtt)) @@ -416,9 +418,13 @@ func (r *DesignateBackendbind9Reconciler) reconcileNormal(ctx context.Context, i 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/designatecentral_controller.go b/controllers/designatecentral_controller.go index 363614c0..c7d35f84 100644 --- a/controllers/designatecentral_controller.go +++ b/controllers/designatecentral_controller.go @@ -39,6 +39,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" designatev1beta1 "github.com/openstack-k8s-operators/designate-operator/api/v1beta1" "github.com/openstack-k8s-operators/designate-operator/pkg/designate" designatecentral "github.com/openstack-k8s-operators/designate-operator/pkg/designatecentral" @@ -520,8 +521,9 @@ func (r *DesignateCentralReconciler) reconcileNormal(ctx context.Context, instan // TODO check when/if Init, Update, or Upgrade should/could be skipped // // 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)) @@ -541,9 +543,13 @@ func (r *DesignateCentralReconciler) reconcileNormal(ctx context.Context, instan 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/designatemdns_controller.go b/controllers/designatemdns_controller.go index aa19dc12..ed16acb7 100644 --- a/controllers/designatemdns_controller.go +++ b/controllers/designatemdns_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" designatev1beta1 "github.com/openstack-k8s-operators/designate-operator/api/v1beta1" "github.com/openstack-k8s-operators/designate-operator/pkg/designate" designatemdns "github.com/openstack-k8s-operators/designate-operator/pkg/designatemdns" @@ -518,8 +519,9 @@ func (r *DesignateMdnsReconciler) reconcileNormal(ctx context.Context, instance // TODO check when/if Init, Update, or Upgrade should/could be skipped // // 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)) @@ -539,9 +541,13 @@ func (r *DesignateMdnsReconciler) 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 { return ctrl.Result{}, fmt.Errorf("failed create network annotation from %s: %w", instance.Spec.NetworkAttachments, err) diff --git a/controllers/designateproducer_controller.go b/controllers/designateproducer_controller.go index cd57b500..8e17e80f 100644 --- a/controllers/designateproducer_controller.go +++ b/controllers/designateproducer_controller.go @@ -23,6 +23,7 @@ import ( "time" "github.com/go-logr/logr" + networkv1 "github.com/k8snetworkplumbingwg/network-attachment-definition-client/pkg/apis/k8s.cni.cncf.io/v1" designatev1beta1 "github.com/openstack-k8s-operators/designate-operator/api/v1beta1" "github.com/openstack-k8s-operators/designate-operator/pkg/designate" designateproducer "github.com/openstack-k8s-operators/designate-operator/pkg/designateproducer" @@ -519,8 +520,9 @@ func (r *DesignateProducerReconciler) reconcileNormal(ctx context.Context, insta // TODO check when/if Init, Update, or Upgrade should/could be skipped // // 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)) @@ -540,9 +542,13 @@ func (r *DesignateProducerReconciler) reconcileNormal(ctx context.Context, insta 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/designateunbound_controller.go b/controllers/designateunbound_controller.go index 0ea5d774..9d2afb1f 100644 --- a/controllers/designateunbound_controller.go +++ b/controllers/designateunbound_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" designatev1 "github.com/openstack-k8s-operators/designate-operator/api/v1beta1" "github.com/openstack-k8s-operators/designate-operator/pkg/designateunbound" appsv1 "k8s.io/api/apps/v1" @@ -266,8 +267,9 @@ func (r *UnboundReconciler) reconcileNormal(ctx context.Context, instance *desig instance.Status.Conditions.MarkTrue(condition.ServiceConfigReadyCondition, condition.ServiceConfigReadyMessage) + nadList := []networkv1.NetworkAttachmentDefinition{} for _, networkAttachment := range instance.Spec.NetworkAttachments { - _, err := nad.GetNADWithName(ctx, helper, networkAttachment, instance.Namespace) + nad, err := nad.GetNADWithName(ctx, helper, networkAttachment, instance.Namespace) if err != nil { if k8s_errors.IsNotFound(err) { r.Log.Info(fmt.Sprintf("network-attachment-definition %s not found", networkAttachment)) @@ -287,9 +289,13 @@ func (r *UnboundReconciler) reconcileNormal(ctx context.Context, instance *desig 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/designateworker_controller.go b/controllers/designateworker_controller.go index a886cc41..8b986b00 100644 --- a/controllers/designateworker_controller.go +++ b/controllers/designateworker_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" designatev1beta1 "github.com/openstack-k8s-operators/designate-operator/api/v1beta1" "github.com/openstack-k8s-operators/designate-operator/pkg/designate" designateworker "github.com/openstack-k8s-operators/designate-operator/pkg/designateworker" @@ -516,8 +517,9 @@ func (r *DesignateWorkerReconciler) reconcileNormal(ctx context.Context, instanc // TODO check when/if Init, Update, or Upgrade should/could be skipped // // 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)) @@ -537,9 +539,13 @@ func (r *DesignateWorkerReconciler) 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/go.mod b/go.mod index 48f91be3..ca36d892 100644 --- a/go.mod +++ b/go.mod @@ -10,7 +10,7 @@ require ( github.com/openstack-k8s-operators/designate-operator/api v0.1.1-0.20240807132522-6c2eca7c6bbb github.com/openstack-k8s-operators/infra-operator/apis v0.4.1-0.20241015064410-3d0bae9c028a github.com/openstack-k8s-operators/keystone-operator/api v0.4.1-0.20241013092400-3f9337945472 - github.com/openstack-k8s-operators/lib-common/modules/common v0.5.1-0.20241029151503-4878b3fa3333 + github.com/openstack-k8s-operators/lib-common/modules/common v0.5.1-0.20241113144931-ff1fd2dcd04a github.com/openstack-k8s-operators/mariadb-operator/api v0.4.1-0.20241015090956-b0954ab72dcd gopkg.in/yaml.v2 v2.4.0 k8s.io/api v0.29.10 diff --git a/go.sum b/go.sum index 810450cf..99c910f9 100644 --- a/go.sum +++ b/go.sum @@ -81,8 +81,8 @@ github.com/openstack-k8s-operators/infra-operator/apis v0.4.1-0.20241015064410-3 github.com/openstack-k8s-operators/infra-operator/apis v0.4.1-0.20241015064410-3d0bae9c028a/go.mod h1:wCgTvuqqepsWIwRB5jMQzc9WvsnpOmNnYa+4NvUhW2w= github.com/openstack-k8s-operators/keystone-operator/api v0.4.1-0.20241013092400-3f9337945472 h1:rT7rpeXxzrrgSGmt/FCxpD2iIdUsmuxgJkMq6E/tiis= github.com/openstack-k8s-operators/keystone-operator/api v0.4.1-0.20241013092400-3f9337945472/go.mod h1:E8azRt+pUzZCAxq2YRWwILorodLbojKBlniPP5qkcQc= -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/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.4.1-0.20241014140317-e5c35d28f3af h1:fevDUHmqcnI4wDTKupKe/CcgVdgNpZXWkJx8u0/xEXs= github.com/openstack-k8s-operators/lib-common/modules/openstack v0.4.1-0.20241014140317-e5c35d28f3af/go.mod h1:djfljx3jfHqywhY3oDvPg/GLKwiFVkds6v7P7/Yg+8g= github.com/openstack-k8s-operators/lib-common/modules/storage v0.4.1-0.20241014140317-e5c35d28f3af h1:l8GXJhv4P/fy7Amz9XPEi8sn+hvxrQf1gICpmOaqOuE=