8000 Operator CRD with generated ServerConfiguration from refactored config by andreaTP · Pull Request #11929 · keycloak/keycloak · GitHub
[go: up one dir, main page]

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions .github/workflows/operator-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,11 @@ jobs:
run: |
eval $(minikube -p minikube docker-env)
(cd quarkus/container && docker build --build-arg KEYCLOAK_DIST=$(ls keycloak-*.tar.gz) . -t keycloak:${{ steps.vars.outputs.version }})
(cd operator && ./scripts/build-testing-docker-images.sh ${{ steps.vars.outputs.version }} keycloak custom-keycloak)
(cd operator/app && ./scripts/build-testing-docker-images.sh ${{ steps.vars.outputs.version }} keycloak custom-keycloak)

- name: Test operator running locally
run: |
mvn -Poperator -pl operator -am clean verify \
mvn clean verify -Poperator -pl :keycloak-operator -am \
-Dquarkus.kubernetes.deployment-target=kubernetes \
-Doperator.keycloak.image=keycloak:${{ steps.vars.outputs.version }} \
-Dtest.operator.custom.image=custom-keycloak:${{ steps.vars.outputs.version }} \
Expand Down Expand Up @@ -121,12 +121,12 @@ jobs:
run: |
eval $(minikube -p minikube docker-env)
(cd quarkus/container && docker build --build-arg KEYCLOAK_DIST=$(ls keycloak-*.tar.gz) . -t keycloak:${{ steps.vars.outputs.version }})
(cd operator && ./scripts/build-testing-docker-images.sh ${{ steps.vars.outputs.version }} keycloak custom-keycloak)
(cd operator/app && ./scripts/build-testing-docker-images.sh ${{ steps.vars.outputs.version }} keycloak custom-keycloak)

- name: Test operator running in cluster
run: |
eval $(minikube -p minikube docker-env)
mvn -Poperator -pl operator -am clean verify \
mvn clean verify -Poperator -pl :keycloak-operator -am \
-Dquarkus.container-image.build=true \
-Dquarkus.kubernetes.deployment-target=kubernetes \
-Doperator.keycloak.image=keycloak:${{ steps.vars.outputs.version }} \
Expand Down Expand Up @@ -163,7 +163,7 @@ jobs:
- name: Install Yq
run: sudo snap install yq
- name: Install OLM
working-directory: operator
working-directory: operator/app
run: ./scripts/install-olm.sh
- name: Download keycloak distribution
id: download-keycloak-dist
Expand All @@ -172,13 +172,13 @@ jobs:
name: keycloak-distribution
path: quarkus/container
- name: Arrange OLM test installation
working-directory: operator
working-directory: operator/app
run: |
eval $(minikube -p minikube docker-env)
./scripts/olm-testing.sh ${GITHUB_SHA::6}

- name: Deploy an example Keycloak and wait for it to be ready
working-directory: operator
working-directory: operator/app
run: |
kubectl apply -f src/main/resources/example-postgres.yaml
./scripts/check-crds-installed.sh
Expand Down
41 changes: 41 additions & 0 deletions config-api/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?xml version="1.0"?>
<!--
~ Copyright 2016 Red Hat, Inc. and/or its affiliates
~ and other contributors as indicated by the @author tags.
~
~ 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/maven-v4_0_0.xsd">
<parent>
<artifactId>keycloak-parent</artifactId>
<groupId>org.keycloak</groupId>
<version>999-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>keycloak-config-api</artifactId>
<name>Keycloak Configuration API</name>
<packaging>jar</packaging>
<description/>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.release>11</maven.compiler.release>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
</properties>

</project>
13 changes: 13 additions & 0 deletions config-api/src/main/java/org/keycloak/config/AllOptions.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package org.keycloak.config;

import java.util.ArrayList;
import java.util.List;

public class AllOptions {

public final static List<Option<?>> ALL_OPTIONS = new ArrayList<>();

static {
ALL_OPTIONS.addAll(HttpOptions.ALL_OPTIONS);
}
}
20 changes: 20 additions & 0 deletions config-api/src/main/java/org/keycloak/config/HttpOptions.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package org.keycloak.config;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;

public class HttpOptions {

public final static Option httpPort = new OptionBuilder<Integer>("http-port", Integer.class)
.description("The used HTTP port.")
.category(OptionCategory.HTTP)
.defaultValue(8080)
.build();

public final static List<Option<?>> ALL_OPTIONS = new ArrayList<>();

static {
ALL_OPTIONS.add(httpPort);
}
}
65 changes: 65 additions & 0 deletions config-api/src/main/java/org/keycloak/config/Option.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package org.keycloak.config;

import java.util.List;
import java.util.Optional;
import java.util.Set;

