Skip to content

Commit 8d0f823

Browse files
shawkinsmanusa
authored andcommitted
fix #3275: filterable should not modify the current context
this introduces a builder for near backwards compatibility
1 parent f7c8469 commit 8d0f823

File tree

14 files changed

+316
-304
lines changed

14 files changed

+316
-304
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/**
2+
* Copyright (C) 2015 Red Hat, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package io.fabric8.kubernetes.client.dsl;
18+
19+
import io.fabric8.kubernetes.api.builder.Builder;
20+
21+
public interface FilterBuilder<T> extends Filterable<FilterBuilder<T>>, Builder<T> {
22+
23+
}

kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/FilterWatchListDeletable.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,11 @@
1616
package io.fabric8.kubernetes.client.dsl;
1717

1818
public interface FilterWatchListDeletable<T, L> extends Filterable<FilterWatchListDeletable<T, L>>, WatchListDeletable<T, L> {
19+
20+
/**
21+
* Accumulate a filter on the context, when done {@link FilterBuilder#build()} must be called
22+
* @return a filter builder
23+
*/
24+
FilterBuilder<FilterWatchListDeletable<T, L>> withFilter();
1925

2026
}

kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/Filterable.java

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,21 @@
2020

2121
import java.util.Map;
2222

23+
/**
24+
* Each filter method applies in an additive way to the previous filter state.
25+
* @param <T>
26+
*/
2327
public interface Filterable<T> {
2428

2529
T withLabels(Map<String, String> labels);
2630

31+
/**
32+
* @deprecated as the underlying implementation does not align with the arguments anymore.
33+
* It is possible to negate multiple values with the same key, e.g.:
34+
* foo != bar , foo != baz
35+
* To support this a multi-value map is needed, as a regular map would override the key with the new value.
36+
*/
37+
@Deprecated
2738
T withoutLabels(Map<String, String> labels);
2839

2940
T withLabelIn(String key, String ... values);
@@ -32,16 +43,29 @@ public interface Filterable<T> {
3243

3344
T withLabel(String key, String value);
3445

35-
T withLabel(String key);
46+
default T withLabel(String key) {
47+
return withLabel(key, null);
48+
}
3649

3750
T withoutLabel(String key, String value);
3851

39-
T withoutLabel(String key);
52+
default T withoutLabel(String key) {
53+
return withoutLabel(key, null);
54+
}
4055

41-
T withFields(Map<String, String> labels);
56+
T withFields(Map<String, String> fields);
4257

4358
T withField(String key, String value);
4459

60+
/**
61+
* @deprecated as the underlying implementation does not align with the arguments fully.
62+
* Method is created to have a similar API as `withoutLabels`, but should eventually be replaced
63+
* with something better for the same reasons.
64+
* It is possible to negate multiple values with the same key, e.g.:
65+
* foo != bar , foo != baz
66+
* To support this a multi-value map is needed, as a regular map would override the key with the new value.
67+
*/
68+
@Deprecated
4569
T withoutFields(Map<String, String> fields);
4670

4771
T withoutField(String key, String value);

0 commit comments

Comments
 (0)