Skip to content

Commit

Permalink
feat (jkube-kit) : Add support for specifying initContainers via reso…
Browse files Browse the repository at this point in the history
…urce configuration (eclipse-jkube#1316)

+ Deprecate all controller specific configuration options in
  ResourceConfig. Move all controller specific options to nested controller configuration.
+ Add controller(s) configuration option in ResourceConfig
+ Add initContainres configuraiton option in Controller configuration

Signed-off-by: Rohan Kumar <rohaan@redhat.com>
  • Loading branch information
rohanKanojia committed Dec 20, 2022
1 parent b212dff commit d94b3c2
Show file tree
Hide file tree
Showing 59 changed files with 920 additions and 483 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ Usage:
./scripts/extract-changelog-for-version.sh 1.3.37 5
```
### 1.11-SNAPSHOT
* Fix #1316: Add support for adding InitContainers via plugin configuration
* Fix #1459: Route Generation should support `8443` as default web port
* Fix #1546: Migrate to JUnit5 testing framework
* Fix #1858: Properties in image name not replaced
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import org.eclipse.jkube.kit.common.AssemblyFile;
import org.eclipse.jkube.kit.common.AssemblyFileEntry;
import org.eclipse.jkube.kit.common.AssemblyFileSet;
import org.eclipse.jkube.kit.config.image.build.Arguments;
import org.eclipse.jkube.kit.common.Arguments;
import org.eclipse.jkube.kit.config.image.build.BuildConfiguration;
import org.junit.jupiter.api.Test;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
import org.eclipse.jkube.kit.common.KitLogger;
import org.eclipse.jkube.kit.common.util.EnvUtil;
import org.eclipse.jkube.kit.config.image.ImageConfiguration;
import org.eclipse.jkube.kit.config.image.build.Arguments;
import org.eclipse.jkube.kit.common.Arguments;

import java.io.File;
import java.util.ArrayList;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

import org.eclipse.jkube.kit.common.JsonFactory;
import org.eclipse.jkube.kit.common.util.EnvUtil;
import org.eclipse.jkube.kit.config.image.build.Arguments;
import org.eclipse.jkube.kit.common.Arguments;

import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import org.eclipse.jkube.kit.build.service.docker.access.log.LogGetHandle;
import org.eclipse.jkube.kit.build.service.docker.access.log.LogOutputSpec;
import org.eclipse.jkube.kit.common.archive.ArchiveCompression;
import org.eclipse.jkube.kit.config.image.build.Arguments;
import org.eclipse.jkube.kit.common.Arguments;

import java.io.File;
import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
import org.eclipse.jkube.kit.common.util.EnvUtil;
import org.eclipse.jkube.kit.config.image.ImageName;
import org.eclipse.jkube.kit.common.archive.ArchiveCompression;
import org.eclipse.jkube.kit.config.image.build.Arguments;
import org.eclipse.jkube.kit.common.Arguments;
import org.apache.commons.io.IOUtils;
import org.apache.http.HttpHeaders;
import org.apache.http.client.HttpResponseException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import org.eclipse.jkube.kit.config.image.RunVolumeConfiguration;
import org.eclipse.jkube.kit.config.image.UlimitConfig;
import org.eclipse.jkube.kit.build.service.docker.helper.VolumeBindingUtil;
import org.eclipse.jkube.kit.config.image.build.Arguments;
import org.eclipse.jkube.kit.common.Arguments;

import java.io.File;
import java.util.ArrayList;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import org.eclipse.jkube.kit.common.util.EnvUtil;
import org.eclipse.jkube.kit.common.util.JKubeProjectUtil;
import org.eclipse.jkube.kit.common.util.MapUtil;
import org.eclipse.jkube.kit.config.image.build.Arguments;
import org.eclipse.jkube.kit.common.Arguments;
import org.eclipse.jkube.kit.common.AssemblyConfiguration;
import org.eclipse.jkube.kit.config.image.build.BuildConfiguration;
import org.eclipse.jkube.kit.config.image.build.HealthCheckConfiguration;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
import org.eclipse.jkube.kit.common.KitLogger;
import org.eclipse.jkube.kit.config.image.ImageConfiguration;
import org.eclipse.jkube.kit.config.image.ImageName;
import org.eclipse.jkube.kit.config.image.build.Arguments;
import org.eclipse.jkube.kit.common.Arguments;
import org.eclipse.jkube.kit.config.image.build.BuildConfiguration;

import com.google.cloud.tools.jib.api.CacheDirectoryCreationException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
import org.eclipse.jkube.kit.common.JKubeConfiguration;
import org.eclipse.jkube.kit.common.JavaProject;
import org.eclipse.jkube.kit.config.image.ImageConfiguration;
import org.eclipse.jkube.kit.config.image.build.Arguments;
import org.eclipse.jkube.kit.common.Arguments;
import org.eclipse.jkube.kit.config.image.build.BuildConfiguration;

import com.google.cloud.tools.jib.api.JibContainerBuilder;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* Contributors:
* Red Hat, Inc. - initial API and implementation
*/
package org.eclipse.jkube.kit.config.image.build;
package org.eclipse.jkube.kit.common;

import java.io.Serializable;
import java.util.ArrayList;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
/**
* 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.common;

import org.junit.jupiter.api.Test;

import java.util.Arrays;
import java.util.List;

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

class ArgumentsTest {

@Test
void testShellArgWithSpaceEscape() {
String[] testSubject = { "java", "-jar", "$HOME/name with space.jar" };
Arguments arg = Arguments.builder().shell("java -jar $HOME/name\\ with\\ space.jar").build();
assertThat(arg.asStrings()).containsExactly(testSubject);
}

@Test
void set_whenInvoked_shouldSetShell() {
// Given
Arguments arg = new Arguments();

// When
arg.set("sleep 10");

// Then
assertThat(arg.asStrings()).containsExactly("sleep", "10");
}

@Test
void exec_withSpaceEscapeArg_shouldReturnCorrectCmd() {
// Given
Arguments arg = Arguments.builder().exec(Arrays.asList("wget", "-O", "/work-dir/index.html", "http://info.cern.ch")).build();

// When
List<String> result = arg.asStrings();

// Then
assertThat(result).containsExactly("wget", "-O", "/work-dir/index.html", "http://info.cern.ch");
}

@Test
void execInlined_withSpaceEscapeArg_shouldReturnCorrectCmd() {
// Given
Arguments arg = new Arguments(null, null, Arrays.asList("wget", "-O", "/work-dir/index.html", "http://info.cern.ch"));

// When
List<String> result = arg.asStrings();

// Then
assertThat(result).containsExactly("wget", "-O", "/work-dir/index.html", "http://info.cern.ch");
}

@Test
void getExec_whenInvoked_thenReturnsEitherExecOrExecInlined() {
// Given
Arguments arg = new Arguments(null, null, Arrays.asList("wget", "-O", "/work-dir/index.html", "http://info.cern.ch"));

// When
List<String> exec = arg.getExec();

// Then
assertThat(exec).containsExactly("wget", "-O", "/work-dir/index.html", "http://info.cern.ch");
}

@Test
void validate_withValidObjects_thenNoExceptionThrown() {
// Given
Arguments shell = new Arguments("sleep 10", null, null);
Arguments exec = new Arguments(null, Arrays.asList("sleep", "10"), null);
Arguments execInlined = new Arguments(null, null, Arrays.asList("sleep", "10"));

// When
shell.validate();
exec.validate();
execInlined.validate();

// Then
assertThat(shell).isNotNull();
assertThat(exec).isNotNull();
assertThat(execInlined).isNotNull();
}

@Test
void validate_whenWrongObjectProvided_thenThrowException() {
// Given
Arguments arg = new Arguments();

// When + Then
assertThatIllegalArgumentException()
.isThrownBy(arg::validate)
.withMessage("Argument conflict: either shell or args should be specified and only in one form.");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import lombok.Getter;
import lombok.NoArgsConstructor;
import org.eclipse.jkube.kit.common.util.EnvUtil;
import org.eclipse.jkube.kit.config.image.build.Arguments;
import org.eclipse.jkube.kit.common.Arguments;

/**
* @author roland
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.Singular;
import org.eclipse.jkube.kit.common.Arguments;
import org.eclipse.jkube.kit.common.AssemblyConfiguration;
import org.eclipse.jkube.kit.common.archive.ArchiveCompression;
import org.eclipse.jkube.kit.common.util.EnvUtil;
Expand Down Expand Up @@ -143,7 +144,7 @@ public class BuildConfiguration implements Serializable {
* Don't use Docker’s build cache.
*/
private Boolean nocache;
/**
/*argum*
* If set to true then it will compress all the {@link BuildConfiguration#runCmds} into a single RUN directive so that
* only one image layer is created.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@

import org.apache.commons.io.FileUtils;
import org.apache.commons.lang3.StringUtils;
import org.eclipse.jkube.kit.common.Arguments;

/**
* Create a dockerfile
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NoArgsConstructor;
import org.eclipse.jkube.kit.common.Arguments;

import java.io.Serializable;
import java.util.Optional;
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import java.util.regex.Pattern;

import org.apache.commons.io.IOUtils;
import org.eclipse.jkube.kit.common.Arguments;
import org.junit.jupiter.api.Test;

import static org.assertj.core.api.Assertions.assertThat;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import java.util.stream.Stream;

import org.eclipse.jkube.kit.common.Arguments;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/**
* 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;
import java.util.Map;

@Builder(toBuilder = true)
@AllArgsConstructor
@NoArgsConstructor
@Getter
@EqualsAndHashCode
public class ControllerResourceConfig {
private Map<String, String> env;
@Singular
private List<VolumeConfig> volumes;
@Singular
private List<InitContainerConfig> initContainers;
private String controllerName;
private ProbeConfig liveness;
private ProbeConfig readiness;
private ProbeConfig startup;
private boolean containerPrivileged;
private String imagePullPolicy;
private Integer replicas;
private String restartPolicy;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/**
* 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 org.eclipse.jkube.kit.common.Arguments;

import java.util.List;
import java.util.Map;

@Builder(toBuilder = true)
@AllArgsConstructor
@NoArgsConstructor
@Getter
@EqualsAndHashCode
public class InitContainerConfig {
private Map<String, String> env;
private String name;
private String imageName;
private String imagePullPolicy;
private Arguments cmd;
private List<VolumeConfig> volumes;
}
Loading

0 comments on commit d94b3c2

Please sign in to comment.