dummy.setSpec(dummySpec); Dummy created = dummyClient.createOrReplace(dummy); dummyClient.createOrReplace(created);
client.serviceAccounts().inNamespace("thisisatest").createOrReplace(fabric8);
public void replaceConfigMap(String namespace, ConfigMap newConfigMap) { client.configMaps().inNamespace(namespace).createOrReplace(newConfigMap); }
public List<IstioResource> createOrReplaceCustomResources(IstioResource... resources) { if(resources != null) { List<IstioResource> results = new ArrayList<>(resources.length); for (IstioResource resource : resources) { final CustomResourceDefinition customResourceDefinition = getCustomResourceDefinition(resource); final IstioResource result = client.customResources(customResourceDefinition, IstioResource.class, KubernetesResourceList.class, DoneableIstioResource.class) .inNamespace(client.getNamespace()) .createOrReplace(resource); results.add(result); } return results; } return Collections.emptyList(); }
log("Created namespace", client.namespaces().createOrReplace(ns)); client.serviceAccounts().inNamespace("thisisatest").createOrReplace(fabric8); for (int i = 0; i < 2; i++) { System.err.println("Iteration:" + (i+1));
public List<IstioResource> createOrReplaceCustomResources(IstioResource... resources) { if(resources != null) { List<IstioResource> results = new ArrayList<>(resources.length); for (IstioResource resource : resources) { final CustomResourceDefinition customResourceDefinition = getCustomResourceDefinition(resource); final IstioResource result = client.customResources(customResourceDefinition, IstioResource.class, KubernetesResourceList.class, DoneableIstioResource.class) .inNamespace(client.getNamespace()) .createOrReplace(resource); results.add(result); } return results; } return Collections.emptyList(); }
/** * Apply new version of resources if considered changed */ public static <T extends HasMetadata, L extends KubernetesResourceList, D extends Doneable<T>> void applyIfDifferent(File resourceDir, NonNamespaceOperation<T, L, D, Resource<T, D>> operation, Class<T> resourceClass, Comparator<T> comparator) { if (resourceDir.isDirectory()) { File[] files = resourceDir.listFiles(); if (files != null) { for (File file : files) { T newResource = readAndParse(file, resourceClass); if (newResource != null) { T currentResource = operation.withName(newResource.getMetadata().getName()).get(); if (currentResource == null) { log.info("Creating {} {}", newResource.getKind(), newResource.getMetadata().getName()); operation.create(newResource); } else if (comparator.compare(currentResource, newResource) != 0) { log.info("Updating {} {}", newResource.getKind(), newResource.getMetadata().getName()); operation.createOrReplace(newResource); } } } } } }
if (existing == null) { log.info("Creating cert secret {} with certBundle input", secret.getMetadata().getName()); client.secrets().inNamespace(namespace).createOrReplace(secret); } else if (!data.equals(existing.getData())) { log.info("Replacing cert secret {} with certBundle input", secret.getMetadata().getName());
/** * Make sure that workspace service account exists and has `view` and `exec` role bindings. * * <p>Note that `view` role is used from cluster scope and `exec` role is created in the current * namespace if does not exit. * * @throws InfrastructureException when any exception occurred */ void prepare() throws InfrastructureException { OpenShiftClient osClient = clientFactory.createOC(workspaceId); if (osClient.serviceAccounts().inNamespace(projectName).withName(serviceAccountName).get() == null) { createWorkspaceServiceAccount(osClient); } String execRoleName = "exec"; if (osClient.roles().inNamespace(projectName).withName(execRoleName).get() == null) { createExecRole(osClient, execRoleName); } osClient.roleBindings().inNamespace(projectName).createOrReplace(createExecRoleBinding()); osClient.roleBindings().inNamespace(projectName).createOrReplace(createViewRoleBinding()); }
.build(); oauthClient = client.oAuthClients().createOrReplace(c); log.info("Created OAuthClient: {} ", oauthClient.getMetadata().getName()); } else {
@Test /** * Step namespace should have priority over anything else. */ public void runWithStepOverriddenNamespace() throws Exception { String overriddenNamespace = testingNamespace + "-overridden-namespace"; String stepNamespace = testingNamespace + "-overridden-namespace2"; KubernetesClient client = cloud.connect(); // Run in our own testing namespace if (client.namespaces().withName(stepNamespace).get() == null) { client.namespaces().createOrReplace( new NamespaceBuilder().withNewMetadata().withName(stepNamespace).endMetadata().build()); } WorkflowJob p = r.jenkins.createProject(WorkflowJob.class, "stepOverriddenNamespace"); p.setDefinition(new CpsFlowDefinition(loadPipelineScript("runWithStepOverriddenNamespace.groovy") .replace("OVERRIDDEN_NAMESPACE", stepNamespace), true)); WorkflowRun b = p.scheduleBuild2(0).waitForStart(); assertNotNull(b); NamespaceAction.push(b, overriddenNamespace); r.assertBuildStatusSuccess(r.waitForCompletion(b)); r.assertLogContains(stepNamespace, b); }
@Test public void runWithOverriddenNamespace() throws Exception { String overriddenNamespace = testingNamespace + "-overridden-namespace"; KubernetesClient client = cloud.connect(); // Run in our own testing namespace if (client.namespaces().withName(overriddenNamespace).get() == null) { client.namespaces().createOrReplace( new NamespaceBuilder().withNewMetadata().withName(overriddenNamespace).endMetadata().build()); } WorkflowJob p = r.jenkins.createProject(WorkflowJob.class, "overriddenNamespace"); p.setDefinition(new CpsFlowDefinition(loadPipelineScript("runWithOverriddenNamespace.groovy"), true)); WorkflowRun b = p.scheduleBuild2(0).waitForStart(); assertNotNull(b); NamespaceAction.push(b, overriddenNamespace); r.assertBuildStatusSuccess(r.waitForCompletion(b)); r.assertLogContains(overriddenNamespace, b); }