diff --git a/.github/workflows/dev_validation.yaml b/.github/workflows/dev_validation.yaml index c0f44f5503..344b701262 100644 --- a/.github/workflows/dev_validation.yaml +++ b/.github/workflows/dev_validation.yaml @@ -36,6 +36,7 @@ jobs: name: Filter changed paths outputs: helm_templates: ${{ steps.paths_filter.outputs.helm_templates }} + vm_route_forge: ${{ steps.paths_filter.outputs.vm_route_forge }} steps: # For pull requests it's not necessary to checkout the code, this action uses Github API. - uses: dorny/paths-filter@v3 @@ -50,6 +51,8 @@ jobs: - .helmignore - Chart.yaml - Taskfile.yaml + route_forge: + - 'images/vm-route-forge/bpf/route_watcher.c' no_cyrillic: if: "!contains(github.event.pull_request.labels.*.name, 'validation/skip/no_cyrillic')" @@ -147,3 +150,110 @@ jobs: - name: Run validation "Helm templates" run: | task validation:helm-templates + + check_gens_files: + name: Check auto-generated files are up-to-date + needs: paths_filter + runs-on: ubuntu-latest + strategy: + matrix: + # Define two groups of components with their respective Go versions + components: + - { component: virtualization-artifact, go-version: "1.23.9" } + - { component: vm-route-forge, go-version: "1.23.9" } + - { component: api, go-version: "1.22.7" } + + steps: + - name: Set skip flag + run: | + # Only run vm-route-forge if relevant files were changed + if [[ "${{ needs.paths_filter.outputs.vm_route_forge }}" == "true" ]]; then + echo "route_forge_skip=false" >> $GITHUB_ENV + else + echo "route_forge_skip=true" >> $GITHUB_ENV + fi + + - name: Setup Go ${{ matrix.components.go-version }} + if: matrix.components.component != 'vm-route-forge' || env.route_forge_skip != 'true' + uses: actions/setup-go@v5 + with: + go-version: ${{ matrix.components.go-version }} + + - name: Install Task + if: matrix.components.component != 'vm-route-forge' || env.route_forge_skip != 'true' + uses: arduino/setup-task@v2 + with: + version: 3.37.2 + + - name: Install dependencies + if: matrix.components.component != 'vm-route-forge' || env.route_forge_skip != 'true' + run: | + echo "Install packages" + export DEBIAN_FRONTEND=noninteractive + sudo apt-get update + sudo apt-get install -y -qq \ + llvm linux-headers-generic clang \ + libbpf-dev uuid-runtime \ + gcc-multilib yq + sudo apt-get clean + + - uses: actions/checkout@v4 + if: matrix.components.component != 'vm-route-forge' || env.route_forge_skip != 'true' + with: + fetch-depth: 0 + ref: ${{ github.event.pull_request.head.sha }} + + - name: Run check gen files - ${{ matrix.components.component }} + if: matrix.components.component != 'vm-route-forge' || env.route_forge_skip != 'true' + run: | + function check_diffs() { + local folder=$1 + if ! git diff --exit-code; then + echo "Error: Some generated files are out of date. Run 'go generate' and commit the changes." + echo "::group::📂 Diffs for ${{ matrix.components.component }}" + echo "=== git diff ===" + git diff origin/main -- "$folder" + echo "=== end git diff ===" + echo "::endgroup::" + exit 1 + else + echo "✅ No differences found in '$folder'. All files are up to date." + fi + } + + case "${{ matrix.components.component }}" in + virtualization-artifact) + cd ./images/virtualization-artifact + echo "Installing go dependencies..." + go install github.com/matryer/moq@v0.5.3 + go install github.com/onsi/ginkgo/v2/ginkgo@v2.21.0 + cd .. + task controller:dev:gogenerate + check_diffs ./images/virtualization-artifact + ;; + vm-route-forge) + task vm-route-forge:gen + check_diffs ./images/vm-route-forge + ;; + api) + cd ./api + export GOPATH=$(go env GOPATH) + echo "GOPATH=$GOPATH" >> $GITHUB_ENV + echo "Installing k8s tools..." + go get k8s.io/code-generator@v0.29.2 + go install github.com/matryer/moq@v0.4.0 + + go install -mod=readonly sigs.k8s.io/controller-tools/cmd/controller-gen@v0.16.4 + go install -mod=readonly k8s.io/kube-openapi/cmd/openapi-gen + + echo "Run generate" + task generate + # task controller:api:generate + cd .. + check_diffs ./api + ;; + *) + echo "❌ Unknown component: ${{ matrix.components.component }}" + exit 1 + ;; + esac diff --git a/api/go.mod b/api/go.mod index 19cef915e8..82c4993c10 100644 --- a/api/go.mod +++ b/api/go.mod @@ -41,17 +41,21 @@ require ( github.com/openshift/custom-resource-status v1.1.2 // indirect github.com/pborman/uuid v1.2.1 // indirect github.com/pkg/errors v0.9.1 // indirect + golang.org/x/mod v0.14.0 // indirect golang.org/x/net v0.19.0 // indirect golang.org/x/oauth2 v0.12.0 // indirect golang.org/x/sys v0.16.0 // indirect golang.org/x/term v0.15.0 // indirect golang.org/x/text v0.14.0 // indirect golang.org/x/time v0.3.0 // indirect + golang.org/x/tools v0.16.1 // indirect google.golang.org/appengine v1.6.7 // indirect google.golang.org/protobuf v1.34.2 // indirect gopkg.in/inf.v0 v0.9.1 // indirect gopkg.in/yaml.v2 v2.4.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect + k8s.io/code-generator v0.29.2 // indirect + k8s.io/gengo v0.0.0-20230829151522-9cce18d56c01 // indirect k8s.io/klog/v2 v2.110.1 // indirect k8s.io/utils v0.0.0-20230726121419-3b25d923346b // indirect kubevirt.io/containerized-data-importer-api v1.57.0-alpha1 // indirect diff --git a/api/go.sum b/api/go.sum index 0e198a4c80..08230da64d 100644 --- a/api/go.sum +++ b/api/go.sum @@ -198,6 +198,8 @@ golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.5.1/go.mod h1:5OXOZSfqPIIbmVBIIKWRFfZjPR0E5r58TLhUjH0a2Ro= +golang.org/x/mod v0.14.0 h1:dGoOF9QVLYng8IHTm7BAyWqCqSheQ5pYWGhzW00YJr0= +golang.org/x/mod v0.14.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= @@ -346,8 +348,12 @@ k8s.io/apimachinery v0.29.2/go.mod h1:6HVkd1FwxIagpYrHSwJlQqZI3G9LfYWRPAkUvLnXTK k8s.io/client-go v0.29.2 h1:FEg85el1TeZp+/vYJM7hkDlSTFZ+c5nnK44DJ4FyoRg= k8s.io/client-go v0.29.2/go.mod h1:knlvFZE58VpqbQpJNbCbctTVXcd35mMyAAwBdpt4jrA= k8s.io/code-generator v0.23.3/go.mod h1:S0Q1JVA+kSzTI1oUvbKAxZY/DYbA/ZUb4Uknog12ETk= +k8s.io/code-generator v0.29.2 h1:c9/iw2KnNpw2IRV+wwuG/Wns2TjPSgjWzbbjTevyiHI= +k8s.io/code-generator v0.29.2/go.mod h1:FwFi3C9jCrmbPjekhaCYcYG1n07CYiW1+PAPCockaos= k8s.io/gengo v0.0.0-20210813121822-485abfe95c7c/go.mod h1:FiNAH4ZV3gBg2Kwh89tzAEV2be7d5xI0vBa/VySYy3E= k8s.io/gengo v0.0.0-20211129171323-c02415ce4185/go.mod h1:FiNAH4ZV3gBg2Kwh89tzAEV2be7d5xI0vBa/VySYy3E= +k8s.io/gengo v0.0.0-20230829151522-9cce18d56c01 h1:pWEwq4Asjm4vjW7vcsmijwBhOr1/shsbSYiWXmNGlks= +k8s.io/gengo v0.0.0-20230829151522-9cce18d56c01/go.mod h1:FiNAH4ZV3gBg2Kwh89tzAEV2be7d5xI0vBa/VySYy3E= k8s.io/klog/v2 v2.0.0/go.mod h1:PBfzABfn139FHAV07az/IF9Wp1bkk3vpT2XSJ76fSDE= k8s.io/klog/v2 v2.2.0/go.mod h1:Od+F08eJP+W3HUb4pSrPpgp9DGU4GzlpG/TmITuYh/Y= k8s.io/klog/v2 v2.30.0/go.mod h1:y1WjHnz7Dj687irZUWR/WLkLc5N1YHtjLdmgWjndZn0= diff --git a/images/virtualization-artifact/pkg/controller/service/mock.go b/images/virtualization-artifact/pkg/controller/service/mock.go index 0e30c69895..32f3b129e8 100644 --- a/images/virtualization-artifact/pkg/controller/service/mock.go +++ b/images/virtualization-artifact/pkg/controller/service/mock.go @@ -8,7 +8,6 @@ import ( "k8s.io/apimachinery/pkg/api/meta" "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime/schema" - "k8s.io/apimachinery/pkg/types" "sigs.k8s.io/controller-runtime/pkg/client" "sync" ) @@ -32,7 +31,7 @@ var _ Client = &ClientMock{} // DeleteAllOfFunc: func(ctx context.Context, obj client.Object, opts ...client.DeleteAllOfOption) error { // panic("mock out the DeleteAllOf method") // }, -// GetFunc: func(ctx context.Context, key types.NamespacedName, obj client.Object, opts ...client.GetOption) error { +// GetFunc: func(ctx context.Context, key client.ObjectKey, obj client.Object, opts ...client.GetOption) error { // panic("mock out the Get method") // }, // GroupVersionKindForFunc: func(obj runtime.Object) (schema.GroupVersionKind, error) { @@ -79,7 +78,7 @@ type ClientMock struct { DeleteAllOfFunc func(ctx context.Context, obj client.Object, opts ...client.DeleteAllOfOption) error // GetFunc mocks the Get method. - GetFunc func(ctx context.Context, key types.NamespacedName, obj client.Object, opts ...client.GetOption) error + GetFunc func(ctx context.Context, key client.ObjectKey, obj client.Object, opts ...client.GetOption) error // GroupVersionKindForFunc mocks the GroupVersionKindFor method. GroupVersionKindForFunc func(obj runtime.Object) (schema.GroupVersionKind, error) @@ -142,7 +141,7 @@ type ClientMock struct { // Ctx is the ctx argument value. Ctx context.Context // Key is the key argument value. - Key types.NamespacedName + Key client.ObjectKey // Obj is the obj argument value. Obj client.Object // Opts is the opts argument value. @@ -338,13 +337,13 @@ func (mock *ClientMock) DeleteAllOfCalls() []struct { } // Get calls GetFunc. -func (mock *ClientMock) Get(ctx context.Context, key types.NamespacedName, obj client.Object, opts ...client.GetOption) error { +func (mock *ClientMock) Get(ctx context.Context, key client.ObjectKey, obj client.Object, opts ...client.GetOption) error { if mock.GetFunc == nil { panic("ClientMock.GetFunc: method is nil but Client.Get was just called") } callInfo := struct { Ctx context.Context - Key types.NamespacedName + Key client.ObjectKey Obj client.Object Opts []client.GetOption }{ @@ -365,13 +364,13 @@ func (mock *ClientMock) Get(ctx context.Context, key types.NamespacedName, obj c // len(mockedClient.GetCalls()) func (mock *ClientMock) GetCalls() []struct { Ctx context.Context - Key types.NamespacedName + Key client.ObjectKey Obj client.Object Opts []client.GetOption } { var calls []struct { Ctx context.Context - Key types.NamespacedName + Key client.ObjectKey Obj client.Object Opts []client.GetOption } diff --git a/images/virtualization-artifact/pkg/controller/vd/internal/source/mock.go b/images/virtualization-artifact/pkg/controller/vd/internal/source/mock.go index 150a4d6eb2..e958641c42 100644 --- a/images/virtualization-artifact/pkg/controller/vd/internal/source/mock.go +++ b/images/virtualization-artifact/pkg/controller/vd/internal/source/mock.go @@ -918,6 +918,420 @@ func (mock *ObjectRefVirtualImageDiskServiceMock) StartCalls() []struct { return calls } +// Ensure, that ObjectRefClusterVirtualImageDiskServiceMock does implement ObjectRefClusterVirtualImageDiskService. +// If this is not the case, regenerate this file with moq. +var _ ObjectRefClusterVirtualImageDiskService = &ObjectRefClusterVirtualImageDiskServiceMock{} + +// ObjectRefClusterVirtualImageDiskServiceMock is a mock implementation of ObjectRefClusterVirtualImageDiskService. +// +// func TestSomethingThatUsesObjectRefClusterVirtualImageDiskService(t *testing.T) { +// +// // make and configure a mocked ObjectRefClusterVirtualImageDiskService +// mockedObjectRefClusterVirtualImageDiskService := &ObjectRefClusterVirtualImageDiskServiceMock{ +// CheckProvisioningFunc: func(ctx context.Context, pvc *corev1.PersistentVolumeClaim) error { +// panic("mock out the CheckProvisioning method") +// }, +// CleanUpFunc: func(ctx context.Context, sup *supplements.Generator) (bool, error) { +// panic("mock out the CleanUp method") +// }, +// CleanUpSupplementsFunc: func(ctx context.Context, sup *supplements.Generator) (bool, error) { +// panic("mock out the CleanUpSupplements method") +// }, +// GetCapacityFunc: func(pvc *corev1.PersistentVolumeClaim) string { +// panic("mock out the GetCapacity method") +// }, +// GetProgressFunc: func(dv *cdiv1.DataVolume, prevProgress string, opts ...service.GetProgressOption) string { +// panic("mock out the GetProgress method") +// }, +// ProtectFunc: func(ctx context.Context, owner client.Object, dv *cdiv1.DataVolume, pvc *corev1.PersistentVolumeClaim) error { +// panic("mock out the Protect method") +// }, +// StartFunc: func(ctx context.Context, pvcSize resource.Quantity, sc *storagev1.StorageClass, source *cdiv1.DataVolumeSource, obj service.ObjectKind, sup *supplements.Generator, opts ...service.Option) error { +// panic("mock out the Start method") +// }, +// } +// +// // use mockedObjectRefClusterVirtualImageDiskService in code that requires ObjectRefClusterVirtualImageDiskService +// // and then make assertions. +// +// } +type ObjectRefClusterVirtualImageDiskServiceMock struct { + // CheckProvisioningFunc mocks the CheckProvisioning method. + CheckProvisioningFunc func(ctx context.Context, pvc *corev1.PersistentVolumeClaim) error + + // CleanUpFunc mocks the CleanUp method. + CleanUpFunc func(ctx context.Context, sup *supplements.Generator) (bool, error) + + // CleanUpSupplementsFunc mocks the CleanUpSupplements method. + CleanUpSupplementsFunc func(ctx context.Context, sup *supplements.Generator) (bool, error) + + // GetCapacityFunc mocks the GetCapacity method. + GetCapacityFunc func(pvc *corev1.PersistentVolumeClaim) string + + // GetProgressFunc mocks the GetProgress method. + GetProgressFunc func(dv *cdiv1.DataVolume, prevProgress string, opts ...service.GetProgressOption) string + + // ProtectFunc mocks the Protect method. + ProtectFunc func(ctx context.Context, owner client.Object, dv *cdiv1.DataVolume, pvc *corev1.PersistentVolumeClaim) error + + // StartFunc mocks the Start method. + StartFunc func(ctx context.Context, pvcSize resource.Quantity, sc *storagev1.StorageClass, source *cdiv1.DataVolumeSource, obj service.ObjectKind, sup *supplements.Generator, opts ...service.Option) error + + // calls tracks calls to the methods. + calls struct { + // CheckProvisioning holds details about calls to the CheckProvisioning method. + CheckProvisioning []struct { + // Ctx is the ctx argument value. + Ctx context.Context + // Pvc is the pvc argument value. + Pvc *corev1.PersistentVolumeClaim + } + // CleanUp holds details about calls to the CleanUp method. + CleanUp []struct { + // Ctx is the ctx argument value. + Ctx context.Context + // Sup is the sup argument value. + Sup *supplements.Generator + } + // CleanUpSupplements holds details about calls to the CleanUpSupplements method. + CleanUpSupplements []struct { + // Ctx is the ctx argument value. + Ctx context.Context + // Sup is the sup argument value. + Sup *supplements.Generator + } + // GetCapacity holds details about calls to the GetCapacity method. + GetCapacity []struct { + // Pvc is the pvc argument value. + Pvc *corev1.PersistentVolumeClaim + } + // GetProgress holds details about calls to the GetProgress method. + GetProgress []struct { + // Dv is the dv argument value. + Dv *cdiv1.DataVolume + // PrevProgress is the prevProgress argument value. + PrevProgress string + // Opts is the opts argument value. + Opts []service.GetProgressOption + } + // Protect holds details about calls to the Protect method. + Protect []struct { + // Ctx is the ctx argument value. + Ctx context.Context + // Owner is the owner argument value. + Owner client.Object + // Dv is the dv argument value. + Dv *cdiv1.DataVolume + // Pvc is the pvc argument value. + Pvc *corev1.PersistentVolumeClaim + } + // Start holds details about calls to the Start method. + Start []struct { + // Ctx is the ctx argument value. + Ctx context.Context + // PvcSize is the pvcSize argument value. + PvcSize resource.Quantity + // Sc is the sc argument value. + Sc *storagev1.StorageClass + // Source is the source argument value. + Source *cdiv1.DataVolumeSource + // Obj is the obj argument value. + Obj service.ObjectKind + // Sup is the sup argument value. + Sup *supplements.Generator + // Opts is the opts argument value. + Opts []service.Option + } + } + lockCheckProvisioning sync.RWMutex + lockCleanUp sync.RWMutex + lockCleanUpSupplements sync.RWMutex + lockGetCapacity sync.RWMutex + lockGetProgress sync.RWMutex + lockProtect sync.RWMutex + lockStart sync.RWMutex +} + +// CheckProvisioning calls CheckProvisioningFunc. +func (mock *ObjectRefClusterVirtualImageDiskServiceMock) CheckProvisioning(ctx context.Context, pvc *corev1.PersistentVolumeClaim) error { + if mock.CheckProvisioningFunc == nil { + panic("ObjectRefClusterVirtualImageDiskServiceMock.CheckProvisioningFunc: method is nil but ObjectRefClusterVirtualImageDiskService.CheckProvisioning was just called") + } + callInfo := struct { + Ctx context.Context + Pvc *corev1.PersistentVolumeClaim + }{ + Ctx: ctx, + Pvc: pvc, + } + mock.lockCheckProvisioning.Lock() + mock.calls.CheckProvisioning = append(mock.calls.CheckProvisioning, callInfo) + mock.lockCheckProvisioning.Unlock() + return mock.CheckProvisioningFunc(ctx, pvc) +} + +// CheckProvisioningCalls gets all the calls that were made to CheckProvisioning. +// Check the length with: +// +// len(mockedObjectRefClusterVirtualImageDiskService.CheckProvisioningCalls()) +func (mock *ObjectRefClusterVirtualImageDiskServiceMock) CheckProvisioningCalls() []struct { + Ctx context.Context + Pvc *corev1.PersistentVolumeClaim +} { + var calls []struct { + Ctx context.Context + Pvc *corev1.PersistentVolumeClaim + } + mock.lockCheckProvisioning.RLock() + calls = mock.calls.CheckProvisioning + mock.lockCheckProvisioning.RUnlock() + return calls +} + +// CleanUp calls CleanUpFunc. +func (mock *ObjectRefClusterVirtualImageDiskServiceMock) CleanUp(ctx context.Context, sup *supplements.Generator) (bool, error) { + if mock.CleanUpFunc == nil { + panic("ObjectRefClusterVirtualImageDiskServiceMock.CleanUpFunc: method is nil but ObjectRefClusterVirtualImageDiskService.CleanUp was just called") + } + callInfo := struct { + Ctx context.Context + Sup *supplements.Generator + }{ + Ctx: ctx, + Sup: sup, + } + mock.lockCleanUp.Lock() + mock.calls.CleanUp = append(mock.calls.CleanUp, callInfo) + mock.lockCleanUp.Unlock() + return mock.CleanUpFunc(ctx, sup) +} + +// CleanUpCalls gets all the calls that were made to CleanUp. +// Check the length with: +// +// len(mockedObjectRefClusterVirtualImageDiskService.CleanUpCalls()) +func (mock *ObjectRefClusterVirtualImageDiskServiceMock) CleanUpCalls() []struct { + Ctx context.Context + Sup *supplements.Generator +} { + var calls []struct { + Ctx context.Context + Sup *supplements.Generator + } + mock.lockCleanUp.RLock() + calls = mock.calls.CleanUp + mock.lockCleanUp.RUnlock() + return calls +} + +// CleanUpSupplements calls CleanUpSupplementsFunc. +func (mock *ObjectRefClusterVirtualImageDiskServiceMock) CleanUpSupplements(ctx context.Context, sup *supplements.Generator) (bool, error) { + if mock.CleanUpSupplementsFunc == nil { + panic("ObjectRefClusterVirtualImageDiskServiceMock.CleanUpSupplementsFunc: method is nil but ObjectRefClusterVirtualImageDiskService.CleanUpSupplements was just called") + } + callInfo := struct { + Ctx context.Context + Sup *supplements.Generator + }{ + Ctx: ctx, + Sup: sup, + } + mock.lockCleanUpSupplements.Lock() + mock.calls.CleanUpSupplements = append(mock.calls.CleanUpSupplements, callInfo) + mock.lockCleanUpSupplements.Unlock() + return mock.CleanUpSupplementsFunc(ctx, sup) +} + +// CleanUpSupplementsCalls gets all the calls that were made to CleanUpSupplements. +// Check the length with: +// +// len(mockedObjectRefClusterVirtualImageDiskService.CleanUpSupplementsCalls()) +func (mock *ObjectRefClusterVirtualImageDiskServiceMock) CleanUpSupplementsCalls() []struct { + Ctx context.Context + Sup *supplements.Generator +} { + var calls []struct { + Ctx context.Context + Sup *supplements.Generator + } + mock.lockCleanUpSupplements.RLock() + calls = mock.calls.CleanUpSupplements + mock.lockCleanUpSupplements.RUnlock() + return calls +} + +// GetCapacity calls GetCapacityFunc. +func (mock *ObjectRefClusterVirtualImageDiskServiceMock) GetCapacity(pvc *corev1.PersistentVolumeClaim) string { + if mock.GetCapacityFunc == nil { + panic("ObjectRefClusterVirtualImageDiskServiceMock.GetCapacityFunc: method is nil but ObjectRefClusterVirtualImageDiskService.GetCapacity was just called") + } + callInfo := struct { + Pvc *corev1.PersistentVolumeClaim + }{ + Pvc: pvc, + } + mock.lockGetCapacity.Lock() + mock.calls.GetCapacity = append(mock.calls.GetCapacity, callInfo) + mock.lockGetCapacity.Unlock() + return mock.GetCapacityFunc(pvc) +} + +// GetCapacityCalls gets all the calls that were made to GetCapacity. +// Check the length with: +// +// len(mockedObjectRefClusterVirtualImageDiskService.GetCapacityCalls()) +func (mock *ObjectRefClusterVirtualImageDiskServiceMock) GetCapacityCalls() []struct { + Pvc *corev1.PersistentVolumeClaim +} { + var calls []struct { + Pvc *corev1.PersistentVolumeClaim + } + mock.lockGetCapacity.RLock() + calls = mock.calls.GetCapacity + mock.lockGetCapacity.RUnlock() + return calls +} + +// GetProgress calls GetProgressFunc. +func (mock *ObjectRefClusterVirtualImageDiskServiceMock) GetProgress(dv *cdiv1.DataVolume, prevProgress string, opts ...service.GetProgressOption) string { + if mock.GetProgressFunc == nil { + panic("ObjectRefClusterVirtualImageDiskServiceMock.GetProgressFunc: method is nil but ObjectRefClusterVirtualImageDiskService.GetProgress was just called") + } + callInfo := struct { + Dv *cdiv1.DataVolume + PrevProgress string + Opts []service.GetProgressOption + }{ + Dv: dv, + PrevProgress: prevProgress, + Opts: opts, + } + mock.lockGetProgress.Lock() + mock.calls.GetProgress = append(mock.calls.GetProgress, callInfo) + mock.lockGetProgress.Unlock() + return mock.GetProgressFunc(dv, prevProgress, opts...) +} + +// GetProgressCalls gets all the calls that were made to GetProgress. +// Check the length with: +// +// len(mockedObjectRefClusterVirtualImageDiskService.GetProgressCalls()) +func (mock *ObjectRefClusterVirtualImageDiskServiceMock) GetProgressCalls() []struct { + Dv *cdiv1.DataVolume + PrevProgress string + Opts []service.GetProgressOption +} { + var calls []struct { + Dv *cdiv1.DataVolume + PrevProgress string + Opts []service.GetProgressOption + } + mock.lockGetProgress.RLock() + calls = mock.calls.GetProgress + mock.lockGetProgress.RUnlock() + return calls +} + +// Protect calls ProtectFunc. +func (mock *ObjectRefClusterVirtualImageDiskServiceMock) Protect(ctx context.Context, owner client.Object, dv *cdiv1.DataVolume, pvc *corev1.PersistentVolumeClaim) error { + if mock.ProtectFunc == nil { + panic("ObjectRefClusterVirtualImageDiskServiceMock.ProtectFunc: method is nil but ObjectRefClusterVirtualImageDiskService.Protect was just called") + } + callInfo := struct { + Ctx context.Context + Owner client.Object + Dv *cdiv1.DataVolume + Pvc *corev1.PersistentVolumeClaim + }{ + Ctx: ctx, + Owner: owner, + Dv: dv, + Pvc: pvc, + } + mock.lockProtect.Lock() + mock.calls.Protect = append(mock.calls.Protect, callInfo) + mock.lockProtect.Unlock() + return mock.ProtectFunc(ctx, owner, dv, pvc) +} + +// ProtectCalls gets all the calls that were made to Protect. +// Check the length with: +// +// len(mockedObjectRefClusterVirtualImageDiskService.ProtectCalls()) +func (mock *ObjectRefClusterVirtualImageDiskServiceMock) ProtectCalls() []struct { + Ctx context.Context + Owner client.Object + Dv *cdiv1.DataVolume + Pvc *corev1.PersistentVolumeClaim +} { + var calls []struct { + Ctx context.Context + Owner client.Object + Dv *cdiv1.DataVolume + Pvc *corev1.PersistentVolumeClaim + } + mock.lockProtect.RLock() + calls = mock.calls.Protect + mock.lockProtect.RUnlock() + return calls +} + +// Start calls StartFunc. +func (mock *ObjectRefClusterVirtualImageDiskServiceMock) Start(ctx context.Context, pvcSize resource.Quantity, sc *storagev1.StorageClass, source *cdiv1.DataVolumeSource, obj service.ObjectKind, sup *supplements.Generator, opts ...service.Option) error { + if mock.StartFunc == nil { + panic("ObjectRefClusterVirtualImageDiskServiceMock.StartFunc: method is nil but ObjectRefClusterVirtualImageDiskService.Start was just called") + } + callInfo := struct { + Ctx context.Context + PvcSize resource.Quantity + Sc *storagev1.StorageClass + Source *cdiv1.DataVolumeSource + Obj service.ObjectKind + Sup *supplements.Generator + Opts []service.Option + }{ + Ctx: ctx, + PvcSize: pvcSize, + Sc: sc, + Source: source, + Obj: obj, + Sup: sup, + Opts: opts, + } + mock.lockStart.Lock() + mock.calls.Start = append(mock.calls.Start, callInfo) + mock.lockStart.Unlock() + return mock.StartFunc(ctx, pvcSize, sc, source, obj, sup, opts...) +} + +// StartCalls gets all the calls that were made to Start. +// Check the length with: +// +// len(mockedObjectRefClusterVirtualImageDiskService.StartCalls()) +func (mock *ObjectRefClusterVirtualImageDiskServiceMock) StartCalls() []struct { + Ctx context.Context + PvcSize resource.Quantity + Sc *storagev1.StorageClass + Source *cdiv1.DataVolumeSource + Obj service.ObjectKind + Sup *supplements.Generator + Opts []service.Option +} { + var calls []struct { + Ctx context.Context + PvcSize resource.Quantity + Sc *storagev1.StorageClass + Source *cdiv1.DataVolumeSource + Obj service.ObjectKind + Sup *supplements.Generator + Opts []service.Option + } + mock.lockStart.RLock() + calls = mock.calls.Start + mock.lockStart.RUnlock() + return calls +} + // Ensure, that ObjectRefVirtualDiskSnapshotDiskServiceMock does implement ObjectRefVirtualDiskSnapshotDiskService. // If this is not the case, regenerate this file with moq. var _ ObjectRefVirtualDiskSnapshotDiskService = &ObjectRefVirtualDiskSnapshotDiskServiceMock{} diff --git a/images/virtualization-artifact/pkg/controller/vm/internal/block_devices_test.go b/images/virtualization-artifact/pkg/controller/vm/internal/block_devices_test.go index 0b03823ad5..f499884de9 100644 --- a/images/virtualization-artifact/pkg/controller/vm/internal/block_devices_test.go +++ b/images/virtualization-artifact/pkg/controller/vm/internal/block_devices_test.go @@ -48,7 +48,7 @@ var _ = Describe("Test BlockDeviceReady condition", func() { }) okBlockDeviceServiceMock := &BlockDeviceServiceMock{ - CountBlockDevicesAttachedToVmFunc: func(_ context.Context, _ *virtv2.VirtualMachine) (int, error) { + CountBlockDevicesAttachedToVMFunc: func(_ context.Context, _ *virtv2.VirtualMachine) (int, error) { return 1, nil }, } @@ -1172,7 +1172,7 @@ var _ = Describe("BlockDeviceHandler", func() { var vdBar *virtv2.VirtualDisk blockDeviceHandlerMock := &BlockDeviceServiceMock{} - blockDeviceHandlerMock.CountBlockDevicesAttachedToVmFunc = func(_ context.Context, vm *virtv2.VirtualMachine) (int, error) { + blockDeviceHandlerMock.CountBlockDevicesAttachedToVMFunc = func(_ context.Context, vm *virtv2.VirtualMachine) (int, error) { return 1, nil } @@ -1375,7 +1375,7 @@ var _ = Describe("Capacity check", func() { It("Should be ok because fewer than 16 devices are connected", func() { okBlockDeviceServiceMock := &BlockDeviceServiceMock{ - CountBlockDevicesAttachedToVmFunc: func(_ context.Context, _ *virtv2.VirtualMachine) (int, error) { + CountBlockDevicesAttachedToVMFunc: func(_ context.Context, _ *virtv2.VirtualMachine) (int, error) { return 1, nil }, } @@ -1391,7 +1391,7 @@ var _ = Describe("Capacity check", func() { }) It("There might be an issue since 16 or more devices are connected.", func() { erroredBlockDeviceServiceMock := &BlockDeviceServiceMock{ - CountBlockDevicesAttachedToVmFunc: func(_ context.Context, _ *virtv2.VirtualMachine) (int, error) { + CountBlockDevicesAttachedToVMFunc: func(_ context.Context, _ *virtv2.VirtualMachine) (int, error) { return 17, nil }, } @@ -1410,7 +1410,7 @@ var _ = Describe("Capacity check", func() { Context("When images are hotplugged into a VirtualMachine", func() { It("checks that `VirtualMachine.Status.BlockDeviceRefs` contains the hotplugged images", func() { blockDeviceServiceMock := &BlockDeviceServiceMock{ - CountBlockDevicesAttachedToVmFunc: func(_ context.Context, _ *virtv2.VirtualMachine) (int, error) { + CountBlockDevicesAttachedToVMFunc: func(_ context.Context, _ *virtv2.VirtualMachine) (int, error) { return 2, nil }, } diff --git a/images/virtualization-artifact/pkg/controller/vm/internal/mock.go b/images/virtualization-artifact/pkg/controller/vm/internal/mock.go index 634ecb1bd5..2a3a5080f4 100644 --- a/images/virtualization-artifact/pkg/controller/vm/internal/mock.go +++ b/images/virtualization-artifact/pkg/controller/vm/internal/mock.go @@ -246,8 +246,8 @@ var _ BlockDeviceService = &BlockDeviceServiceMock{} // // // make and configure a mocked BlockDeviceService // mockedBlockDeviceService := &BlockDeviceServiceMock{ -// CountBlockDevicesAttachedToVmFunc: func(ctx context.Context, vm *virtv2.VirtualMachine) (int, error) { -// panic("mock out the CountBlockDevicesAttachedToVm method") +// CountBlockDevicesAttachedToVMFunc: func(ctx context.Context, vm *virtv2.VirtualMachine) (int, error) { +// panic("mock out the CountBlockDevicesAttachedToVM method") // }, // } // @@ -256,26 +256,26 @@ var _ BlockDeviceService = &BlockDeviceServiceMock{} // // } type BlockDeviceServiceMock struct { - // CountBlockDevicesAttachedToVmFunc mocks the CountBlockDevicesAttachedToVm method. - CountBlockDevicesAttachedToVmFunc func(ctx context.Context, vm *virtv2.VirtualMachine) (int, error) + // CountBlockDevicesAttachedToVMFunc mocks the CountBlockDevicesAttachedToVM method. + CountBlockDevicesAttachedToVMFunc func(ctx context.Context, vm *virtv2.VirtualMachine) (int, error) // calls tracks calls to the methods. calls struct { - // CountBlockDevicesAttachedToVm holds details about calls to the CountBlockDevicesAttachedToVm method. - CountBlockDevicesAttachedToVm []struct { + // CountBlockDevicesAttachedToVM holds details about calls to the CountBlockDevicesAttachedToVM method. + CountBlockDevicesAttachedToVM []struct { // Ctx is the ctx argument value. Ctx context.Context // VM is the vm argument value. VM *virtv2.VirtualMachine } } - lockCountBlockDevicesAttachedToVm sync.RWMutex + lockCountBlockDevicesAttachedToVM sync.RWMutex } -// CountBlockDevicesAttachedToVm calls CountBlockDevicesAttachedToVmFunc. +// CountBlockDevicesAttachedToVM calls CountBlockDevicesAttachedToVMFunc. func (mock *BlockDeviceServiceMock) CountBlockDevicesAttachedToVM(ctx context.Context, vm *virtv2.VirtualMachine) (int, error) { - if mock.CountBlockDevicesAttachedToVmFunc == nil { - panic("BlockDeviceServiceMock.CountBlockDevicesAttachedToVmFunc: method is nil but BlockDeviceService.CountBlockDevicesAttachedToVm was just called") + if mock.CountBlockDevicesAttachedToVMFunc == nil { + panic("BlockDeviceServiceMock.CountBlockDevicesAttachedToVMFunc: method is nil but BlockDeviceService.CountBlockDevicesAttachedToVM was just called") } callInfo := struct { Ctx context.Context @@ -284,17 +284,17 @@ func (mock *BlockDeviceServiceMock) CountBlockDevicesAttachedToVM(ctx context.Co Ctx: ctx, VM: vm, } - mock.lockCountBlockDevicesAttachedToVm.Lock() - mock.calls.CountBlockDevicesAttachedToVm = append(mock.calls.CountBlockDevicesAttachedToVm, callInfo) - mock.lockCountBlockDevicesAttachedToVm.Unlock() - return mock.CountBlockDevicesAttachedToVmFunc(ctx, vm) + mock.lockCountBlockDevicesAttachedToVM.Lock() + mock.calls.CountBlockDevicesAttachedToVM = append(mock.calls.CountBlockDevicesAttachedToVM, callInfo) + mock.lockCountBlockDevicesAttachedToVM.Unlock() + return mock.CountBlockDevicesAttachedToVMFunc(ctx, vm) } -// CountBlockDevicesAttachedToVmCalls gets all the calls that were made to CountBlockDevicesAttachedToVm. +// CountBlockDevicesAttachedToVMCalls gets all the calls that were made to CountBlockDevicesAttachedToVM. // Check the length with: // -// len(mockedBlockDeviceService.CountBlockDevicesAttachedToVmCalls()) -func (mock *BlockDeviceServiceMock) CountBlockDevicesAttachedToVmCalls() []struct { +// len(mockedBlockDeviceService.CountBlockDevicesAttachedToVMCalls()) +func (mock *BlockDeviceServiceMock) CountBlockDevicesAttachedToVMCalls() []struct { Ctx context.Context VM *virtv2.VirtualMachine } { @@ -302,8 +302,8 @@ func (mock *BlockDeviceServiceMock) CountBlockDevicesAttachedToVmCalls() []struc Ctx context.Context VM *virtv2.VirtualMachine } - mock.lockCountBlockDevicesAttachedToVm.RLock() - calls = mock.calls.CountBlockDevicesAttachedToVm - mock.lockCountBlockDevicesAttachedToVm.RUnlock() + mock.lockCountBlockDevicesAttachedToVM.RLock() + calls = mock.calls.CountBlockDevicesAttachedToVM + mock.lockCountBlockDevicesAttachedToVM.RUnlock() return calls } diff --git a/images/vm-route-forge/internal/controller/route/gen.go b/images/vm-route-forge/internal/controller/route/gen.go index c40b001a22..7f593ca619 100644 --- a/images/vm-route-forge/internal/controller/route/gen.go +++ b/images/vm-route-forge/internal/controller/route/gen.go @@ -17,4 +17,4 @@ limitations under the License. package route // We save the generated code in this directory because bpf2go generates non-exported functions and structures. -//go:generate go run github.com/cilium/ebpf/cmd/bpf2go -target amd64 -type route_event ebpf ../../../bpf/route_watcher.c +//go:generate go run github.com/cilium/ebpf/cmd/bpf2go@v0.16.0 -target amd64 -type route_event ebpf ../../../bpf/route_watcher.c