Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Dockerfile.base
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ RUN dnf install -y --nodocs \
dnf clean all

ARG ovsver=3.1.0-10.el9fdp
ARG ovnver=23.03.0-7.el9fdp
ARG ovnver=23.03.0-49.el9fdp

RUN INSTALL_PKGS="iptables" && \
ovsver_short=$(echo "$ovsver" | cut -d'.' -f1,2) && \
Expand Down
2 changes: 1 addition & 1 deletion dist/images/Dockerfile.fedora
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ USER root

ENV PYTHONDONTWRITEBYTECODE yes

ARG ovnver=ovn-23.03.0-4.fc37
ARG ovnver=ovn-23.03.0-16.fc37
# Automatically populated when using docker buildx
ARG TARGETPLATFORM
ARG BUILDPLATFORM
Expand Down
6 changes: 3 additions & 3 deletions go-controller/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ else
CONTAINER_RUNTIME=docker
endif
CONTAINER_RUNNABLE ?= $(shell $(CONTAINER_RUNTIME) -v > /dev/null 2>&1; echo $$?)
OVN_VERSION ?= v22.03.0
OVN_SCHEMA_VERSION ?= v23.03.0
ifeq ($(NOROOT),TRUE)
C_ARGS = -e NOROOT=TRUE
else
Expand Down Expand Up @@ -88,7 +88,7 @@ else
endif

pkg/nbdb/ovn-nb.ovsschema:
curl -sSL https://raw.githubusercontent.com/ovn-org/ovn/$(OVN_VERSION)/ovn-nb.ovsschema -o $@
curl -sSL https://raw.githubusercontent.com/ovn-org/ovn/$(OVN_SCHEMA_VERSION)/ovn-nb.ovsschema -o $@

