@@ -10,6 +10,7 @@ import (
10
10
"context"
11
11
"fmt"
12
12
"os"
13
+ "reflect"
13
14
"strings"
14
15
"time"
15
16
@@ -947,25 +948,41 @@ var _ = deploy.DescribeForSome("API", func(d *deploy.Deployment) bool {
947
948
Expect (alphaCR .Status ).Should (BeEquivalentTo (cr .Status ), "status mismatch" )
948
949
})
949
950
It ("with explicit values" , func () {
950
- alphaDep := getAlphaDeployment ("alpha-explicit-values" )
951
- alphaDep .Spec .NodeResources = & corev1.ResourceRequirements {
952
- Requests : corev1.ResourceList {
953
- corev1 .ResourceCPU : resource .MustParse ("10m" ),
954
- corev1 .ResourceMemory : resource .MustParse ("25Mi" ),
955
- },
956
- Limits : corev1.ResourceList {
957
- corev1 .ResourceCPU : resource .MustParse ("100m" ),
958
- corev1 .ResourceMemory : resource .MustParse ("50Mi" ),
959
- },
960
- }
961
- alphaDep .Spec .ControllerResources = & corev1.ResourceRequirements {
962
- Requests : corev1.ResourceList {
963
- corev1 .ResourceCPU : resource .MustParse ("20m" ),
964
- corev1 .ResourceMemory : resource .MustParse ("50Mi" ),
951
+ alphaDep := alphaapi.Deployment {
952
+ ObjectMeta : metav1.ObjectMeta {
953
+ Name : "explict-values" ,
965
954
},
966
- Limits : corev1.ResourceList {
967
- corev1 .ResourceCPU : resource .MustParse ("200m" ),
968
- corev1 .ResourceMemory : resource .MustParse ("100Mi" ),
955
+ Spec : alphaapi.DeploymentSpec {
956
+ Image : dummyImage ,
957
+ PullPolicy : corev1 .PullAlways ,
958
+ ProvisionerImage : "no-such-provisioner" ,
959
+ NodeRegistrarImage : "no-such-registrar" ,
960
+ NodeResources : & corev1.ResourceRequirements {
961
+ Requests : corev1.ResourceList {
962
+ corev1 .ResourceCPU : resource .MustParse ("10m" ),
963
+ corev1 .ResourceMemory : resource .MustParse ("25Mi" ),
964
+ },
965
+ Limits : corev1.ResourceList {
966
+ corev1 .ResourceCPU : resource .MustParse ("100m" ),
967
+ corev1 .ResourceMemory : resource .MustParse ("50Mi" ),
968
+ },
969
+ },
970
+ ControllerResources : & corev1.ResourceRequirements {
971
+ Requests : corev1.ResourceList {
972
+ corev1 .ResourceCPU : resource .MustParse ("20m" ),
973
+ corev1 .ResourceMemory : resource .MustParse ("50Mi" ),
974
+ },
975
+ Limits : corev1.ResourceList {
976
+ corev1 .ResourceCPU : resource .MustParse ("200m" ),
977
+ corev1 .ResourceMemory : resource .MustParse ("100Mi" ),
978
+ },
979
+ },
980
+ DeviceMode : alphaapi .DeviceModeDirect ,
981
+ LogLevel : 5 ,
982
+ NodeSelector : map [string ]string {"no-such-label" : "no-such-key" },
983
+ PMEMPercentage : 99 ,
984
+ Labels : map [string ]string {"app" : "explicit" },
985
+ KubeletDir : "/tmp" ,
969
986
},
970
987
}
971
988
deploy .CreateAlphaDeploymentCR (f , alphaDep )
@@ -985,14 +1002,32 @@ var _ = deploy.DescribeForSome("API", func(d *deploy.Deployment) bool {
985
1002
986
1003
defer deploy .DeleteDeploymentCR (f , deployment .Name )
987
1004
988
- validateDriver ( deployment , true )
989
-
990
- // Expect to ruturn alpha object converting from stored beta CR
1005
+ // Expect the same spec to be returned for the
1006
+ // stored CR, regardless of the version that
1007
+ // is used to retrieve it.
991
1008
alphaCR := deploy .GetAlphaDeploymentCR (f , deployment .Name )
992
- betaCR := deploy .GetDeploymentCR (f , deployment .Name )
1009
+ cr := deploy .GetDeploymentCR (f , deployment .Name )
993
1010
Expect (alphaCR ).ShouldNot (BeNil (), "get alpha CR" )
994
1011
Expect (alphaCR .Spec ).Should (BeEquivalentTo (alphaDep .Spec ), "alpha CR spec mismatch" )
995
- Expect (alphaCR .Status ).Should (BeEquivalentTo (betaCR .Status ), "alpha CR status mismatch" )
1012
+ Expect (alphaCR .Status ).Should (BeEquivalentTo (cr .Status ), "status mismatch" )
1013
+
1014
+ // We can also compare the full spec by iterating over all fields. Those that have no match
1015
+ // must be blanked out first.
1016
+ // BeEquivalentTo cannot be used here because the structs cannot be converted into each other.
1017
+ alphaDep .Spec .NodeResources = nil
1018
+ alphaDep .Spec .ControllerResources = nil
1019
+ alphaV := reflect .ValueOf (alphaDep .Spec )
1020
+ alphaType := reflect .TypeOf (alphaDep .Spec )
1021
+ v := reflect .ValueOf (cr .Spec )
1022
+ for i := 0 ; i < alphaType .NumField (); i ++ {
1023
+ name := alphaType .Field (i ).Name
1024
+ actual := v .FieldByName (name )
1025
+ if actual .Kind () == reflect .Invalid {
1026
+ // Zero value, ignore the field.
1027
+ continue
1028
+ }
1029
+ Expect (actual .Interface ()).Should (BeEquivalentTo (alphaV .FieldByName (name ).Interface ()), "current CR field %s mismatch" , name )
1030
+ }
996
1031
})
997
1032
})
998
1033
})
0 commit comments