public class Option<T> {

public enum Runtime {
QUARKUS,
DOCS,
OPERATOR;
}

private final Class<T> type;
private final String key;
private final OptionCategory category;
private final Set<Runtime> supportedRuntimes;
private final boolean buildTime;
private final String description;
private final Optional<T> defaultValue;
private final List<T> expectedValues;

public Option(Class<T> type, String key, OptionCategory category, Set<Runtime> supportedRuntimes, boolean buildTime, String description, Optional<T> defaultValue, List<T> expectedValues) {
this.type = type;
this.key = key;
this.category = category;
this.supportedRuntimes = supportedRuntimes;
this.buildTime = buildTime;
this.description = description;
this.defaultValue = defaultValue;
this.expectedValues = expectedValues;
}

public Class<T> getType() {
return type;
}

public Set<Runtime> getSupportedRuntimes() {
return supportedRuntimes;
}

public boolean isBuildTime() {
return buildTime;
}

public String getKey() {
return key;
}

public OptionCategory getCategory() {
return category;
}

public String getDescription() { return description; }

public Optional<T> getDefaultValue() {
return defaultValue;
}

public List<T> getExpectedValues() {
return expectedValues;
}

}
85 changes: 85 additions & 0 deletions config-api/src/main/java/org/keycloak/config/OptionBuilder.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
package org.keycloak.config;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;

