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

Fix #231: IngressEnricher ignores IngressRules defined in XML config #512

Merged
merged 4 commits into from
Jan 26, 2021
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ Usage:
* Fix #511: Namespace as resource fragment results in NullPointerException
* Fix #521: NPE on Buildconfig#getContextDir if `<dockerFile>` references a file with no directory
* Fix #513: openshift-maven-plugin: service.yml fragment with ports creates service with unnamed port mapping
* Fix #231: IngressEnricher ignores IngressRules defined in XML config

### 1.0.2 (2020-10-30)
* Fix #429: Added quickstart for Micronaut framework
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/**
* Copyright (c) 2019 Red Hat, Inc.
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at:
*
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Red Hat, Inc. - initial API and implementation
*/
package org.eclipse.jkube.kit.config.resource;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Singular;

import java.util.List;

@Builder(toBuilder = true)
@AllArgsConstructor
@NoArgsConstructor
@Getter
@EqualsAndHashCode
public class IngressRuleConfig {
private String host;
@Singular
private List<IngressRulePathConfig> paths;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/**
* Copyright (c) 2019 Red Hat, Inc.
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at:
*
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Red Hat, Inc. - initial API and implementation
*/
package org.eclipse.jkube.kit.config.resource;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Builder(toBuilder = true)
@AllArgsConstructor
@NoArgsConstructor
@Getter
@EqualsAndHashCode
public class IngressRulePathConfig {
private String pathType;
private String path;
private String serviceName;
private int servicePort;
private IngressRulePathResourceConfig resource;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/**
* Copyright (c) 2019 Red Hat, Inc.
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at:
*
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Red Hat, Inc. - initial API and implementation
*/
package org.eclipse.jkube.kit.config.resource;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Builder(toBuilder = true)
@AllArgsConstructor
@NoArgsConstructor
@Getter
@EqualsAndHashCode
public class IngressRulePathResourceConfig {
private String apiGroup;
private String kind;
private String name;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/**
* Copyright (c) 2019 Red Hat, Inc.
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at:
*
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Red Hat, Inc. - initial API and implementation
*/
package org.eclipse.jkube.kit.config.resource;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Singular;

import java.util.List;

@Builder(toBuilder = true)
@AllArgsConstructor
@NoArgsConstructor
@Getter
@EqualsAndHashCode
public class IngressTlsConfig {
@Singular
private List<String> hosts;
private String secretName;
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
*/
package org.eclipse.jkube.kit.config.resource;

import io.fabric8.kubernetes.api.model.extensions.IngressRule;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.EqualsAndHashCode;
Expand Down Expand Up @@ -79,7 +78,10 @@ public class ResourceConfig {
@Singular
private List<ServiceAccountConfig> serviceAccounts;
@Singular
private List<IngressRule> ingressRules;
private List<IngressRuleConfig> ingressRules;

@Singular
private List<IngressTlsConfig> ingressTlsConfigs;
private OpenshiftBuildConfig openshiftBuildConfig;
private String routeDomain;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/**
* Copyright (c) 2019 Red Hat, Inc.
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at:
*
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Red Hat, Inc. - initial API and implementation
*/
package org.eclipse.jkube.kit.config.resource;

import com.fasterxml.jackson.databind.MapperFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.eclipse.jkube.kit.common.AssemblyConfiguration;
import org.junit.Test;

import java.io.IOException;

import static org.assertj.core.api.Assertions.assertThat;

public class IngressRuleConfigTest {
/**
* Verifies that deserialization works for raw deserialization (Maven-Plexus).
*/
@Test
public void rawDeserialization() throws IOException {
// Given
final ObjectMapper mapper = new ObjectMapper();
mapper.configure(MapperFeature.USE_ANNOTATIONS, false);
// When
final IngressRuleConfig result = mapper.readValue(
IngressRuleConfigTest.class.getResourceAsStream("/ingress-rule-config.json"),
IngressRuleConfig.class);
// Then
assertThat(result).isEqualTo(IngressRuleConfig.builder()
.host("example.com")
.path(IngressRulePathConfig.builder()
.pathType("ImplementationSpecific")
.path("/path")
.serviceName("service-name")
.servicePort(8080)
.resource(IngressRulePathResourceConfig.builder()
.apiGroup("group.k8s.io")
.kind("ResourceKind")
.name("resource-name")
.build())
.build())
.build()
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"host": "example.com",
"paths": [{
"pathType": "ImplementationSpecific",
"path": "/path",
"serviceName": "service-name",
"servicePort": 8080,
"resource": {
"apiGroup": "group.k8s.io",
"kind": "ResourceKind",
"name": "resource-name"
}
}]
}
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
import io.fabric8.kubernetes.client.KubernetesClientException;
import io.fabric8.openshift.api.model.Build;
import io.fabric8.openshift.api.model.Template;
import org.eclipse.jkube.kit.config.resource.JKubeAnnotations;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -98,6 +99,7 @@ private KubernetesResourceUtil() { }
public static final String OPENSHIFT_V1_VERSION = "apps.openshift.io/v1";
public static final String CRONJOB_VERSION = "batch/v1beta1";
public static final String RBAC_VERSION = "rbac.authorization.k8s.io/v1";
public static final String EXPOSE_LABEL = "expose";

public static final ResourceVersioning DEFAULT_RESOURCE_VERSIONING = new ResourceVersioning()
.withCoreVersion(API_VERSION)
Expand Down Expand Up @@ -934,4 +936,9 @@ private static boolean isLocalCustomisation(PodSpec podSpec) {
}
return true;
}

public static boolean isExposedService(ObjectMeta objectMeta) {
return containsLabelInMetadata(objectMeta, EXPOSE_LABEL, "true") ||
containsLabelInMetadata(objectMeta, JKubeAnnotations.SERVICE_EXPOSE_URL.value(), "true");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import io.fabric8.kubernetes.api.model.HasMetadata;
import io.fabric8.kubernetes.api.model.KubernetesList;
import io.fabric8.kubernetes.api.model.KubernetesListBuilder;
import io.fabric8.kubernetes.api.model.ObjectMetaBuilder;
import io.fabric8.kubernetes.api.model.PodSpec;
import io.fabric8.kubernetes.api.model.PodSpecBuilder;
import io.fabric8.kubernetes.api.model.Quantity;
Expand Down Expand Up @@ -266,6 +267,12 @@ public void testGetResourceShouldLoadNetworkV1Ingress() throws IOException {
assertEquals("my-ingress", result.getMetadata().getName());
}

@Test
public void testIsExposedService() {
assertTrue(KubernetesResourceUtil.isExposedService(new ObjectMetaBuilder().addToLabels("expose", "true").build()));
assertTrue(KubernetesResourceUtil.isExposedService(new ObjectMetaBuilder().addToLabels("jkube.io/exposeUrl", "true").build()));
}

private PodSpec getDefaultGeneratedPodSpec() {
return new PodSpecBuilder()
.addNewContainer()
Expand Down
Loading