use of io.fabric8.kubernetes.api.model.Binding in project strimzi 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"));
}
use of io.fabric8.kubernetes.api.model.Binding in project strimzi-kafka-operator by strimzi.
the class SetupClusterOperator method applyClusterOperatorInstallFiles.
/**
* Perform application of ServiceAccount, Roles and CRDs needed for proper cluster operator deployment.
* Configuration files are loaded from packaging/install/cluster-operator directory.
*/
public void applyClusterOperatorInstallFiles(String namespace) {
List<File> operatorFiles = Arrays.stream(new File(CO_INSTALL_DIR).listFiles()).sorted().filter(File::isFile).filter(file -> !file.getName().matches(".*(Binding|Deployment)-.*")).collect(Collectors.toList());
for (File operatorFile : operatorFiles) {
File createFile = operatorFile;
if (createFile.getName().contains(Constants.CLUSTER_ROLE + "-")) {
createFile = switchClusterRolesToRolesIfNeeded(createFile);
}
final String resourceType = createFile.getName().split("-")[1];
LOGGER.debug("Installation resource type: {}", resourceType);
switch(resourceType) {
case Constants.ROLE:
Role role = TestUtils.configFromYaml(createFile, Role.class);
ResourceManager.getInstance().createResource(extensionContext, new RoleBuilder(role).editMetadata().withNamespace(namespace).endMetadata().build());
break;
case Constants.CLUSTER_ROLE:
ClusterRole clusterRole = TestUtils.configFromYaml(createFile, ClusterRole.class);
ResourceManager.getInstance().createResource(extensionContext, clusterRole);
break;
case Constants.SERVICE_ACCOUNT:
ServiceAccount serviceAccount = TestUtils.configFromYaml(createFile, ServiceAccount.class);
ResourceManager.getInstance().createResource(extensionContext, new ServiceAccountBuilder(serviceAccount).editMetadata().withNamespace(namespace).endMetadata().build());
break;
case Constants.CONFIG_MAP:
ConfigMap configMap = TestUtils.configFromYaml(createFile, ConfigMap.class);
ResourceManager.getInstance().createResource(extensionContext, new ConfigMapBuilder(configMap).editMetadata().withNamespace(namespace).endMetadata().build());
break;
case Constants.CUSTOM_RESOURCE_DEFINITION_SHORT:
CustomResourceDefinition customResourceDefinition = TestUtils.configFromYaml(createFile, CustomResourceDefinition.class);
ResourceManager.getInstance().createResource(extensionContext, customResourceDefinition);
break;
default:
LOGGER.error("Unknown installation resource type: {}", resourceType);
throw new RuntimeException("Unknown installation resource type:" + resourceType);
}
}
}
use of io.fabric8.kubernetes.api.model.Binding in project cos-fleetshard by bf2fc6cc711aee1a0c2a.
the class KameletBindingSteps method klb_phase_and_conditions.
@SuppressWarnings("unchecked")
@When("the klb phase is {string} with conditions:")
public void klb_phase_and_conditions(String phase, DataTable table) {
// TODO: investigate using KubernetesClient.resources(KameletBinding.class) result in a bad patch
kubernetesClient.genericKubernetesResources(KameletBinding.RESOURCE_DEFINITION).inNamespace(ctx.connector().getMetadata().getNamespace()).withName(ctx.connector().getMetadata().getName()).editStatus(binding -> {
Map<String, Object> status = (Map<String, Object>) binding.getAdditionalProperties().get("status");
if (status == null) {
status = new HashMap<>();
}
List<Map<String, String>> rows = table.asMaps(String.class, String.class);
List<Condition> conditions = new ArrayList<>(rows.size());
for (Map<String, String> columns : rows) {
conditions.add(new ConditionBuilder().withMessage(columns.get("message")).withReason(columns.get("reason")).withStatus(columns.get("status")).withType(columns.get("type")).withLastTransitionTime(columns.get("lastTransitionTime")).build());
}
status.put("phase", phase);
status.put("conditions", conditions);
binding.getAdditionalProperties().put("status", status);
return binding;
});
// kubernetesClient.resources(KameletBinding.class)
// .inNamespace(ctx.connector().getMetadata().getNamespace())
// .withName(ctx.connector().getMetadata().getName())
// .editStatus(binding -> {
// if (binding.getStatus() == null) {
// binding.setStatus(new KameletBindingStatus());
// }
//
// List<Map<String, String>> rows = table.asMaps(String.class, String.class);
// List<Condition> conditions = new ArrayList<>(rows.size());
//
// for (Map<String, String> columns : rows) {
// conditions.add(new ConditionBuilder()
// .withMessage(columns.get("message"))
// .withReason(columns.get("reason"))
// .withStatus(columns.get("status"))
// .withType(columns.get("type"))
// .withLastTransitionTime(columns.get("lastTransitionTime"))
// .build());
// }
//
// binding.getStatus().setPhase(phase);
// binding.getStatus().setConditions(conditions);
//
// return binding;
// });
}
use of io.fabric8.kubernetes.api.model.Binding 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"));
}
use of io.fabric8.kubernetes.api.model.Binding in project quarkus-operator-sdk by quarkiverse.
the class AddRoleBindingsDecorator method visit.
@Override
public void visit(KubernetesListBuilder list) {
final var serviceAccountName = getMandatoryDeploymentMetadata(list).getName();
for (Entry<String, QuarkusControllerConfiguration> entry : configs.entrySet()) {
String controllerName = entry.getKey();
QuarkusControllerConfiguration<?> config = entry.getValue();
if (config.watchCurrentNamespace()) {
// create a RoleBinding that will be applied in the current namespace if watching only the current NS
list.addToItems(new RoleBindingBuilder().withNewMetadata().withName(controllerName + "-role-binding").endMetadata().withNewRoleRef(RBAC_AUTHORIZATION_GROUP, CLUSTER_ROLE, getClusterRoleName(controllerName)).addNewSubject(null, SERVICE_ACCOUNT, serviceAccountName, null).build());
} else if (config.watchAllNamespaces()) {
handleClusterRoleBinding(list, serviceAccountName, controllerName, controllerName + "-cluster-role-binding", "watch all namespaces", getClusterRoleName(controllerName));
} else {
config.getEffectiveNamespaces().forEach(ns -> list.addToItems(new RoleBindingBuilder().withNewMetadata().withName(controllerName + "-role-binding").withNamespace(ns).endMetadata().withNewRoleRef(RBAC_AUTHORIZATION_GROUP, CLUSTER_ROLE, getClusterRoleName(controllerName)).addNewSubject(null, SERVICE_ACCOUNT, serviceAccountName, null).build()));
}
// if we validate the CRDs, also create a binding for the CRD validating role
if (validateCRDs) {
final var crBindingName = controllerName + "-crd-validating-role-binding";
handleClusterRoleBinding(list, serviceAccountName, controllerName, crBindingName, "validate CRDs", AddClusterRolesDecorator.JOSDK_CRD_VALIDATING_CLUSTER_ROLE);
}
}
}
Aggregations