Skip to content

Commit

Permalink
Fix fabric8io#2321: Add new objects to OpenShift model
Browse files Browse the repository at this point in the history
+ Add new OpenShift resources in OpenShift Model as per listed
  resources in https://docs.openshift.com/container-platform/4.4/rest_api/operator_apis/operator-apis-index.html

+ Added these new modules in kubernetes-model-generator:
  - openshift-console-model
  - openshift-monitoring-model
  - openshift-operatorhub-model
  - openshift-operator-model
+ Added new endpoints in openshift-client DSL:
  - client.config() - config.openshift.io/v1
  - client.operator() - operator.openshift.io/v1 and operator.openshift.io/v1alpha1
  - client.operatorHub() - operators.coreos.com/v1alpha1
  - client.console() - console.openshift.io/v1
  - client.quota() - quota.openshift.io/v1
  - client.monitoring() - monitoring.coreosc.com/v1
  • Loading branch information
rohanKanojia authored and manusa committed Aug 20, 2020
1 parent 3a6587f commit 0a418af
Show file tree
Hide file tree
Showing 81 changed files with 178,067 additions and 6,379 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Expand Up @@ -6,6 +6,7 @@
* Fix #2316: Cannot load resource from stream without apiVersion
* Fix #2389: KubernetesServer does not use value from https in crud mode
* Fix #2306: Make KubernetesServer CRUD mode work with informers
* Fix #2404: Readiness.isReady doesn't handle extensions/v1beta1 Deployment

#### Improvements
* Fix #2331: Fixed documentation for namespaced informer for all custom types implementing `Namespaced` interface
Expand All @@ -16,11 +17,14 @@
* Fix #2355: bump jandex from 2.1.3.Final to 2.2.0.Final
* Fix #2353: chore: bump workflow action-setup versions + kubernetes to 1.18.6
* Fix #2292: Update createOrReplace to do replace when create fails with conflict
* Fix #2401: bump maven-resources-plugin from 3.1.0 to 3.2.0
* Fix #2405: bump mockito-core from 3.4.4 to 3.5.0

#### New Features
* Fix #2311: Add Support for creating bootstrap project template
* Fix #2287: Add support for V1 and V1Beta1 CustomResourceDefinition
* Fix #2319: Create Config without using auto-configure functionality or setting env variables
* Fix #2321: Add Support for new resources in OpenShift Model

