Skip to content

Commit

Permalink
Merge branch 'main' into cachelock
Browse files Browse the repository at this point in the history
  • Loading branch information
shawkins authored May 6, 2024
2 parents 67ba9fa + c6437af commit c2a222c
Show file tree
Hide file tree
Showing 110 changed files with 7,392 additions and 28 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/sonar.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
name: Sonar Scanner

env:
MAVEN_ARGS: -B -C -V -ntp -Dhttp.keepAlive=false -e
MAVEN_OPTIONS: -B -C -V -ntp -Dhttp.keepAlive=false -e

on:
push:
Expand Down Expand Up @@ -55,5 +55,5 @@ jobs:
with:
java-version: '17'
distribution: 'temurin'
- name: Maven Sonar
run: ./mvnw ${MAVEN_ARGS} clean install sonar:sonar -Psonar
- name: Sonar
run: make clean sonar
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#### Improvements
* Fix #5973: CacheImpl locking for reading indexes (Cache.byIndex|indexKeys|index) was reduced
* Fix #5605: proxy configs support proxy URLs without a scheme
* Fix #5878: (java-generator) Add implements Editable for extraAnnotations
* Fix #5878: (java-generator) Update documentation to include dependencies
* Fix #5867: (crd-generator) Imply schemaFrom via JsonFormat shape (SchemaFrom takes precedence)
Expand Down
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
# limitations under the License.
#

MAVEN_OPTIONS=
MAVEN_OPTIONS ?=

.PHONY: clean-java
clean-java:
Expand All @@ -26,3 +26,7 @@ clean: clean-java
.PHONY: generate-model
generate-model:
cd kubernetes-model-generator && ./generateModel.sh

.PHONY: sonar
sonar:
mvn $(MAVEN_OPTIONS) clean install sonar:sonar -Psonar
81 changes: 81 additions & 0 deletions crd-generator/api-v2/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (C) 2015 Red Hat, Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>crd-generator-parent</artifactId>
<groupId>io.fabric8</groupId>
<version>6.13-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>crd-generator-api-v2</artifactId>
<name>Fabric8 :: CRD generator :: API V2</name>

<dependencies>
<dependency>
<groupId>io.fabric8</groupId>
<artifactId>kubernetes-client-api</artifactId>
<scope>compile</scope>
</dependency>

<dependency>
<groupId>com.fasterxml.jackson.module</groupId>
<artifactId>jackson-module-jsonSchema</artifactId>
</dependency>

<dependency>
<groupId>io.fabric8</groupId>
<artifactId>generator-annotations</artifactId>
</dependency>

<dependency>
<groupId>io.fabric8</groupId>
<artifactId>kubernetes-model-common</artifactId>
</dependency>

<!-- Testing -->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/*
* Copyright (C) 2015 Red Hat, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.fabric8.crdv2.generator;

import io.fabric8.crd.generator.annotation.PrinterColumn;
import io.fabric8.crdv2.generator.AbstractJsonSchema.AnnotationMetadata;
import io.fabric8.kubernetes.api.model.HasMetadata;
import io.fabric8.kubernetes.client.utils.Utils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Map;
import java.util.Set;
import java.util.TreeMap;
import java.util.stream.Stream;

/**
* This class encapsulates the common behavior between different CRD generation logic. The
* intent is that each CRD spec version is implemented as a sub-class of this one.
*/
public abstract class AbstractCustomResourceHandler {

private static final Logger LOGGER = LoggerFactory.getLogger(AbstractJsonSchema.class);

public abstract void handle(CustomResourceInfo config, ResolvingContext resolvingContext);

public interface PrinterColumnHandler {
void addPrinterColumn(String path, String column, String format,
int priority, String type, String description);
}

protected void handlePrinterColumns(AbstractJsonSchema<?, ?> resolver, PrinterColumnHandler handler) {
TreeMap<String, AnnotationMetadata> sortedCols = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
sortedCols.putAll(resolver.getAllPaths(PrinterColumn.class));
sortedCols.forEach((path, property) -> {
PrinterColumn printerColumn = ((PrinterColumn) property.annotation);
String column = printerColumn.name();
if (Utils.isNullOrEmpty(column)) {
column = path.substring(path.lastIndexOf(".") + 1).toUpperCase();
}
String format = printerColumn.format();
format = Utils.isNotNullOrEmpty(format) ? format : null;
int priority = printerColumn.priority();
String type = property.schema.getType();
if ("object".equals(type) || "array".equals(type)) {
LOGGER.warn("Printer column '{}' has a type '{}' that is not allowed, will use string intead", column, type);
type = "string";
} else if ("string".equals(type) && "date".equals(property.schema.getFormat())) {
type = "date";
}

// TODO: add description to the annotation? The previous logic considered the comments, which are not available here
String description = property.schema.getDescription();
description = Utils.isNotNullOrEmpty(description) ? description : null;

handler.addPrinterColumn(path, column, format, priority, type, description);
});
}

public abstract Stream<Map.Entry<? extends HasMetadata, Set<String>>> finish();

}
Loading

0 comments on commit c2a222c

Please sign in to comment.