Java Code Examples for io.fabric8.kubernetes.api.model.ObjectMeta
The following examples show how to use
io.fabric8.kubernetes.api.model.ObjectMeta.
These examples are extracted from open source projects.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source Project: dekorate Author: dekorateio File: AddBasicAuthSecretDecorator.java License: Apache License 2.0 | 6 votes |
@Override public void visit(KubernetesListBuilder list) { ObjectMeta meta = getMandatoryDeploymentMetadata(list); String name = Strings.isNullOrEmpty(this.name) ? meta.getName() : this.name; Map<String, String> data = new HashMap<String, String>() { { put(USERNAME, username); put(PASSWORD, password); } }; list.addToItems(new SecretBuilder() .withNewMetadata() .withName(name) .withAnnotations(annotations) .endMetadata() .withType(KUBERNETES_IO_BASIC_AUTH).addToStringData(data).build()); }
Example #2
Source Project: che Author: eclipse File: ContainerResourceProvisionerTest.java License: Eclipse Public License 2.0 | 6 votes |
@BeforeMethod public void setup() { resourceProvisioner = new ContainerResourceProvisioner(1024, 512, "500m", "100m"); container = new Container(); container.setName(CONTAINER_NAME); when(k8sEnv.getMachines()).thenReturn(of(MACHINE_NAME, internalMachineConfig)); when(internalMachineConfig.getAttributes()) .thenReturn( of( MEMORY_LIMIT_ATTRIBUTE, RAM_LIMIT_VALUE, MEMORY_REQUEST_ATTRIBUTE, RAM_REQUEST_VALUE, CPU_LIMIT_ATTRIBUTE, CPU_LIMIT_VALUE, CPU_REQUEST_ATTRIBUTE, CPU_REQUEST_VALUE)); final ObjectMeta podMetadata = mock(ObjectMeta.class); when(podMetadata.getName()).thenReturn(POD_NAME); final PodSpec podSpec = mock(PodSpec.class); when(podSpec.getContainers()).thenReturn(Collections.singletonList(container)); when(k8sEnv.getPodsData()).thenReturn(of(POD_NAME, new PodData(podSpec, podMetadata))); }
Example #3
Source Project: dekorate Author: dekorateio File: AddApplicationResourceDecorator.java License: Apache License 2.0 | 6 votes |
public void visit(KubernetesListBuilder list) { ObjectMeta meta = getMandatoryDeploymentMetadata(list); list.addToItems(new ApplicationBuilder() .withNewMetadata() .withName(meta.getName()) .withLabels(meta.getLabels()) .endMetadata() .withNewSpec() .withNewSelector() .withMatchLabels(meta.getLabels()) .endSelector() .withNewDescriptor() .withVersion(meta.getLabels().getOrDefault(Labels.VERSION, "latest")) .withOwners(Arrays.stream(config.getOwners()).map(AddApplicationResourceDecorator::adapt).collect(Collectors.toList())) .withLinks(Arrays.stream(config.getLinks()).map(AddApplicationResourceDecorator::adapt).collect(Collectors.toList())) .withMaintainers(Arrays.stream(config.getMaintainers()).map(AddApplicationResourceDecorator::adapt).collect(Collectors.toList())) .withIcons(Arrays.stream(config.getIcons()).map(AddApplicationResourceDecorator::adapt).collect(Collectors.toList())) .withKeywords(config.getKeywords()) .withNotes(config.getNotes()) .endDescriptor() .endSpec()); }
Example #4
Source Project: che Author: eclipse File: KubernetesInternalRuntime.java License: Eclipse Public License 2.0 | 6 votes |
private List<PodData> getAllInjectablePods( ObjectMeta toCreateMeta, List<Container> toCreateContainers, Map<String, Map<String, Pod>> injectables) { return toCreateContainers .stream() .map(c -> Names.machineName(toCreateMeta, c)) .map(injectables::get) // we're only interested in pods for which we require injection .filter(Objects::nonNull) // now reduce to a map keyed by injected pod name so that if 2 pods require injection // of the same thing, we don't inject twice .flatMap(m -> m.entrySet().stream()) // collect to map, ignoring duplicate entries .collect(toMap(Entry::getKey, Entry::getValue, (v1, v2) -> v1)) // ok, we only have 1 of each injectable pods keyed by their names, so let's just get them // all and return as list .values() .stream() .map(PodData::new) .collect(Collectors.toList()); }
Example #5
Source Project: spring-cloud-kubernetes Author: spring-cloud File: KubernetesDiscoveryClientFilterTest.java License: Apache License 2.0 | 6 votes |
@Test public void testFilteredServices() { List<String> springBootServiceNames = Arrays.asList("serviceA", "serviceB"); List<Service> services = createSpringBootServiceByName(springBootServiceNames); // Add non spring boot service Service service = new Service(); ObjectMeta objectMeta = new ObjectMeta(); objectMeta.setName("ServiceNonSpringBoot"); service.setMetadata(objectMeta); services.add(service); ServiceList serviceList = new ServiceList(); serviceList.setItems(services); when(this.serviceOperation.list()).thenReturn(serviceList); when(this.kubernetesClient.services()).thenReturn(this.serviceOperation); when(this.properties.getFilter()) .thenReturn("metadata.additionalProperties['spring-boot']"); List<String> filteredServices = this.underTest.getServices(); System.out.println("Filtered Services: " + filteredServices); assertThat(filteredServices).isEqualTo(springBootServiceNames); }
Example #6
Source Project: vxms Author: amoAHCP File: KubernetesMockTest.java License: Apache License 2.0 | 6 votes |
@Test public void findServices() { final ObjectMeta build = new ObjectMetaBuilder().addToLabels("test", "test").build(); final ServiceSpec spec = new ServiceSpecBuilder().addNewPort().and().withClusterIP("192.168.1.1").build(); final Service service = new ServiceBuilder().withMetadata(build).withSpec(spec).build(); server .expect() .withPath("/api/v1/namespaces/default/services") .andReturn(200, new ServiceListBuilder().addToItems().addToItems(service).build()) .once(); KubernetesClient client = this.client; final ServiceList list = client.services().inNamespace("default").list(); assertNotNull(list); assertEquals("test", list.getItems().get(0).getMetadata().getLabels().get("test")); System.out.println(list.getItems().get(0).getSpec().getClusterIP()); }
Example #7
Source Project: dekorate Author: dekorateio File: AddServiceMonitorResourceDecorator.java License: Apache License 2.0 | 6 votes |
public void visit(KubernetesListBuilder list) { ObjectMeta meta = getMandatoryDeploymentMetadata(list); list.addToItems(new ServiceMonitorBuilder() .withNewMetadata() .withName(meta.getName()) .withLabels(meta.getLabels()) .endMetadata() .withNewSpec() .withNewSelector() .addToMatchLabels(meta.getLabels()) .endSelector() .addNewEndpoint() .withPort(config.getPort()) .withNewPath(config.getPath()) .withInterval(config.getInterval() + "s") .withHonorLabels(config.isHonorLabels()) .endEndpoint() .endSpec()); }
Example #8
Source Project: kogito-runtimes Author: kiegroup File: MockKubernetesServerSupport.java License: Apache License 2.0 | 6 votes |
protected void createMockService(final String serviceName, final String ip, final Map<String, String> labels, final String namespace) { final ServiceSpec serviceSpec = new ServiceSpec(); serviceSpec.setPorts(Collections.singletonList(new ServicePort("http", 0, 8080, "http", new IntOrString(8080)))); serviceSpec.setClusterIP(ip); serviceSpec.setType("ClusterIP"); serviceSpec.setSessionAffinity("ClientIP"); final ObjectMeta metadata = new ObjectMeta(); metadata.setName(serviceName); metadata.setNamespace(MOCK_NAMESPACE); metadata.setLabels(labels); final Service service = new Service("v1", "Service", metadata, serviceSpec, new ServiceStatus(new LoadBalancerStatus())); if (namespace != null) { this.server.getClient().inNamespace(namespace).services().create(service); } else { this.server.getClient().services().create(service); } }
Example #9
Source Project: vault-crd Author: DaspawnW File: KubernetesService.java License: Apache License 2.0 | 6 votes |
private ObjectMeta metaData(ObjectMeta resource, String compare) { ObjectMeta meta = new ObjectMeta(); meta.setNamespace(resource.getNamespace()); meta.setName(resource.getName()); if (resource.getLabels() != null) { meta.setLabels(resource.getLabels()); } HashMap<String, String> annotations = new HashMap<>(); if (resource.getAnnotations() != null) { annotations.putAll(resource.getAnnotations()); } annotations.put(crdName + LAST_UPDATE_ANNOTATION, LocalDateTime.now().toString()); annotations.put(crdName + COMPARE_ANNOTATION, compare); meta.setAnnotations(annotations); return meta; }
Example #10
Source Project: dekorate Author: dekorateio File: ApplyDeploymentTriggerDecorator.java License: Apache License 2.0 | 6 votes |
@Override public void andThenVisit(DeploymentConfigSpecFluent<?> deploymentConfigSpec, ObjectMeta resourceMeta) { DeploymentConfigSpecFluent.TriggersNested<?> target; if (deploymentConfigSpec.buildMatchingTrigger(predicate) != null) { target = deploymentConfigSpec.editMatchingTrigger(predicate); } else { target = deploymentConfigSpec.addNewTrigger(); } target.withType(IMAGECHANGE) .withNewImageChangeParams() .withAutomatic(true) .withContainerNames(containerName) .withNewFrom() .withKind(IMAGESTREAMTAG) .withName(imageStreamTag) .endFrom() .endImageChangeParams() .endTrigger(); }
Example #11
Source Project: dekorate Author: dekorateio File: AddBuilderImageStreamResourceDecorator.java License: Apache License 2.0 | 6 votes |
public void visit(KubernetesListBuilder list) { ObjectMeta meta = getMandatoryDeploymentMetadata(list); String repository = Images.getRepository(config.getBuilderImage()); String name = !repository.contains("/") ? repository : repository.substring(repository.lastIndexOf("/") + 1); String dockerImageRepo = Images.removeTag(config.getBuilderImage()); list.addToItems(new ImageStreamBuilder() .withNewMetadata() .withName(name) .withLabels(meta.getLabels()) .endMetadata() .withNewSpec() .withDockerImageRepository(dockerImageRepo) .endSpec()); }
Example #12
Source Project: spring-cloud-deployer-kubernetes Author: spring-cloud File: KubernetesAppDeployerIntegrationTests.java License: Apache License 2.0 | 5 votes |
private Secret randomSecret() { Map<String, String> secretData = new HashMap<>(); secretData.put("d-" + UUID.randomUUID().toString().substring(0, 5), "dmFsdWUx"); secretData.put("d-" + UUID.randomUUID().toString().substring(0, 5), "dmFsdWUy"); Secret secret = new Secret(); secret.setData(secretData); ObjectMeta objectMeta = new ObjectMeta(); objectMeta.setName("secret-" + UUID.randomUUID().toString().substring(0, 5)); secret.setMetadata(objectMeta); return kubernetesClient.secrets().create(secret); }
Example #13
Source Project: dekorate Author: dekorateio File: ApplyServiceAccountNamedDecorator.java License: Apache License 2.0 | 5 votes |
@Override public void andThenVisit(PodSpecFluent podSpec, ObjectMeta resourceMeta) { if (Strings.isNotNullOrEmpty(serviceAccount)) { podSpec.withServiceAccount(serviceAccount); } else { podSpec.withServiceAccount(resourceMeta.getName()); } }
Example #14
Source Project: rabbitmq-operator Author: indeedeng File: TestUserReconciler.java License: Apache License 2.0 | 5 votes |
private RabbitMQUser generateRabbitMQUser(final List<VhostPermissions> vhostPermissions, final List<String> tags) { final Secret userSecret = new SecretBuilder() .withNewMetadata().withName(RabbitMQSecrets.getUserSecretName("username", CLUSTER_NAME)).withNamespace("ns").endMetadata() .withData(ImmutableMap.of(Constants.Secrets.USERNAME_KEY, "username", Constants.Secrets.PASSWORD_KEY, "password")) .build(); final ObjectMeta clusterMetadata = new ObjectMetaBuilder().withName(CLUSTER_NAME).withNamespace(NAMESPACE).build(); return new RabbitMQUser("username", userSecret, clusterMetadata, null, vhostPermissions, tags); }
Example #15
Source Project: dekorate Author: dekorateio File: AddImagePullSecretDecorator.java License: Apache License 2.0 | 5 votes |
public void andThenVisit(PodSpecFluent<?> podSpec, ObjectMeta resourceMeta) { if (Strings.isNotNullOrEmpty(imagePullSecret) && !podSpec.hasMatchingImagePullSecret(r -> imagePullSecret.equals(r.getName()))) { podSpec.addNewImagePullSecret() .withName(imagePullSecret) .endImagePullSecret(); } }
Example #16
Source Project: onos Author: opennetworkinglab File: K8sNamespaceManagerTest.java License: Apache License 2.0 | 5 votes |
private static Namespace createK8sNamespace(String uid, String name) { ObjectMeta meta = new ObjectMeta(); meta.setUid(uid); meta.setName(name); Namespace namespace = new Namespace(); namespace.setApiVersion("v1"); namespace.setKind("Namespace"); namespace.setMetadata(meta); return namespace; }
Example #17
Source Project: spring-cloud-kubernetes Author: spring-cloud File: KubernetesDiscoveryClientFilterTest.java License: Apache License 2.0 | 5 votes |
@Test public void testFilteredServicesByPrefix() { List<String> springBootServiceNames = Arrays.asList("serviceA", "serviceB", "serviceC"); List<Service> services = createSpringBootServiceByName(springBootServiceNames); // Add non spring boot service Service service = new Service(); ObjectMeta objectMeta = new ObjectMeta(); objectMeta.setName("anotherService"); service.setMetadata(objectMeta); services.add(service); ServiceList serviceList = new ServiceList(); serviceList.setItems(services); when(this.serviceOperation.list()).thenReturn(serviceList); when(this.kubernetesClient.services()).thenReturn(this.serviceOperation); when(this.properties.getFilter()) .thenReturn("metadata.name.startsWith('service')"); List<String> filteredServices = this.underTest.getServices(); System.out.println("Filtered Services: " + filteredServices); assertThat(filteredServices).isEqualTo(springBootServiceNames); }
Example #18
Source Project: microbean-helm Author: microbean File: TillerInstaller.java License: Apache License 2.0 | 5 votes |
protected Deployment createDeployment(String namespace, final String deploymentName, final int replicas, Map<String, String> labels, final Map<String, String> nodeSelector, final String serviceAccountName, final String imageName, final ImagePullPolicy imagePullPolicy, final int maxHistory, final boolean hostNetwork, final boolean tls, final boolean verifyTls) { namespace = normalizeNamespace(namespace); labels = normalizeLabels(labels); final Deployment deployment = new Deployment(); final ObjectMeta metadata = new ObjectMeta(); metadata.setNamespace(namespace); metadata.setName(normalizeDeploymentName(deploymentName)); metadata.setLabels(labels); deployment.setMetadata(metadata); deployment.setSpec(this.createDeploymentSpec(Math.max(1, replicas), labels, nodeSelector, serviceAccountName, imageName, imagePullPolicy, maxHistory, namespace, hostNetwork, tls, verifyTls)); return deployment; }
Example #19
Source Project: kubernetes-client Author: fabric8io File: ReflectUtilsTest.java License: Apache License 2.0 | 5 votes |
@Test public void testInstanceOf() throws ReflectiveOperationException { ObjectMeta meta = new ObjectMeta(); Baz baz = new Baz(); baz.setMetadata(meta); assertSame(meta, ReflectUtils.objectMetadata(baz)); }
Example #20
Source Project: onos Author: opennetworkinglab File: K8sServiceManagerTest.java License: Apache License 2.0 | 5 votes |
private static Service createK8sService(String uid, String name) { ObjectMeta meta = new ObjectMeta(); meta.setUid(uid); meta.setName(name); Service service = new Service(); service.setApiVersion("v1"); service.setKind("service"); service.setMetadata(meta); return service; }
Example #21
Source Project: kubernetes-elastic-agents Author: gocd File: KubernetesAgentInstancesTest.java License: Apache License 2.0 | 5 votes |
@Test public void shouldNotCreatePodsWhenOutstandingLimitOfPendingKubernetesPodsHasReached() throws IOException { //set maximum pending pod count to 1 when(mockPluginSettings.getMaxPendingPods()).thenReturn(1); //pending kubernetes pod KubernetesInstance kubernetesInstance = new KubernetesInstance(new DateTime(), "test", "test-agent", new HashMap<>(), 100L, PodState.Pending); when(mockKubernetesInstanceFactory.create(mockCreateAgentRequest, mockPluginSettings, mockKubernetesClient, mockPluginRequest)). thenReturn(kubernetesInstance); testProperties.put("PodSpecType", "properties"); //first create agent request KubernetesAgentInstances agentInstances = new KubernetesAgentInstances(factory, mockKubernetesInstanceFactory); JobIdentifier jobId = new JobIdentifier("test", 1L, "Test pipeline", "test name", "1", "test job", 100L); when(mockCreateAgentRequest.jobIdentifier()).thenReturn(jobId); agentInstances.create(mockCreateAgentRequest, mockPluginSettings, mockPluginRequest, consoleLogAppender); verify(mockKubernetesInstanceFactory, times(1)).create(any(), any(), any(), any()); reset(mockKubernetesInstanceFactory); final Map<String, String> labels = new HashMap<>(); labels.put(JOB_ID_LABEL_KEY, jobId.getJobId().toString()); labels.put(Constants.KUBERNETES_POD_KIND_LABEL_KEY, Constants.KUBERNETES_POD_KIND_LABEL_VALUE); final Pod pod = mock(Pod.class); final ObjectMeta objectMeta = mock(ObjectMeta.class); when(pod.getMetadata()).thenReturn(objectMeta); when(objectMeta.getLabels()).thenReturn(labels); when(objectMeta.getName()).thenReturn("test-agent"); when(podList.getItems()).thenReturn(Arrays.asList(pod)); when(mockKubernetesInstanceFactory.fromKubernetesPod(pod)).thenReturn(kubernetesInstance); //second create agent request agentInstances.create(mockCreateAgentRequest, mockPluginSettings, mockPluginRequest, consoleLogAppender); verify(mockKubernetesInstanceFactory, times(0)).create(any(), any(), any(), any()); }
Example #22
Source Project: onos Author: opennetworkinglab File: K8sNetworkPolicyManagerTest.java License: Apache License 2.0 | 5 votes |
private static NetworkPolicy createK8sNetworkPolicy(String uid, String name) { ObjectMeta meta = new ObjectMeta(); meta.setUid(uid); meta.setName(name); NetworkPolicy networkPolicy = new NetworkPolicy(); networkPolicy.setApiVersion("v1"); networkPolicy.setKind("NetworkPolicy"); networkPolicy.setMetadata(meta); return networkPolicy; }
Example #23
Source Project: che Author: eclipse File: OpenShiftUniqueNamesProvisioner.java License: Eclipse Public License 2.0 | 5 votes |
@Override public void provision(OpenShiftEnvironment osEnv, RuntimeIdentity identity) throws InfrastructureException { super.provision(osEnv, identity); final Set<Route> routes = new HashSet<>(osEnv.getRoutes().values()); osEnv.getRoutes().clear(); for (Route route : routes) { final ObjectMeta routeMeta = route.getMetadata(); putLabel(route, Constants.CHE_ORIGINAL_NAME_LABEL, routeMeta.getName()); final String routeName = Names.generateName("route"); routeMeta.setName(routeName); osEnv.getRoutes().put(routeName, route); } }
Example #24
Source Project: che Author: eclipse File: PodMergerTest.java License: Eclipse Public License 2.0 | 5 votes |
private void verifyContainsAllFrom(ObjectMeta source, ObjectMeta toCheck) { assertTrue(source.getLabels().entrySet().containsAll(toCheck.getLabels().entrySet())); assertTrue(source.getAnnotations().entrySet().containsAll(toCheck.getAnnotations().entrySet())); assertTrue( source .getAdditionalProperties() .entrySet() .containsAll(toCheck.getAdditionalProperties().entrySet())); }
Example #25
Source Project: che Author: eclipse File: OpenShiftUniqueNamesProvisionerTest.java License: Eclipse Public License 2.0 | 5 votes |
@Test public void provideUniquePodsNames() throws Exception { when(runtimeIdentity.getWorkspaceId()).thenReturn(WORKSPACE_ID); Pod pod = newPod(); PodData podData = new PodData(pod.getSpec(), pod.getMetadata()); doReturn(ImmutableMap.of(POD_NAME, podData)).when(osEnv).getPodsData(); uniqueNamesProvisioner.provision(osEnv, runtimeIdentity); ObjectMeta podMetadata = pod.getMetadata(); assertNotEquals(podMetadata.getName(), POD_NAME); assertEquals(podMetadata.getLabels().get(CHE_ORIGINAL_NAME_LABEL), POD_NAME); }
Example #26
Source Project: syndesis Author: syndesisio File: KnativeMetaDataSupport.java License: Apache License 2.0 | 5 votes |
private static List<String> listResources(CustomResourceDefinition crd) { try (OpenShiftClient client = new DefaultOpenShiftClient()) { return client.customResources(crd, KnativeResource.class, KnativeResourceList.class, KnativeResourceDoneable.class) .inNamespace(getTargetNamespace()) .list() .getItems() .stream() .map(KnativeResource::getMetadata) .map(ObjectMeta::getName) .collect(Collectors.toList()); } }
Example #27
Source Project: che Author: eclipse File: OpenShiftPreviewUrlExposerTest.java License: Eclipse Public License 2.0 | 5 votes |
@Test public void shouldNotProvisionWhenServiceAndRouteFound() throws InternalInfrastructureException { final int PORT = 8080; final String SERVER_PORT_NAME = "server-" + PORT; CommandImpl command = new CommandImpl("a", "a", "a", new PreviewUrlImpl(PORT, null), Collections.emptyMap()); Service service = new Service(); ObjectMeta serviceMeta = new ObjectMeta(); serviceMeta.setName("servicename"); service.setMetadata(serviceMeta); ServiceSpec serviceSpec = new ServiceSpec(); serviceSpec.setPorts( singletonList(new ServicePort(SERVER_PORT_NAME, null, PORT, "TCP", new IntOrString(PORT)))); service.setSpec(serviceSpec); Route route = new Route(); RouteSpec routeSpec = new RouteSpec(); routeSpec.setPort(new RoutePort(new IntOrString(SERVER_PORT_NAME))); routeSpec.setTo(new RouteTargetReference("routekind", "servicename", 1)); route.setSpec(routeSpec); Map<String, Service> services = new HashMap<>(); services.put("servicename", service); Map<String, Route> routes = new HashMap<>(); routes.put("routename", route); OpenShiftEnvironment env = OpenShiftEnvironment.builder() .setCommands(singletonList(new CommandImpl(command))) .setServices(services) .setRoutes(routes) .build(); assertEquals(env.getRoutes().size(), 1); previewUrlEndpointsProvisioner.expose(env); assertEquals(env.getRoutes().size(), 1); }
Example #28
Source Project: dekorate Author: dekorateio File: EndpointPathDecorator.java License: Apache License 2.0 | 5 votes |
@Override public void andThenVisit(ServiceMonitorBuilder serviceMonitor, ObjectMeta resourceMeta) { serviceMonitor.accept(new TypedVisitor<EndpointBuilder>() { @Override public void visit(EndpointBuilder endpoint) { if (port.equals(endpoint.getPort())) { endpoint.withPath(path); } } }); }
Example #29
Source Project: jkube Author: eclipse File: KubernetesHelper.java License: Eclipse Public License 2.0 | 5 votes |
/** * Returns the resource version for the entity or null if it does not have one * * @param entity entity as HasMetadata object * @return resource version as string value */ public static String getResourceVersion(HasMetadata entity) { if (entity != null) { ObjectMeta metadata = entity.getMetadata(); if (metadata != null) { String resourceVersion = metadata.getResourceVersion(); if (StringUtils.isNotBlank(resourceVersion)) { return resourceVersion; } } } return null; }
Example #30
Source Project: kubernetes-client Author: fabric8io File: ReflectUtilsTest.java License: Apache License 2.0 | 5 votes |
@Test public void testDirectReflection () throws ReflectiveOperationException { ObjectMeta meta = new ObjectMeta(); Foo foo = new Foo(); foo.setMetadata(meta); assertSame(meta, ReflectUtils.objectMetadata(foo)); }