io.fabric8.kubernetes.api.model.OwnerReferenceBuilder Java Examples
The following examples show how to use
io.fabric8.kubernetes.api.model.OwnerReferenceBuilder.
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 File: KafkaAssemblyOperator.java From strimzi-kafka-operator with Apache License 2.0 | 5 votes |
Future<ReconciliationState> clusterOperatorSecret(Supplier<Date> dateSupplier) { oldCoSecret = clusterCa.clusterOperatorSecret(); Labels labels = Labels.fromResource(kafkaAssembly) .withStrimziKind(reconciliation.kind()) .withStrimziCluster(reconciliation.name()) .withKubernetesName(Labels.APPLICATION_NAME) .withKubernetesInstance(reconciliation.name()) .withKubernetesPartOf(reconciliation.name()) .withKubernetesManagedBy(AbstractModel.STRIMZI_CLUSTER_OPERATOR_NAME); OwnerReference ownerRef = new OwnerReferenceBuilder() .withApiVersion(kafkaAssembly.getApiVersion()) .withKind(kafkaAssembly.getKind()) .withName(kafkaAssembly.getMetadata().getName()) .withUid(kafkaAssembly.getMetadata().getUid()) .withBlockOwnerDeletion(false) .withController(false) .build(); Secret secret = ModelUtils.buildSecret(clusterCa, clusterCa.clusterOperatorSecret(), namespace, ClusterOperator.secretName(name), "cluster-operator", "cluster-operator", labels, ownerRef, isMaintenanceTimeWindowsSatisfied(dateSupplier)); return withVoid(secretOperations.reconcile(namespace, ClusterOperator.secretName(name), secret)); }
Example #2
Source File: AbstractModel.java From strimzi-kafka-operator with Apache License 2.0 | 5 votes |
/** * Generate the OwnerReference object to link newly created objects to their parent (the custom resource) * * @return The OwnerReference object */ protected OwnerReference createOwnerReference() { return new OwnerReferenceBuilder() .withApiVersion(ownerApiVersion) .withKind(ownerKind) .withName(cluster) .withUid(ownerUid) .withBlockOwnerDeletion(false) .withController(false) .build(); }
Example #3
Source File: KafkaUserModel.java From strimzi-kafka-operator with Apache License 2.0 | 5 votes |
/** * Generate the OwnerReference object to link newly created objects to their parent (the custom resource) * * @return The owner reference. */ protected OwnerReference createOwnerReference() { return new OwnerReferenceBuilder() .withApiVersion(ownerApiVersion) .withKind(ownerKind) .withName(name) .withUid(ownerUid) .withBlockOwnerDeletion(false) .withController(false) .build(); }
Example #4
Source File: SecretCertProviderTest.java From strimzi-kafka-operator with Apache License 2.0 | 5 votes |
@BeforeAll public static void before() { Assumptions.assumeTrue(System.getProperty("os.name").contains("nux")); ssl = new OpenSslCertManager(); secretCertProvider = new SecretCertProvider(); ownerReference = new OwnerReferenceBuilder() .withApiVersion("myapi/v1") .withKind("mykind") .withName("myname") .withUid("myuid") .build(); }
Example #5
Source File: DynamicPVCWorkspaceVolume.java From kubernetes-plugin with Apache License 2.0 | 5 votes |
@Override public PersistentVolumeClaim createVolume(KubernetesClient client, ObjectMeta podMetaData){ String namespace = podMetaData.getNamespace(); String podId = podMetaData.getName(); LOGGER.log(Level.FINE, "Adding workspace volume from pod: {0}/{1}", new Object[] { namespace, podId }); OwnerReference ownerReference = new OwnerReferenceBuilder(). withApiVersion("v1"). withKind("Pod"). withBlockOwnerDeletion(true). withController(true). withName(podMetaData.getName()). withUid(podMetaData.getUid()).build(); PersistentVolumeClaim pvc = new PersistentVolumeClaimBuilder() .withNewMetadata() .withName("pvc-" + podMetaData.getName()) .withOwnerReferences(ownerReference) .withLabels(DEFAULT_POD_LABELS) .endMetadata() .withNewSpec() .withAccessModes(getAccessModesOrDefault()) .withNewResources() .withRequests(getResourceMap()) .endResources() .withStorageClassName(getStorageClassNameOrDefault()) .endSpec() .build(); pvc = client.persistentVolumeClaims().inNamespace(podMetaData.getNamespace()).create(pvc); LOGGER.log(INFO, "Created PVC: {0}/{1}", new Object[] { namespace, pvc.getMetadata().getName() }); return pvc; }
Example #6
Source File: Fabric8FlinkKubeClient.java From flink with Apache License 2.0 | 5 votes |
private void setOwnerReference(Deployment deployment, List<HasMetadata> resources) { final OwnerReference deploymentOwnerReference = new OwnerReferenceBuilder() .withName(deployment.getMetadata().getName()) .withApiVersion(deployment.getApiVersion()) .withUid(deployment.getMetadata().getUid()) .withKind(deployment.getKind()) .withController(true) .withBlockOwnerDeletion(true) .build(); resources.forEach(resource -> resource.getMetadata().setOwnerReferences(Collections.singletonList(deploymentOwnerReference))); }
Example #7
Source File: TopicOperatorIT.java From strimzi-kafka-operator with Apache License 2.0 | 4 votes |
@Test public void testKafkaTopicWithOwnerRef() throws InterruptedException, ExecutionException, TimeoutException { String topicName = "test-kafka-topic-with-owner-ref-1"; // this CM is created to be the owner of the KafkaTopic we're about to create. String cmName = "hodor"; HashMap<String, String> cmData = new HashMap<>(); cmData.put("strimzi", "rulez"); kubeClient.configMaps().inNamespace(NAMESPACE).create(new ConfigMapBuilder().withNewMetadata().withName(cmName) .withNamespace(NAMESPACE).endMetadata().withApiVersion("v1").withData(cmData).build()); String uid = kubeClient.configMaps().inNamespace(NAMESPACE).withName(cmName).get().getMetadata().getUid(); ObjectMeta metadata = new ObjectMeta(); OwnerReference or = new OwnerReferenceBuilder().withName(cmName) .withApiVersion("v1") .withController(false) .withBlockOwnerDeletion(false) .withUid(uid) .withKind("ConfigMap") .build(); metadata.getOwnerReferences().add(or); Map<String, String> annos = new HashMap<>(); annos.put("iam", "groot"); Map<String, String> lbls = new HashMap<>(); lbls.put("iam", "root"); metadata.setAnnotations(annos); metadata.setLabels(lbls); // create topic and test OR, labels, annotations Topic topic = new Topic.Builder(topicName, 1, (short) 1, emptyMap(), metadata).build(); KafkaTopic topicResource = TopicSerialization.toTopicResource(topic, labels); createKafkaTopicResource(topicResource); assertThat(operation().inNamespace(NAMESPACE).withName(topicName).get().getMetadata().getOwnerReferences().size(), is(1)); assertThat(operation().inNamespace(NAMESPACE).withName(topicName).get().getMetadata().getOwnerReferences().get(0).getUid(), is(uid)); assertThat(operation().inNamespace(NAMESPACE).withName(topicName).get().getMetadata().getAnnotations().size(), is(1)); assertThat(operation().inNamespace(NAMESPACE).withName(topicName).get().getMetadata().getAnnotations().get("iam"), is("groot")); assertThat(operation().inNamespace(NAMESPACE).withName(topicName).get().getMetadata().getLabels().size(), is(2)); assertThat(operation().inNamespace(NAMESPACE).withName(topicName).get().getMetadata().getLabels().get("iam"), is("root")); // edit kafka topic topicName = "test-kafka-topic-with-owner-ref-2"; Topic topic2 = new Topic.Builder(topicName, 1, (short) 1, emptyMap(), metadata).build(); KafkaTopic topicResource2 = TopicSerialization.toTopicResource(topic2, labels); topicResource = TopicSerialization.toTopicResource(topic2, labels); topicResource.getMetadata().getAnnotations().put("han", "solo"); createKafkaTopicResource(topicResource2); assertThat(operation().inNamespace(NAMESPACE).withName(topicName).get().getMetadata().getOwnerReferences().get(0).getUid(), is(uid)); assertThat(operation().inNamespace(NAMESPACE).withName(topicName).get().getMetadata().getAnnotations().size(), is(2)); assertThat(operation().inNamespace(NAMESPACE).withName(topicName).get().getMetadata().getAnnotations().get("iam"), is("groot")); assertThat(operation().inNamespace(NAMESPACE).withName(topicName).get().getMetadata().getAnnotations().get("han"), is("solo")); // edit k8s topic topicName = "test-kafka-topic-with-owner-ref-3"; Topic topic3 = new Topic.Builder(topicName, 1, (short) 1, emptyMap(), metadata).build(); topic3.getMetadata().getLabels().put("stan", "lee"); topicResource = TopicSerialization.toTopicResource(topic3, labels); createKafkaTopicResource(topicResource); assertThat(operation().inNamespace(NAMESPACE).withName(topicName).get().getMetadata().getOwnerReferences().get(0).getUid(), is(uid)); assertThat(operation().inNamespace(NAMESPACE).withName(topicName).get().getMetadata().getLabels().size(), is(3)); assertThat(operation().inNamespace(NAMESPACE).withName(topicName).get().getMetadata().getLabels().get("stan"), is("lee")); assertThat(operation().inNamespace(NAMESPACE).withName(topicName).get().getMetadata().getLabels().get("iam"), is("root")); }