Skip to content
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
72 changes: 27 additions & 45 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,9 @@
</versionName>
<maven.build.timestamp.format>yyyy-MM-dd HH:mm</maven.build.timestamp.format>

<versionNameVersion>2.2.0</versionNameVersion>
<okhttpVersion>5.3.2</okhttpVersion>
<retrofitVersion>3.0.0</retrofitVersion>
<jsonschema.version>5.0.0</jsonschema.version>
<kubernetes.client.java.version>27.0.0</kubernetes.client.java.version>
<kubernetes.fabric8.java.version>7.8.0</kubernetes.fabric8.java.version>
<wiremock.version>3.13.2</wiremock.version>
<netty.version>4.2.17.Final</netty.version>
Expand Down Expand Up @@ -227,7 +225,7 @@

<dependency>
<groupId>org.wiremock</groupId>
<artifactId>wiremock-jetty12</artifactId>
<artifactId>wiremock-standalone</artifactId>
<version>${wiremock.version}</version>
<scope>test</scope>
</dependency>
Expand Down Expand Up @@ -262,20 +260,13 @@
<scope>test</scope>
</dependency>

<!-- Source: https://mvnrepository.com/artifact/io.fabric8/openshift-client -->
<!-- Source: https://mvnrepository.com/artifact/io.fabric8/kubernetes-client -->
<dependency>
<groupId>io.fabric8</groupId>
<artifactId>openshift-client</artifactId>
<artifactId>kubernetes-client</artifactId>
<version>${kubernetes.fabric8.java.version}</version>
</dependency>

<dependency>
<groupId>io.kubernetes</groupId>
<artifactId>client-java</artifactId>
<version>${kubernetes.client.java.version}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>io.micronaut</groupId>
<artifactId>micronaut-http-client</artifactId>
Expand All @@ -298,12 +289,25 @@
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<scope>test</scope>
<exclusions>
<!-- Runtime bytecode manipulation via Java agent is prohibited by the blocklist. -->
<exclusion>
<groupId>net.bytebuddy</groupId>
<artifactId>byte-buddy-agent</artifactId>
</exclusion>
</exclusions>
</dependency>

<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-junit-jupiter</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>net.bytebuddy</groupId>
<artifactId>byte-buddy-agent</artifactId>
</exclusion>
</exclusions>
</dependency>

<dependency>
Expand All @@ -313,15 +317,6 @@
<scope>test</scope>
</dependency>

<!-- Provides withEnvironmentVariable in tests. Replaces the unmaintained system-lambda
implementation with a Byte Buddy based implementation that supports current JDKs. -->
<dependency>
<groupId>uk.org.webcompere</groupId>
<artifactId>system-stubs-core</artifactId>
<version>2.1.8</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
Expand Down Expand Up @@ -359,21 +354,6 @@
</exclusions>
</dependency>

<dependency>
<groupId>com.cloudogu.versionName</groupId>
<artifactId>processor</artifactId>
<version>${versionNameVersion}</version>
<!-- This dependency is only necessary during compile time -->
<scope>provided</scope>
</dependency>

<dependency>
<groupId>org.awaitility</groupId>
<artifactId>awaitility</artifactId>
<version>4.3.0</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>io.github.classgraph</groupId>
<artifactId>classgraph</artifactId>
Expand Down Expand Up @@ -403,6 +383,17 @@
</dependencies>

<build>
<resources>
<resource>
<directory>src/main/resources</directory>
</resource>
<resource>
<directory>src/main/version</directory>
<targetPath>com/cloudogu/gitops/cli</targetPath>
<filtering>true</filtering>
</resource>
</resources>

<plugins>
<plugin>
<groupId>com.diffplug.spotless</groupId>
Expand Down Expand Up @@ -517,16 +508,7 @@
<artifactId>micronaut-inject-java</artifactId>
<version>${micronaut.version}</version>
</path>
<path>
<groupId>com.cloudogu.versionName</groupId>
<artifactId>processor</artifactId>
<version>${versionNameVersion}</version>
</path>
</annotationProcessorPaths>

<compilerArgs>
<arg>-AversionName=${versionName}</arg>
</compilerArgs>
</configuration>
</plugin>

Expand Down
18 changes: 13 additions & 5 deletions src/main/java/com/cloudogu/gitops/cli/ApplicationConfigurator.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,25 @@

import com.cloudogu.gitops.config.Config;
import com.cloudogu.gitops.config.Credentials;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;

import java.io.IOException;
import java.io.UncheckedIOException;
import java.net.MalformedURLException;
import java.net.URI;
import java.util.function.Function;

