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