Search in sources :

Example 26 with RoleBinding

use of io.fabric8.kubernetes.api.model.rbac.RoleBinding in project strimzi by strimzi.

the class EntityTopicOperator method generateRoleBindingForRole.

public RoleBinding generateRoleBindingForRole(String namespace, String watchedNamespace) {
    Subject ks = new SubjectBuilder().withKind("ServiceAccount").withName(EntityOperator.entityOperatorServiceAccountName(cluster)).withNamespace(namespace).build();
    RoleRef roleRef = new RoleRefBuilder().withName(getRoleName()).withApiGroup("rbac.authorization.k8s.io").withKind("Role").build();
    RoleBinding rb = generateRoleBinding(roleBindingForRoleName(cluster), watchedNamespace, roleRef, singletonList(ks));
    // We set OwnerReference only within the same namespace since it does not work cross-namespace
    if (!namespace.equals(watchedNamespace)) {
        rb.getMetadata().setOwnerReferences(Collections.emptyList());
    }
    return rb;
}
Also used : RoleRef(io.fabric8.kubernetes.api.model.rbac.RoleRef) RoleBinding(io.fabric8.kubernetes.api.model.rbac.RoleBinding) SubjectBuilder(io.fabric8.kubernetes.api.model.rbac.SubjectBuilder) Subject(io.fabric8.kubernetes.api.model.rbac.Subject) RoleRefBuilder(io.fabric8.kubernetes.api.model.rbac.RoleRefBuilder)

Example 27 with RoleBinding

use of io.fabric8.kubernetes.api.model.rbac.RoleBinding in project strimzi by strimzi.

the class EntityTopicOperatorTest method testRoleBindingInTheSameNamespace.

@ParallelTest
public void testRoleBindingInTheSameNamespace() {
    RoleBinding binding = entityTopicOperator.generateRoleBindingForRole(namespace, namespace);
    assertThat(binding.getSubjects().get(0).getNamespace(), is(namespace));
    assertThat(binding.getMetadata().getNamespace(), is(namespace));
    assertThat(binding.getMetadata().getOwnerReferences().size(), is(1));
    assertThat(binding.getRoleRef().getKind(), is("Role"));
    assertThat(binding.getRoleRef().getName(), is("foo-entity-operator"));
}
Also used : RoleBinding(io.fabric8.kubernetes.api.model.rbac.RoleBinding) ParallelTest(io.strimzi.test.annotations.ParallelTest)

Example 28 with RoleBinding

use of io.fabric8.kubernetes.api.model.rbac.RoleBinding in project strimzi-kafka-operator by strimzi.

the class EntityUserOperatorTest method testRoleBindingInOtherNamespace.

@ParallelTest
public void testRoleBindingInOtherNamespace() {
    RoleBinding binding = entityUserOperator.generateRoleBindingForRole(namespace, uoWatchedNamespace);
    assertThat(binding.getSubjects().get(0).getNamespace(), is(namespace));
    assertThat(binding.getMetadata().getNamespace(), is(uoWatchedNamespace));
    assertThat(binding.getMetadata().getOwnerReferences().size(), is(0));
    assertThat(binding.getRoleRef().getKind(), is("Role"));
    assertThat(binding.getRoleRef().getName(), is("foo-entity-operator"));
}
Also used : RoleBinding(io.fabric8.kubernetes.api.model.rbac.RoleBinding) ParallelTest(io.strimzi.test.annotations.ParallelTest)

Example 29 with RoleBinding

use of io.fabric8.kubernetes.api.model.rbac.RoleBinding in project strimzi-kafka-operator by strimzi.

the class RoleBindingOperatorIT method getModified.

@Override
protected RoleBinding getModified() {
    Subject ks = new SubjectBuilder().withKind("ServiceAccount").withName("my-service-account2").withNamespace("my-namespace2").build();
    // RoleRef cannot be changed
    RoleRef roleRef = new RoleRefBuilder().withName("my-cluster-role").withApiGroup("rbac.authorization.k8s.io").withKind("ClusterRole").build();
    return new RoleBindingBuilder().withNewMetadata().withName(resourceName).withNamespace(namespace).withLabels(singletonMap("state", "modified")).endMetadata().withSubjects(ks).withRoleRef(roleRef).build();
}
Also used : RoleBindingBuilder(io.fabric8.kubernetes.api.model.rbac.RoleBindingBuilder) RoleRef(io.fabric8.kubernetes.api.model.rbac.RoleRef) SubjectBuilder(io.fabric8.kubernetes.api.model.rbac.SubjectBuilder) Subject(io.fabric8.kubernetes.api.model.rbac.Subject) RoleRefBuilder(io.fabric8.kubernetes.api.model.rbac.RoleRefBuilder)

Example 30 with RoleBinding

use of io.fabric8.kubernetes.api.model.rbac.RoleBinding in project strimzi-kafka-operator by strimzi.

the class RoleBindingOperatorTest method resource.

@Override
protected RoleBinding resource() {
    Subject ks = new SubjectBuilder().withKind("ServiceAccount").withName("some-service-account").withNamespace(NAMESPACE).build();
    RoleRef roleRef = new RoleRefBuilder().withName("some-role").withApiGroup("rbac.authorization.k8s.io").withKind("ClusterRole").build();
    return new RoleBindingBuilder().withNewMetadata().withName(RESOURCE_NAME).withNamespace(NAMESPACE).withLabels(singletonMap("foo", "bar")).endMetadata().withRoleRef(roleRef).withSubjects(singletonList(ks)).build();
}
Also used : RoleBindingBuilder(io.fabric8.kubernetes.api.model.rbac.RoleBindingBuilder) RoleRef(io.fabric8.kubernetes.api.model.rbac.RoleRef) SubjectBuilder(io.fabric8.kubernetes.api.model.rbac.SubjectBuilder) Subject(io.fabric8.kubernetes.api.model.rbac.Subject) RoleRefBuilder(io.fabric8.kubernetes.api.model.rbac.RoleRefBuilder)

Aggregations

RoleBinding (io.fabric8.kubernetes.api.model.rbac.RoleBinding)33 RoleRefBuilder (io.fabric8.kubernetes.api.model.rbac.RoleRefBuilder)20 RoleBinding (io.fabric8.openshift.api.model.RoleBinding)19 Test (org.junit.jupiter.api.Test)19 RoleBindingBuilder (io.fabric8.kubernetes.api.model.rbac.RoleBindingBuilder)16 RoleRef (io.fabric8.kubernetes.api.model.rbac.RoleRef)16 SubjectBuilder (io.fabric8.kubernetes.api.model.rbac.SubjectBuilder)14 RoleBindingBuilder (io.fabric8.openshift.api.model.RoleBindingBuilder)13 Role (io.fabric8.kubernetes.api.model.rbac.Role)10 Subject (io.fabric8.kubernetes.api.model.rbac.Subject)10 KubernetesClientException (io.fabric8.kubernetes.client.KubernetesClientException)10 OpenShiftClient (io.fabric8.openshift.client.OpenShiftClient)10 List (java.util.List)8 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)6 ServiceAccount (io.fabric8.kubernetes.api.model.ServiceAccount)6 Kafka (io.strimzi.api.kafka.model.Kafka)6 KafkaBuilder (io.strimzi.api.kafka.model.KafkaBuilder)6 CertManager (io.strimzi.certs.CertManager)6 KubernetesVersion (io.strimzi.operator.KubernetesVersion)6 PlatformFeaturesAvailability (io.strimzi.operator.PlatformFeaturesAvailability)6