Skip to content

Commit

Permalink
Merge pull request #1 from fabiobrz/update_kn_client.fabiobrz
Browse files Browse the repository at this point in the history
Bumping fabric8 k8s client to 6.7.2 and adjusting OpenShift class accordingly
  • Loading branch information
RoyalKarma authored Aug 24, 2023
2 parents b264a47 + 0d0f706 commit bf5cd0c
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,14 @@
import io.fabric8.kubernetes.api.model.Quantity;
import io.fabric8.openshift.api.model.BinaryBuildSource;
import io.fabric8.openshift.api.model.BuildConfig;
import io.fabric8.openshift.api.model.BuildConfigFluent.SpecNested;
import io.fabric8.openshift.api.model.BuildConfigFluent;
import io.fabric8.openshift.api.model.BuildConfigSpecFluent;
import io.fabric8.openshift.api.model.BuildSourceBuilder;
import io.fabric8.openshift.api.model.BuildTriggerPolicy;
import io.fabric8.openshift.api.model.BuildTriggerPolicyBuilder;
import io.fabric8.openshift.api.model.GitBuildSourceBuilder;
import io.fabric8.openshift.api.model.ImageSourceBuilder;
import io.fabric8.openshift.api.model.ImageSourceFluent.FromNested;
import io.fabric8.openshift.api.model.ImageSourceFluent;
import io.fabric8.openshift.api.model.SecretBuildSourceBuilder;

