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

Checkup, tests: Remove Pod and NAD from client stub #128

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
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ go 1.19

require (
github.com/google/goexpect v0.0.0-20210430020637-ab937bf7fd6f
github.com/k8snetworkplumbingwg/network-attachment-definition-client v1.4.0
github.com/kiagnose/kiagnose v0.2.1-0.20221208132946-95d8c7995fab
github.com/onsi/ginkgo/v2 v2.7.0
github.com/onsi/gomega v1.24.2
Expand Down Expand Up @@ -36,6 +35,7 @@ require (
github.com/gorilla/websocket v1.5.0 // indirect
github.com/imdario/mergo v0.3.10 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/k8snetworkplumbingwg/network-attachment-definition-client v1.4.0 // indirect
github.com/kubernetes-csi/external-snapshotter/client/v4 v4.2.0 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
Expand Down
62 changes: 0 additions & 62 deletions pkg/internal/checkup/checkup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,10 @@ import (
"strings"
"testing"

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

k8scorev1 "k8s.io/api/core/v1"
k8serrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime/schema"

kvcorev1 "kubevirt.io/api/core/v1"
Expand Down Expand Up @@ -85,7 +83,6 @@ func TestSetupShouldFail(t *testing.T) {

assert.ErrorContains(t, testCheckup.Setup(context.Background()), expectedVMICreationFailure.Error())
assert.Empty(t, testClient.createdVMIs)
assert.Empty(t, testClient.createdPods)
})

t.Run("when wait for VMI to boot fails", func(t *testing.T) {
Expand All @@ -98,7 +95,6 @@ func TestSetupShouldFail(t *testing.T) {

assert.ErrorContains(t, testCheckup.Setup(context.Background()), expectedVMIReadFailure.Error())
assert.Empty(t, testClient.createdVMIs)
assert.Empty(t, testClient.createdPods)
})
}

Expand Down Expand Up @@ -182,10 +178,6 @@ chpasswd:

type clientStub struct {
createdVMIs map[string]*kvcorev1.VirtualMachineInstance
createdPods map[string]*k8scorev1.Pod
podCreationFailure error
podReadFailure error
podDeletionFailure error
vmiCreationFailure error
vmiReadFailure error
vmiDeletionFailure error
Expand All @@ -194,7 +186,6 @@ type clientStub struct {
func newClientStub() *clientStub {
return &clientStub{
createdVMIs: map[string]*kvcorev1.VirtualMachineInstance{},
createdPods: map[string]*k8scorev1.Pod{},
}
}

Expand Down Expand Up @@ -248,59 +239,6 @@ func (cs *clientStub) DeleteVirtualMachineInstance(_ context.Context, namespace,
return nil
}

func (cs *clientStub) CreatePod(_ context.Context, namespace string, pod *k8scorev1.Pod) (*k8scorev1.Pod, error) {
if cs.podCreationFailure != nil {
return nil, cs.podCreationFailure
}

pod.Namespace = namespace

podFullName := checkup.ObjectFullName(pod.Namespace, pod.Name)
pod.Status.Phase = k8scorev1.PodRunning
cs.createdPods[podFullName] = pod

return pod, nil
}

func (cs *clientStub) DeletePod(_ context.Context, namespace, name string) error {
if cs.podDeletionFailure != nil {
return cs.podDeletionFailure
}

podFullName := checkup.ObjectFullName(namespace, name)
_, exist := cs.createdPods[podFullName]
if !exist {
return k8serrors.NewNotFound(schema.GroupResource{Group: "", Resource: "pods"}, name)
}

delete(cs.createdPods, podFullName)

return nil
}

func (cs *clientStub) GetPod(_ context.Context, namespace, name string) (*k8scorev1.Pod, error) {
if cs.podReadFailure != nil {
return nil, cs.podReadFailure
}

podFullName := checkup.ObjectFullName(namespace, name)
pod, exist := cs.createdPods[podFullName]
if !exist {
return nil, k8serrors.NewNotFound(schema.GroupResource{Group: "", Resource: "pods"}, name)
}
return pod, nil
}

func (cs *clientStub) GetNetworkAttachmentDefinition(_ context.Context, _, _ string) (*networkv1.NetworkAttachmentDefinition, error) {
return &networkv1.NetworkAttachmentDefinition{
ObjectMeta: metav1.ObjectMeta{
Annotations: map[string]string{
"k8s.v1.cni.cncf.io/resourceName": "openshift.io/dpdk-net",
},
},
}, nil
}

func (cs *clientStub) VMIName() string {
for _, vmi := range cs.createdVMIs {
if strings.Contains(vmi.Name, checkup.VMINamePrefix) {
Expand Down