Skip to content

Commit

Permalink
applying spotless
Browse files Browse the repository at this point in the history
  • Loading branch information
shawkins committed Apr 22, 2022
1 parent c3f132b commit 1e944fc
Show file tree
Hide file tree
Showing 153 changed files with 5,202 additions and 4,846 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ void delete() {
.once();

// When
boolean isDeleted = client.clusters().managedClusterSetBindings().inNamespace("ns1").withName("clustersetbinding").delete().size() == 1;
boolean isDeleted = client.clusters().managedClusterSetBindings().inNamespace("ns1").withName("clustersetbinding").delete()
.size() == 1;

// Then
assertThat(isDeleted).isTrue();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ void delete() {
.once();

// When
boolean isDeleted = client.discovery().discoveryConfigs().inNamespace("ns1").withName("sample-discoveryconfig").delete().size() == 1;
boolean isDeleted = client.discovery().discoveryConfigs().inNamespace("ns1").withName("sample-discoveryconfig").delete()
.size() == 1;

// Then
assertThat(isDeleted).isTrue();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ void delete() {
.once();

// When
boolean isDeleted = client.search().searchOperators().inNamespace("ns1").withName("sample-searchoperator").delete().size() == 1;
boolean isDeleted = client.search().searchOperators().inNamespace("ns1").withName("sample-searchoperator").delete()
.size() == 1;

// Then
assertThat(isDeleted).isTrue();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,27 @@
package io.fabric8.servicecatalog.examples; /**
* Copyright (C) 2015 Red Hat, Inc.
*
* 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.fabric8.servicecatalog.examples;

/**
* Copyright (C) 2015 Red Hat, Inc.
*
* 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.
*/

import io.fabric8.servicecatalog.client.ServiceCatalogClient;

public class RemoveBroker {

public static void main(String[] args) {
ServiceCatalogClient client = ClientFactory.newClient(args);
client.clusterServiceBrokers().withName("my-broker").delete();
ServiceCatalogClient client = ClientFactory.newClient(args);
client.clusterServiceBrokers().withName("my-broker").delete();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public interface Deletable {
* as determined by the api server response(s).
* <p>
* It is not guaranteed that the returned list will contain all values marked for deletion
* - see <a href="#{@link}">{@link https://github.com/fabric8io/kubernetes-client/pull/3058}</a>
* - see <a href="#{@link}">{@link https://github.com/fabric8io/kubernetes-client/pull/3058}</a>
*
* @throws io.fabric8.kubernetes.client.KubernetesClientException if an error occurs.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ private ListOptions defaultListOptions(ListOptions options, Boolean watch) {

static void toStatusDetails(KubernetesResource obj, List<StatusDetails> details) {
if (obj instanceof HasMetadata) {
HasMetadata meta = (HasMetadata)obj;
HasMetadata meta = (HasMetadata) obj;
ObjectMeta metadata = meta.getMetadata();
details.add(new StatusDetailsBuilder()
.withGroup(ApiVersionUtil.trimGroup(meta.getApiVersion()))
Expand Down Expand Up @@ -462,13 +462,14 @@ public List<StatusDetails> delete() {
if (useOptions) {
resourceURLForWriteOperation = appendListOptionParams(resourceURLForWriteOperation, options);
}
KubernetesResource result = handleDelete(resourceURLForWriteOperation, gracePeriodSeconds, propagationPolicy, resourceVersion);
KubernetesResource result = handleDelete(resourceURLForWriteOperation, gracePeriodSeconds, propagationPolicy,
resourceVersion);
toStatusDetails(result, details);
return details;
} catch (Exception e) {
RuntimeException re = KubernetesClientException.launderThrowable(forOperationType("delete"), e);
if (re instanceof KubernetesClientException) {
KubernetesClientException ke = (KubernetesClientException)re;
KubernetesClientException ke = (KubernetesClientException) re;
if (Utils.isNotNullOrEmpty(name)) {
if (ke.getCode() == HttpURLConnection.HTTP_NOT_FOUND) {
return Collections.emptyList();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
import java.util.UUID;

/**
* This is an example of secret.
* This is an example of secret.
*/
public class SecretExamples {
private static final Logger logger = LoggerFactory.getLogger(SecretExamples.class);
Expand All @@ -45,29 +45,28 @@ public static void main(String[] args) {
final String namespace = "default";
logger.info("List of existent Secret:");
client.secrets().inNamespace(namespace).list().getItems()
.forEach(sc -> logger.info(" - {}", sc.getMetadata().getName()));
.forEach(sc -> logger.info(" - {}", sc.getMetadata().getName()));

logger.info("Creating new Secret");
Map<String, String> data = new HashMap<>();
data.put("tls.crt", "YWFh");
data.put("tls.key", "YmJi");
final Secret secret = new SecretBuilder()
.withNewMetadata().withName(secretName).endMetadata()
.withType("kubernetes.io/tls")
.withImmutable(false)
.addToData(data)
.build();
.withNewMetadata().withName(secretName).endMetadata()
.withType("kubernetes.io/tls")
.withImmutable(false)
.addToData(data)
.build();
Secret secretCreated = client.secrets().inNamespace(namespace).create(secret);
logger.info("Newly created Secret details:\n{}", secretCreated);

logger.info("Updated list of existent Secret:");
client.secrets().inNamespace(namespace).list().getItems()
.forEach(sc -> logger.info(" - {}", sc.getMetadata().getName()));
.forEach(sc -> logger.info(" - {}", sc.getMetadata().getName()));

logger.info("Updating {} Secret to add new label", secretName);
final Secret updatedSecret = client.secrets().inNamespace(namespace).withName(secretName).edit(s ->
new SecretBuilder(s).editMetadata().addToLabels("testLabel", "testLabelValue").endMetadata().build()
);
final Secret updatedSecret = client.secrets().inNamespace(namespace).withName(secretName)
.edit(s -> new SecretBuilder(s).editMetadata().addToLabels("testLabel", "testLabelValue").endMetadata().build());
logger.info("Updated Secret details:\n{}", updatedSecret);

//delete Secret
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,30 +40,28 @@ public static void main(String[] args) {
final String storageClassName = UUID.randomUUID().toString();
logger.info("List of existent storage classes:");
client.storage().storageClasses().list().getItems()
.forEach(sc -> logger.info(" - {}", sc.getMetadata().getName()));
.forEach(sc -> logger.info(" - {}", sc.getMetadata().getName()));

logger.info("Creating new Storage class");
final StorageClass storageClass = client.storage().storageClasses().create(
new StorageClassBuilder()
.withNewMetadata().withName(storageClassName).endMetadata()
.addToParameters("resturl", "http://localhost:8080")
.addToParameters("restuser", "")
.addToParameters("secretNamespace", "")
.addToParameters("secretName", "")
.addToParameters("key", "value1")
.withProvisioner("k8s.io/minikube-hostpath")
.build()
);
new StorageClassBuilder()
.withNewMetadata().withName(storageClassName).endMetadata()
.addToParameters("resturl", "http://localhost:8080")
.addToParameters("restuser", "")
.addToParameters("secretNamespace", "")
.addToParameters("secretName", "")
.addToParameters("key", "value1")
.withProvisioner("k8s.io/minikube-hostpath")
.build());
logger.info("Newly created storage class details:\n{}", storageClass);

logger.info("Updated list of existent storage classes:");
client.storage().storageClasses().list().getItems()
.forEach(sc -> logger.info(" - {}", sc.getMetadata().getName()));
.forEach(sc -> logger.info(" - {}", sc.getMetadata().getName()));

logger.info("Updating {} storage clas to add new label", storageClassName);
final StorageClass updatedStorageClass = client.storage().storageClasses().withName(storageClassName).edit(s ->
new StorageClassBuilder(s).editMetadata().addToLabels("testLabel", "testLabelValue").endMetadata().build()
);
final StorageClass updatedStorageClass = client.storage().storageClasses().withName(storageClassName).edit(
s -> new StorageClassBuilder(s).editMetadata().addToLabels("testLabel", "testLabelValue").endMetadata().build());
logger.info("Updated storage class details:\n{}", updatedStorageClass);

//delete storage class
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,18 @@ public static void main(String[] args) throws InterruptedException {
final String project = Optional.ofNullable(client.getNamespace()).orElse("myproject");
final String isTagName = "bar1:1.0.12";
final ImageStreamTag isTag = client.imageStreamTags().inNamespace(project).createOrReplace(
new ImageStreamTagBuilder().withNewMetadata().withName(isTagName).endMetadata()
.withNewTag().withNewFrom().withKind("DockerImage").withName("openshift/wildfly-81-centos7:latest").endFrom().endTag()
.build()
);
new ImageStreamTagBuilder().withNewMetadata().withName(isTagName).endMetadata()
.withNewTag().withNewFrom().withKind("DockerImage").withName("openshift/wildfly-81-centos7:latest").endFrom()
.endTag()
.build());
logger.info("Created ImageStreamTag: {}", isTag.getMetadata().getName());
int limit = 0;
while (client.imageStreamTags().inNamespace(project).withName(isTagName).fromServer().get() == null && limit++ < 10){
while (client.imageStreamTags().inNamespace(project).withName(isTagName).fromServer().get() == null && limit++ < 10) {
TimeUnit.SECONDS.sleep(1);
}
logger.info("ImageStreamTags in {}:", project);
client.imageStreamTags().inNamespace(project).list().getItems().forEach(ist ->
logger.info(" - {}", ist.getMetadata().getName()));
client.imageStreamTags().inNamespace(project).list().getItems()
.forEach(ist -> logger.info(" - {}", ist.getMetadata().getName()));
final boolean deletedIsTag = client.imageStreamTags().withName(isTagName).delete().size() == 1;
logger.info("Deleted ImageStreamTag: {}", deletedIsTag);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,6 @@
package io.fabric8.openshift.examples;

import io.fabric8.kubernetes.api.model.HasMetadata;

/**
* Copyright (C) 2015 Red Hat, Inc.
*
* 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.
*/

import io.fabric8.kubernetes.api.model.KubernetesList;
import io.fabric8.kubernetes.client.KubernetesClientBuilder;
import io.fabric8.openshift.api.model.Parameter;
Expand All @@ -42,48 +25,50 @@ public static void main(String[] args) {
try {
logger.info("Creating temporary project '{}' for example", NAMESPACE);
client.projectrequests().create(
new ProjectRequestBuilder()
.withNewMetadata()
.withName(NAMESPACE)
.endMetadata()
.build()
);
new ProjectRequestBuilder()
.withNewMetadata()
.withName(NAMESPACE)
.endMetadata()
.build());
logger.info("Created project: {}", NAMESPACE);

final Template loadedTemplate = client.templates()
.load(TemplateExample.class.getResourceAsStream(TEST_TEMPLATE_RESOURCE)).get();
.load(TemplateExample.class.getResourceAsStream(TEST_TEMPLATE_RESOURCE)).get();
for (Parameter p : loadedTemplate.getParameters()) {
final String required = Boolean.TRUE.equals(p.getRequired()) ? "*" : "";
logger.info("Loaded parameter from template: {}{} - '{}' ({})",
p.getName(), required, p.getValue(), p.getGenerate());
p.getName(), required, p.getValue(), p.getGenerate());
}

final Template serverUploadedTemplate = client.templates()
.inNamespace(NAMESPACE)
.load(TemplateExample.class.getResourceAsStream(TEST_TEMPLATE_RESOURCE))
.create();
.inNamespace(NAMESPACE)
.load(TemplateExample.class.getResourceAsStream(TEST_TEMPLATE_RESOURCE))
.create();
logger.info("Template {} successfully created on server", serverUploadedTemplate.getMetadata().getName());
final Template serverDownloadedTemplate = client.templates().inNamespace(NAMESPACE).withName(DEFAULT_NAME_OF_TEMPLATE).get();
final Template serverDownloadedTemplate = client.templates().inNamespace(NAMESPACE).withName(DEFAULT_NAME_OF_TEMPLATE)
.get();
logger.info("Template {} successfully downloaded from server", serverDownloadedTemplate.getMetadata().getName());

final KubernetesList processedTemplateWithDefaultParameters = client.templates()
.inNamespace(NAMESPACE).withName(DEFAULT_NAME_OF_TEMPLATE).process();
.inNamespace(NAMESPACE).withName(DEFAULT_NAME_OF_TEMPLATE).process();
logger.info("Template {} successfully processed to list with {} items, and requiredBoolean = {}",
processedTemplateWithDefaultParameters.getItems().get(0).getMetadata().getLabels().get("template"),
processedTemplateWithDefaultParameters.getItems().size(),
processedTemplateWithDefaultParameters.getItems().get(0).getMetadata().getLabels().get("requiredBoolean"));
processedTemplateWithDefaultParameters.getItems().get(0).getMetadata().getLabels().get("template"),
processedTemplateWithDefaultParameters.getItems().size(),
processedTemplateWithDefaultParameters.getItems().get(0).getMetadata().getLabels().get("requiredBoolean"));

final KubernetesList processedTemplateWithCustomParameters = client.templates()
.inNamespace(NAMESPACE).withName(DEFAULT_NAME_OF_TEMPLATE).process(Collections.singletonMap("REQUIRED_BOOLEAN", "true"));
.inNamespace(NAMESPACE).withName(DEFAULT_NAME_OF_TEMPLATE)
.process(Collections.singletonMap("REQUIRED_BOOLEAN", "true"));
logger.info("Template {} successfully processed to list with {} items, and requiredBoolean = {}",
processedTemplateWithCustomParameters.getItems().get(0).getMetadata().getLabels().get("template"),
processedTemplateWithCustomParameters.getItems().size(),
processedTemplateWithCustomParameters.getItems().get(0).getMetadata().getLabels().get("requiredBoolean"));
processedTemplateWithCustomParameters.getItems().get(0).getMetadata().getLabels().get("template"),
processedTemplateWithCustomParameters.getItems().size(),
processedTemplateWithCustomParameters.getItems().get(0).getMetadata().getLabels().get("requiredBoolean"));

List<HasMetadata> l = client.load(TemplateExample.class.getResourceAsStream("/test-list.yml")).get();
logger.info("{}", l.size());

final boolean templateDeleted = client.templates().inNamespace(NAMESPACE).withName(DEFAULT_NAME_OF_TEMPLATE).delete().size() == 1;
final boolean templateDeleted = client.templates().inNamespace(NAMESPACE).withName(DEFAULT_NAME_OF_TEMPLATE).delete()
.size() == 1;
logger.info("Template {} was {}deleted", DEFAULT_NAME_OF_TEMPLATE, templateDeleted ? "" : "**NOT** ");
client.load(TemplateExample.class.getResourceAsStream("/test-list.yml")).inNamespace(NAMESPACE).create();
} finally {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ class APIServiceTest {
void get() {
// Given
server.expect().get().withPath("/apis/apiregistration.k8s.io/v1/apiservices/test-apiservice")
.andReturn(HttpURLConnection.HTTP_OK, new APIServiceBuilder()
.withNewMetadata().withName("as1").endMetadata().build())
.once();
.andReturn(HttpURLConnection.HTTP_OK, new APIServiceBuilder()
.withNewMetadata().withName("as1").endMetadata().build())
.once();

// When
APIService apiService = client.apiServices().withName("test-apiservice").get();
Expand Down Expand Up @@ -73,10 +73,10 @@ void load() {
void list() {
// Given
server.expect().get().withPath("/apis/apiregistration.k8s.io/v1/apiservices")
.andReturn(HttpURLConnection.HTTP_OK, new APIServiceListBuilder()
.addNewItem()
.withNewMetadata().withName("as1").endMetadata().endItem().build())
.once();
.andReturn(HttpURLConnection.HTTP_OK, new APIServiceListBuilder()
.addNewItem()
.withNewMetadata().withName("as1").endMetadata().endItem().build())
.once();

// When
APIServiceList apiServiceList = client.apiServices().list();
Expand All @@ -92,9 +92,9 @@ void list() {
void delete() {
// Given
server.expect().delete().withPath("/apis/apiregistration.k8s.io/v1/apiservices/v1alpha1.demo.fabric8.io")
.andReturn(HttpURLConnection.HTTP_OK, new APIServiceBuilder()
.withNewMetadata().withName("v1alpha1.demo.fabric8.io").endMetadata().build())
.once();
.andReturn(HttpURLConnection.HTTP_OK, new APIServiceBuilder()
.withNewMetadata().withName("v1alpha1.demo.fabric8.io").endMetadata().build())
.once();

// When
boolean isDeleted = client.apiServices().withName("v1alpha1.demo.fabric8.io").delete().size() == 1;
Expand Down
Loading

0 comments on commit 1e944fc

Please sign in to comment.