Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert back label values in tokenClient chain element #499

Merged
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
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