7
7
import io .fabric8 .kubernetes .api .model .HasMetadata ;
8
8
import io .javaoperatorsdk .operator .api .config .ConfigurationService ;
9
9
import io .javaoperatorsdk .operator .api .config .DefaultResourceConfiguration ;
10
+ import io .javaoperatorsdk .operator .api .reconciler .EventSourceContext ;
10
11
import io .javaoperatorsdk .operator .processing .event .ResourceID ;
11
12
import io .javaoperatorsdk .operator .processing .event .source .AssociatedSecondaryResourceIdentifier ;
12
13
import io .javaoperatorsdk .operator .processing .event .source .PrimaryResourcesRetriever ;
@@ -18,23 +19,7 @@ public class InformerConfiguration<R extends HasMetadata, P extends HasMetadata>
18
19
private final AssociatedSecondaryResourceIdentifier <P > associatedWith ;
19
20
private final boolean skipUpdateEventPropagationIfNoChange ;
20
21
21
- public InformerConfiguration (ConfigurationService service , String labelSelector ,
22
- Class <R > resourceClass , String ... namespaces ) {
23
- this (service , labelSelector , resourceClass , Mappers .fromOwnerReference (), null , true ,
24
- namespaces );
25
- }
26
-
27
- public InformerConfiguration (ConfigurationService service , String labelSelector ,
28
- Class <R > resourceClass ,
29
- PrimaryResourcesRetriever <R > secondaryToPrimaryResourcesIdSet ,
30
- AssociatedSecondaryResourceIdentifier <P > associatedWith ,
31
- boolean skipUpdateEventPropagationIfNoChange , String ... namespaces ) {
32
- this (service , labelSelector , resourceClass , secondaryToPrimaryResourcesIdSet , associatedWith ,
33
- skipUpdateEventPropagationIfNoChange ,
34
- namespaces != null ? Set .of (namespaces ) : Collections .emptySet ());
35
- }
36
-
37
- public InformerConfiguration (ConfigurationService service , String labelSelector ,
22
+ private InformerConfiguration (ConfigurationService service , String labelSelector ,
38
23
Class <R > resourceClass ,
39
24
PrimaryResourcesRetriever <R > secondaryToPrimaryResourcesIdSet ,
40
25
AssociatedSecondaryResourceIdentifier <P > associatedWith ,
@@ -59,4 +44,89 @@ public AssociatedSecondaryResourceIdentifier<P> getAssociatedResourceIdentifier(
59
44
public boolean isSkipUpdateEventPropagationIfNoChange () {
60
45
return skipUpdateEventPropagationIfNoChange ;
61
46
}
47
+
48
+ public static class InformerConfigurationBuilder <R extends HasMetadata , P extends HasMetadata > {
49
+
50
+ private PrimaryResourcesRetriever <R > secondaryToPrimaryResourcesIdSet ;
51
+ private AssociatedSecondaryResourceIdentifier <P > associatedWith ;
52
+ private boolean skipUpdateEventPropagationIfNoChange = true ;
53
+ private Set <String > namespaces ;
54
+ private String labelSelector ;
55
+ private final Class <R > resourceClass ;
56
+ private final ConfigurationService configurationService ;
57
+
58
+ private InformerConfigurationBuilder (Class <R > resourceClass ,
59
+ ConfigurationService configurationService ) {
60
+ this .resourceClass = resourceClass ;
61
+ this .configurationService = configurationService ;
62
+ }
63
+
64
+ public InformerConfigurationBuilder <R , P > withPrimaryResourcesRetriever (
65
+ PrimaryResourcesRetriever <R > primaryResourcesRetriever ) {
66
+ this .secondaryToPrimaryResourcesIdSet = primaryResourcesRetriever ;
67
+ return this ;
68
+ }
69
+
70
+ public InformerConfigurationBuilder <R , P > withAssociatedSecondaryResourceIdentifier (
71
+ AssociatedSecondaryResourceIdentifier <P > associatedWith ) {
72
+ this .associatedWith = associatedWith ;
73
+ return this ;
74
+ }
75
+
76
+ public InformerConfigurationBuilder <R , P > withoutSkippingEventPropagationIfUnchanged () {
77
+ this .skipUpdateEventPropagationIfNoChange = false ;
78
+ return this ;
79
+ }
80
+
81
+ public InformerConfigurationBuilder <R , P > skippingEventPropagationIfUnchanged (
82
+ boolean skipIfUnchanged ) {
83
+ this .skipUpdateEventPropagationIfNoChange = skipIfUnchanged ;
84
+ return this ;
85
+ }
86
+
87
+ public InformerConfigurationBuilder <R , P > withNamespaces (String ... namespaces ) {
88
+ this .namespaces = namespaces != null ? Set .of (namespaces ) : Collections .emptySet ();
89
+ return this ;
90
+ }
91
+
92
+ public InformerConfigurationBuilder <R , P > withNamespaces (Set <String > namespaces ) {
93
+ this .namespaces = namespaces != null ? namespaces : Collections .emptySet ();
94
+ return this ;
95
+ }
96
+
97
+
98
+ public InformerConfigurationBuilder <R , P > withLabelSelector (String labelSelector ) {
99
+ this .labelSelector = labelSelector ;
100
+ return this ;
101
+ }
102
+
103
+ public InformerConfiguration <R , P > build () {
104
+ return new InformerConfiguration <>(configurationService , labelSelector , resourceClass ,
105
+ secondaryToPrimaryResourcesIdSet , associatedWith , skipUpdateEventPropagationIfNoChange ,
106
+ namespaces );
107
+ }
108
+ }
109
+
110
+ public static <R extends HasMetadata , P extends HasMetadata > InformerConfigurationBuilder <R , P > from (
111
+ EventSourceContext <P > context , Class <R > resourceClass ) {
112
+ return new InformerConfigurationBuilder <>(resourceClass , context .getConfigurationService ());
113
+ }
114
+
115
+ public static InformerConfigurationBuilder from (ConfigurationService configurationService ,
116
+ Class resourceClass ) {
117
+ return new InformerConfigurationBuilder <>(resourceClass , configurationService );
118
+ }
119
+
120
+ public static <R extends HasMetadata , P extends HasMetadata > InformerConfigurationBuilder <R , P > from (
121
+ InformerConfiguration <R , P > configuration ) {
122
+ return new InformerConfigurationBuilder <R , P >(configuration .getResourceClass (),
123
+ configuration .getConfigurationService ())
124
+ .withNamespaces (configuration .getNamespaces ())
125
+ .withLabelSelector (configuration .getLabelSelector ())
126
+ .skippingEventPropagationIfUnchanged (
127
+ configuration .isSkipUpdateEventPropagationIfNoChange ())
128
+ .withAssociatedSecondaryResourceIdentifier (
129
+ configuration .getAssociatedResourceIdentifier ())
130
+ .withPrimaryResourcesRetriever (configuration .getPrimaryResourcesRetriever ());
131
+ }
62
132
}
0 commit comments