10BC8 public class OptionBuilder<T> {
private Class<T> type;
private String key;
private OptionCategory category;
private Set<Option.Runtime> supportedRuntimes;
private boolean build;
private String description;
private Optional<T> defaultValue;
private List<T> expectedValues;

public OptionBuilder(String key, Class<T> type) {
this.type = type;
this.key = key;
category = OptionCategory.GENERAL;
supportedRuntimes = Arrays.stream(Option.Runtime.values()).collect(Collectors.toSet());
build = false;
description = "";
defaultValue = Optional.empty();
expectedValues = new ArrayList<>();
}

public OptionBuilder<T> category(OptionCategory category) {
this.category = category;
return this;
}

public OptionBuilder<T> runtimes(Option.Runtime ... runtimes) {
this.supportedRuntimes.clear();
this.supportedRuntimes.addAll(Arrays.asList(runtimes));
return this;
}

public OptionBuilder<T> runtimes(Set<Option.Runtime> runtimes) {
this.supportedRuntimes.clear();
this.supportedRuntimes.addAll(runtimes);
return this;
}

public OptionBuilder<T> buildTime(boolean build) {
this.build = build;
return this;
}

public OptionBuilder<T> description(String description) {
this.description = description;
return this;
}

public OptionBuilder<T> defaultValue(Optional<T> defaultV) {
this.defaultValue = defaultV;
return this;
}

public OptionBuilder<T> defaultValue(T defaultV) {
this.defaultValue = Optional.ofNullable(defaultV);
return this;
}

public OptionBuilder<T> expectedValues(List<T> expected) {
this.expectedValues.clear();
this.expectedValues.addAll(expected);
return this;
}

public OptionBuilder<T> expectedValues(T ... expected) {
this.expectedValues.clear();
this.expectedValues.addAll(Arrays.asList(expected));
return this;
}

public Option<T> build() {
return new Option<T>(type, key, category, supportedRuntimes, build, description, defaultValue, expectedValues);
}

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package org.keycloak.quarkus.runtime.configuration.mappers;
package org.keycloak.config;

public enum ConfigCategory {
public enum OptionCategory {
// ordered by name asc
CLUSTERING("Cluster", 10),
DATABASE("Database", 20),
Expand All @@ -20,7 +20,7 @@ public enum ConfigCategory {
//Categories with a lower number are shown before groups with a higher number
private final int order;

ConfigCategory(String heading, int order) {
OptionCategory(String heading, int order) {
this.heading = heading; this.order = order;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,22 @@
import static org.keycloak.quarkus.runtime.configuration.MicroProfileConfigProvider.NS_KEYCLOAK_PREFIX;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't we replace this class and Option now we have similar types in from the new module?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can replace some of this, unfortunately, looks like SPIs configuration is still not covered:

for (Spi loadSpi : providerManager.loadSpis().stream().sorted(Comparator.comparing(Spi::getName)).collect(Collectors.toList())) {
for (ProviderFactory providerFactory : providerManager.load(loadSpi).stream().sorted(Comparator.comparing(ProviderFactory::getId)).collect(Collectors.toList())) {
List<ProviderConfigProperty> configMetadata = providerFactory.getConfigMetadata();
if (configMetadata == null) {
continue;
}
String optionPrefix = NS_KEYCLOAK_PREFIX + String.join(OPTION_PART_SEPARATOR, ArrayUtils.insert(0, new String[] {loadSpi.getName(), providerFactory.getId()}, "spi"));
List<Option> options = configMetadata.stream()
.map(m -> new Option(Configuration.toDashCase(optionPrefix.concat("-") + m.getName()), ConfigCategory.GENERAL, false,
m.getHelpText(),
m.getDefaultValue() == null ? "none" : m.getDefaultValue().toString(),
m.getOptions() == null ? (m.getType() == null ? Collections.emptyList() : Collections.singletonList(m.getType())) : m.getOptions()))
.sorted(Comparator.comparing(Option::getKey)).collect(Collectors.toList());
if (!options.isEmpty()) {
providerOptions.computeIfAbsent(toDashCase(loadSpi.getName()), k -> new LinkedHashMap<>()).put(toDashCase(providerFactory.getId()), options);
}
}
}

In this PR I took out the docs bit to be able to perform the change incrementally (i.e. with subsequent non-breaking PRs)
E.g. the docs sub-module will rely on the new configuration only after we move all the configuration keys to the new encoding.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Although we don't have yet a proper support for exposing SPI configuration options, the new module should be able to provide them similarly to what you did to HttpOptions.

The difference here is that these options are dynamic as they come from whatever provider is installed on the server. In the future, and that is related to the extension story, it should also resolve options from custom providers.

If you want, I can look at this closer and try to come up with something to support this.


import org.apache.commons.lang3.ArrayUtils;
import org.keycloak.config.OptionCategory;
import org.keycloak.provider.ProviderConfigProperty;
import org.keycloak.provider.ProviderFactory;
import org.keycloak.provider.ProviderManager;
import org.keycloak.provider.Spi;
import org.keycloak.quarkus.runtime.Providers;
import org.keycloak.quarkus.runtime.configuration.Configuration;
import org.keycloak.quarkus.runtime.configuration.mappers.ConfigCategory;
import org.keycloak.quarkus.runtime.configuration.mappers.PropertyMapper;
import org.keycloak.quarkus.runtime.configuration.mappers.PropertyMappers;

import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.function.Predicate;
import java.util.stream.Collectors;
import java.util.stream.StreamSupport;

Expand All @@ -36,7 +33,7 @@ public Options() {
options = PropertyMappers.getMappers().stream()
.filter(m -> !m.isHidden())
.filter(propertyMapper -> Objects.nonNull(propertyMapper.getDescription()))
.map(m -> new Option(m.getFrom(), m.getCategory(), m.isBuildTime(), m.getDescription(), m.getDefaultValue(), m.getExpectedValues()))
.map(m -> new Option(m.getFrom(), m.getCategory(), m.isBuildTime(), m.getDescription(), (String) m.getDefaultValue().map(d -> d.toString()).orElse(null), m.getExpectedValues()))
.sorted(Comparator.comparing(Option::getKey))
.collect(Collectors.toMap(Option::getKey, o -> o, (o1, o2) -> o1, LinkedHashMap::new)); // Need to ignore duplicate keys??
ProviderManager providerManager = Providers.getProviderManager(Thread.currentThread().getContextClassLoader());
Expand All @@ -51,7 +48,7 @@ public Options() {

String optionPrefix = NS_KEYCLOAK_PREFIX + String.join(OPTION_PART_SEPARATOR, ArrayUtils.insert(0, new String[] {loadSpi.getName(), providerFactory.getId()}, "spi"));
List<Option> options = configMetadata.stream()
.map(m -> new Option(Configuration.toDashCase(optionPrefix.concat("-") + m.getName()), ConfigCategory.GENERAL, false,
.map(m -> new Option(Configuration.toDashCase(optionPrefix.concat("-") + m.getName()), OptionCategory.GENERAL, false,
m.getHelpText(),
m.getDefaultValue() == null ? "none" : m.getDefaultValue().toString(),
m.getOptions() == null ? (m.getType() == null ? Collections.emptyList() : Collections.singletonList(m.getType())) : m.getOptions()))
Expand All @@ -64,15 +61,15 @@ public Options() {
}
}

public ConfigCategory[] getCategories() {
return ConfigCategory.values();
public OptionCategory[] getCategories() {
return OptionCategory.values();
}

public Collection<Option> getValues() {
return options.values();
}

public Collection<Option> getValues(ConfigCategory category) {
public Collection<Option> getValues(OptionCategory category) {
return options.values().stream().filter(o -> o.category.equals(category)).collect(Collectors.toList());
}

Expand All @@ -92,13 +89,13 @@ public Map<String, Map<String, List<Option>>> getProviderOptions() {
public class Option {

private String key;
private ConfigCategory category;
private OptionCategory category;
private boolean build;
private String description;
private String defaultValue;
private List<String> expectedValues;

public Option(String key, ConfigCategory category, boolean build, String description, String defaultValue, Iterable<String> expectedValues) {
public Option(String key, OptionCategory category, boolean build, String description, String defaultValue, Iterable<String> expectedValues) {
this.key = key;
this.category = category;
this.build = build;
Expand Down
File renamed without changes.
File renamed without changes.
Loading
0