@@ -961,3 +961,82 @@ func TestValidateURLs(t *testing.T) {
961
961
}
962
962
}
963
963
}
964
+
965
+ func TestValidateEtcd (t * testing.T ) {
966
+ var tests = []struct {
967
+ name string
968
+ etcd * kubeadm.Etcd
969
+ expectedErrors bool
970
+ }{
971
+ {
972
+ name : "either .Etcd.Local or .Etcd.External is required" ,
973
+ etcd : & kubeadm.Etcd {},
974
+ expectedErrors : true ,
975
+ },
976
+ {
977
+ name : ".Etcd.Local and .Etcd.External are mutually exclusive" ,
978
+ etcd : & kubeadm.Etcd {
979
+ Local : & kubeadm.LocalEtcd {
980
+ DataDir : "/some/path" ,
981
+ },
982
+ External : & kubeadm.ExternalEtcd {
983
+ Endpoints : []string {"10.100.0.1:2379" , "10.100.0.2:2379" },
984
+ },
985
+ },
986
+ expectedErrors : true ,
987
+ },
988
+ {
989
+ name : "either both or none of .Etcd.External.CertFile and .Etcd.External.KeyFile must be set" ,
990
+ etcd : & kubeadm.Etcd {
991
+ External : & kubeadm.ExternalEtcd {
992
+ Endpoints : []string {"https://external.etcd1:2379" , "https://external.etcd2:2379" },
993
+ CertFile : "/some/file.crt" ,
994
+ },
995
+ },
996
+ expectedErrors : true ,
997
+ },
998
+ {
999
+ name : "setting .Etcd.External.CertFile and .Etcd.External.KeyFile requires .Etcd.External.CAFile" ,
1000
+ etcd : & kubeadm.Etcd {
1001
+ External : & kubeadm.ExternalEtcd {
1002
+ Endpoints : []string {"https://external.etcd1:2379" , "https://external.etcd2:2379" },
1003
+ CertFile : "/some/file.crt" ,
1004
+ KeyFile : "/some/file.key" ,
1005
+ },
1006
+ },
1007
+ expectedErrors : true ,
1008
+ },
1009
+ {
1010
+ name : "valid external etcd" ,
1011
+ etcd : & kubeadm.Etcd {
1012
+ External : & kubeadm.ExternalEtcd {
1013
+ Endpoints : []string {"https://external.etcd1:2379" , "https://external.etcd2:2379" },
1014
+ CertFile : "/etcd.crt" ,
1015
+ KeyFile : "/etcd.key" ,
1016
+ CAFile : "/etcd-ca.crt" ,
1017
+ },
1018
+ },
1019
+ expectedErrors : false ,
1020
+ },
1021
+ {
1022
+ name : "valid external etcd (no TLS)" ,
1023
+ etcd : & kubeadm.Etcd {
1024
+ External : & kubeadm.ExternalEtcd {
1025
+ Endpoints : []string {"http://10.100.0.1:2379" , "http://10.100.0.2:2379" },
1026
+ },
1027
+ },
1028
+ expectedErrors : false ,
1029
+ },
1030
+ }
1031
+
1032
+ for _ , tc := range tests {
1033
+ actual := ValidateEtcd (tc .etcd , field .NewPath ("etcd" ))
1034
+ actualErrors := len (actual ) > 0
1035
+ if actualErrors != tc .expectedErrors {
1036
+ t .Errorf ("Error: \n \t expected: %t\n \t actual: %t" ,
1037
+ tc .expectedErrors ,
1038
+ actualErrors ,
1039
+ )
1040
+ }
1041
+ }
1042
+ }
0 commit comments