Skip to content

Commit

Permalink
Revert back label values in tokenClient chain element
Browse files Browse the repository at this point in the history
Signed-off-by: Artem Glazychev <artem.glazychev@xored.com>
  • Loading branch information
glazychev-art committed Feb 15, 2023
1 parent 528783e commit 93d3973
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
16 changes: 13 additions & 3 deletions pkg/networkservice/common/token/multitoken/client.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// Copyright (c) 2020-2022 Doc.ai and/or its affiliates.
// Copyright (c) 2020-2023 Doc.ai and/or its affiliates.
//
// Copyright (c) 2021-2022 Nordix Foundation.
// Copyright (c) 2021-2023 Nordix Foundation.
//
// Copyright (c) 2023 Cisco and/or its affiliates.
//
// SPDX-License-Identifier: Apache-2.0
//
Expand Down Expand Up @@ -58,8 +60,10 @@ func (c *tokenClient) Request(ctx context.Context, request *networkservice.Netwo
isEstablished := c.config.get(request.GetConnection()) != ""

var tokenID string
var tokenName string
if labels := request.GetConnection().GetLabels(); labels != nil {
if tokenName, ok := labels[sriovTokenLabel]; ok {
var ok bool
if tokenName, ok = labels[sriovTokenLabel]; ok {
tokenID = c.config.assign(tokenName, request.GetConnection())
if tokenID == "" {
return nil, errors.Errorf("no free token for the name: %v", tokenName)
Expand All @@ -83,6 +87,12 @@ func (c *tokenClient) Request(ctx context.Context, request *networkservice.Netwo
c.config.release(request.GetConnection())
}

if tokenName != "" {
// Set the previous values in the labels. We need them for healing
delete(conn.GetLabels(), serviceDomainLabel)
conn.GetLabels()[sriovTokenLabel] = tokenName
}

return conn, err
}

Expand Down
10 changes: 6 additions & 4 deletions pkg/networkservice/common/token/multitoken/client_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// Copyright (c) 2020-2022 Doc.ai and/or its affiliates.
// Copyright (c) 2020-2023 Doc.ai and/or its affiliates.
//
// Copyright (c) 2021-2022 Nordix Foundation.
// Copyright (c) 2021-2023 Nordix Foundation.
//
// Copyright (c) 2023 Cisco and/or its affiliates.
//
// SPDX-License-Identifier: Apache-2.0
//
Expand Down Expand Up @@ -73,12 +75,12 @@ func TestTokenClient_Request(t *testing.T) {
token.NewClient(),
&validateClient{t},
)
_, err = client.Request(context.TODO(), request)
conn, err := client.Request(context.Background(), request)
require.NoError(t, err)

require.Equal(t, map[string]string{
sriovTokenLabel: tokenName,
}, request.GetConnection().GetLabels())
}, conn.GetLabels())
}

type validateClient struct {
Expand Down

0 comments on commit 93d3973

Please sign in to comment.