Skip to content

Commit

Permalink
Merge pull request #377 from stuggi/nad_annotation_gw
Browse files Browse the repository at this point in the history
Use new nad.EnsureNetworksAnnotation() func to get NAD annotations
  • Loading branch information
openshift-merge-bot[bot] authored Nov 14, 2024
2 parents 8e80218 + 0823d99 commit c25a6e4
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 10 deletions.
2 changes: 1 addition & 1 deletion api/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions api/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
9 changes: 7 additions & 2 deletions controllers/ovncontroller_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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)
Expand Down
10 changes: 8 additions & 2 deletions controllers/ovndbcluster_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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))
Expand All @@ -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
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down

0 comments on commit c25a6e4

Please sign in to comment.