Skip to content

Commit

Permalink
refactor: Simplify the KubernetesClient DSL
Browse files Browse the repository at this point in the history
  • Loading branch information
iocanel committed Nov 12, 2020
1 parent bec9ac9 commit 10d55aa
Show file tree
Hide file tree
Showing 325 changed files with 1,490 additions and 2,298 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -22,6 +22,7 @@
* Fix #2507: Add a test for creating a Job with generateName
* Fix #2509: Reversed order + Add Kubernetes 1.16.0 + OpenShift 4.5.14 to Compatibility matrix
* Add cache in github actions for integration tests
* Eliminated the use of Doneables and simplified the internal DSL implementation.

#### Dependency Upgrade
* Fix #2513: Update Kubernetes Model to v1.19.1
Expand Down
16 changes: 8 additions & 8 deletions README.md
Expand Up @@ -144,35 +144,35 @@ Service myservice = client.services().inNamespace("default").withName("myservice
Editing resources uses the inline builders from the Kubernetes Model:

```java
Namespace myns = client.namespaces().withName("myns").edit()
Namespace myns = client.namespaces().withName("myns").edit(n -> new NamespaceBuilder(n))
.editMetadata()
.addToLabels("a", "label")
.endMetadata()
.done();
.build());

Service myservice = client.services().inNamespace("default").withName("myservice").edit()
Service myservice = client.services().inNamespace("default").withName("myservice").edit(s -> new ServiceBuilder(s))
.editMetadata()
.addToLabels("another", "label")
.endMetadata()
.done();
.build());
```

In the same spirit you can inline builders to create:

```java
Namespace myns = client.namespaces().createNew()
Namespace myns = client.namespaces().create(new NamespaceBuilder()
.withNewMetadata()
.withName("myns")
.addToLabels("a", "label")
.endMetadata()
.done();
.build());

Service myservice = client.services().inNamespace("default").createNew()
Service myservice = client.services().inNamespace("default").create(new ServiceBuilder()
.withNewMetadata()
.withName("myservice")
.addToLabels("another", "label")
.endMetadata()
.done();
.build());
```

You can also set the apiVersion of the resource like in the case of SecurityContextConstraints :
Expand Down
4 changes: 2 additions & 2 deletions doc/CHEATSHEET.md
Expand Up @@ -1879,8 +1879,8 @@ CustomResourceDefinitionContext context = new CustomResourceDefinitionContext.Bu
.withPlural("crontabs")
.withKind("CronTab")
.build()
MixedOperation<CronTab, CronTabList, DoneableCronTab, Resource<CronTab, DoneableCronTab>> cronTabClient = client
.customResources(cronTabCrd, CronTab.class, CronTabList.class, DoneableCronTab.class);
MixedOperation<CronTab, CronTabList, Resource<CronTab>> cronTabClient = client
.customResources(cronTabCrd, CronTab.class, CronTabList.class);
```
- Register your `CustomResource` to `KubernetesDeserializer`:
```
Expand Down
Expand Up @@ -42,61 +42,40 @@
import io.fabric8.knative.client.sources.v1beta1.internal.SinkBindingOperationsImpl;
import io.fabric8.knative.eventing.contrib.awssqs.v1alpha1.AwsSqsSource;
import io.fabric8.knative.eventing.contrib.awssqs.v1alpha1.AwsSqsSourceList;
import io.fabric8.knative.eventing.contrib.awssqs.v1alpha1.DoneableAwsSqsSource;
import io.fabric8.knative.eventing.contrib.couchdb.v1alpha1.CouchDbSource;
import io.fabric8.knative.eventing.contrib.couchdb.v1alpha1.CouchDbSourceList;
import io.fabric8.knative.eventing.contrib.couchdb.v1alpha1.DoneableCouchDbSource;
import io.fabric8.knative.eventing.contrib.github.v1alpha1.DoneableGitHubBinding;
import io.fabric8.knative.eventing.contrib.github.v1alpha1.DoneableGitHubSource;
import io.fabric8.knative.eventing.contrib.github.v1alpha1.GitHubBinding;
import io.fabric8.knative.eventing.contrib.github.v1alpha1.GitHubBindingList;
import io.fabric8.knative.eventing.contrib.github.v1alpha1.GitHubSource;
import io.fabric8.knative.eventing.contrib.github.v1alpha1.GitHubSourceList;
import io.fabric8.knative.eventing.contrib.gitlab.v1alpha1.DoneableGitLabBinding;
import io.fabric8.knative.eventing.contrib.gitlab.v1alpha1.DoneableGitLabSource;
import io.fabric8.knative.eventing.contrib.gitlab.v1alpha1.GitLabBinding;
import io.fabric8.knative.eventing.contrib.gitlab.v1alpha1.GitLabBindingList;
import io.fabric8.knative.eventing.contrib.gitlab.v1alpha1.GitLabSource;
import io.fabric8.knative.eventing.contrib.gitlab.v1alpha1.GitLabSourceList;
import io.fabric8.knative.eventing.contrib.kafka.v1beta1.DoneableKafkaBinding;
import io.fabric8.knative.eventing.contrib.kafka.v1beta1.DoneableKafkaChannel;
import io.fabric8.knative.eventing.contrib.kafka.v1beta1.DoneableKafkaSource;
import io.fabric8.knative.eventing.contrib.kafka.v1beta1.KafkaBinding;
import io.fabric8.knative.eventing.contrib.kafka.v1beta1.KafkaBindingList;
import io.fabric8.knative.eventing.contrib.kafka.v1beta1.KafkaChannel;
import io.fabric8.knative.eventing.contrib.kafka.v1beta1.KafkaChannelList;
import io.fabric8.knative.eventing.contrib.kafka.v1beta1.KafkaSource;
import io.fabric8.knative.eventing.contrib.kafka.v1beta1.KafkaSourceList;
import io.fabric8.knative.eventing.contrib.prometheus.v1alpha1.DoneablePrometheusSource;
import io.fabric8.knative.eventing.contrib.prometheus.v1alpha1.PrometheusSource;
import io.fabric8.knative.eventing.contrib.prometheus.v1alpha1.PrometheusSourceList;
import io.fabric8.knative.eventing.v1.Broker;
import io.fabric8.knative.eventing.v1.BrokerList;
import io.fabric8.knative.eventing.v1.DoneableBroker;
import io.fabric8.knative.eventing.v1.DoneableTrigger;
import io.fabric8.knative.eventing.v1.Trigger;
import io.fabric8.knative.eventing.v1.TriggerList;
import io.fabric8.knative.eventing.v1beta1.DoneableEventType;
import io.fabric8.knative.eventing.v1beta1.EventType;
import io.fabric8.knative.eventing.v1beta1.EventTypeList;
import io.fabric8.knative.flows.v1.DoneableSequence;
import io.fabric8.knative.flows.v1.Sequence;
import io.fabric8.knative.flows.v1.SequenceList;
import io.fabric8.knative.messaging.v1.Channel;
import io.fabric8.knative.messaging.v1.ChannelList;
import io.fabric8.knative.messaging.v1.DoneableChannel;
import io.fabric8.knative.messaging.v1.DoneableInMemoryChannel;
import io.fabric8.knative.messaging.v1.DoneableSubscription;
import io.fabric8.knative.messaging.v1.InMemoryChannel;
import io.fabric8.knative.messaging.v1.InMemoryChannelList;
import io.fabric8.knative.messaging.v1.Subscription;
import io.fabric8.knative.messaging.v1.SubscriptionList;
import io.fabric8.knative.serving.v1.Configuration;
import io.fabric8.knative.serving.v1.ConfigurationList;
import io.fabric8.knative.serving.v1.DoneableConfiguration;
import io.fabric8.knative.serving.v1.DoneableRevision;
import io.fabric8.knative.serving.v1.DoneableRoute;
import io.fabric8.knative.serving.v1.DoneableService;
import io.fabric8.knative.serving.v1.Revision;
import io.fabric8.knative.serving.v1.RevisionList;
import io.fabric8.knative.serving.v1.Route;
Expand All @@ -107,10 +86,6 @@
import io.fabric8.knative.sources.v1beta1.ApiServerSourceList;
import io.fabric8.knative.sources.v1beta1.ContainerSource;
import io.fabric8.knative.sources.v1beta1.ContainerSourceList;
import io.fabric8.knative.sources.v1beta1.DoneableApiServerSource;
import io.fabric8.knative.sources.v1beta1.DoneableContainerSource;
import io.fabric8.knative.sources.v1beta1.DoneablePingSource;
import io.fabric8.knative.sources.v1beta1.DoneableSinkBinding;
import io.fabric8.knative.sources.v1beta1.PingSource;
import io.fabric8.knative.sources.v1beta1.PingSourceList;
import io.fabric8.knative.sources.v1beta1.SinkBinding;
Expand Down Expand Up @@ -157,127 +132,127 @@ public FunctionCallable<NamespacedKnativeClient> withRequestConfig(RequestConfig
}

@Override
public MixedOperation<Service, ServiceList, DoneableService, Resource<Service, DoneableService>> services() {
public MixedOperation<Service, ServiceList, Resource<Service>> services() {
return new ServiceOperationsImpl(this.getHttpClient(), this.getConfiguration());
}

@Override
public MixedOperation<Route, RouteList, DoneableRoute, Resource<Route, DoneableRoute>> routes() {
public MixedOperation<Route, RouteList, Resource<Route>> routes() {
return new RouteOperationsImpl(this.getHttpClient(), this.getConfiguration());
}

@Override
public MixedOperation<Revision, RevisionList, DoneableRevision, Resource<Revision, DoneableRevision>> revisions() {
public MixedOperation<Revision, RevisionList, Resource<Revision>> revisions() {
return new RevisionOperationsImpl(this.getHttpClient(), this.getConfiguration());
}

@Override
public MixedOperation<Configuration, ConfigurationList, DoneableConfiguration, Resource<Configuration, DoneableConfiguration>> configurations() {
public MixedOperation<Configuration, ConfigurationList, Resource<Configuration>> configurations() {
return new ConfigurationOperationsImpl(this.getHttpClient(), this.getConfiguration());
}

@Override
public MixedOperation<Broker, BrokerList, DoneableBroker, Resource<Broker, DoneableBroker>> brokers() {
public MixedOperation<Broker, BrokerList, Resource<Broker>> brokers() {
return new BrokerOperationsImpl(this.getHttpClient(), this.getConfiguration());
}

@Override
public MixedOperation<Trigger, TriggerList, DoneableTrigger, Resource<Trigger, DoneableTrigger>> triggers() {
public MixedOperation<Trigger, TriggerList, Resource<Trigger>> triggers() {
return new TriggerOperationsImpl(this.getHttpClient(), this.getConfiguration());
}

@Override
public MixedOperation<Channel, ChannelList, DoneableChannel, Resource<Channel, DoneableChannel>> channels() {
public MixedOperation<Channel, ChannelList, Resource<Channel>> channels() {
return new ChannelOperationsImpl(this.getHttpClient(), this.getConfiguration());
}

@Override
public MixedOperation<Subscription, SubscriptionList, DoneableSubscription, Resource<Subscription, DoneableSubscription>> subscriptions() {
public MixedOperation<Subscription, SubscriptionList, Resource<Subscription>> subscriptions() {
return new SubscriptionOperationsImpl(this.getHttpClient(), this.getConfiguration());
}

@Override
public MixedOperation<EventType, EventTypeList, DoneableEventType, Resource<EventType, DoneableEventType>> eventTypes() {
public MixedOperation<EventType, EventTypeList, Resource<EventType>> eventTypes() {
return new EventTypeOperationsImpl(this.getHttpClient(), this.getConfiguration());
}

@Override
public MixedOperation<Sequence, SequenceList, DoneableSequence, Resource<Sequence, DoneableSequence>> sequences() {
public MixedOperation<Sequence, SequenceList, Resource<Sequence>> sequences() {
return new SequenceOperationsImpl(this.getHttpClient(), this.getConfiguration());
}

@Override
public MixedOperation<InMemoryChannel, InMemoryChannelList, DoneableInMemoryChannel, Resource<InMemoryChannel, DoneableInMemoryChannel>> inMemoryChannels() {
public MixedOperation<InMemoryChannel, InMemoryChannelList, Resource<InMemoryChannel>> inMemoryChannels() {
return new InMemoryChannelOperationsImpl(this.getHttpClient(), this.getConfiguration());
}

@Override
public MixedOperation<PingSource, PingSourceList, DoneablePingSource, Resource<PingSource, DoneablePingSource>> pingSources() {
public MixedOperation<PingSource, PingSourceList, Resource<PingSource>> pingSources() {
return new PingSourceOperationsImpl(this.getHttpClient(), this.getConfiguration());
}

@Override
public MixedOperation<SinkBinding, SinkBindingList, DoneableSinkBinding, Resource<SinkBinding, DoneableSinkBinding>> sinkBindings() {
public MixedOperation<SinkBinding, SinkBindingList, Resource<SinkBinding>> sinkBindings() {
return new SinkBindingOperationsImpl(this.getHttpClient(), this.getConfiguration());
}

@Override
public MixedOperation<ContainerSource, ContainerSourceList, DoneableContainerSource, Resource<ContainerSource, DoneableContainerSource>> containerSources() {
public MixedOperation<ContainerSource, ContainerSourceList, Resource<ContainerSource>> containerSources() {
return new ContainerSourceOperationsImpl(this.getHttpClient(), this.getConfiguration());
}

@Override
public MixedOperation<ApiServerSource, ApiServerSourceList, DoneableApiServerSource, Resource<ApiServerSource, DoneableApiServerSource>> apiServerSources() {
public MixedOperation<ApiServerSource, ApiServerSourceList, Resource<ApiServerSource>> apiServerSources() {
return new ApiServerSourceOperationsImpl(this.getHttpClient(), this.getConfiguration());
}

@Override
public MixedOperation<AwsSqsSource, AwsSqsSourceList, DoneableAwsSqsSource, Resource<AwsSqsSource, DoneableAwsSqsSource>> awsSqsSources() {
public MixedOperation<AwsSqsSource, AwsSqsSourceList, Resource<AwsSqsSource>> awsSqsSources() {
return new AwsSqsSourceOperationsImpl(this.getHttpClient(), this.getConfiguration());
}

@Override
public MixedOperation<CouchDbSource, CouchDbSourceList, DoneableCouchDbSource, Resource<CouchDbSource, DoneableCouchDbSource>> couchDbSources() {
public MixedOperation<CouchDbSource, CouchDbSourceList, Resource<CouchDbSource>> couchDbSources() {
return new CouchDbSourceOperationsImpl(this.getHttpClient(), this.getConfiguration());
}

@Override
public MixedOperation<GitHubSource, GitHubSourceList, DoneableGitHubSource, Resource<GitHubSource, DoneableGitHubSource>> gitHubSources() {
public MixedOperation<GitHubSource, GitHubSourceList, Resource<GitHubSource>> gitHubSources() {
return new GitHubSourceOperationsImpl(this.getHttpClient(), this.getConfiguration());
}

@Override
public MixedOperation<GitHubBinding, GitHubBindingList, DoneableGitHubBinding, Resource<GitHubBinding, DoneableGitHubBinding>> gitHubBindings() {
public MixedOperation<GitHubBinding, GitHubBindingList, Resource<GitHubBinding>> gitHubBindings() {
return new GitHubBindingOperationsImpl(this.getHttpClient(), this.getConfiguration());
}

@Override
public MixedOperation<GitLabSource, GitLabSourceList, DoneableGitLabSource, Resource<GitLabSource, DoneableGitLabSource>> gitLabSources() {
public MixedOperation<GitLabSource, GitLabSourceList, Resource<GitLabSource>> gitLabSources() {
return new GitLabSourceOperationsImpl(this.getHttpClient(), this.getConfiguration());
}

@Override
public MixedOperation<GitLabBinding, GitLabBindingList, DoneableGitLabBinding, Resource<GitLabBinding, DoneableGitLabBinding>> gitLabBindings() {
public MixedOperation<GitLabBinding, GitLabBindingList, Resource<GitLabBinding>> gitLabBindings() {
return new GitLabBindingOperationsImpl(this.getHttpClient(), this.getConfiguration());
}

@Override
public MixedOperation<PrometheusSource, PrometheusSourceList, DoneablePrometheusSource, Resource<PrometheusSource, DoneablePrometheusSource>> prometheusSources() {
public MixedOperation<PrometheusSource, PrometheusSourceList, Resource<PrometheusSource>> prometheusSources() {
return new PrometheusSourceOperationsImpl(this.getHttpClient(), this.getConfiguration());
}

@Override
public MixedOperation<KafkaChannel, KafkaChannelList, DoneableKafkaChannel, Resource<KafkaChannel, DoneableKafkaChannel>> kafkaChannels() {
public MixedOperation<KafkaChannel, KafkaChannelList, Resource<KafkaChannel>> kafkaChannels() {
return new KafkaChannelOperationsImpl(this.getHttpClient(), this.getConfiguration());
}

@Override
public MixedOperation<KafkaSource, KafkaSourceList, DoneableKafkaSource, Resource<KafkaSource, DoneableKafkaSource>> kafkasSources() {
public MixedOperation<KafkaSource, KafkaSourceList, Resource<KafkaSource>> kafkasSources() {
return new KafkaSourceOperationsImpl(this.getHttpClient(), this.getConfiguration());
}

@Override
public MixedOperation<KafkaBinding, KafkaBindingList, DoneableKafkaBinding, Resource<KafkaBinding, DoneableKafkaBinding>> kafkaBindings() {
public MixedOperation<KafkaBinding, KafkaBindingList, Resource<KafkaBinding>> kafkaBindings() {
return new KafkaBindingOperationsImpl(this.getHttpClient(), this.getConfiguration());
}
}

0 comments on commit 10d55aa

Please sign in to comment.