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

Fix networks-status annotation in e2e tests #413

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
8 changes: 4 additions & 4 deletions test/util/network/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func CreateSriovPolicy(clientSet *testclient.ClientSet, generatedName string, op
func GetNicsByPrefix(pod *k8sv1.Pod, ifcPrefix string) ([]string, error) {
var nets []Network
nics := []string{}
err := json.Unmarshal([]byte(pod.ObjectMeta.Annotations["k8s.v1.cni.cncf.io/networks-status"]), &nets)
err := json.Unmarshal([]byte(pod.ObjectMeta.Annotations[netattdefv1.NetworkStatusAnnot]), &nets)
if err != nil {
return nil, err
}
Expand All @@ -101,15 +101,15 @@ func GetNicsByPrefix(pod *k8sv1.Pod, ifcPrefix string) ([]string, error) {
// GetSriovNicIPs returns the list of ip addresses related to the given
// interface name for the given pod.
func GetSriovNicIPs(pod *k8sv1.Pod, ifcName string) ([]string, error) {
networksStatus, ok := pod.ObjectMeta.Annotations["k8s.v1.cni.cncf.io/networks-status"]
networksStatus, ok := pod.ObjectMeta.Annotations[netattdefv1.NetworkStatusAnnot]
if !ok {
return nil, fmt.Errorf("pod [%s] has no annotation `k8s.v1.cni.cncf.io/networks-status`", pod.Name)
return nil, fmt.Errorf("pod [%s] has no annotation `%s`", netattdefv1.NetworkStatusAnnot, pod.Name)
}

var nets []Network
err := json.Unmarshal([]byte(networksStatus), &nets)
if err != nil {
return nil, fmt.Errorf("can't unmarshal annotation `k8s.v1.cni.cncf.io/networks-status`: %w", err)
return nil, fmt.Errorf("can't unmarshal annotation `%s`: %w", netattdefv1.NetworkStatusAnnot, err)
}
for _, net := range nets {
if net.Interface != ifcName {
Expand Down
9 changes: 5 additions & 4 deletions test/util/network/network_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@ package network
import (
"testing"

netattdefv1 "github.com/k8snetworkplumbingwg/network-attachment-definition-client/pkg/apis/k8s.cni.cncf.io/v1"
"github.com/stretchr/testify/assert"

k8sv1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

func TestGetSriovNicIPs(t *testing.T) {
networksStatus := `[{
networkStatus := `[{
"name": "network1",
"interface": "eth0",
"ips": [
Expand Down Expand Up @@ -39,7 +40,7 @@ func TestGetSriovNicIPs(t *testing.T) {
p := &k8sv1.Pod{
ObjectMeta: metav1.ObjectMeta{
Annotations: map[string]string{
"k8s.v1.cni.cncf.io/networks-status": networksStatus,
netattdefv1.NetworkStatusAnnot: networkStatus,
},
},
}
Expand All @@ -61,12 +62,12 @@ func TestGetSriovNicIPsErrors(t *testing.T) {
p := &k8sv1.Pod{}
_, err := GetSriovNicIPs(p, "eth0")
assert.Error(t, err)
assert.Contains(t, err.Error(), "has no annotation `k8s.v1.cni.cncf.io/networks-status`")
assert.Contains(t, err.Error(), "has no annotation `k8s.v1.cni.cncf.io/network-status`")

p = &k8sv1.Pod{
ObjectMeta: metav1.ObjectMeta{
Annotations: map[string]string{
"k8s.v1.cni.cncf.io/networks-status": "xxx",
"k8s.v1.cni.cncf.io/network-status": "xxx",
},
},
}
Expand Down