Skip to content

Commit

Permalink
Merge branch 'master' into wait
Browse files Browse the repository at this point in the history
  • Loading branch information
shawkins authored Jun 28, 2021
2 parents 7498c51 + bde7b96 commit 967bf19
Show file tree
Hide file tree
Showing 9 changed files with 271 additions and 80 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
* Fix #3225: Pod metric does not have corresponding label selector variant
* Fix #3243: pipes provided to exec command are no longer closed on connection close, so that client can fully read the buffer after the command finishes.
* Fix #3271: waitUntilReady and waitUntilCondition should handle resource too old
* Fix #3272: prevent index npe after informer sees an empty list

#### Improvements
* Fix #3078: adding javadocs to further clarify patch, edit, replace, etc. and note the possibility of items being modified.
Expand Down Expand Up @@ -50,6 +51,8 @@
* Add DSL support for OpenShift Whereabouts CNI Model `whereabouts.cni.cncf.io` to OpenShiftClient DSL
* Add DSL support for OpenShift Kube Storage Version Migrator resources in OpenShiftClient DSL
* Fix #3228: Add support for Dynamic informers for custom resources in KubernetesClient
* Add DSL support for ClusterInterceptors to TektonClient


#### _**Note**_: Breaking changes in the API
##### DSL Changes:
Expand Down
118 changes: 59 additions & 59 deletions README.md

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,7 @@
import io.fabric8.kubernetes.client.dsl.Resource;
import io.fabric8.tekton.client.dsl.V1alpha1APIGroupDSL;
import io.fabric8.tekton.client.internal.v1alpha1.*;
import io.fabric8.tekton.pipeline.v1alpha1.ClusterTask;
import io.fabric8.tekton.pipeline.v1alpha1.ClusterTaskList;
import io.fabric8.tekton.pipeline.v1alpha1.Condition;
import io.fabric8.tekton.pipeline.v1alpha1.ConditionList;
import io.fabric8.tekton.pipeline.v1alpha1.Pipeline;
import io.fabric8.tekton.pipeline.v1alpha1.PipelineList;
import io.fabric8.tekton.pipeline.v1alpha1.PipelineRun;
import io.fabric8.tekton.pipeline.v1alpha1.PipelineRunList;
import io.fabric8.tekton.pipeline.v1alpha1.Task;
import io.fabric8.tekton.pipeline.v1alpha1.TaskList;
import io.fabric8.tekton.pipeline.v1alpha1.TaskRun;
import io.fabric8.tekton.pipeline.v1alpha1.TaskRunList;
import io.fabric8.tekton.pipeline.v1alpha1.*;
import io.fabric8.tekton.resource.v1alpha1.PipelineResource;
import io.fabric8.tekton.resource.v1alpha1.PipelineResourceList;
import io.fabric8.tekton.triggers.v1alpha1.*;
Expand Down Expand Up @@ -107,4 +96,9 @@ public NonNamespaceOperation<ClusterTask, ClusterTaskList, Resource<ClusterTask>
public NonNamespaceOperation<ClusterTriggerBinding, ClusterTriggerBindingList, Resource<ClusterTriggerBinding>> clusterTriggerBindings() {
return new ClusterTriggerBindingOperationsImpl(this.getHttpClient(),this.getConfiguration());
}

