@@ -29,6 +29,7 @@ import (
29
29
30
30
kubeadmapi "k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm"
31
31
kubeadmapiv1 "k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm/v1beta3"
32
+ "k8s.io/kubernetes/cmd/kubeadm/app/features"
32
33
)
33
34
34
35
func TestValidateToken (t * testing.T ) {
@@ -805,82 +806,118 @@ func TestValidateIgnorePreflightErrors(t *testing.T) {
805
806
ignorePreflightErrorsFromConfigFile []string
806
807
expectedSet sets.Set [string ]
807
808
expectedError bool
809
+ mergeCLIArgumentsWithConfig bool
808
810
}{
811
+ // FG is off
809
812
{ // empty lists in CLI and config file
810
813
[]string {},
811
814
[]string {},
812
815
sets .New [string ](),
813
816
false ,
814
- },
815
- { // empty list in CLI only
816
- []string {},
817
- []string {"a" },
818
- sets .New ("a" ),
819
817
false ,
820
818
},
821
819
{ // empty list in config file only
822
820
[]string {"a" },
823
821
[]string {},
824
822
sets .New ("a" ),
825
823
false ,
824
+ false ,
826
825
},
827
826
{ // no duplicates, no overlap
828
827
[]string {"a" , "b" },
829
828
[]string {"c" , "d" },
830
- sets .New ("a" , "b" , "c" , "d" ),
829
+ sets .New ("a" , "b" ),
830
+ false ,
831
831
false ,
832
832
},
833
833
{ // some duplicates, with some overlapping duplicates
834
834
[]string {"a" , "b" , "a" },
835
835
[]string {"c" , "b" },
836
- sets .New ("a" , "b" , "c" ),
836
+ sets .New ("a" , "b" ),
837
+ false ,
837
838
false ,
838
839
},
839
- { // empty list in CLI , but 'all' present in config file
840
- [] string {} ,
840
+ { // CLI is not set , but 'all' present in config file
841
+ nil ,
841
842
[]string {"all" },
842
843
sets .New ("all" ),
843
844
false ,
845
+ false ,
844
846
},
845
847
{ // empty list in config file, but 'all' present in CLI
846
848
[]string {"all" },
847
849
[]string {},
848
850
sets .New ("all" ),
849
851
false ,
852
+ false ,
850
853
},
851
854
{ // some duplicates, only 'all' present in CLI and config file
852
855
[]string {"all" },
853
856
[]string {"all" },
854
857
sets .New ("all" ),
855
858
false ,
859
+ false ,
856
860
},
857
861
{ // non-duplicate, but 'all' present together with individual checks in CLI
858
862
[]string {"a" , "b" , "all" },
859
863
[]string {},
860
864
sets .New [string ](),
861
865
true ,
866
+ false ,
862
867
},
863
868
{ // non-duplicate, but 'all' present together with individual checks in config file
864
- [] string {} ,
869
+ nil ,
865
870
[]string {"a" , "b" , "all" },
866
871
sets .New [string ](),
867
872
true ,
873
+ false ,
868
874
},
869
- { // non-duplicate, but 'all' present in config file, while values are in CLI, which is forbidden
875
+ { // non-duplicate, but 'all' present in config file, while values are in CLI, "all" from config file will be ignored
870
876
[]string {"a" , "b" },
871
877
[]string {"all" },
872
- sets .New [string ](),
873
- true ,
878
+ sets .New [string ]("a" , "b" ),
879
+ false ,
880
+ false ,
874
881
},
875
- { // non-duplicate, but 'all' present in CLI, while values are in config file, which is forbidden
882
+ { // non-duplicate, but 'all' present in CLI, while values are in config file, values from config file will be ignored
876
883
[]string {"all" },
877
884
[]string {"a" , "b" },
885
+ sets.New [string ]("all" ),
886
+ false ,
887
+ false ,
888
+ },
889
+ { // set from CLI will take precedence of the config file
890
+ []string {"a" , "b" },
891
+ []string {"c" , "d" },
892
+ sets .New [string ]("a" , "b" ),
893
+ false ,
894
+ false ,
895
+ },
896
+ { // empty list in CLI only
897
+ []string {},
898
+ []string {"a" },
878
899
sets .New [string ](),
900
+ false ,
901
+ false ,
902
+ },
903
+ { // flag from CLI is not set
904
+ nil ,
905
+ []string {"c" , "d" },
906
+ sets .New [string ]("c" , "d" ),
907
+ false ,
908
+ false ,
909
+ },
910
+ // FG is on
911
+ {
912
+ []string {"a" , "b" },
913
+ []string {"c" , "d" },
914
+ sets .New [string ]("a" , "b" , "c" , "d" ),
915
+ false ,
879
916
true ,
880
917
},
881
918
}
882
919
for _ , rt := range tests {
883
- result , err := ValidateIgnorePreflightErrors (rt .ignorePreflightErrorsFromCLI , rt .ignorePreflightErrorsFromConfigFile )
920
+ result , err := ValidateIgnorePreflightErrors (map [ string ] bool { features . MergeCLIArgumentsWithConfig : rt . mergeCLIArgumentsWithConfig }, rt .ignorePreflightErrorsFromCLI , rt .ignorePreflightErrorsFromConfigFile )
884
921
switch {
885
922
case err != nil && ! rt .expectedError :
886
923
t .Errorf ("ValidateIgnorePreflightErrors: unexpected error for input (%s, %s), error: %v" , rt .ignorePreflightErrorsFromCLI , rt .ignorePreflightErrorsFromConfigFile , err )
0 commit comments