Skip to content

Commit

Permalink
NewFakeClusterConfig: Simplify interface used
Browse files Browse the repository at this point in the history
Signed-off-by: fossedihelm <[email protected]>
  • Loading branch information
fossedihelm committed Jun 21, 2024
1 parent 0e32773 commit 7bb0d27
Show file tree
Hide file tree
Showing 24 changed files with 252 additions and 254 deletions.
8 changes: 4 additions & 4 deletions pkg/storage/backend-storage/backend-storage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,15 @@ import (
var _ = Describe("Backend Storage", func() {
var backendStorage *BackendStorage
var config *virtconfig.ClusterConfig
var kvInformer cache.SharedIndexInformer
var kvStore cache.Store
var storageClassInformer cache.SharedIndexInformer
var storageProfileInformer cache.SharedIndexInformer

BeforeEach(func() {
ctrl := gomock.NewController(GinkgoT())
virtClient := kubecli.NewMockKubevirtClient(ctrl)
kubevirtFakeConfig := &virtv1.KubeVirtConfiguration{}
config, _, kvInformer = testutils.NewFakeClusterConfigUsingKVConfig(kubevirtFakeConfig)
config, _, kvStore = testutils.NewFakeClusterConfigUsingKVConfig(kubevirtFakeConfig)
storageClassInformer, _ = testutils.NewFakeInformerFor(&storagev1.StorageClass{})
storageProfileInformer, _ = testutils.NewFakeInformerFor(&v1beta1.StorageProfile{})
pvcInformer, _ := testutils.NewFakeInformerFor(&v1.PersistentVolumeClaim{})
Expand All @@ -60,9 +60,9 @@ var _ = Describe("Backend Storage", func() {
Context("Storage class", func() {
It("Should return VMStateStorageClass and RWX when set", func() {
By("Setting a VM state storage class in the CR")
kvCR := testutils.GetFakeKubeVirtClusterConfig(kvInformer)
kvCR := testutils.GetFakeKubeVirtClusterConfig(kvStore)
kvCR.Spec.Configuration.VMStateStorageClass = "myfave"
testutils.UpdateFakeKubeVirtClusterConfig(kvInformer.GetStore(), kvCR)
testutils.UpdateFakeKubeVirtClusterConfig(kvStore, kvCR)

By("Expecting getStorageClass() to return that one")
sc, err := backendStorage.getStorageClass()
Expand Down
12 changes: 6 additions & 6 deletions pkg/testutils/mock_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ const (
kvObjectName = "kubevirt"
)

func NewFakeClusterConfigUsingKV(kv *KVv1.KubeVirt) (*virtconfig.ClusterConfig, cache.SharedIndexInformer, cache.SharedIndexInformer) {
func NewFakeClusterConfigUsingKV(kv *KVv1.KubeVirt) (*virtconfig.ClusterConfig, cache.SharedIndexInformer, cache.Store) {
return NewFakeClusterConfigUsingKVWithCPUArch(kv, runtime.GOARCH)
}

func NewFakeClusterConfigUsingKVWithCPUArch(kv *KVv1.KubeVirt, CPUArch string) (*virtconfig.ClusterConfig, cache.SharedIndexInformer, cache.SharedIndexInformer) {
func NewFakeClusterConfigUsingKVWithCPUArch(kv *KVv1.KubeVirt, CPUArch string) (*virtconfig.ClusterConfig, cache.SharedIndexInformer, cache.Store) {
kv.ResourceVersion = rand.String(10)
kv.Status.Phase = "Deployed"
crdInformer, _ := NewFakeInformerFor(&extv1.CustomResourceDefinition{})
Expand All @@ -34,10 +34,10 @@ func NewFakeClusterConfigUsingKVWithCPUArch(kv *KVv1.KubeVirt, CPUArch string) (

AddDataVolumeAPI(crdInformer)
cfg, _ := virtconfig.NewClusterConfigWithCPUArch(crdInformer, kubeVirtInformer, kvObjectNamespace, CPUArch)
return cfg, crdInformer, kubeVirtInformer
return cfg, crdInformer, kubeVirtInformer.GetStore()
}

func NewFakeClusterConfigUsingKVConfig(config *KVv1.KubeVirtConfiguration) (*virtconfig.ClusterConfig, cache.SharedIndexInformer, cache.SharedIndexInformer) {
func NewFakeClusterConfigUsingKVConfig(config *KVv1.KubeVirtConfiguration) (*virtconfig.ClusterConfig, cache.SharedIndexInformer, cache.Store) {
kv := &KVv1.KubeVirt{
ObjectMeta: metav1.ObjectMeta{
Name: kvObjectName,
Expand Down Expand Up @@ -95,8 +95,8 @@ func AddDataVolumeAPI(crdInformer cache.SharedIndexInformer) {
})
}

func GetFakeKubeVirtClusterConfig(kubeVirtInformer cache.SharedIndexInformer) *KVv1.KubeVirt {
obj, _, _ := kubeVirtInformer.GetStore().GetByKey(kvObjectNamespace + "/" + kvObjectName)
func GetFakeKubeVirtClusterConfig(kubeVirtStore cache.Store) *KVv1.KubeVirt {
obj, _, _ := kubeVirtStore.GetByKey(kvObjectNamespace + "/" + kvObjectName)
return obj.(*KVv1.KubeVirt)

}
Expand Down
4 changes: 1 addition & 3 deletions pkg/util/tls/tls_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,7 @@ var _ = Describe("TLS", func() {
},
},
}
config, _, kubeVirtInformer := testutils.NewFakeClusterConfigUsingKV(kv)
clusterConfig = config
kubeVirtStore = kubeVirtInformer.GetStore()
clusterConfig, _, kubeVirtStore = testutils.NewFakeClusterConfigUsingKV(kv)
})

DescribeTable("on virt-handler with self-signed CA should", func(serverSecret, clientSecret string, errStr string) {
Expand Down
6 changes: 3 additions & 3 deletions pkg/virt-api/rest/profiler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ var _ = Describe("Cluster Profiler Subresources", func() {
},
}

config, _, kvInformer := testutils.NewFakeClusterConfigUsingKV(kv)
config, _, kvStore := testutils.NewFakeClusterConfigUsingKV(kv)

app := SubresourceAPIApp{}
BeforeEach(func() {
Expand All @@ -102,10 +102,10 @@ var _ = Describe("Cluster Profiler Subresources", func() {
enableFeatureGate := func(featureGate string) {
kvConfig := kv.DeepCopy()
kvConfig.Spec.Configuration.DeveloperConfiguration.FeatureGates = []string{featureGate}
testutils.UpdateFakeKubeVirtClusterConfig(kvInformer.GetStore(), kvConfig)
testutils.UpdateFakeKubeVirtClusterConfig(kvStore, kvConfig)
}
disableFeatureGates := func() {
testutils.UpdateFakeKubeVirtClusterConfig(kvInformer.GetStore(), kv)
testutils.UpdateFakeKubeVirtClusterConfig(kvStore, kv)
}

expectPodList := func() {
Expand Down
6 changes: 3 additions & 3 deletions pkg/virt-api/rest/subresource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ var _ = Describe("VirtualMachineInstance Subresources", func() {
},
}

config, _, kvInformer := testutils.NewFakeClusterConfigUsingKV(kv)
config, _, kvStore := testutils.NewFakeClusterConfigUsingKV(kv)

app := SubresourceAPIApp{}
BeforeEach(func() {
Expand Down Expand Up @@ -166,10 +166,10 @@ var _ = Describe("VirtualMachineInstance Subresources", func() {
enableFeatureGate := func(featureGate string) {
kvConfig := kv.DeepCopy()
kvConfig.Spec.Configuration.DeveloperConfiguration.FeatureGates = []string{featureGate}
testutils.UpdateFakeKubeVirtClusterConfig(kvInformer.GetStore(), kvConfig)
testutils.UpdateFakeKubeVirtClusterConfig(kvStore, kvConfig)
}
disableFeatureGates := func() {
testutils.UpdateFakeKubeVirtClusterConfig(kvInformer.GetStore(), kv)
testutils.UpdateFakeKubeVirtClusterConfig(kvStore, kv)
}

expectHandlerPod := func() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ import (

var _ = Describe("VirtualMachine Mutator", func() {
var vm *v1.VirtualMachine
var kvInformer cache.SharedIndexInformer
var kvStore cache.Store
var mutator *VMsMutator
var ctrl *gomock.Controller
var virtClient *kubecli.MockKubevirtClient
Expand Down Expand Up @@ -137,7 +137,7 @@ var _ = Describe("VirtualMachine Mutator", func() {
vm.Spec.Template = &v1.VirtualMachineInstanceTemplateSpec{}

mutator = &VMsMutator{}
mutator.ClusterConfig, _, kvInformer = testutils.NewFakeClusterConfigUsingKVConfig(&v1.KubeVirtConfiguration{})
mutator.ClusterConfig, _, kvStore = testutils.NewFakeClusterConfigUsingKVConfig(&v1.KubeVirtConfiguration{})

ctrl = gomock.NewController(GinkgoT())
virtClient = kubecli.NewMockKubevirtClient(ctrl)
Expand Down Expand Up @@ -179,7 +179,7 @@ var _ = Describe("VirtualMachine Mutator", func() {
})

DescribeTable("should apply configurable defaults on VM create", func(arch string, amd64MachineType string, arm64MachineType string, ppc64leMachineType string, s390xMachineType string, result string) {
testutils.UpdateFakeKubeVirtClusterConfig(kvInformer.GetStore(), &v1.KubeVirt{
testutils.UpdateFakeKubeVirtClusterConfig(kvStore, &v1.KubeVirt{
Spec: v1.KubeVirtSpec{
Configuration: v1.KubeVirtConfiguration{
ArchitectureConfiguration: &v1.ArchConfiguration{
Expand All @@ -202,7 +202,7 @@ var _ = Describe("VirtualMachine Mutator", func() {
)

It("should not override default architecture with defaults on VM create", func() {
testutils.UpdateFakeKubeVirtClusterConfig(kvInformer.GetStore(), &v1.KubeVirt{
testutils.UpdateFakeKubeVirtClusterConfig(kvStore, &v1.KubeVirt{
Status: v1.KubeVirtStatus{
DefaultArchitecture: "arm64",
},
Expand All @@ -214,7 +214,7 @@ var _ = Describe("VirtualMachine Mutator", func() {
})

It("should not override specified properties with defaults on VM create", func() {
testutils.UpdateFakeKubeVirtClusterConfig(kvInformer.GetStore(), &v1.KubeVirt{
testutils.UpdateFakeKubeVirtClusterConfig(kvStore, &v1.KubeVirt{
Spec: v1.KubeVirtSpec{
Configuration: v1.KubeVirtConfiguration{
MachineType: machineTypeFromConfig,
Expand Down Expand Up @@ -252,7 +252,7 @@ var _ = Describe("VirtualMachine Mutator", func() {
Kind: apiinstancetype.SingularPreferenceResourceName,
}

testutils.UpdateFakeKubeVirtClusterConfig(kvInformer.GetStore(), &v1.KubeVirt{
testutils.UpdateFakeKubeVirtClusterConfig(kvStore, &v1.KubeVirt{
Spec: v1.KubeVirtSpec{
Configuration: v1.KubeVirtConfiguration{
MachineType: machineTypeFromConfig,
Expand Down Expand Up @@ -287,7 +287,7 @@ var _ = Describe("VirtualMachine Mutator", func() {
Kind: apiinstancetype.SingularPreferenceResourceName,
}

testutils.UpdateFakeKubeVirtClusterConfig(kvInformer.GetStore(), &v1.KubeVirt{
testutils.UpdateFakeKubeVirtClusterConfig(kvStore, &v1.KubeVirt{
Spec: v1.KubeVirtSpec{
Configuration: v1.KubeVirtConfiguration{
MachineType: machineTypeFromConfig,
Expand All @@ -305,7 +305,7 @@ var _ = Describe("VirtualMachine Mutator", func() {
Kind: apiinstancetype.SingularPreferenceResourceName,
}

testutils.UpdateFakeKubeVirtClusterConfig(kvInformer.GetStore(), &v1.KubeVirt{
testutils.UpdateFakeKubeVirtClusterConfig(kvStore, &v1.KubeVirt{
Spec: v1.KubeVirtSpec{
Configuration: v1.KubeVirtConfiguration{
ArchitectureConfiguration: &v1.ArchConfiguration{
Expand Down
Loading

0 comments on commit 7bb0d27

Please sign in to comment.