2727
2828use std:: collections:: BTreeMap ;
2929
30- use derivative:: Derivative ;
3130use kube:: CustomResource ;
3231use schemars:: JsonSchema ;
3332use serde:: { Deserialize , Serialize } ;
@@ -56,6 +55,20 @@ pub struct ListenerClassSpec {
5655 /// Annotations that should be added to the Service object.
5756 #[ serde( default ) ]
5857 pub service_annotations : BTreeMap < String , String > ,
58+
59+ /// `externalTrafficPolicy` that should be set on the created [`Service`] objects.
60+ ///
61+ /// The default is `Local` (in contrast to `Cluster`), as we aim to direct traffic to a node running the workload
62+ /// and we should keep testing that as the primary configuration. Cluster is a fallback option for providers that
63+ /// break Local mode (IONOS so far).
64+ #[ serde( default = "ListenerClassSpec::default_service_external_traffic_policy" ) ]
65+ pub service_external_traffic_policy : KubernetesTrafficPolicy ,
66+ }
67+
68+ impl ListenerClassSpec {
69+ const fn default_service_external_traffic_policy ( ) -> KubernetesTrafficPolicy {
70+ KubernetesTrafficPolicy :: Local
71+ }
5972}
6073
6174/// The method used to access the services.
@@ -100,9 +113,8 @@ pub enum KubernetesTrafficPolicy {
100113///
101114/// Learn more in the [Listener documentation](DOCS_BASE_URL_PLACEHOLDER/listener-operator/listener).
102115#[ derive(
103- CustomResource , Serialize , Deserialize , Clone , Debug , JsonSchema , PartialEq , Eq , Derivative ,
116+ CustomResource , Serialize , Deserialize , Default , Clone , Debug , JsonSchema , PartialEq , Eq ,
104117) ]
105- #[ derivative( Default ) ]
106118#[ kube(
107119 group = "listeners.stackable.tech" ,
108120 version = "v1alpha1" ,
@@ -125,25 +137,12 @@ pub struct ListenerSpec {
125137 /// Whether incoming traffic should also be directed to Pods that are not `Ready`.
126138 #[ serde( default = "ListenerSpec::default_publish_not_ready_addresses" ) ]
127139 pub publish_not_ready_addresses : Option < bool > ,
128-
129- /// `externalTrafficPolicy` that should be set on the [`Service`] object.
130- ///
131- /// The default is `Local` (in contrast to `Cluster`), as we aim to direct traffic to a node running the workload
132- /// and we should keep testing that as the primary configuration. Cluster is a fallback option for providers that
133- /// break Local mode (IONOS so far).
134- #[ derivative( Default ( value = "ListenerSpec::default_service_external_traffic_policy()" ) ) ]
135- #[ serde( default = "ListenerSpec::default_service_external_traffic_policy" ) ]
136- pub service_external_traffic_policy : KubernetesTrafficPolicy ,
137140}
138141
139142impl ListenerSpec {
140143 const fn default_publish_not_ready_addresses ( ) -> Option < bool > {
141144 Some ( true )
142145 }
143-
144- const fn default_service_external_traffic_policy ( ) -> KubernetesTrafficPolicy {
145- KubernetesTrafficPolicy :: Local
146- }
147146}
148147
149148#[ derive( Serialize , Deserialize , Clone , Debug , JsonSchema , PartialEq , Eq ) ]
0 commit comments