Skip to content

Commit

Permalink
Merge branch 'master' of github.com:fabric8io/kubernetes-client
Browse files Browse the repository at this point in the history
  • Loading branch information
shawkins committed Jun 23, 2022
2 parents 98d134d + b90ee77 commit e1b1055
Show file tree
Hide file tree
Showing 258 changed files with 25,645 additions and 18,145 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Expand Up @@ -3,8 +3,12 @@
### 6.0-SNAPSHOT

#### Bugs
* Fix #2811: Approve/Reject CSR not supported in v1beta1 CertificateSigningRequest API
* Fix #4216: Update metadata when `replaceStatus()` is called

#### Improvements
* Fix #3227 : Move `config.openshift.io` apiGroup resources out of `openshift-model/`
* Fix #4006: Remove outdated shared test classes in `kubernetes-client/` and `openshift-client/` modules

#### Dependency Upgrade

Expand Down
2 changes: 2 additions & 0 deletions README.md
Expand Up @@ -33,6 +33,8 @@ This client provides access to the full [Kubernetes](http://kubernetes.io/) &
- [Passing a reference of a resource to the client](#passing-a-reference-of-a-resource-to-the-client)
- [Adapting a client](#adapting-the-client)
- [Adapting and close](#adapting-and-close)
- [Generating CRD from Java](doc/CRD-generator.md)
- [Generating Java from CRD](doc/java-generation-from-CRD.md)
- [Mocking Kubernetes](#mocking-kubernetes)
- [Who Uses Fabric8 Kubernetes Client?](#who-uses-kubernetes--openshift-java-client)
- [Kubernetes Operators in Java Written using Fabric8 Kubernetes Client](./doc/KubernetesOperatorsInJavaWrittenUsingFabric8.md)
Expand Down
Expand Up @@ -23,27 +23,29 @@
import io.fabric8.kubernetes.api.model.apiextensions.v1beta1.CustomResourceDefinitionVersionBuilder;
import io.fabric8.kubernetes.api.model.apiextensions.v1beta1.CustomResourceSubresources;
import io.fabric8.kubernetes.api.model.apiextensions.v1beta1.CustomResourceValidation;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.Set;
import java.util.stream.Collectors;

public class PromoteSingleVersionAttributesDecorator extends CustomResourceDefinitionDecorator<CustomResourceDefinitionSpecFluent<?>> {
public class PromoteSingleVersionAttributesDecorator
extends CustomResourceDefinitionDecorator<CustomResourceDefinitionSpecFluent<?>> {

public PromoteSingleVersionAttributesDecorator(String name) {
super(name);
}
public PromoteSingleVersionAttributesDecorator(String name) {
super(name);
}

@Override
public void andThenVisit(CustomResourceDefinitionSpecFluent<?> spec, ObjectMeta resourceMeta) {
@Override
public void andThenVisit(CustomResourceDefinitionSpecFluent<?> spec, ObjectMeta resourceMeta) {
List<CustomResourceDefinitionVersion> versions = spec.buildVersions();

if (versions.size() == 1) {
CustomResourceDefinitionVersion version = versions.get(0);
spec.withSubresources(version.getSubresources())
.withValidation(version.getSchema())
.withAdditionalPrinterColumns(version.getAdditionalPrinterColumns());


CustomResourceDefinitionVersion newVersion = new CustomResourceDefinitionVersionBuilder(version).build();
newVersion.setSubresources(null);
Expand All @@ -53,18 +55,28 @@ public void andThenVisit(CustomResourceDefinitionSpecFluent<?> spec, ObjectMeta
spec.removeAllFromVersions(versions);
spec.withVersions(newVersion);
} else {
Set<CustomResourceSubresources> subresources = versions.stream().map(CustomResourceDefinitionVersion::getSubresources).collect(Collectors.toSet());
Set<List<CustomResourceColumnDefinition>> additionalPrinterColumns = versions.stream().map(CustomResourceDefinitionVersion::getAdditionalPrinterColumns).collect(Collectors.toSet());
Set<CustomResourceValidation> schemas = versions.stream().map(CustomResourceDefinitionVersion::getSchema).collect(Collectors.toSet());

Set<CustomResourceSubresources> subresources = versions.stream().map(CustomResourceDefinitionVersion::getSubresources)
.filter(o -> o != null).collect(Collectors.toSet());
Set<List<CustomResourceColumnDefinition>> additionalPrinterColumns = versions.stream()
.map(CustomResourceDefinitionVersion::getAdditionalPrinterColumns).filter(o -> o != null).collect(Collectors.toSet());
Set<CustomResourceValidation> schemas = versions.stream().map(CustomResourceDefinitionVersion::getSchema)
.filter(o -> o != null).collect(Collectors.toSet());

boolean hasIdenticalSubresources = subresources.size() == 1;
boolean hasIdenticalAdditionalPrinterColumns = additionalPrinterColumns.size() == 1;
boolean hasIdenticalSchemas = schemas.size() == 1;

spec
.withValidation(hasIdenticalSchemas ? schemas.iterator().next() : null)
.withSubresources(hasIdenticalSubresources ? subresources.iterator().next() : null)
.withAdditionalPrinterColumns(hasIdenticalAdditionalPrinterColumns ? additionalPrinterColumns.iterator().next() : null);

if (hasIdenticalSchemas) {
spec.withValidation(schemas.iterator().next());
}

if (hasIdenticalSubresources) {
spec.withSubresources(subresources.iterator().next());
}

if (hasIdenticalAdditionalPrinterColumns) {
spec.withAdditionalPrinterColumns(additionalPrinterColumns.iterator().next());
}

spec.removeAllFromVersions(versions);
List<CustomResourceDefinitionVersion> newVersions = new ArrayList<>();
Expand All @@ -84,17 +96,17 @@ public void andThenVisit(CustomResourceDefinitionSpecFluent<?> spec, ObjectMeta

spec.withVersions(newVersions);
}
}
}

@Override
public Class<? extends Decorator>[] after() {
return new Class[]{
AddCustomResourceDefinitionResourceDecorator.class,
AddCustomResourceDefinitionVersionDecorator.class,
CustomResourceDefinitionVersionDecorator.class,
AddSchemaToCustomResourceDefinitionVersionDecorator.class,
AddSubresourcesDecorator.class, AddStatusSubresourceDecorator.class,
AddStatusReplicasPathDecorator.class, AddSpecReplicasPathDecorator.class,
AddLabelSelectorPathDecorator.class};
}
@Override
public Class<? extends Decorator>[] after() {
return new Class[] {
AddCustomResourceDefinitionResourceDecorator.class,
AddCustomResourceDefinitionVersionDecorator.class,
CustomResourceDefinitionVersionDecorator.class,
AddSchemaToCustomResourceDefinitionVersionDecorator.class,
AddSubresourcesDecorator.class, AddStatusSubresourceDecorator.class,
AddStatusReplicasPathDecorator.class, AddSpecReplicasPathDecorator.class,
AddLabelSelectorPathDecorator.class };
}
}
5 changes: 5 additions & 0 deletions doc/MIGRATION-v6.md
Expand Up @@ -19,6 +19,7 @@
- [evict Changes](#evict-changes)
- [Delete Behavior](#delete-behavior)
- [Stream Changes](#stream-changes)
- [OpenShift Config Model Changes](#openshift-config-model-changes)

## API/Impl split

Expand Down Expand Up @@ -305,3 +306,7 @@ The usage of Piped streams is no longer supported - they make assumptions about
`TtyExecErrorChannelable` methods have been deprecated in favor of `ExecWatch.exitCode` and `ExecListener.onExit`.

`ContainerResource.readingInput(InputStream in)` has been deprecated - use `redirectingInput` instead.

## OpenShift Config Model Changes

All OpenShift resources belonging to `config.openshift.io/v1` apigroup have been moved out of `io.fabric8.openshift.api.model` package. They should now be available in `io.fabric8.openshift.api.model.config.v1` package.
123 changes: 123 additions & 0 deletions doc/java-generation-from-CRD.md
@@ -0,0 +1,123 @@
# Java generation from CRD (preview)

This document shows how to generate java sources from CRD manifests.

## Quick start CLI

The Java generator CLI is available for download on Sonatype at the link:

```
https://oss.sonatype.org/content/repositories/releases/io/fabric8/java-generator-cli/<version>/java-generator-cli-<version>.sh
```

you can get it working locally with few lines:

```bash
export VERSION=$(wget -q -O - http://github.com/fabric8io/kubernetes-client/releases/latest --header "Accept: application/json" | jq -r '.tag_name' | cut -c 2-)
wget https://oss.sonatype.org/content/repositories/releases/io/fabric8/java-generator-cli/$VERSION/java-generator-cli-$VERSION.sh
chmod a+x java-generator-cli-$VERSION.sh
./java-generator-cli-$VERSION.sh --version
```

Alternatively, if you already have [jbang](https://www.jbang.dev/) installed, you can run the CLI using it:

```bash
jbang io.fabric8:java-generator-cli:<version>
```

## Quick start Maven

The Java generator Maven plugin can be used from your project `pom.xml` adding a section like:

```xml
<plugin>
<groupId>io.fabric8</groupId>
<artifactId>java-generator-maven-plugin</artifactId>
<version>${kubernetes-client.version}</version>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
<configuration>
<source>src/main/resources/kubernetes</source>
...
</configuration>
</plugin>
```

## Usage

Provide a `source` referencing a file or a folder containing your CRDs definitions in `yaml` or `json` format and a `target` directory where the relevant Java code should be generated.

The full list of options of the CLI is (output of `--help`):

```
Usage: java-gen [-hV] [-add-extra-annotations] [-enum-uppercase] -s=<source>
[-suffix-strategy=<suffixStrategy>] -t=<target>
-add-extra-annotations, --add-extra-annotations
Add extra lombok and sundrio annotation to the
generated classes
-enum-uppercase, --enum-uppercase
Uppercase the enum values
-h, --help Show this help message and exit.
-s, --source=<source> The source(file or folder) with the
CustomResourceDefinition(s) to use
-suffix-strategy, --suffix-strategy=<suffixStrategy>
The suffix strategy to be used
-t, --target=<target> The folder to write the generated sources
-V, --version Print version information and exit.
```

And the corresponding configurations of the Maven plugin are (output of `mvn help:describe -DgroupId=io.fabric8 -DartifactId=java-generator-maven-plugin -Dversion=<version> -Ddetail`):

```
enumUppercase
User property: fabric8.java-generator.enum-uppercase
extraAnnotations
User property: fabric8.java-generator.extra-annotations
source
Required: true
User property: fabric8.java-generator.source
suffixStrategy
User property: fabric8.java-generator.suffix-strategy
target (Default: ${basedir}/target/generated-sources/java)
User property: fabric8.java-generator.target
```

## Compiling the generated code

The generated code depends on a few dependencies to succesfully compile:

```xml
<dependency>
<groupId>io.fabric8</groupId>
<artifactId>kubernetes-client</artifactId>
</dependency>
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
<version>2.0.1.Final</version>
<scope>provided</scope>
</dependency>
```

and, if `--add-extra-annotations`/`extraAnnotations` has been set, the following dependencies should be included as well:
```xml
<dependency>
<groupId>io.sundr</groupId>
<artifactId>builder-annotations</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<scope>provided</scope>
</dependency>
```
35 changes: 0 additions & 35 deletions java-generator/README.md

This file was deleted.

Expand Up @@ -250,7 +250,6 @@ public MockResponse handlePatch(RecordedRequest request) {
}

setDefaultMetadata(updated, pathValues, source);

String updatedAsString = Serialization.asJson(updated);

return validateRequestBodyAndHandleRequest(updatedAsString, h -> {
Expand Down Expand Up @@ -414,8 +413,9 @@ private MockResponse doCreateOrModify(String path, String initial, HasMetadata v
if (isStatusPath(path)) {
JsonNode status = removeStatus(updated);
// set the status on the existing node
updated = existingNode;
updated = existingNode.deepCopy();
setStatus(updated, status);
setDefaultMetadata(updated, pathValues, existingNode);
} else {
// preserve status and generated fields
if (statusSubresource) {
Expand Down

0 comments on commit e1b1055

Please sign in to comment.