use of io.fabric8.kubernetes.client.DefaultKubernetesClient in project fabric8 by jboss-fuse.
the class Example method main.
public static void main(String... args) {
System.out.println("\n\nfabric8 Kubernetes-api example");
KubernetesClient kube = new DefaultKubernetesClient();
System.out.println("=========================================================================");
try {
listPods(kube);
listReplicationControllers(kube);
listServices(kube);
listServiceAccounts(kube);
listEndpoints(kube);
} catch (Exception e) {
System.out.println("FAILED: " + e);
e.printStackTrace();
} finally {
kube.close();
}
System.out.println("=========================================================================");
}
use of io.fabric8.kubernetes.client.DefaultKubernetesClient in project fabric8 by jboss-fuse.
the class ViewPipeline method main.
public static void main(String[] args) {
if (args.length == 0) {
System.err.println("Usage: ViewPipeline jobName [branchName] [gitUrl]");
return;
}
String jobName = args[0];
String branchName = "master";
String gitUrl = null;
if (args.length > 1) {
branchName = args[1];
}
if (args.length > 2) {
gitUrl = args[2];
}
try {
JobEnvironment environment = new JobEnvironment();
environment.setJobName(jobName);
environment.setBranchName(branchName);
environment.setGitUrl(gitUrl);
KubernetesClient kubernetesClient = new DefaultKubernetesClient();
String namespace = kubernetesClient.getNamespace();
if (Strings.isNullOrBlank(namespace)) {
namespace = KubernetesHelper.defaultNamespace();
}
Pipeline pipeline = Pipelines.getPipeline(kubernetesClient, namespace, environment);
System.out.println("Found pipeline for job: " + pipeline.getJobName() + " of kind: " + pipeline.getKind());
} catch (IntrospectionException e) {
System.out.println("Failed with: " + e);
e.printStackTrace();
}
}
use of io.fabric8.kubernetes.client.DefaultKubernetesClient in project fabric8 by jboss-fuse.
the class WatchServicesExample method main.
public static void main(String... args) throws Exception {
KubernetesClient client = new DefaultKubernetesClient();
client.services().watch(new io.fabric8.kubernetes.client.Watcher<Service>() {
@Override
public void eventReceived(Action action, Service service) {
System.out.println(action + ": " + service);
}
@Override
public void onClose(KubernetesClientException e) {
System.out.println("Closed: " + e);
}
});
client.close();
}
use of io.fabric8.kubernetes.client.DefaultKubernetesClient in project fabric8 by jboss-fuse.
the class ListEnvironments method main.
public static void main(String[] args) {
KubernetesClient kubernetesClient = new DefaultKubernetesClient();
Environments environments;
if (args.length > 0) {
String namespace = args[0];
System.out.println("Listing environments for namespace: " + namespace);
environments = Environments.load(namespace);
} else {
environments = Environments.load();
}
String environmentKey = "testing";
if (args.length > 1) {
environmentKey = args[1];
}
System.out.println("Space namespace: " + environments.getNamespace());
SortedSet<Environment> set = environments.getEnvironmentSet();
for (Environment environment : set) {
String onCluster = "";
String clusterAPiServer = environment.getClusterAPiServer();
if (Strings.isNotBlank(clusterAPiServer)) {
onCluster += " on API server: " + clusterAPiServer;
}
System.out.println("Environment " + environment.getName() + " maps to namespace: " + environment.getNamespace() + onCluster);
}
System.out.println("Namespace for environment key: " + environmentKey + " is " + Environments.namespaceForEnvironment(environmentKey));
}
use of io.fabric8.kubernetes.client.DefaultKubernetesClient in project kubernetes by ballerinax.
the class OpenShiftBuildConfigTest method mainFunctionTest.
/**
* Test case openshift build config annotation with a main function.
*/
@Test(groups = { "openshift" })
public void mainFunctionTest() throws IOException, InterruptedException, KubernetesPluginException {
Assert.assertEquals(KubernetesTestUtils.compileBallerinaFile(BAL_DIRECTORY, "main_function.bal"), 0);
File yamlFile = new File(KUBERNETES_TARGET_PATH + File.separator + "main_function.yaml");
Assert.assertTrue(yamlFile.exists());
KubernetesClient client = new DefaultKubernetesClient();
List<HasMetadata> k8sItems = client.load(new FileInputStream(yamlFile)).get();
for (HasMetadata data : k8sItems) {
switch(data.getKind()) {
case "Service":
case "Deployment":
break;
case "BuildConfig":
BuildConfig bc = (BuildConfig) data;
// metadata
Assert.assertNotNull(bc.getMetadata());
Assert.assertEquals(bc.getMetadata().getName(), "main-openshift-bc", "Invalid name found.");
Assert.assertNotNull(bc.getMetadata().getLabels(), "Labels are missing");
Assert.assertEquals(bc.getMetadata().getLabels().size(), 1, "Labels are missing");
Assert.assertNotNull(bc.getMetadata().getLabels().get("build"), "'build' label is missing");
Assert.assertEquals(bc.getMetadata().getLabels().get("build"), "main-openshift-bc", "Invalid label 'build' label value.");
// spec
Assert.assertNotNull(bc.getSpec());
Assert.assertNotNull(bc.getSpec().getOutput());
Assert.assertNotNull(bc.getSpec().getOutput().getTo());
Assert.assertEquals(bc.getSpec().getOutput().getTo().getKind(), "ImageStreamTag", "Invalid output kind.");
Assert.assertEquals(bc.getSpec().getOutput().getTo().getName(), "main_function:latest", "Invalid image stream name.");
Assert.assertNotNull(bc.getSpec().getSource());
Assert.assertNotNull(bc.getSpec().getSource().getBinary(), "Binary source is missing");
Assert.assertNotNull(bc.getSpec().getStrategy());
Assert.assertNotNull(bc.getSpec().getStrategy().getDockerStrategy(), "Docker strategy is missing.");
Assert.assertEquals(bc.getSpec().getStrategy().getDockerStrategy().getBuildArgs().size(), 0, "Invalid number of build args.");
Assert.assertEquals(bc.getSpec().getStrategy().getDockerStrategy().getDockerfilePath(), "kubernetes/docker/Dockerfile", "Invalid docker path.");
Assert.assertFalse(bc.getSpec().getStrategy().getDockerStrategy().getForcePull(), "Force pull image set to false");
Assert.assertFalse(bc.getSpec().getStrategy().getDockerStrategy().getNoCache(), "No cache for image build set to false");
break;
case "ImageStream":
ImageStream is = (ImageStream) data;
Assert.assertNotNull(is.getMetadata());
Assert.assertEquals(is.getMetadata().getName(), "main_function", "Invalid name found.");
Assert.assertEquals(is.getMetadata().getLabels().size(), 1, "Labels are missing");
Assert.assertNotNull(is.getMetadata().getLabels().get("build"), "'build' label is missing");
Assert.assertEquals(is.getMetadata().getLabels().get("build"), "main-openshift-bc", "Invalid label 'build' label value.");
Assert.assertNull(is.getSpec());
break;
default:
Assert.fail("Unexpected k8s resource found: " + data.getKind());
break;
}
}
KubernetesUtils.deleteDirectory(KUBERNETES_TARGET_PATH);
KubernetesUtils.deleteDirectory(DOCKER_TARGET_PATH);
}
Aggregations