Skip to content

Commit

Permalink
refactor: remove unused jkube.docker.apiVersion and minimalApiVersi…
Browse files Browse the repository at this point in the history
…on fields

Signed-off-by: Marc Nuri <marc@marcnuri.com>
  • Loading branch information
manusa committed May 3, 2023
1 parent 7831d04 commit 987b700
Show file tree
Hide file tree
Showing 15 changed files with 25 additions and 131 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,6 @@
|====
| Element | Description | Property

| *apiVersion*
| Use this variable if you are using an older version of docker not compatible with the current default use to
communicate with the server.
| `jkube.docker.apiVersion`

| *authConfig*
| Authentication information when pulling from or pushing to Docker registry. There is a dedicated section
<<authentication, Authentication>> for how to do security.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,6 @@ public abstract class KubernetesExtension {

public abstract Property<String> getCertPath();

public abstract Property<String> getMinimalApiVersion();

public abstract Property<Boolean> getSkipMachine();

public abstract Property<Boolean> getForcePull();
Expand Down Expand Up @@ -585,10 +583,6 @@ public String getFilterOrNull() {
return getOrDefaultString("jkube.image.filter", this::getFilter, null);
}

public String getApiVersionOrNull() {
return getOrDefaultString("jkube.docker.apiVersion", this::getApiVersion, null);
}

public String getImagePullPolicyOrNull() {
return getOrDefaultString("jkube.docker.imagePullPolicy", this::getImagePullPolicy, null);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,6 @@ protected ProcessorConfig extractGeneratorConfig() {

protected List<ImageConfiguration> resolveImages(ImageConfigResolver imageConfigResolver) throws IOException {
return initImageConfiguration(
kubernetesExtension.getApiVersionOrNull(),
getBuildTimestamp(null, null, kubernetesExtension.javaProject.getBuildDirectory().getAbsolutePath(),
DOCKER_BUILD_TIMESTAMP),
kubernetesExtension.images, imageConfigResolver, kitLogger,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ public static DockerAccess initDockerAccess(KubernetesExtension kubernetesExtens
.dockerHost(kubernetesExtension.getDockerHostOrNull())
.certPath(kubernetesExtension.getCertPathOrNull())
.machine(kubernetesExtension.machine)
.minimalApiVersion(kubernetesExtension.getMinimalApiVersion().getOrNull())
.skipMachine(kubernetesExtension.getSkipMachineOrDefault())
.build();
DockerAccessFactory dockerAccessFactory = new DockerAccessFactory();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ static Stream<Arguments> defaultValues() {
arguments("getUseColorOrDefault", true),
arguments("getMaxConnectionsOrDefault", 100),
arguments("getFilterOrNull", null),
arguments("getApiVersionOrNull", null),
arguments("getImagePullPolicyOrNull", null),
arguments("getAutoPullOrNull", null),
arguments("getDockerHostOrNull", null),
Expand Down Expand Up @@ -178,7 +177,6 @@ static Stream<Arguments> propertiesAndValues() {
arguments("getUseColorOrDefault", "jkube.useColor", "false", false),
arguments("getMaxConnectionsOrDefault", "jkube.docker.maxConnections", "1337", 1337),
arguments("getFilterOrNull", "jkube.image.filter", "foo", "foo"),
arguments("getApiVersionOrNull", "jkube.docker.apiVersion", "1.24", "1.24"),
arguments("getImagePullPolicyOrNull", "jkube.docker.imagePullPolicy", "Always", "Always"),
arguments("getAutoPullOrNull", "jkube.docker.autoPull", "true", "true"),
arguments("getDockerHostOrNull", "jkube.docker.host", "unix:///var/run/docker.sock", "unix:///var/run/docker.sock"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,6 @@ public Property<String> getCertPath() {
return new DefaultProperty<>(String.class);
}

@Override
public Property<String> getMinimalApiVersion() {
return new DefaultProperty<>(String.class);
}

@Override
public Property<Boolean> getSkipMachine() {
return new DefaultProperty<>(Boolean.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,6 @@ public Property<String> getCertPath() {
return new DefaultProperty<>(String.class);
}

@Override
public Property<String> getMinimalApiVersion() {
return new DefaultProperty<>(String.class);
}

@Override
public Property<Boolean> getSkipMachine() {
return new DefaultProperty<>(Boolean.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,6 @@ public static class DockerAccessContext implements Serializable {
private DockerMachineConfiguration machine;
private List<DockerConnectionDetector.DockerHostProvider> dockerHostProviders;
private boolean skipMachine;
private String minimalApiVersion;
private String dockerHost;
private String certPath;
private int maxConnections;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import org.eclipse.jkube.kit.build.service.docker.config.handler.property.PropertyMode;
import org.eclipse.jkube.kit.common.JavaProject;
import org.eclipse.jkube.kit.common.KitLogger;
import org.eclipse.jkube.kit.common.util.EnvUtil;
import org.eclipse.jkube.kit.common.util.JKubeProjectUtil;

import java.io.File;
Expand Down Expand Up @@ -119,22 +118,6 @@ public static String getExternalConfigActivationProperty(JavaProject project) {
return value;
}

/**
* Initialize and validate the configuration.
*
*
* @param images the images to check
* @param apiVersion the original API version intended to use
* @param nameFormatter formatter for image names
*/
private static void initAndValidate(List<ImageConfiguration> images, String apiVersion, NameFormatter nameFormatter, KitLogger log, JKubeConfiguration jKubeConfiguration) {
// Init and validate configs. After this step, getResolvedImages() contains the valid configuration.
for (ImageConfiguration imageConfiguration : images) {
apiVersion = EnvUtil.extractLargerVersion(apiVersion, initAndValidate(nameFormatter, imageConfiguration));
printDockerfileInfoIfDockerfileMode(imageConfiguration, log, jKubeConfiguration);
}
}

// Check if the provided image configuration matches the given
public static boolean matchesConfiguredImages(String imageList, ImageConfiguration imageConfig) {
if (imageList == null) {
Expand Down Expand Up @@ -181,16 +164,15 @@ private static void verifyImageNames(List<ImageConfiguration> ret) {
}
}

public static List<ImageConfiguration> initImageConfiguration(String apiVersion, Date buildTimeStamp, List<ImageConfiguration> images, ImageConfigResolver imageConfigResolver, KitLogger log, String filter, ConfigHelper.Customizer customizer, JKubeConfiguration jKubeConfiguration) {
List<ImageConfiguration> resolvedImages;
ImageNameFormatter imageNameFormatter = new ImageNameFormatter(jKubeConfiguration.getProject(), buildTimeStamp);
public static List<ImageConfiguration> initImageConfiguration(Date buildTimeStamp, List<ImageConfiguration> unresolvedImages, ImageConfigResolver imageConfigResolver, KitLogger log, String filter, ConfigHelper.Customizer customizer, JKubeConfiguration jKubeConfiguration) {
final ImageNameFormatter imageNameFormatter = new ImageNameFormatter(jKubeConfiguration.getProject(), buildTimeStamp);
// Resolve images
resolvedImages = ConfigHelper.resolveImages(
final List<ImageConfiguration> resolvedImages = ConfigHelper.resolveImages(
log,
images, // Unresolved images
unresolvedImages,
(ImageConfiguration image) -> imageConfigResolver.resolve(image, jKubeConfiguration.getProject()),
filter, // A filter which image to process
customizer); // customizer (can be overwritten by a subclass)
customizer); // customizer (can be overwritten by a subclass)

// Check for simple Dockerfile mode
ImageConfiguration dockerFileImageConfig = createImageConfigurationForSimpleDockerfile(resolvedImages, jKubeConfiguration, imageNameFormatter);
Expand All @@ -202,8 +184,17 @@ public static List<ImageConfiguration> initImageConfiguration(String apiVersion,
}
}

// Initialize configuration and detect minimal API version
initAndValidate(resolvedImages, apiVersion, imageNameFormatter, log, jKubeConfiguration);
// Init and validate Image configurations. After this step, getResolvedImages() contains the valid configuration.
for (ImageConfiguration imageConfiguration : resolvedImages) {
imageConfiguration.setName(imageNameFormatter.format(imageConfiguration.getName()));
if (imageConfiguration.getBuild() != null) {
imageConfiguration.getBuild().initAndValidate();
}
if (imageConfiguration.getRun() != null) {
imageConfiguration.getRun().initAndValidate();
}
printDockerfileInfoIfDockerfileMode(imageConfiguration, log, jKubeConfiguration);
}

return resolvedImages;
}
Expand Down Expand Up @@ -249,18 +240,6 @@ private interface Resolver {
List<ImageConfiguration> resolve(ImageConfiguration image);
}

public static String initAndValidate(ConfigHelper.NameFormatter nameFormatter, ImageConfiguration imageConfiguration) {
imageConfiguration.setName(nameFormatter.format(imageConfiguration.getName()));
String minimalApiVersion = null;
if (imageConfiguration.getBuild() != null) {
minimalApiVersion = imageConfiguration.getBuild().initAndValidate();
}
if (imageConfiguration.getRun() != null) {
minimalApiVersion = EnvUtil.extractLargerVersion(minimalApiVersion, imageConfiguration.getRun().initAndValidate());
}
return minimalApiVersion;
}

/**
* Format an image name by replacing certain placeholders
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public class ImageNameFormatter implements ConfigHelper.NameFormatter {
private final FormatParameterReplacer formatParamReplacer;

private final Date now;
private JavaProject project;
private final JavaProject project;

public ImageNameFormatter(JavaProject project, Date now) {
this.now = now;
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ void initImageConfiguration_withSimpleImageConfiguration_shouldReturnImageConfig
when(imageConfigResolver.resolve(dummyImageConfiguration, javaProject)).thenReturn(images);

// When
List<ImageConfiguration> resolvedImages = ConfigHelper.initImageConfiguration("1.12", new Date(), images, imageConfigResolver, logger, null, configs -> configs, jKubeConfiguration);
List<ImageConfiguration> resolvedImages = ConfigHelper.initImageConfiguration(new Date(), images, imageConfigResolver, logger, null, configs -> configs, jKubeConfiguration);

// Then
assertThat(resolvedImages).isNotNull()
Expand All @@ -93,7 +93,7 @@ void initImageConfiguration_withSimpleDockerFileInProjectBaseDir_shouldCreateIma
.build();

// When
List<ImageConfiguration> resolvedImages = ConfigHelper.initImageConfiguration("1.12", new Date(), images, imageConfigResolver, logger, null, configs -> configs, jKubeConfiguration);
List<ImageConfiguration> resolvedImages = ConfigHelper.initImageConfiguration(new Date(), images, imageConfigResolver, logger, null, configs -> configs, jKubeConfiguration);

// Then
assertThat(resolvedImages).isNotNull()
Expand All @@ -119,7 +119,7 @@ void initImageConfiguration_withSimpleDockerFileModeEnabledAndImageConfiguration
when(imageConfigResolver.resolve(dummyImageConfiguration, jKubeConfiguration.getProject())).thenReturn(images);

// When
List<ImageConfiguration> resolvedImages = ConfigHelper.initImageConfiguration("1.12", new Date(), images, imageConfigResolver, logger, null, configs -> configs, jKubeConfiguration);
List<ImageConfiguration> resolvedImages = ConfigHelper.initImageConfiguration(new Date(), images, imageConfigResolver, logger, null, configs -> configs, jKubeConfiguration);

// Then
assertThat(resolvedImages).isNotNull()
Expand All @@ -140,7 +140,7 @@ void initImageConfiguration_whenImageConfigurationNameBlank_thenThrowException()

// When + Then
assertThatIllegalArgumentException()
.isThrownBy(() -> ConfigHelper.initImageConfiguration("1.12", new Date(), images, imageConfigResolver, logger, null, configs -> configs, jKubeConfiguration))
.isThrownBy(() -> ConfigHelper.initImageConfiguration(new Date(), images, imageConfigResolver, logger, null, configs -> configs, jKubeConfiguration))
.withMessage("Configuration error: <image> must have a non-null <name>");
}

Expand All @@ -152,7 +152,7 @@ void initImageConfiguration_whenNoMatchForImageFilter_thenLogWarning() {
when(imageConfigResolver.resolve(dummyImageConfiguration, javaProject)).thenReturn(images);

// When
ConfigHelper.initImageConfiguration("1.12", new Date(), images, imageConfigResolver, logger, "i-dont-exist", configs -> configs, jKubeConfiguration);
ConfigHelper.initImageConfiguration(new Date(), images, imageConfigResolver, logger, "i-dont-exist", configs -> configs, jKubeConfiguration);

// Then
verify(logger).warn("None of the resolved images [%s] match the configured filter '%s'", "foo/bar:latest", "i-dont-exist");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ a| Defines what build strategy to choose while building container image.
Possible values are `docker` and `jib` out of which `docker` is default.

ifeval::["{goal-prefix}" == "oc"]
If the effective <<build-mode,mode>> is `openshift` an additional `s2i` option is available
If the build is performed in an OpenShift cluster an additional `s2i` option is available
and selected by default.

Available strategies for OpenShift are:
Expand All @@ -149,11 +149,6 @@ Available strategies for OpenShift are:
endif::[]
| `jkube.build.strategy`

| *apiVersion*
| Use this variable if you are using an older version of docker not compatible with the current default use to
communicate with the server.
| `jkube.docker.apiVersion`

| *authConfig*
| Authentication information when pulling from or pushing to Docker registry. There is a dedicated section
<<authentication, Authentication>> for how to do security.
Expand All @@ -170,7 +165,7 @@ a| Decide how to pull missing base images or images to start:
| `jkube.docker.autoPull`

| *buildRecreate*
a| If the effective <<build-mode,mode>> is `openshift` then this option decides how the OpenShift resource objects
a| If the build is performed in an OpenShift cluster then this option decides how the OpenShift resource objects
associated with the build should be treated when they already exist:

* `buildConfig` or `bc` : Only the BuildConfig is recreated
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,6 @@ public abstract class AbstractDockerMojo extends AbstractMojo
@Parameter(defaultValue = "${mojoExecution}", readonly = true)
protected MojoExecution mojoExecution;

@Parameter(property = "jkube.docker.apiVersion")
protected String apiVersion;

// For verbose output
@Parameter(property = "jkube.docker.verbose", defaultValue = "false")
protected String verbose;
Expand Down Expand Up @@ -322,8 +319,6 @@ public abstract class AbstractDockerMojo extends AbstractMojo

protected LogOutputSpecFactory logOutputSpecFactory;

protected String minimalApiVersion;

// Access for creating OpenShift binary builds
protected ClusterAccess clusterAccess;

Expand Down Expand Up @@ -447,7 +442,7 @@ protected void doExecute() throws MojoExecutionException {
.buildServiceConfig(buildServiceConfigBuilder().build())
.offline(offline)
.build();
resolvedImages = ConfigHelper.initImageConfiguration(apiVersion, getBuildTimestamp(getPluginContext(), CONTEXT_KEY_BUILD_TIMESTAMP, project.getBuild().getDirectory(), DOCKER_BUILD_TIMESTAMP), images, imageConfigResolver, log, filter, this, jkubeServiceHub.getConfiguration());
resolvedImages = ConfigHelper.initImageConfiguration(getBuildTimestamp(getPluginContext(), CONTEXT_KEY_BUILD_TIMESTAMP, project.getBuild().getDirectory(), DOCKER_BUILD_TIMESTAMP), images, imageConfigResolver, log, filter, this, jkubeServiceHub.getConfiguration());
executeInternal();
} catch (IOException | DependencyResolutionRequiredException exp) {
logException(exp);
Expand Down Expand Up @@ -520,7 +515,6 @@ protected DockerAccessFactory.DockerAccessContext getDockerAccessContext() {
.certPath(certPath)
.machine(machine)
.maxConnections(maxConnections)
.minimalApiVersion(minimalApiVersion)
.projectProperties(project.getProperties())
.skipMachine(skipMachine)
.log(log)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,6 @@ private ProcessorConfig extractGeneratorConfig() throws IOException {
private List<ImageConfiguration> getResolvedImages(List<ImageConfiguration> images, final KitLogger log)
throws IOException {
return ConfigHelper.initImageConfiguration(
null /* no minimal api version */,
getBuildTimestamp(getPluginContext(), CONTEXT_KEY_BUILD_TIMESTAMP, project.getBuild().getDirectory(),
DOCKER_BUILD_TIMESTAMP),
images, imageConfigResolver,
Expand Down

0 comments on commit 987b700

Please sign in to comment.