Skip to content

Commit

Permalink
Knative: not rename the container port for all deployments
Browse files Browse the repository at this point in the history
  • Loading branch information
Sgitario committed Dec 21, 2022
1 parent e494096 commit a452b1e
Show file tree
Hide file tree
Showing 8 changed files with 246 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ public void generate(KnativeConfig config) {
resourceRegistry.decorate(KNATIVE, new AddCommitIdAnnotationDecorator());

resourceRegistry.decorate(KNATIVE,
new ApplyPortNameDecorator(null, null,
new ApplyPortNameDecorator(config.getName(), null,
config.getHttpTransportVersion() != null ? config.getHttpTransportVersion().name().toLowerCase() : "http1",
Ports.webPortNames().toArray(new String[Ports.webPortNames().size()])));
addDecorators(KNATIVE, config);
Expand Down
82 changes: 82 additions & 0 deletions tests/issue-knative-existing-deployment-resource/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
<?xml version="1.0" encoding="UTF-8"?>
<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">
<modelVersion>4.0.0</modelVersion>

<parent>
<artifactId>dekorate-tests</artifactId>
<groupId>io.dekorate</groupId>
<version>3.1-SNAPSHOT</version>
<relativePath>../</relativePath>
</parent>

<groupId>io.dekorate</groupId>
<artifactId>issue-knative-existing-deployment-resource</artifactId>
<name>Dekorate :: Tests :: Annotations :: Knative :: Existing Deployment resource</name>
<description></description>

<properties>
<property.secret.name>my-secret</property.secret.name>
</properties>

<dependencies>
<dependency>
<groupId>io.dekorate</groupId>
<artifactId>kubernetes-annotations</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.dekorate</groupId>
<artifactId>knative-annotations</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.dekorate</groupId>
<artifactId>dekorate-spring-boot</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>${version.spring-boot}</version>
</dependency>

<!-- Testing -->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>${version.junit-jupiter}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>${version.junit-jupiter}</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<inherited>true</inherited>
<configuration>
<useSystemClassLoader>false</useSystemClassLoader>
</configuration>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>${version.spring-boot}</version>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/**
* Copyright 2018 The original authors.
*
* 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.dekorate.annotationless;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class DemoApplication {

public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/**
* Copyright 2018 The original authors.
*
* 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.dekorate.annotationless;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class HelloController {

private static final String HELLO = "hello world!";

@RequestMapping("/")
public String hello() {
return HELLO;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dekorate.options.input-path=kubernetes
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: example
spec:
replicas: 1
selector:
matchLabels:
name: example
template:
metadata:
labels:
name: example
spec:
containers:
- image: docker.io/group/app
name: example
livenessProbe:
failureThreshold: 3
httpGet:
path: /health/live
port: 8080
scheme: HTTP
initialDelaySeconds: 0
periodSeconds: 30
successThreshold: 1
timeoutSeconds: 10
readinessProbe:
failureThreshold: 3
httpGet:
path: /health/ready
port: 8080
scheme: HTTP
initialDelaySeconds: 0
periodSeconds: 30
successThreshold: 1
timeoutSeconds: 10
ports:
- containerPort: 8080
name: http
protocol: TCP
env:
- name: REGISTRY_AUTH_ANONYMOUS_READ_ACCESS_ENABLED
value: "true"
resources:
limits:
memory: 768Mi
requests:
memory: 128Mi
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/**
* Copyright 2018 The original authors.
*
* 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.dekorate.example;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;

import java.util.Optional;

import org.junit.jupiter.api.Test;

import io.dekorate.utils.Serialization;
import io.fabric8.kubernetes.api.model.HasMetadata;
import io.fabric8.kubernetes.api.model.KubernetesList;
import io.fabric8.kubernetes.api.model.apps.Deployment;

public class IssueExistingDeploymentResourceTest {

@Test
public void shouldContainSecret() {
KubernetesList list = Serialization
.unmarshalAsList(getClass().getClassLoader().getResourceAsStream("META-INF/dekorate/knative.yml"));
assertNotNull(list);
Deployment deployment = findFirst(list, Deployment.class).orElseThrow(() -> new IllegalStateException());
assertEquals("http", deployment.getSpec().getTemplate().getSpec().getContainers()
.stream()
.flatMap(c -> c.getPorts().stream())
.map(p -> p.getName())
.findFirst().orElse(null));
}

<T extends HasMetadata> Optional<T> findFirst(KubernetesList list, Class<T> t) {
return (Optional<T>) list.getItems().stream()
.filter(i -> t.isInstance(i))
.findFirst();
}
}
1 change: 1 addition & 0 deletions tests/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@
<module>feat-1083-ingress-rules</module>
<module>issue-existing-route-resource</module>
<module>feat-ingress-class-name</module>
<module>issue-knative-existing-deployment-resource</module>
</modules>

</project>

0 comments on commit a452b1e

Please sign in to comment.