use of io.fabric8.kubernetes.api.model.Namespace in project fabric8 by fabric8io.
the class KubernetesAssert method getServiceSpec.
protected ServiceSpec getServiceSpec(String serviceId, String namespace) {
Service service = getService(serviceId, namespace);
ServiceSpec spec = service.getSpec();
assertThat(spec).isNotNull();
return spec;
}
use of io.fabric8.kubernetes.api.model.Namespace in project fabric8 by fabric8io.
the class KubernetesAssert method hasServicePort.
/**
* Asserts that the service can be found for the given name and has a port of the given value
*/
public void hasServicePort(String serviceId, int port) {
ServiceSpec spec = getServiceSpec(serviceId, namespace());
boolean found = false;
List<ServicePort> ports = spec.getPorts();
List<Integer> portNumbers = new ArrayList<>();
if (ports != null) {
for (ServicePort servicePort : ports) {
Integer aPort = servicePort.getPort();
if (aPort != null) {
if (aPort == port) {
found = true;
break;
} else {
portNumbers.add(aPort);
}
}
}
}
assertThat(found).describedAs("No port found for " + port + " but found ports: " + portNumbers).isTrue();
}
use of io.fabric8.kubernetes.api.model.Namespace in project fabric8 by fabric8io.
the class KubernetesAssert method getPod.
protected Pod getPod(String podId, String namespace) {
assertThat(podId).isNotNull();
Pod pod = null;
try {
pod = client.pods().inNamespace(namespace).withName(podId).get();
} catch (Exception e) {
fail("Could not find pod for '" + podId + "'");
}
assertThat(pod).isNotNull();
return pod;
}
use of io.fabric8.kubernetes.api.model.Namespace in project fabric8 by fabric8io.
the class PodIdToReplicationControllerIDExample method main.
public static void main(String[] args) {
if (args.length < 3) {
System.out.println("Arguments: kuberneteMasterUrl namespace podID");
return;
}
String kuberneteMasterUrl = args[0];
String namespace = args[1];
String podID = args[2];
System.out.println("Looking up ReplicationController for pod ID: " + podID);
KubernetesClient client = new DefaultKubernetesClient(new ConfigBuilder().withMasterUrl(kuberneteMasterUrl).build());
Pod pod = (Pod) client.pods().inNamespace(namespace).withName(podID);
pod.getMetadata().getLabels();
List<ReplicationController> replicationControllers = client.replicationControllers().inNamespace(namespace).withLabels(pod.getMetadata().getLabels()).list().getItems();
if (replicationControllers.size() == 1) {
ReplicationController replicationController = replicationControllers.get(0);
String id = KubernetesHelper.getName(replicationController);
System.out.println("Found replication controller: " + id);
} else {
System.out.println("Could not find replication controller!");
}
}
use of io.fabric8.kubernetes.api.model.Namespace in project fabric8 by fabric8io.
the class PipelineConfiguration method savePipelineConfiguration.
/**
* Saves the {@link PipelineConfiguration} into a {@link ConfigMap} in the given namespace
*/
public static void savePipelineConfiguration(KubernetesClient kubernetesClient, String namespace, PipelineConfiguration configuration) {
ConfigMap configMap = configuration.createConfigMap();
kubernetesClient.configMaps().inNamespace(namespace).withName(FABRIC8_PIPELINES).createOrReplace(configMap);
}
Aggregations