1+ use k8s_openapi:: { DeepMerge , merge_strategies} ;
2+
13use crate :: crd:: listener:: listeners:: v1alpha1:: {
24 Listener , ListenerIngress , ListenerPort , ListenerSpec , ListenerStatus ,
35} ;
@@ -8,87 +10,139 @@ impl ListenerSpec {
810 }
911}
1012
11- impl k8s_openapi :: DeepMerge for Listener {
13+ impl DeepMerge for Listener {
1214 fn merge_from ( & mut self , other : Self ) {
13- k8s_openapi :: DeepMerge :: merge_from ( & mut self . metadata , other. metadata ) ;
14- k8s_openapi :: DeepMerge :: merge_from ( & mut self . spec , other. spec ) ;
15- k8s_openapi :: DeepMerge :: merge_from ( & mut self . status , other. status ) ;
15+ DeepMerge :: merge_from ( & mut self . metadata , other. metadata ) ;
16+ DeepMerge :: merge_from ( & mut self . spec , other. spec ) ;
17+ DeepMerge :: merge_from ( & mut self . status , other. status ) ;
1618 }
1719}
1820
19- impl k8s_openapi :: DeepMerge for ListenerSpec {
21+ impl DeepMerge for ListenerSpec {
2022 fn merge_from ( & mut self , other : Self ) {
21- k8s_openapi :: DeepMerge :: merge_from ( & mut self . class_name , other. class_name ) ;
22- k8s_openapi :: merge_strategies:: map:: granular (
23+ DeepMerge :: merge_from ( & mut self . class_name , other. class_name ) ;
24+ merge_strategies:: map:: granular (
2325 & mut self . extra_pod_selector_labels ,
2426 other. extra_pod_selector_labels ,
2527 |current_item, other_item| {
26- k8s_openapi :: DeepMerge :: merge_from ( current_item, other_item) ;
28+ DeepMerge :: merge_from ( current_item, other_item) ;
2729 } ,
2830 ) ;
29- k8s_openapi :: merge_strategies:: list:: map (
31+ merge_strategies:: list:: map (
3032 & mut self . ports ,
3133 other. ports ,
3234 & [ |lhs, rhs| lhs. name == rhs. name ] ,
3335 |current_item, other_item| {
34- k8s_openapi :: DeepMerge :: merge_from ( current_item, other_item) ;
36+ DeepMerge :: merge_from ( current_item, other_item) ;
3537 } ,
3638 ) ;
37- k8s_openapi :: DeepMerge :: merge_from (
39+ DeepMerge :: merge_from (
3840 & mut self . publish_not_ready_addresses ,
3941 other. publish_not_ready_addresses ,
4042 ) ;
41- todo ! ( )
4243 }
4344}
4445
45- impl k8s_openapi :: DeepMerge for ListenerStatus {
46+ impl DeepMerge for ListenerStatus {
4647 fn merge_from ( & mut self , other : Self ) {
47- k8s_openapi :: DeepMerge :: merge_from ( & mut self . service_name , other. service_name ) ;
48- k8s_openapi :: merge_strategies:: list:: map (
48+ DeepMerge :: merge_from ( & mut self . service_name , other. service_name ) ;
49+ merge_strategies:: list:: map (
4950 & mut self . ingress_addresses ,
5051 other. ingress_addresses ,
5152 & [ |lhs, rhs| lhs. address == rhs. address ] ,
5253 |current_item, other_item| {
53- k8s_openapi :: DeepMerge :: merge_from ( current_item, other_item) ;
54+ DeepMerge :: merge_from ( current_item, other_item) ;
5455 } ,
5556 ) ;
56- k8s_openapi :: merge_strategies:: map:: granular (
57+ merge_strategies:: map:: granular (
5758 & mut self . node_ports ,
5859 other. node_ports ,
5960 |current_item, other_item| {
60- k8s_openapi :: DeepMerge :: merge_from ( current_item, other_item) ;
61+ DeepMerge :: merge_from ( current_item, other_item) ;
6162 } ,
6263 ) ;
6364 }
6465}
6566
66- impl k8s_openapi :: DeepMerge for ListenerIngress {
67+ impl DeepMerge for ListenerIngress {
6768 fn merge_from ( & mut self , other : Self ) {
68- k8s_openapi :: DeepMerge :: merge_from ( & mut self . address , other. address ) ;
69+ DeepMerge :: merge_from ( & mut self . address , other. address ) ;
6970 self . address_type = other. address_type ;
70- k8s_openapi :: merge_strategies:: map:: granular (
71+ merge_strategies:: map:: granular (
7172 & mut self . ports ,
7273 other. ports ,
7374 |current_item, other_item| {
74- k8s_openapi :: DeepMerge :: merge_from ( current_item, other_item) ;
75+ DeepMerge :: merge_from ( current_item, other_item) ;
7576 } ,
7677 ) ;
7778 }
7879}
7980
80- impl k8s_openapi :: DeepMerge for ListenerPort {
81+ impl DeepMerge for ListenerPort {
8182 fn merge_from ( & mut self , other : Self ) {
82- k8s_openapi :: DeepMerge :: merge_from ( & mut self . name , other. name ) ;
83- k8s_openapi :: DeepMerge :: merge_from ( & mut self . port , other. port ) ;
84- k8s_openapi :: DeepMerge :: merge_from ( & mut self . protocol , other. protocol ) ;
83+ DeepMerge :: merge_from ( & mut self . name , other. name ) ;
84+ DeepMerge :: merge_from ( & mut self . port , other. port ) ;
85+ DeepMerge :: merge_from ( & mut self . protocol , other. protocol ) ;
8586 }
8687}
8788
8889#[ cfg( test) ]
8990mod tests {
91+ use super :: * ;
92+
9093 #[ test]
9194 fn deep_merge_listener ( ) {
92- todo ! ( "Add some basic tests for merging" ) ;
95+ let mut base: ListenerSpec = serde_yaml:: from_str (
96+ "
97+ className: my-listener-class
98+ extraPodSelectorLabels:
99+ foo: bar
100+ ports:
101+ - name: http
102+ port: 8080
103+ protocol: http
104+ - name: https
105+ port: 8080
106+ protocol: https
107+ # publishNotReadyAddresses defaults to true
108+ " ,
109+ )
110+ . unwrap ( ) ;
111+
112+ let patch: ListenerSpec = serde_yaml:: from_str (
113+ "
114+ className: custom-listener-class
115+ extraPodSelectorLabels:
116+ foo: overridden
117+ extra: label
118+ ports:
119+ - name: https
120+ port: 8443
121+ publishNotReadyAddresses: false
122+ " ,
123+ )
124+ . unwrap ( ) ;
125+
126+ base. merge_from ( patch) ;
127+
128+ let expected: ListenerSpec = serde_yaml:: from_str (
129+ "
130+ className: custom-listener-class
131+ extraPodSelectorLabels:
132+ foo: overridden
133+ extra: label
134+ ports:
135+ - name: http
136+ port: 8080
137+ protocol: http
138+ - name: https
139+ port: 8443 # overridden
140+ protocol: https
141+ publishNotReadyAddresses: false
142+ " ,
143+ )
144+ . unwrap ( ) ;
145+
146+ assert_eq ! ( base, expected) ;
93147 }
94148}
0 commit comments