pkg/sbdb/ovn-sb.ovsschema:
curl -sSL https://raw.githubusercontent.com/ovn-org/ovn/$(OVN_VERSION)/ovn-sb.ovsschema -o $@
curl -sSL https://raw.githubusercontent.com/ovn-org/ovn/$(OVN_SCHEMA_VERSION)/ovn-sb.ovsschema -o $@
11 changes: 11 additions & 0 deletions go-controller/pkg/libovsdbops/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ func getUUID(model model.Model) string {
return t.UUID
case *nbdb.QoS:
return t.UUID
case *nbdb.ChassisTemplateVar:
return t.UUID
default:
panic(fmt.Sprintf("getUUID: unknown model %T", t))
}
Expand Down Expand Up @@ -117,6 +119,8 @@ func setUUID(model model.Model, uuid string) {
t.UUID = uuid
case *nbdb.QoS:
t.UUID = uuid
case *nbdb.ChassisTemplateVar:
t.UUID = uuid
default:
panic(fmt.Sprintf("setUUID: unknown model %T", t))
}
Expand Down Expand Up @@ -236,6 +240,11 @@ func copyIndexes(model model.Model) model.Model {
return &nbdb.QoS{
UUID: t.UUID,
}
case *nbdb.ChassisTemplateVar:
return &nbdb.ChassisTemplateVar{
UUID: t.UUID,
Chassis: t.Chassis,
}
default:
panic(fmt.Sprintf("copyIndexes: unknown model %T", t))
}
Expand Down Expand Up @@ -289,6 +298,8 @@ func getListFromModel(model model.Model) interface{} {
return &[]*sbdb.MACBinding{}
case *nbdb.QoS:
return &[]nbdb.QoS{}
case *nbdb.ChassisTemplateVar:
return &[]*nbdb.ChassisTemplateVar{}
default:
panic(fmt.Sprintf("getModelList: unknown model %T", t))
}
Expand Down
14 changes: 14 additions & 0 deletions go-controller/pkg/libovsdbops/model_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,20 @@ func buildMutationsFromFields(fields []interface{}, mutator ovsdb.Mutator) ([]mo
}
continue
}
// RFC 7047, section 5.1: a MutateOperationDelete is generated
// automatically for every updated key.
removeKeys := make([]string, 0, len(*v))
for key := range *v {
removeKeys = append(removeKeys, key)
}
if len(removeKeys) > 0 {
mutation := model.Mutation{
Field: field,
Mutator: ovsdb.MutateOperationDelete,
Value: removeKeys,
}
mutations = append(mutations, mutation)
}
mutation := model.Mutation{
Field: field,
Mutator: mutator,
Expand Down
11 changes: 11 additions & 0 deletions go-controller/pkg/libovsdbops/model_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"github.com/onsi/ginkgo"
"reflect"
"sort"
"testing"

"github.com/onsi/gomega/types"
Expand Down Expand Up @@ -1458,6 +1459,11 @@ func TestBuildMutationsFromFields(t *testing.T) {
fields: []interface{}{&mapField},
mutator: ovsdb.MutateOperationInsert,
mutations: []model.Mutation{
{
Field: &mapField,
Mutator: ovsdb.MutateOperationDelete,
Value: []string{"", "key1", "key2"},
},
{
Field: &mapField,
Mutator: ovsdb.MutateOperationInsert,
Expand Down Expand Up @@ -1534,6 +1540,11 @@ func TestBuildMutationsFromFields(t *testing.T) {
if err != nil && !tCase.err {
t.Fatalf("%s: got unexpected error: %v", tCase.name, err)
}
for _, m := range mutations {
if v, ok := m.Value.([]string); ok {
sort.Strings(v)
}
}
if !reflect.DeepEqual(mutations, tCase.mutations) {
t.Fatalf("%s: unexpected mutations, got: %+v expected: %+v", tCase.name, mutations, tCase.mutations)
}
Expand Down
112 changes: 112 additions & 0 deletions go-controller/pkg/libovsdbops/template_var.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
package libovsdbops

import (
"context"

libovsdbclient "github.com/ovn-org/libovsdb/client"
libovsdb "github.com/ovn-org/libovsdb/ovsdb"
"github.com/ovn-org/ovn-kubernetes/go-controller/pkg/nbdb"
"github.com/ovn-org/ovn-kubernetes/go-controller/pkg/types"
)

type chassisTemplateVarPredicate func(*nbdb.ChassisTemplateVar) bool

// ListTemplateVar looks up all chassis template variables.
func ListTemplateVar(nbClient libovsdbclient.Client) ([]*nbdb.ChassisTemplateVar, error) {
ctx, cancel := context.WithTimeout(context.Background(), types.OVSDBTimeout)
defer cancel()

templatesList := []*nbdb.ChassisTemplateVar{}
err := nbClient.List(ctx, &templatesList)
return templatesList, err
}

// CreateOrUpdateChassisTemplateVarOps creates or updates the provided
// 'template' variable and returns the corresponding ops.
func CreateOrUpdateChassisTemplateVarOps(nbClient libovsdbclient.Client,
ops []libovsdb.Operation, template *nbdb.ChassisTemplateVar) ([]libovsdb.Operation, error) {

modelClient := newModelClient(nbClient)
return modelClient.CreateOrUpdateOps(ops, operationModel{
Model: template,
OnModelMutations: []interface{}{&template.Variables},
ErrNotFound: false,
BulkOp: false,
})
}

// deleteChassisTemplateVarVariablesOps removes the variables listed as
// keys of 'template.Variables' and returns the corresponding ops.
// It applies the mutation to all records that are selected by 'predicate'.
func deleteChassisTemplateVarVariablesOps(nbClient libovsdbclient.Client,
ops []libovsdb.Operation, template *nbdb.ChassisTemplateVar,
predicate chassisTemplateVarPredicate) ([]libovsdb.Operation, error) {

deleteTemplate := &nbdb.ChassisTemplateVar{
Chassis: template.Chassis,
Variables: map[string]string{},
}
for name := range template.Variables {
deleteTemplate.Variables[name] = ""
}
modelClient := newModelClient(nbClient)
return modelClient.DeleteOps(ops, operationModel{
Model: deleteTemplate,
ModelPredicate: predicate,
OnModelMutations: []interface{}{&deleteTemplate.Variables},
ErrNotFound: false,
BulkOp: true,
})
}

// DeleteChassisTemplateVarVariablesOps removes all variables listed as
// keys of 'template.Variables' from the record matching the same chassis
// as 'template'. It returns the corresponding ops.
func DeleteChassisTemplateVarVariablesOps(nbClient libovsdbclient.Client,
ops []libovsdb.Operation, template *nbdb.ChassisTemplateVar) ([]libovsdb.Operation, error) {

return deleteChassisTemplateVarVariablesOps(nbClient, ops, template, nil)
}

// DeleteAllChassisTemplateVarVariables removes the variables listed as
// in 'varNames' and commits the transaction to the database. It applies
// the mutation to all records that contain these variable names.
func DeleteAllChassisTemplateVarVariables(nbClient libovsdbclient.Client, varNames []string) error {
deleteTemplateVar := &nbdb.ChassisTemplateVar{
Variables: make(map[string]string, len(varNames)),
}
for _, name := range varNames {
deleteTemplateVar.Variables[name] = ""
}
ops, err := deleteChassisTemplateVarVariablesOps(nbClient, nil, deleteTemplateVar,
func(item *nbdb.ChassisTemplateVar) bool {
for _, name := range varNames {
if _, found := item.Variables[name]; found {
return true
}
}
return false
})
if err != nil {
return err
}

_, err = TransactAndCheck(nbClient, ops)
return err
}

// DeleteChassisTemplateVar deletes all complete Chassis_Template_Var
// records matching 'templates'.
func DeleteChassisTemplateVar(nbClient libovsdbclient.Client, templates ...*nbdb.ChassisTemplateVar) error {
opModels := make([]operationModel, 0, len(templates))
for i := range templates {
template := templates[i]
opModels = append(opModels, operationModel{
Model: template,
ErrNotFound: false,
BulkOp: false,
})
}
m := newModelClient(nbClient)
return m.Delete(opModels...)
}
120 changes: 120 additions & 0 deletions go-controller/pkg/nbdb/chassis_template_var.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading