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

Apply checkstyle to test modules + fix checkstyle issues #112

Merged
merged 1 commit into from
Jun 28, 2024
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
4 changes: 3 additions & 1 deletion checkstyle.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,10 @@

<module name="Indentation">
<property name="basicOffset" value="4"/>
<property name="braceAdjustment" value="0"/>
<property name="caseIndent" value="4"/>
<property name="throwsIndent" value="4"/>
<property name="lineWrappingIndentation" value="4"/>
<property name="tabWidth" value="4"/>
</module>

<!-- Checks for Naming Conventions. -->
Expand Down
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,7 @@
<configuration>
<consoleOutput>true</consoleOutput>
<failsOnError>true</failsOnError>
<includeTestSourceDirectory>true</includeTestSourceDirectory>
</configuration>
<goals>
<goal>check</goal>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
public @interface ResourceManager {
/**
* Enables cleaner extension for resource manager
*
* @return enable/disable cleaner
*/
boolean cleanResources() default true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ public KubernetesClient getClient() {
/**
* Test method only
* Reconnect client with new config
*
* @param config kubernetes config
*/
void testReconnect(Config config) {
Expand Down Expand Up @@ -116,14 +117,14 @@ public List<HasMetadata> readResourcesFromFile(InputStream is) throws IOExceptio
*/
public boolean namespaceExists(String namespace) {
return client.namespaces().list().getItems().stream()
.anyMatch(n -> n.getMetadata().getName().equals(namespace));
.anyMatch(n -> n.getMetadata().getName().equals(namespace));
}

/**
* Creates resource and apply modifier
*
* @param resources resources
* @param modifier modifier
* @param modifier modifier
*/
public void create(List<HasMetadata> resources, Function<HasMetadata, HasMetadata> modifier) {
create(null, resources, modifier);
Expand All @@ -133,7 +134,7 @@ public void create(List<HasMetadata> resources, Function<HasMetadata, HasMetadat
* Updates resources and apply modifier
*
* @param resources resources
* @param modifier modifier
* @param modifier modifier
*/
public void update(List<HasMetadata> resources, Function<HasMetadata, HasMetadata> modifier) {
update(null, resources, modifier);
Expand All @@ -144,13 +145,13 @@ public void update(List<HasMetadata> resources, Function<HasMetadata, HasMetadat
*
* @param namespace namespace
* @param resources resources
* @param modifier modifier
* @param modifier modifier
*/
public void create(String namespace, List<HasMetadata> resources, Function<HasMetadata, HasMetadata> modifier) {
resources.forEach(res -> {
HasMetadata h = modifier.apply(res);
LOGGER.debug(LoggerUtils.RESOURCE_WITH_NAMESPACE_LOGGER_PATTERN,
"Creating", h.getKind(), h.getMetadata().getName(), namespace);
"Creating", h.getKind(), h.getMetadata().getName(), namespace);
if (namespace == null) {
client.resource(h).create();
} else {
Expand All @@ -164,13 +165,13 @@ public void create(String namespace, List<HasMetadata> resources, Function<HasMe
*
* @param namespace namespace
* @param resources resources
* @param modifier modifier
* @param modifier modifier
*/
public void update(String namespace, List<HasMetadata> resources, Function<HasMetadata, HasMetadata> modifier) {
resources.forEach(res -> {
HasMetadata h = modifier.apply(res);
LOGGER.debug(LoggerUtils.RESOURCE_WITH_NAMESPACE_LOGGER_PATTERN,
"Updating", h.getKind(), h.getMetadata().getName(), namespace);
"Updating", h.getKind(), h.getMetadata().getName(), namespace);
if (namespace == null) {
client.resource(h).update();
} else {
Expand All @@ -183,7 +184,7 @@ public void update(String namespace, List<HasMetadata> resources, Function<HasMe
* Create or update resources from file and apply modifier
*
* @param resources resources
* @param modifier modifier method
* @param modifier modifier method
*/
public void createOrUpdate(List<HasMetadata> resources, Function<HasMetadata, HasMetadata> modifier) {
createOrUpdate(null, resources, modifier);
Expand All @@ -192,25 +193,25 @@ public void createOrUpdate(List<HasMetadata> resources, Function<HasMetadata, Ha
/**
* Create or update resources from file and apply modifier
*
* @param ns namespace
* @param ns namespace
* @param resources resources
* @param modifier modifier method
* @param modifier modifier method
*/
public void createOrUpdate(String ns, List<HasMetadata> resources, Function<HasMetadata, HasMetadata> modifier) {
resources.forEach(i -> {
HasMetadata h = modifier.apply(i);
if (h != null) {
if (client.resource(h).get() == null) {
LOGGER.debug(LoggerUtils.RESOURCE_WITH_NAMESPACE_LOGGER_PATTERN,
"Creating", h.getKind(), h.getMetadata().getName(), h.getMetadata().getNamespace());
"Creating", h.getKind(), h.getMetadata().getName(), h.getMetadata().getNamespace());
if (ns == null) {
client.resource(h).create();
} else {
client.resource(h).inNamespace(ns).create();
}
} else {
LOGGER.debug(LoggerUtils.RESOURCE_WITH_NAMESPACE_LOGGER_PATTERN,
"Updating", h.getKind(), h.getMetadata().getName(), h.getMetadata().getNamespace());
"Updating", h.getKind(), h.getMetadata().getName(), h.getMetadata().getNamespace());
if (ns == null) {
client.resource(h).update();
} else {
Expand All @@ -231,7 +232,7 @@ public void delete(List<HasMetadata> resources) {
if (h != null) {
if (client.resource(h).get() != null) {
LOGGER.debug(LoggerUtils.RESOURCE_WITH_NAMESPACE_LOGGER_PATTERN,
"Deleting", h.getKind(), h.getMetadata().getName(), h.getMetadata().getNamespace());
"Deleting", h.getKind(), h.getMetadata().getName(), h.getMetadata().getNamespace());
client.resource(h).delete();
}
}
Expand All @@ -249,7 +250,7 @@ public void delete(List<HasMetadata> resources, String namespace) {
if (h != null) {
if (client.resource(h).inNamespace(namespace).get() != null) {
LOGGER.debug(LoggerUtils.RESOURCE_WITH_NAMESPACE_LOGGER_PATTERN,
"Deleting", h.getKind(), h.getMetadata().getName(), namespace);
"Deleting", h.getKind(), h.getMetadata().getName(), namespace);
client.resource(h).inNamespace(namespace).delete();
}
}
Expand All @@ -270,7 +271,7 @@ public List<Pod> listPods(String namespaceName) {
* Get all pods with prefix nanme
*
* @param namespaceName namespace
* @param selector prefix
* @param selector prefix
* @return lust of pods
*/
public List<Pod> listPods(String namespaceName, LabelSelector selector) {
Expand All @@ -286,15 +287,15 @@ public List<Pod> listPods(String namespaceName, LabelSelector selector) {
*/
public List<Pod> listPodsByPrefixInName(String namespaceName, String podNamePrefix) {
return listPods(namespaceName)
.stream().filter(p -> p.getMetadata().getName().startsWith(podNamePrefix))
.collect(Collectors.toList());
.stream().filter(p -> p.getMetadata().getName().startsWith(podNamePrefix))
.collect(Collectors.toList());
}

/**
* Return log from pod with one container
*
* @param namespaceName namespace of the pod
* @param podName pod name
* @param podName pod name
* @return logs
*/
public String getLogsFromPod(String namespaceName, String podName) {
Expand All @@ -305,7 +306,7 @@ public String getLogsFromPod(String namespaceName, String podName) {
* Return log from pods specific container
*
* @param namespaceName namespace of the pod
* @param podName pod name
* @param podName pod name
* @param containerName container name
* @return logs
*/
Expand All @@ -316,14 +317,14 @@ public String getLogsFromContainer(String namespaceName, String podName, String
/**
* Returns list of deployments with prefix name
*
* @param namespace namespace
* @param namespace namespace
* @param namePrefix prefix
* @return list of deployments
*/
public String getDeploymentNameByPrefix(String namespace, String namePrefix) {
List<Deployment> prefixDeployments = client.apps().deployments()
.inNamespace(namespace).list().getItems().stream().filter(rs ->
rs.getMetadata().getName().startsWith(namePrefix)).toList();
.inNamespace(namespace).list().getItems().stream().filter(rs ->
rs.getMetadata().getName().startsWith(namePrefix)).toList();

if (!prefixDeployments.isEmpty()) {
return prefixDeployments.get(0).getMetadata().getName();
Expand All @@ -341,11 +342,11 @@ private Config getConfig() {
if (TestFrameEnv.KUBE_URL != null && TestFrameEnv.KUBE_TOKEN != null) {
kubeconfigPath = createLocalKubeconfig();
return new ConfigBuilder()
.withOauthToken(TestFrameEnv.KUBE_TOKEN)
.withMasterUrl(TestFrameEnv.KUBE_URL)
.withDisableHostnameVerification(true)
.withTrustCerts(true)
.build();
.withOauthToken(TestFrameEnv.KUBE_TOKEN)
.withMasterUrl(TestFrameEnv.KUBE_URL)
.withDisableHostnameVerification(true)
.withTrustCerts(true)
.build();
} else {
return Config.autoConfigure(System.getenv().getOrDefault("KUBE_CONTEXT", null));
}
Expand Down Expand Up @@ -378,9 +379,9 @@ private String createLocalKubeconfig() {
*/
private void createLocalOcKubeconfig(String token, String apiUrl) {
Exec.exec(null, Arrays.asList("oc", "login", "--token", token,
"--insecure-skip-tls-verify",
"--kubeconfig", TestFrameEnv.USER_PATH + "/test.kubeconfig",
apiUrl), 0, false, true);
"--insecure-skip-tls-verify",
"--kubeconfig", TestFrameEnv.USER_PATH + "/test.kubeconfig",
apiUrl), 0, false, true);
}

/**
Expand All @@ -391,10 +392,10 @@ private void createLocalOcKubeconfig(String token, String apiUrl) {
*/
private void createLocalKubectlContext(String token, String apiUrl) {
Exec.exec(null, Arrays.asList("kubectl", "config",
"set-credentials", "test-user",
"--token", token,
"--kubeconfig", TestFrameEnv.USER_PATH + "/test.kubeconfig"),
0, false, true);
"set-credentials", "test-user",
"--token", token,
"--kubeconfig", TestFrameEnv.USER_PATH + "/test.kubeconfig"),
0, false, true);
buildKubectlContext(apiUrl);
}

Expand All @@ -405,20 +406,20 @@ private void createLocalKubectlContext(String token, String apiUrl) {
*/
private void buildKubectlContext(String apiUrl) {
Exec.exec(null, Arrays.asList("kubectl", "config",
"set-cluster", "test-cluster",
"--insecure-skip-tls-verify=true", "--server", apiUrl,
"--kubeconfig", TestFrameEnv.USER_PATH + "/test.kubeconfig"),
0, false, true);
"set-cluster", "test-cluster",
"--insecure-skip-tls-verify=true", "--server", apiUrl,
"--kubeconfig", TestFrameEnv.USER_PATH + "/test.kubeconfig"),
0, false, true);
Exec.exec(null, Arrays.asList("kubectl", "config",
"set-context", "test-context",
"--user", "test-user",
"--cluster", "test-cluster",
"--namespace", "default",
"--kubeconfig", TestFrameEnv.USER_PATH + "/test.kubeconfig"),
0, false, true);
"set-context", "test-context",
"--user", "test-user",
"--cluster", "test-cluster",
"--namespace", "default",
"--kubeconfig", TestFrameEnv.USER_PATH + "/test.kubeconfig"),
0, false, true);
Exec.exec(null, Arrays.asList("kubectl", "config",
"use-context", "test-context",
"--kubeconfig", TestFrameEnv.USER_PATH + "/test.kubeconfig"),
0, false, true);
"use-context", "test-context",
"--kubeconfig", TestFrameEnv.USER_PATH + "/test.kubeconfig"),
0, false, true);
}
}
Loading
Loading