Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CRD generation from RealmRepresentation #9759

Merged
merged 6 commits into from
Jan 27, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ public void setPriority(int priority) {
*
* @return
*/
@Deprecated
private boolean autheticatorFlow;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Instead of adding this unused field I would be happy to remove the following accessors, unfortunately, the latter is a breaking change for the import/export functionality.
cc. @stianst @pedroigor

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm probably missing something, but why do you need to remove a simple boolean field?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Here we are adding back the field, that remains unused, since it's emitted by the Json serialization.
If we don't add it, you would need to remove all the relevant fields autheticatorFlow (WITH the typo) from the exported RealmRepresentation before importing it as a CR.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@stianst this is the only change in the core I'm leaving, as far as I can tell it should be ok, but let me know if I have to duplicate even this file.


@Deprecated
public boolean isAutheticatorFlow() {
return authenticatorFlow;
Expand Down
56 changes: 56 additions & 0 deletions operator/patch-sources.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#!/usr/bin/env bash

sedCommand="sed"
if [ "$(uname)" == "Darwin" ]; then
if hash gsed 2>/dev/null; then
sedCommand="gsed"
fi
fi

function addAnnotation() {
local match=$1
local annotation=$2
local file=$3

$sedCommand -i "/^.*${match}.*/i ${annotation}" ${file}
}

addAnnotation \
"protected List<GroupRepresentation> subGroups;" \
"@io.fabric8.crd.generator.annotation.SchemaFrom(type = org.keycloak.representations.overrides.NoSubGroupsGroupRepresentationList.class)" \
target/keycloak-core/org/keycloak/representations/idm/GroupRepresentation.java

addAnnotation \
"private MultivaluedHashMap<String, ComponentExportRepresentation> components;" \
"@io.fabric8.crd.generator.annotation.SchemaFrom(type = org.keycloak.representations.overrides.ComponentExportRepresentationMap.class)" \
target/keycloak-core/org/keycloak/representations/idm/RealmRepresentation.java

addAnnotation \
"private MultivaluedHashMap<String, String> config;" \
"@io.fabric8.crd.generator.annotation.SchemaFrom(type = org.keycloak.representations.overrides.MultivaluedStringStringHashMap.class)" \
target/keycloak-core/org/keycloak/representations/idm/CredentialRepresentation.java

addAnnotation \
"private MultivaluedHashMap<String, String> config;" \
"@io.fabric8.crd.generator.annotation.SchemaFrom(type = org.keycloak.representations.overrides.MultivaluedStringStringHashMap.class)" \
target/keycloak-core/org/keycloak/representations/idm/ComponentRepresentation.java

addAnnotation \
"private MultivaluedHashMap<String, ComponentExportRepresentation> subComponents = new MultivaluedHashMap<>();" \
"@io.fabric8.crd.generator.annotation.SchemaFrom(type = org.keycloak.representations.overrides.NoSubcomponentsComponentExportRepresentationMap.class)" \
target/keycloak-core/org/keycloak/representations/idm/ComponentExportRepresentation.java

addAnnotation \
"private MultivaluedHashMap<String, String> config = new MultivaluedHashMap<>();" \
"@io.fabric8.crd.generator.annotation.SchemaFrom(type = org.keycloak.representations.overrides.MultivaluedStringStringHashMap.class)" \
target/keycloak-core/org/keycloak/representations/idm/ComponentExportRepresentation.java

addAnnotation \
"private List<PolicyRepresentation> policies;" \
"@com.fasterxml.jackson.annotation.JsonIgnore" \
target/keycloak-core/org/keycloak/representations/idm/authorization/ScopeRepresentation.java

addAnnotation \
"private List<ResourceRepresentation> resources;" \
"@com.fasterxml.jackson.annotation.JsonIgnore" \
target/keycloak-core/org/keycloak/representations/idm/authorization/ScopeRepresentation.java
98 changes: 83 additions & 15 deletions operator/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
-->
<resteasy.version>4.7.4.Final</resteasy.version>
<wildfly.common.version>1.5.4.Final-format-001</wildfly.common.version>
<jackson.version>2.13.1</jackson.version>
<kubernetes-client.version>5.12.0</kubernetes-client.version>

<compiler-plugin.version>3.8.1</compiler-plugin.version>
<maven.compiler.parameters>true</maven.compiler.parameters>
Expand Down Expand Up @@ -58,6 +60,18 @@


<dependencies>
<!-- Fabric8 -->
<dependency>
<groupId>io.fabric8</groupId>
<artifactId>crd-generator-api</artifactId>
<version>${kubernetes-client.version}</version>
</dependency>
<dependency>
<groupId>io.fabric8</groupId>
<artifactId>crd-generator-apt</artifactId>
<version>${kubernetes-client.version}</version>
</dependency>

<!-- Quarkus -->
<dependency>
<groupId>io.quarkiverse.operatorsdk</groupId>
Expand Down Expand Up @@ -103,7 +117,7 @@
<!-- Keycloak -->
<dependency>
<groupId>org.keycloak</groupId>
<artifactId>keycloak-core</artifactId>
<artifactId>keycloak-common</artifactId>
</dependency>
</dependencies>

Expand Down Expand Up @@ -138,23 +152,77 @@
<artifactId>maven-resources-plugin</artifactId>
<executions>
<execution>
<id>copy-resources</id>
<phase>validate</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${basedir}/target</outputDirectory>
<resources>
<resource>
<directory>src/main/kubernetes</directory>
<filtering>true</filtering>
</resource>
</resources>
</configuration>
<id>copy-resources</id>
<phase>validate</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${basedir}/target</outputDirectory>
<resources>
<resource>
<directory>src/main/kubernetes</directory>
<filtering>true</filtering>
</resource>
</resources>
</configuration>
</execution>
<execution>
<id>import-keycloak-core</id>
<phase>validate</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${basedir}/target/keycloak-core</outputDirectory>
<resources>
<resource>
<directory>${basedir}/../core/src/main/java</directory>
<filtering>true</filtering>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>

<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>3.2.0</version>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>${basedir}/target/keycloak-core</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>

<plugin>
<artifactId>exec-maven-plugin</artifactId>
<groupId>org.codehaus.mojo</groupId>
<version>1.6.0</version>
<executions>
<execution>
<id>patch-core-sources</id>
<phase>generate-sources</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>${basedir}/patch-sources.sh</executable>
</configuration>
</execution>
</executions>
</plugin>

</plugins>
</build>

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Copyright 2021 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.
*/
package org.keycloak.operator.v2alpha1.crds;

import io.fabric8.kubernetes.api.model.Namespaced;
import io.fabric8.kubernetes.client.CustomResource;
import io.fabric8.kubernetes.model.annotation.Group;
import io.fabric8.kubernetes.model.annotation.Plural;
import io.fabric8.kubernetes.model.annotation.ShortNames;
import io.fabric8.kubernetes.model.annotation.Version;
import org.keycloak.operator.Constants;

@Group(Constants.CRDS_GROUP)
@Version(Constants.CRDS_VERSION)
public class Realm extends CustomResource<RealmSpec, Void> implements Namespaced {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* Copyright 2021 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.
*/
package org.keycloak.operator.v2alpha1.crds;

import org.keycloak.representations.idm.RealmRepresentation;

import javax.validation.constraints.NotNull;

public class RealmSpec {

@NotNull
private String keycloakCRName;
@NotNull
private RealmRepresentation realm;

public String getKeycloakCRName() {
return keycloakCRName;
}

public void setKeycloakCRName(String keycloakCRName) {
this.keycloakCRName = keycloakCRName;
}

public RealmRepresentation getRealm() {
return realm;
}

public void setRealm(RealmRepresentation realm) {
this.realm = realm;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* 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.
*/

package org.keycloak.representations.overrides;

import java.util.HashMap;
import java.util.List;
import org.keycloak.representations.idm.ComponentExportRepresentation;

public class ComponentExportRepresentationMap extends HashMap<String, List<ComponentExportRepresentation>> {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* 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.
*/

package org.keycloak.representations.overrides;

import java.util.HashMap;
import java.util.List;

public class MultivaluedStringStringHashMap extends HashMap<String, List<String>> {
}