public class BuildConfigBuilder extends AbstractBuilder<BuildConfig, BuildConfigBuilder> implements ResourceLimitBuilder {
Expand Down Expand Up @@ -183,7 +184,7 @@ public BuildConfig build() {

if (imageSource != null) {
final ImageSourceBuilder isb = new ImageSourceBuilder();
FromNested<ImageSourceBuilder> from = isb.withNewFrom()
ImageSourceFluent<ImageSourceBuilder>.FromNested<ImageSourceBuilder> from = isb.withNewFrom()
.withName(imageSource.getName())
.withKind(imageSource.getKind());
if (imageSource.getNamespace() != null) {
Expand All @@ -200,15 +201,16 @@ public BuildConfig build() {
.withMetadata(metadataBuilder().build());

// spec
final SpecNested<io.fabric8.openshift.api.model.BuildConfigBuilder> spec = builder.withNewSpec();
final BuildConfigFluent<io.fabric8.openshift.api.model.BuildConfigBuilder>.SpecNested<io.fabric8.openshift.api.model.BuildConfigBuilder> spec = builder
.withNewSpec();

// limits
final List<ComputingResource> requests = computingResources.values().stream().filter(x -> x.getRequests() != null)
.collect(Collectors.toList());
final List<ComputingResource> limits = computingResources.values().stream().filter(x -> x.getLimits() != null)
.collect(Collectors.toList());
if (!requests.isEmpty() || !limits.isEmpty()) {
io.fabric8.openshift.api.model.BuildConfigSpecFluent.ResourcesNested<SpecNested<io.fabric8.openshift.api.model.BuildConfigBuilder>> resources = spec
BuildConfigSpecFluent<BuildConfigFluent<io.fabric8.openshift.api.model.BuildConfigBuilder>.SpecNested<io.fabric8.openshift.api.model.BuildConfigBuilder>>.ResourcesNested<BuildConfigFluent<io.fabric8.openshift.api.model.BuildConfigBuilder>.SpecNested<io.fabric8.openshift.api.model.BuildConfigBuilder>> resources = spec
.withNewResources();
if (!requests.isEmpty()) {
resources.withRequests(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public ImageStreamBuilder addTag(String tag, String sourceUrl, boolean insecure,
.withName(tag);

if (StringUtils.isNotBlank(sourceUrl)) {
trb.withImportPolicy(new TagImportPolicy(insecure, SCHEDULED));
trb.withImportPolicy(new TagImportPolicy("Legacy", insecure, SCHEDULED));

trb.withNewFrom()
.withKind("DockerImage")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public RoleBindingBuilder roleRefNamespace(String roleRefNamespace) {

@Override
public RoleBinding build() {
RoleBindingFluent.SubjectsNested<io.fabric8.kubernetes.api.model.rbac.RoleBindingBuilder> subject = new io.fabric8.kubernetes.api.model.rbac.RoleBindingBuilder()
RoleBindingFluent<io.fabric8.kubernetes.api.model.rbac.RoleBindingBuilder>.SubjectsNested<io.fabric8.kubernetes.api.model.rbac.RoleBindingBuilder> subject = new io.fabric8.kubernetes.api.model.rbac.RoleBindingBuilder()
.withNewMetadata()
.withName(this.getName())
.endMetadata()
Expand All @@ -105,7 +105,7 @@ public RoleBinding build() {
if (subjectNamespace != null && !subjectNamespace.isEmpty())
subject.withNamespace(subjectNamespace);

RoleBindingFluent.RoleRefNested<io.fabric8.kubernetes.api.model.rbac.RoleBindingBuilder> roleRef = subject
RoleBindingFluent<io.fabric8.kubernetes.api.model.rbac.RoleBindingBuilder>.RoleRefNested<io.fabric8.kubernetes.api.model.rbac.RoleBindingBuilder> roleRef = subject
.endSubject()
.withNewRoleRef()
.withKind(roleRefKind)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public ConfigMapVolume(String name, String configMapName, String defaultMode) {

@Override
protected void addVolumeParameters(VolumeBuilder builder) {
VolumeFluent.ConfigMapNested<VolumeBuilder> cfm = builder.withNewConfigMap();
VolumeFluent<VolumeBuilder>.ConfigMapNested<VolumeBuilder> cfm = builder.withNewConfigMap();
cfm.withName(configMapName);
if (defaultMode != null) {
int defaultModeIntVal = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import cz.xtf.builder.builders.route.TransportProtocol;
import io.fabric8.kubernetes.api.model.ConfigMapKeySelectorBuilder;
import io.fabric8.kubernetes.api.model.Container;
import io.fabric8.kubernetes.api.model.ContainerFluent.ResourcesNested;
import io.fabric8.kubernetes.api.model.ContainerFluent;
import io.fabric8.kubernetes.api.model.ContainerPortBuilder;
import io.fabric8.kubernetes.api.model.EnvVar;
import io.fabric8.kubernetes.api.model.EnvVarSource;
Expand Down Expand Up @@ -251,7 +251,8 @@ public Container build() {
final List<ComputingResource> limits = computingResources.values().stream().filter(x -> x.getLimits() != null)
.collect(Collectors.toList());
if (!requests.isEmpty() || !limits.isEmpty()) {
ResourcesNested<io.fabric8.kubernetes.api.model.ContainerBuilder> resources = builder.withNewResources();
ContainerFluent<io.fabric8.kubernetes.api.model.ContainerBuilder>.ResourcesNested<io.fabric8.kubernetes.api.model.ContainerBuilder> resources = builder
.withNewResources();
if (!requests.isEmpty()) {
resources.withRequests(
requests.stream().collect(Collectors.toMap(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public String getSecretName() {
@Override
protected void addVolumeParameters(VolumeBuilder builder) {

final VolumeFluent.SecretNested<VolumeBuilder> volumeBuilderSecretNested = builder.withNewSecret()
final VolumeFluent<VolumeBuilder>.SecretNested<VolumeBuilder> volumeBuilderSecretNested = builder.withNewSecret()
.withSecretName(getSecretName());

if (items != null) {
Expand Down
23 changes: 17 additions & 6 deletions core/src/main/java/cz/xtf/core/openshift/OpenShift.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
import io.fabric8.kubernetes.api.model.GenericKubernetesResourceList;
import io.fabric8.kubernetes.api.model.HasMetadata;
import io.fabric8.kubernetes.api.model.KubernetesList;
import io.fabric8.kubernetes.api.model.KubernetesResourceList;
import io.fabric8.kubernetes.api.model.LocalObjectReferenceBuilder;
import io.fabric8.kubernetes.api.model.Node;
import io.fabric8.kubernetes.api.model.ObjectMetaBuilder;
Expand All @@ -72,9 +73,12 @@
import io.fabric8.kubernetes.api.model.rbac.Subject;
import io.fabric8.kubernetes.api.model.rbac.SubjectBuilder;
import io.fabric8.kubernetes.client.Config;
import io.fabric8.kubernetes.client.KubernetesClientBuilder;
import io.fabric8.kubernetes.client.KubernetesClientException;
import io.fabric8.kubernetes.client.LocalPortForward;
import io.fabric8.kubernetes.client.dsl.LogWatch;
import io.fabric8.kubernetes.client.dsl.base.ResourceDefinitionContext;
import io.fabric8.kubernetes.client.dsl.internal.HasMetadataOperationsImpl;
import io.fabric8.openshift.api.model.Build;
import io.fabric8.openshift.api.model.BuildConfig;
import io.fabric8.openshift.api.model.BuildRequest;
Expand All @@ -88,16 +92,17 @@
import io.fabric8.openshift.api.model.Route;
import io.fabric8.openshift.api.model.RouteSpecBuilder;
import io.fabric8.openshift.api.model.Template;
import io.fabric8.openshift.client.NamespacedOpenShiftClient;
import io.fabric8.openshift.client.NamespacedOpenShiftClientAdapter;
import io.fabric8.openshift.client.OpenShiftConfig;
import io.fabric8.openshift.client.OpenShiftConfigBuilder;
import io.fabric8.openshift.client.ParameterValue;
import io.fabric8.openshift.client.impl.OpenShiftClientImpl;
import lombok.extern.slf4j.Slf4j;
import rx.Observable;
import rx.observables.StringObservable;

@Slf4j
public class OpenShift extends OpenShiftClientImpl {
public class OpenShift extends NamespacedOpenShiftClientAdapter {
private static ServiceLoader<CustomResourceDefinitionContextProvider> crdContextProviderLoader;
private static volatile String routeSuffix;

Expand Down Expand Up @@ -187,7 +192,7 @@ private static OpenShift get(OpenShiftConfig openShiftConfig) {
// check whether such a client already exists
Optional<OpenShift> optionalOpenShift = namespaceToOpenshiftClientMap
.get(openShiftConfig.getNamespace()).stream()
.filter(oc -> isEqualOpenshiftConfig(openShiftConfig, oc.getConfiguration()))
.filter(oc -> isEqualOpenshiftConfig(openShiftConfig, (OpenShiftConfig) oc.getConfiguration()))
.findFirst();

if (optionalOpenShift.isPresent()) {
Expand Down Expand Up @@ -215,8 +220,9 @@ protected static synchronized ServiceLoader<CustomResourceDefinitionContextProvi
private final OpenShiftWaiters waiters;

public OpenShift(OpenShiftConfig openShiftConfig) {
super(openShiftConfig);

NamespacedOpenShiftClient delegate = new KubernetesClientBuilder().withConfig(openShiftConfig).build()
.adapt(NamespacedOpenShiftClient.class);
this.init(delegate);
this.waiters = new OpenShiftWaiters(this);
}

Expand Down Expand Up @@ -1387,8 +1393,13 @@ private static boolean isEqualOpenshiftConfig(OpenShiftConfig newConfig, OpenShi
.append(newConfig.getNamespace(), existingConfig.getNamespace())
.append(newConfig.getUsername(), existingConfig.getUsername())
.append(newConfig.getPassword(), existingConfig.getPassword())
.append(newConfig.getRequestConfig().getOauthToken(), existingConfig.getRequestConfig().getOauthToken())
.append(newConfig.getOauthToken(), existingConfig.getOauthToken())
.append(newConfig.isTrustCerts(), existingConfig.isTrustCerts())
.isEquals();
}

public <T extends HasMetadata, L extends KubernetesResourceList<T>> HasMetadataOperationsImpl<T, L> newHasMetadataOperation(
ResourceDefinitionContext rdContext, Class<T> resourceType, Class<L> listClass) {
return new HasMetadataOperationsImpl<>(this, rdContext, resourceType, listClass);
}
}
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@

<!-- Dependency version properties -->
<version.httpclient>4.5.13</version.httpclient>
<version.openshift-client>6.4.1</version.openshift-client>
<version.openshift-client>6.8.1</version.openshift-client>
<version.commons-io>2.8.0</version.commons-io>
<version.commons-lang3>3.11</version.commons-lang3>
<version.commons-compress>1.21</version.commons-compress>
Expand Down

0 comments on commit bf5cd0c

Please sign in to comment.