@@ -19,9 +19,55 @@ func NewManager() *Manager {
19
19
return & Manager {}
20
20
}
21
21
22
+ // ExcludeInvalidItems Verify whether clusterNodes and clusters are valid and give instructions
23
+ func ExcludeInvalidItems (clusters []v1alpha1.Cluster , clusterNodes []v1alpha1.ClusterNode ) (cs []v1alpha1.Cluster , cns []v1alpha1.ClusterNode ) {
24
+ klog .Infof ("Start verifying clusterNodes and clusters" )
25
+ clustersMap := map [string ]v1alpha1.Cluster {}
26
+ for _ , c := range clusters {
27
+ if c .Spec .ClusterLinkOptions == nil {
28
+ klog .Infof ("the cluster %s's ClusterLinkOptions is empty, will exclude." , c .Name )
29
+ continue
30
+ }
31
+ clustersMap [c .Name ] = c
32
+ cs = append (cs , c )
33
+ }
34
+
35
+ for _ , cn := range clusterNodes {
36
+ if len (cn .Spec .ClusterName ) == 0 {
37
+ klog .Infof ("the clusterNode %s's clusterName is empty, will exclude." , cn .Name )
38
+ continue
39
+ }
40
+ if len (cn .Spec .InterfaceName ) == 0 {
41
+ klog .Infof ("the clusterNode %s's interfaceName is empty, will exclude." , cn .Name )
42
+ continue
43
+ }
44
+
45
+ if _ , ok := clustersMap [cn .Spec .ClusterName ]; ! ok {
46
+ klog .Infof ("the cluster which clusterNode %s belongs to does not exist, or the cluster lacks the spec.clusterLinkOptions configuration." , cn .Name )
47
+ continue
48
+ }
49
+
50
+ c := clustersMap [cn .Spec .ClusterName ]
51
+ supportIPv4 := c .Spec .ClusterLinkOptions .IPFamily == v1alpha1 .IPFamilyTypeALL || c .Spec .ClusterLinkOptions .IPFamily == v1alpha1 .IPFamilyTypeIPV4
52
+ supportIPv6 := c .Spec .ClusterLinkOptions .IPFamily == v1alpha1 .IPFamilyTypeALL || c .Spec .ClusterLinkOptions .IPFamily == v1alpha1 .IPFamilyTypeIPV6
53
+ if supportIPv4 && len (cn .Spec .IP ) == 0 {
54
+ klog .Infof ("the clusterNode %s's ip is empty, but cluster's ipFamily is %s" , cn .Name , c .Spec .ClusterLinkOptions .IPFamily )
55
+ continue
56
+ }
57
+ if supportIPv6 && len (cn .Spec .IP6 ) == 0 {
58
+ klog .Infof ("the clusterNode %s's ip6 is empty, but cluster's ipFamily is %s" , cn .Name , c .Spec .ClusterLinkOptions .IPFamily )
59
+ continue
60
+ }
61
+
62
+ cns = append (cns , cn )
63
+ }
64
+ return
65
+ }
66
+
22
67
// CalculateNetworkConfigs Calculate the network configuration required for each node
23
68
func (n * Manager ) CalculateNetworkConfigs (clusters []v1alpha1.Cluster , clusterNodes []v1alpha1.ClusterNode , nodeConfigs []v1alpha1.NodeConfig ) (map [string ]* handlers.NodeConfig , error ) {
24
- filter := helpers .NewFilter (clusterNodes , clusters , nodeConfigs )
69
+ cs , cns := ExcludeInvalidItems (clusters , clusterNodes )
70
+ filter := helpers .NewFilter (cs , cns , nodeConfigs )
25
71
26
72
c := & handlers.Context {
27
73
Filter : filter ,
0 commit comments