@Override
public NonNamespaceOperation<ClusterInterceptor, ClusterInterceptorList, Resource<ClusterInterceptor>> clusterInterceptors() {
return new ClusterInterceptorOperationsImpl(this.getHttpClient(), this.getConfiguration());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -119,4 +119,11 @@ public interface V1alpha1APIGroupDSL extends Client {
* @return MixedOperation for ClusterTriggerBinding class
*/
NonNamespaceOperation<ClusterTriggerBinding, ClusterTriggerBindingList, Resource<ClusterTriggerBinding>> clusterTriggerBindings();

/**
* API entrypoint for ClusterInterceptor(triggers.tekton.dev/v1alpha1)
*
* @return MixedOperation for ClusterInterceptor class
*/
NonNamespaceOperation<ClusterInterceptor, ClusterInterceptorList, Resource<ClusterInterceptor>> clusterInterceptors();
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ func main() {
reflect.TypeOf(triggers.TriggerBindingList{}): schemagen.Namespaced,
reflect.TypeOf(triggers.EventListenerList{}): schemagen.Namespaced,
reflect.TypeOf(triggers.ClusterTriggerBindingList{}): schemagen.Cluster,
reflect.TypeOf(triggers.ClusterInterceptorList{}): schemagen.Cluster,
}

// constraints and patterns for fields
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public TektonTriggersResourceMappingProvider() {
mappings.put("triggers.tekton.dev/v1alpha1#EventListener", io.fabric8.tekton.triggers.v1alpha1.EventListener.class);
mappings.put("triggers.tekton.dev/v1alpha1#ClusterTriggerBinding", io.fabric8.tekton.triggers.v1alpha1.ClusterTriggerBinding.class);
mappings.put("triggers.tekton.dev/v1alpha1#Trigger", io.fabric8.tekton.triggers.v1alpha1.Trigger.class);
mappings.put("triggers.tekton.dev/v1alpha1#ClusterInterceptor", io.fabric8.tekton.triggers.v1alpha1.ClusterInterceptor.class);
}

public Map<String, Class<? extends KubernetesResource>> getMappings() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,124 @@
"io.fabric8.kubernetes.api.model.KubernetesResource"
]
},
"github_com_tektoncd_triggers_pkg_apis_triggers_v1alpha1_ClientConfig": {
"type": "object",
"properties": {
"service": {
"$ref": "#/definitions/github_com_tektoncd_triggers_pkg_apis_triggers_v1alpha1_ServiceReference",
"existingJavaType": "io.fabric8.tekton.triggers.v1alpha1.ServiceReference"
},
"url": {
"existingJavaType": "java.lang.String"
}
},
"javaType": "io.fabric8.tekton.triggers.v1alpha1.ClientConfig",
"javaInterfaces": [
"io.fabric8.kubernetes.api.model.KubernetesResource"
]
},
"github_com_tektoncd_triggers_pkg_apis_triggers_v1alpha1_ClusterInterceptor": {
"type": "object",
"properties": {
"apiVersion": {
"type": "string",
"default": "triggers.tekton.dev/v1alpha1",
"required": true
},
"kind": {
"type": "string",
"default": "ClusterInterceptor",
"required": true
},
"metadata": {
"existingJavaType": "io.fabric8.kubernetes.api.model.ObjectMeta"
},
"spec": {
"$ref": "#/definitions/github_com_tektoncd_triggers_pkg_apis_triggers_v1alpha1_ClusterInterceptorSpec",
"existingJavaType": "io.fabric8.tekton.triggers.v1alpha1.ClusterInterceptorSpec"
},
"status": {
"$ref": "#/definitions/github_com_tektoncd_triggers_pkg_apis_triggers_v1alpha1_ClusterInterceptorStatus",
"existingJavaType": "io.fabric8.tekton.triggers.v1alpha1.ClusterInterceptorStatus"
}
},
"javaType": "io.fabric8.tekton.triggers.v1alpha1.ClusterInterceptor",
"javaInterfaces": [
"io.fabric8.kubernetes.api.model.HasMetadata"
]
},
"github_com_tektoncd_triggers_pkg_apis_triggers_v1alpha1_ClusterInterceptorList": {
"type": "object",
"properties": {
"apiVersion": {
"type": "string",
"default": "triggers.tekton.dev/v1alpha1",
"required": true
},
"items": {
"type": "array",
"items": {
"$ref": "#/definitions/github_com_tektoncd_triggers_pkg_apis_triggers_v1alpha1_ClusterInterceptor",
"existingJavaType": "io.fabric8.tekton.triggers.v1alpha1.ClusterInterceptor"
}
},
"kind": {
"type": "string",
"default": "ClusterInterceptorList",
"required": true
},
"metadata": {
"existingJavaType": "io.fabric8.kubernetes.api.model.ListMeta"
}
},
"javaType": "io.fabric8.tekton.triggers.v1alpha1.ClusterInterceptorList",
"javaInterfaces": [
"io.fabric8.kubernetes.api.model.KubernetesResource",
"io.fabric8.kubernetes.api.model.KubernetesResourceList\u003cio.fabric8.tekton.triggers.v1alpha1.ClusterInterceptor\u003e"
]
},
"github_com_tektoncd_triggers_pkg_apis_triggers_v1alpha1_ClusterInterceptorSpec": {
"type": "object",
"properties": {
"clientConfig": {
"$ref": "#/definitions/github_com_tektoncd_triggers_pkg_apis_triggers_v1alpha1_ClientConfig",
"existingJavaType": "io.fabric8.tekton.triggers.v1alpha1.ClientConfig"
}
},
"javaType": "io.fabric8.tekton.triggers.v1alpha1.ClusterInterceptorSpec",
"javaInterfaces": [
"io.fabric8.kubernetes.api.model.KubernetesResource"
]
},
"github_com_tektoncd_triggers_pkg_apis_triggers_v1alpha1_ClusterInterceptorStatus": {
"type": "object",
"properties": {
"address": {
"$ref": "#/definitions/knative_dev_pkg_apis_duck_v1_Addressable",
"existingJavaType": "io.fabric8.tekton.triggers.internal.knative.pkg.apis.duck.v1.Addressable"
},
"annotations": {
"type": "object",
"existingJavaType": "java.util.Map\u003cString,String\u003e"
},
"conditions": {
"type": "array",
"javaOmitEmpty": true,
"items": {
"$ref": "#/definitions/knative_dev_pkg_apis_Condition",
"existingJavaType": "io.fabric8.tekton.triggers.internal.knative.pkg.apis.Condition"
}
},
"observedGeneration": {
"type": "integer",
"existingJavaType": "Long"
}
},
"javaType": "io.fabric8.tekton.triggers.v1alpha1.ClusterInterceptorStatus",
"javaInterfaces": [
"io.fabric8.kubernetes.api.model.KubernetesResource"
]
},
"github_com_tektoncd_triggers_pkg_apis_triggers_v1alpha1_ClusterTriggerBinding": {
"type": "object",
"properties": {
Expand Down Expand Up @@ -496,6 +614,28 @@
"io.fabric8.kubernetes.api.model.KubernetesResource"
]
},
"github_com_tektoncd_triggers_pkg_apis_triggers_v1alpha1_ServiceReference": {
"type": "object",
"properties": {
"name": {
"type": "string"
},
"namespace": {
"type": "string"
},
"path": {
"type": "string"
},
"port": {
"type": "integer",
"existingJavaType": "Integer"
}
},
"javaType": "io.fabric8.tekton.triggers.v1alpha1.ServiceReference",
"javaInterfaces": [
"io.fabric8.kubernetes.api.model.KubernetesResource"
]
},
"github_com_tektoncd_triggers_pkg_apis_triggers_v1alpha1_Trigger": {
"type": "object",
"properties": {
Expand Down Expand Up @@ -908,6 +1048,18 @@
"io.fabric8.kubernetes.api.model.KubernetesResource"
]
},
"knative_dev_pkg_apis_duck_v1_Addressable": {
"type": "object",
"properties": {
"url": {
"existingJavaType": "java.lang.String"
}
},
"javaType": "io.fabric8.tekton.triggers.internal.knative.pkg.apis.duck.v1.Addressable",
"javaInterfaces": [
"io.fabric8.kubernetes.api.model.KubernetesResource"
]
},
"knative_dev_pkg_apis_duck_v1_PodSpecable": {
"type": "object",
"properties": {
Expand Down Expand Up @@ -966,6 +1118,26 @@
"$ref": "#/definitions/github_com_tektoncd_triggers_pkg_apis_triggers_v1alpha1_CELOverlay",
"existingJavaType": "io.fabric8.tekton.triggers.v1alpha1.CELOverlay"
},
"github_com_tektoncd_triggers_pkg_apis_triggers_v1alpha1_ClientConfig": {
"$ref": "#/definitions/github_com_tektoncd_triggers_pkg_apis_triggers_v1alpha1_ClientConfig",
"existingJavaType": "io.fabric8.tekton.triggers.v1alpha1.ClientConfig"
},
"github_com_tektoncd_triggers_pkg_apis_triggers_v1alpha1_ClusterInterceptor": {
"$ref": "#/definitions/github_com_tektoncd_triggers_pkg_apis_triggers_v1alpha1_ClusterInterceptor",
"existingJavaType": "io.fabric8.tekton.triggers.v1alpha1.ClusterInterceptor"
},
"github_com_tektoncd_triggers_pkg_apis_triggers_v1alpha1_ClusterInterceptorList": {
"$ref": "#/definitions/github_com_tektoncd_triggers_pkg_apis_triggers_v1alpha1_ClusterInterceptorList",
"existingJavaType": "io.fabric8.tekton.triggers.v1alpha1.ClusterInterceptorList"
},
"github_com_tektoncd_triggers_pkg_apis_triggers_v1alpha1_ClusterInterceptorSpec": {
"$ref": "#/definitions/github_com_tektoncd_triggers_pkg_apis_triggers_v1alpha1_ClusterInterceptorSpec",
"existingJavaType": "io.fabric8.tekton.triggers.v1alpha1.ClusterInterceptorSpec"
},
"github_com_tektoncd_triggers_pkg_apis_triggers_v1alpha1_ClusterInterceptorStatus": {
"$ref": "#/definitions/github_com_tektoncd_triggers_pkg_apis_triggers_v1alpha1_ClusterInterceptorStatus",
"existingJavaType": "io.fabric8.tekton.triggers.v1alpha1.ClusterInterceptorStatus"
},
"github_com_tektoncd_triggers_pkg_apis_triggers_v1alpha1_ClusterTriggerBinding": {
"$ref": "#/definitions/github_com_tektoncd_triggers_pkg_apis_triggers_v1alpha1_ClusterTriggerBinding",
"existingJavaType": "io.fabric8.tekton.triggers.v1alpha1.ClusterTriggerBinding"
Expand Down Expand Up @@ -1042,6 +1214,10 @@
"$ref": "#/definitions/github_com_tektoncd_triggers_pkg_apis_triggers_v1alpha1_SecretRef",
"existingJavaType": "io.fabric8.tekton.triggers.v1alpha1.SecretRef"
},
"github_com_tektoncd_triggers_pkg_apis_triggers_v1alpha1_ServiceReference": {
"$ref": "#/definitions/github_com_tektoncd_triggers_pkg_apis_triggers_v1alpha1_ServiceReference",
"existingJavaType": "io.fabric8.tekton.triggers.v1alpha1.ServiceReference"
},
"github_com_tektoncd_triggers_pkg_apis_triggers_v1alpha1_Trigger": {
"$ref": "#/definitions/github_com_tektoncd_triggers_pkg_apis_triggers_v1alpha1_Trigger",
"existingJavaType": "io.fabric8.tekton.triggers.v1alpha1.Trigger"
Expand Down Expand Up @@ -1106,6 +1282,10 @@
"$ref": "#/definitions/knative_dev_pkg_apis_Condition",
"existingJavaType": "io.fabric8.tekton.triggers.internal.knative.pkg.apis.Condition"
},
"knative_dev_pkg_apis_duck_v1_Addressable": {
"$ref": "#/definitions/knative_dev_pkg_apis_duck_v1_Addressable",
"existingJavaType": "io.fabric8.tekton.triggers.internal.knative.pkg.apis.duck.v1.Addressable"
},
"knative_dev_pkg_apis_duck_v1_PodSpecable": {
"$ref": "#/definitions/knative_dev_pkg_apis_duck_v1_PodSpecable",
"existingJavaType": "io.fabric8.tekton.triggers.internal.knative.pkg.apis.duck.v1.PodSpecable"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,13 @@ public class Cache<T> implements Indexer<T> {
public static final String NAMESPACE_INDEX = "namespace";

// indexers stores index functions by their names
private Map<String, Function<T, List<String>>> indexers = new HashMap<>();
private final Map<String, Function<T, List<String>>> indexers = new HashMap<>();

// items stores object instances
private volatile ConcurrentHashMap<String, T> items = new ConcurrentHashMap<>();

// indices stores objects' key by their indices
private Map<String, Map<String, Set<String>>> indices = new HashMap<>();
private final Map<String, Map<String, Set<String>>> indices = new HashMap<>();

private BooleanSupplier isRunning = () -> false;

Expand All @@ -74,12 +74,12 @@ public void setIsRunning(BooleanSupplier isRunning) {
* @return registered indexers
*/
@Override
public Map<String, Function<T, List<String>>> getIndexers() {
return indexers;
public synchronized Map<String, Function<T, List<String>>> getIndexers() {
return Collections.unmodifiableMap(indexers);
}

@Override
public void addIndexers(Map<String, Function<T, List<String>>> indexersNew) {
public synchronized void addIndexers(Map<String, Function<T, List<String>>> indexersNew) {
if (isRunning.getAsBoolean()) {
throw new IllegalStateException("Cannot add indexers to a running informer.");
}
Expand Down Expand Up @@ -147,7 +147,7 @@ public synchronized Map<String, T> replace(List<T> list) {
this.items = newItems;

// rebuild any index
this.indices = new HashMap<>();
this.indices.values().stream().forEach(Map::clear);
for (Map.Entry<String, T> itemEntry : items.entrySet()) {
this.updateIndices(null, itemEntry.getValue(), itemEntry.getKey());
}
Expand Down Expand Up @@ -294,7 +294,7 @@ public synchronized List<T> byIndex(String indexName, String indexKey) {
* @param newObj new object
* @param key the key
*/
public void updateIndices(T oldObj, T newObj, String key) {
void updateIndices(T oldObj, T newObj, String key) {
if (oldObj != null) {
deleteFromIndices(oldObj, key);
}
Expand All @@ -307,7 +307,7 @@ public void updateIndices(T oldObj, T newObj, String key) {
continue;
}

Map<String, Set<String>> index = this.indices.computeIfAbsent(indexName, k -> new HashMap<>());
Map<String, Set<String>> index = this.indices.get(indexName);
for (String indexValue : indexValues) {
Set<String> indexSet = index.computeIfAbsent(indexValue, k -> new HashSet<>());
indexSet.add(key);
Expand Down Expand Up @@ -350,7 +350,7 @@ private void deleteFromIndices(T oldObj, String key) {
* @param indexName the index name
* @param indexFunc the index func
*/
public void addIndexFunc(String indexName, Function<T, List<String>> indexFunc) {
public synchronized void addIndexFunc(String indexName, Function<T, List<String>> indexFunc) {
this.indices.put(indexName, new HashMap<>());
this.indexers.put(indexName, indexFunc);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,14 @@
import org.junit.jupiter.api.Test;

import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.function.Function;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;

class CacheTest {
private static Cache cache = new Cache("mock", CacheTest::mockIndexFunction, CacheTest::mockKeyFunction);
Expand All @@ -49,6 +51,9 @@ void testCacheIndex() {
List<String> allExistingKeys = cache.listKeys();
assertEquals(1, allExistingKeys.size());
assertEquals(key, allExistingKeys.get(0));

cache.replace(Collections.emptyList());
assertEquals(0, cache.byIndex("mock", "y").size());
}

@Test
Expand Down

0 comments on commit 967bf19

Please sign in to comment.