### 4.10.3 (2020-07-14)
#### Bugs
Expand Down
217 changes: 217 additions & 0 deletions doc/CHEATSHEET.md
Expand Up @@ -43,6 +43,12 @@ This document contains common usages of different resources using Fabric8 Kubern
* [Route](#route)
* [Project](#project)
* [ImageStream](#imagestream)
* [CatalogSource](#catalogsource)
* [PrometheusRule](#prometheusrule)
* [ServiceMonitor](#servicemonitor)
* [CluserResourceQuota](#clusterresourcequota)
* [ClusterVersion](#clusterversion)
* [EgressNetworkPolicy](#egressnetworkpolicy)

* [Tekton Client](#tekton-client)
* [Initializing Tekton Client](#initializing-tekton-client)
Expand Down Expand Up @@ -2487,6 +2493,217 @@ ImageStreamList isList = client.imageStreams().inNamespace("default").withLabel(
```
Boolean bDeleted = client.imageStreams().inNamespace("default").withName("example-camel-cdi").delete();
```
#### CatalogSource
`CatalogSource` is available for usage in OpenShift Client via `client.operatorHub().catalogSources()`. Here are some common examples of it's usage:
- Load `CatalogSource` from YAML:
```
CatalogSource cs = client.operatorHub().catalogSources()
.load(new FileInputStream("/test-catalogsource.yml").get();
```
- Create `CatalogSource`:
```
CatalogSource cs = new CatalogSourceBuilder()
.withNewMetadata().withName("foo").endMetadata()
.withNewSpec()
.withSourceType("Foo")
.withImage("nginx:latest")
.withDisplayName("Foo Bar")
.withPublisher("Fabric8")
.endSpec()
.build();
client.operatorHub().catalogSources().inNamespace("default").createOrReplace(cs);
```
- List `CatalogSource` in some namespace:
```
CatalogSourceList csList = client.operatorHub().catalogSources().inNamespace("ns1").list();
```
- List `CatalogSource` in any namespace:
```
CatalogSourceList csList = client.operatorHub().catalogSources().inAnyNamespace().list();
```
- List `CatalogSource` in some namespace with some labels:
```
CatalogSourceList csList = client.operatorHub().catalogSources().inNamespace("default").withLabel("foo", "bar").list();
```
- Delete `CatalogSource`:
```
client.operatorHub().catalogSources().inNamespace("default").withName("foo").delete();
```

#### PrometheusRule
`PrometheusRule` is available for usage in OpenShift Client via `client.monitoring().prometheusRules()`. Here are some common examples of it's usage:
- Load `PrometheusRule` from YAML:
```
PrometheusRule prometheusRule = client.monitoring().prometheusRules()
.load(new FileInputStream("/test-prometheusrule.yml").get();
```
- Create `PrometheusRule`:
```
PrometheusRule prometheusRule = new PrometheusRuleBuilder()
.withNewMetadata().withName("foo").endMetadata()
.withNewSpec()
.addNewGroup()
.withName("./example-rules")
.addNewRule()
.withAlert("ExampleAlert")
.withNewExpr().withStrVal("vector(1)").endExpr()
.endRule()
.endGroup()
.endSpec()
.build();
client.monitoring().prometheusRules().inNamespace("default").createOrReplace(prometheusRule);
```
- List `PrometheusRule` in some namespace:
```
PrometheusRuleList prList = client.monitoring().prometheusRules().inNamespace("ns1").list();
```
- List `PrometheusRule` in any namespace:
```
PrometheusRuleList prList = client.monitoring().prometheusRules().inAnyNamespace().list();
```
- List `PrometheusRule` in some namespace with some labels:
```
PrometheusRuleList prList = client.monitoring().prometheusRules().inNamespace("default").withLabel("foo", "bar").list();
```
- Delete `PrometheusRule`:
```
client.monitoring().prometheusRules().inNamespace("default").withName("foo").delete();
```

#### ServiceMonitor
`ServiceMonitor` is available for usage in OpenShift Client via `client.monitoring().serviceMonitors()`. Here are some common examples of it's usage:
- Load `ServiceMonitor` from YAML:
```
ServiceMonitor serviceMonitor = client.monitoring().serviceMonitors()
.load(new FileInputStream("/test-servicemonitor.yml").get();
```
- Create `ServiceMonitor`:
```
ServiceMonitor serviceMonitor = new ServiceMonitorBuilder()
.withNewMetadata()
.withName("foo")
.addToLabels("prometheus", "frontend")
.endMetadata()
.withNewSpec()
.withNewNamespaceSelector().withAny(true).endNamespaceSelector()
.withNewSelector()
.addToMatchLabels("prometheus", "frontend")
.endSelector()
.addNewEndpoint()
.withPort("http-metric")
.withInterval("15s")
.endEndpoint()
.endSpec()
.build();
client.monitoring().serviceMonitors().inNamespace("rokumar").createOrReplace(serviceMonitor)
```
- List `ServiceMonitor` in some namespace:
```
ServiceMonitorList serviceMonitorList = client.monitoring().serviceMonitors().inNamespace("ns1").list();
```
- List `ServiceMonitor` in any namespace:
```
ServiceMonitorList serviceMonitorList = client.monitoring().serviceMonitors().inAnyNamespace().list();
```
- List `ServiceMonitor` in some namespace with some labels:
```
ServiceMonitorList serviceMonitorList = client.monitoring().catalogSources().inNamespace("default").withLabel("foo", "bar").list();
```
- Delete `ServiceMonitor`:
```
client.operatorHub().monitoring().inNamespace("default").withName("foo").delete();
```

#### ClusterResourceQuota
- Create `ClusterResourceQuota`:
```
try (OpenShiftClient client = new DefaultOpenShiftClient()) {
Map<String, Quantity> hard = new HashMap<>();
hard.put("pods", new Quantity("10"));
hard.put("secrets", new Quantity("20"));
ClusterResourceQuota acrq = new ClusterResourceQuotaBuilder()
.withNewMetadata().withName("foo").endMetadata()
.withNewSpec()
.withNewSelector()
.addToAnnotations("openshift.io/requester", "foo-user")
.endSelector()
.withQuota(new ResourceQuotaSpecBuilder()
.withHard(hard)
.build())
.endSpec()
.build();
client.quotas().clusterResourceQuotas().createOrReplace(acrq);
}
```
- List `ClusterResourceQuota` from server:
```
ClusterResourceQuotaList clusterResourceQuotaList = client.quotas().clusterResourceQuotas().list();
```
- Delete `ClusterResourceQuota`:
```
client.quotas().clusterResourceQuotas().withName("foo").delete();
```

#### ClusterVersion
- Fetch Cluster Version:
```
try (OpenShiftClient client = new DefaultOpenShiftClient()) {
ClusterVersion clusterVersion = client.config().clusterVersions().withName("version").get();
System.out.println("Cluster Version: " + clusterVersion.getStatus().getDesired().getVersion());
}
```

### EgressNetworkPolicy
`EgressNetworkPolicy` is available for usage in OpenShift Client via `client..egressNetworkPolicys()`. Here are some common examples of it's usage:
- Load `EgressNetworkPolicy` from YAML:
```
EgressNetworkPolicy egressNetworkPolicy = client.egressNetworkPolicies()
.load(new FileInputStream("/test-enp.yml").get();
```
- Create `EgressNetworkPolicy`:
```
try (OpenShiftClient client = new DefaultOpenShiftClient()) {
EgressNetworkPolicy enp = new EgressNetworkPolicyBuilder()
.withNewMetadata()
.withName("foo")
.withNamespace("default")
.endMetadata()
.withNewSpec()
.addNewEgress()
.withType("Allow")
.withNewTo()
.withCidrSelector("1.2.3.0/24")
.endTo()
.endEgress()
.addNewEgress()
.withType("Allow")
.withNewTo()
.withDnsName("www.foo.com")
.endTo()
.endEgress()
.endSpec()
.build();
client.egressNetworkPolicies().inNamespace("default").createOrReplace(enp);
}
```
- List `EgressNetworkPolicy` in some namespace:
```
EgressNetworkPolicyList egressNetworkPolicyList = client.egressNetworkPolicies().inNamespace("default").list();
```
- List `EgressNetworkPolicy` in any namespace:
```
EgressNetworkPolicyList egressNetworkPolicyList = client.egressNetworkPolicies().inAnyNamespace().list();
```
- List `EgressNetworkPolicy` in some namespace with some labels:
```
EgressNetworkPolicyList egressNetworkPolicyList = client.egressNetworkPolicies().inNamespace("default").withLabel("foo", "bar").list();
```
- Delete `EgressNetworkPolicy`:
```
client.egressNetworkPolicies().inNamespace("default").withName("foo").delete();
```

### Tekton Client
Fabric8 Kubernetes Client also has an extension for Tekton.
Expand Down
12 changes: 7 additions & 5 deletions kubernetes-model-generator/go.mod
Expand Up @@ -3,11 +3,13 @@ module github.com/fabric8io/kubernetes-client/kubernetes-model-generator
go 1.14

require (
github.com/openshift/api v0.0.0-20200413201024-c6e8c9b6eb9a
k8s.io/api v0.18.0
k8s.io/apiextensions-apiserver v0.18.0
k8s.io/apimachinery v0.18.0
k8s.io/client-go v0.18.0
github.com/coreos/prometheus-operator v0.41.1 // indirect
github.com/openshift/api v0.0.0-20200803131051-87466835fcc0
github.com/operator-framework/api v0.3.12
k8s.io/api v0.19.0-rc.2
k8s.io/apiextensions-apiserver v0.18.2
k8s.io/apimachinery v0.19.0-rc.2
k8s.io/client-go v0.18.3
k8s.io/kubernetes v1.18.0
k8s.io/metrics v0.18.0
)
Expand Down

0 comments on commit 0a418af

Please sign in to comment.