@RequiredArgsConstructor
@Slf4j
public class ApplicationConfigurator {
private final Function<String, String> environment;

public ApplicationConfigurator() {
this(System::getenv);
}

ApplicationConfigurator(Function<String, String> environment) {
this.environment = environment;
}

private static boolean hasText(String value) {
return value != null && !value.isEmpty();
Expand Down Expand Up @@ -128,7 +136,7 @@ private static void addRegistryConfig(Config newConfig) {
}

private void addAdditionalApplicationConfig(Config newConfig) {
if (System.getenv("KUBERNETES_SERVICE_HOST") != null) {
if (environment.apply("KUBERNETES_SERVICE_HOST") != null) {
log.debug("installation is running in kubernetes.");
newConfig.getApplication().setRunningInsideK8s(true);
}
Expand Down Expand Up @@ -350,8 +358,8 @@ public boolean isUrlSetAndValid(Config config) {
public void buildAndValidateURLFromEnvironment(Config config) {
log.debug("Attempting to set features.argocd.resourceInclusionsCluster via Kubernetes ENV variables.");

String host = System.getenv("KUBERNETES_SERVICE_HOST");
String port = System.getenv("KUBERNETES_SERVICE_PORT");
String host = environment.apply("KUBERNETES_SERVICE_HOST");
String port = environment.apply("KUBERNETES_SERVICE_PORT");

String errorMessage = "Could not determine 'features.argocd.resourceInclusionsCluster' which is required when argocd.operator=true. " + "Ensure Kubernetes environment variables 'KUBERNETES_SERVICE_HOST' and 'KUBERNETES_SERVICE_PORT' are set properly. " + "Alternatively, try setting 'features.argocd.resourceInclusionsCluster' in the config to manually override.";

Expand Down
27 changes: 27 additions & 0 deletions src/main/java/com/cloudogu/gitops/cli/Version.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.cloudogu.gitops.cli;

import java.io.IOException;
import java.io.InputStream;
import java.io.UncheckedIOException;
import java.nio.charset.StandardCharsets;

public final class Version {

private static final String VERSION_RESOURCE = "/com/cloudogu/gitops/cli/version-name.txt";

public static final String NAME = loadName();

private Version() {
}

private static String loadName() {
try (InputStream input = Version.class.getResourceAsStream(VERSION_RESOURCE)) {
if (input == null) {
throw new IllegalStateException("Version resource not found: " + VERSION_RESOURCE);
}
return new String(input.readAllBytes(), StandardCharsets.UTF_8);
} catch (IOException e) {
throw new UncheckedIOException("Failed to read version resource: " + VERSION_RESOURCE, e);
}
}
}
7 changes: 0 additions & 7 deletions src/main/java/com/cloudogu/gitops/cli/package-info.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import io.fabric8.kubernetes.api.model.ConfigMap;
import io.fabric8.kubernetes.api.model.ConfigMapBuilder;
import io.fabric8.kubernetes.api.model.GenericKubernetesResource;
import io.fabric8.kubernetes.api.model.GenericKubernetesResourceBuilder;
import io.fabric8.kubernetes.api.model.GenericKubernetesResourceList;
import io.fabric8.kubernetes.api.model.HasMetadata;
import io.fabric8.kubernetes.api.model.IntOrString;
Expand All @@ -32,9 +33,6 @@
import io.fabric8.kubernetes.client.dsl.base.PatchContext;
import io.fabric8.kubernetes.client.dsl.base.ResourceDefinitionContext;
import io.fabric8.kubernetes.client.utils.Serialization;
import io.fabric8.openshift.api.model.Project;
import io.fabric8.openshift.api.model.ProjectBuilder;
import io.fabric8.openshift.client.OpenShiftClient;
import jakarta.inject.Singleton;
import lombok.Getter;
import lombok.Setter;
Expand Down Expand Up @@ -78,6 +76,13 @@ public class K8sClient {
private static final String DOCKER_CONFIG_JSON_KEY = ".dockerconfigjson";
private static final String NOT_FOUND_IN_NAMESPACE = " not found in namespace ";
private static final String APPLIED_PREFIX = "Applied ";
private static final ResourceDefinitionContext OPENSHIFT_PROJECT_CONTEXT = new ResourceDefinitionContext.Builder()
.withGroup("project.openshift.io")
.withVersion("v1")
.withKind("Project")
.withPlural("projects")
.withNamespaced(false)
.build();

private static final int DEFAULT_TIMEOUT_SECONDS = 60;
private static final int DEFAULT_CHECK_INTERVAL_SECONDS = 1;
Expand Down Expand Up @@ -337,12 +342,16 @@ public void createNamespace(String name) {
log.debug("Namespace {} does not exist, proceeding to create.", name);

if (runInOpenshift()) {
OpenShiftClient osClient = client.adapt(OpenShiftClient.class);

Project project = new ProjectBuilder().withNewMetadata().withName(name).endMetadata().build();
GenericKubernetesResource project = new GenericKubernetesResourceBuilder()
.withApiVersion("project.openshift.io/v1")
.withKind("Project")
.withNewMetadata()
.withName(name)
.endMetadata()
.build();
executeWithErrorHandling(
"create project " + name, () -> {
osClient.projects().resource(project).create();
client.genericKubernetesResources(OPENSHIFT_PROJECT_CONTEXT).resource(project).create();
return null;
}
);
Expand Down
1 change: 1 addition & 0 deletions src/main/version/version-name.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
${versionName}
Loading