use of io.fabric8.agent.model.Feature in project che-server by eclipse-che.
the class KubernetesNamespace method annotate.
/**
* Applies given `ensureAnnotations` into given `namespace` and update the `namespace` in the
* Kubernetes.
*
* <p>If we do not have permissions to do so (code=403), this method does not throw any exception.
*
* @param namespace namespace to annotate
* @param ensureAnnotations these annotations should be applied on given `namespace`
* @throws InfrastructureException if something goes wrong with update, except lack of permissions
*/
protected void annotate(Namespace namespace, Map<String, String> ensureAnnotations) throws InfrastructureException {
if (ensureAnnotations.isEmpty()) {
return;
}
Map<String, String> currentAnnotations = namespace.getMetadata().getAnnotations();
Map<String, String> newAnnotations = currentAnnotations != null ? new HashMap<>(currentAnnotations) : new HashMap<>();
if (newAnnotations.entrySet().containsAll(ensureAnnotations.entrySet())) {
LOG.debug("Nothing to do, namespace [{}] already has all required annotations.", namespace.getMetadata().getName());
return;
}
try {
// update the namespace with new annotations
cheSAClientFactory.create().namespaces().createOrReplace(new NamespaceBuilder(namespace).editMetadata().addToAnnotations(ensureAnnotations).endMetadata().build());
} catch (KubernetesClientException kce) {
if (kce.getCode() == 403) {
LOG.warn("Can't annotate the namespace due to lack of permissions. Grant cluster-wide permissions " + "to `get` and `update` the `namespaces` to the `che` service account " + "(Che operator might have already prepared a cluster role called " + "`che-namespace-editor` for this, depending on its configuration). " + "Alternatively, consider disabling the feature by setting " + "`che.infra.kubernetes.namepsace.annotate` to `false`.");
return;
}
throw new InfrastructureException(kce);
}
}
use of io.fabric8.agent.model.Feature in project intellij-tekton by redhat-developer.
the class TknCli method updateTektonInfos.
private void updateTektonInfos() {
try {
ConfigMap pipelineInfoMap = getConfigMap("tekton-pipelines", "pipelines-info");
tektonVersion = pipelineInfoMap.getData().get("version");
ConfigMap alphaMap = getConfigMap("tekton-pipelines", "feature-flags");
hasAlphaFeaturesEnabled = alphaMap.getData().get("enable-api-fields").equalsIgnoreCase("alpha");
initConfigMapWatchers();
} catch (Exception e) {
LOGGER.warn(e.getLocalizedMessage(), e);
}
}
use of io.fabric8.agent.model.Feature in project strimzi by strimzi.
the class KafkaAssemblyOperatorRbacScopeTest method testRolesDeployedWhenNamespaceRbacScope.
/**
* This test checks that when STRIMZI_RBAC_SCOPE feature is set to 'NAMESPACE', the cluster operator only
* deploys and binds to Roles
*/
@Test
public void testRolesDeployedWhenNamespaceRbacScope(VertxTestContext context) {
Kafka kafka = new KafkaBuilder().withNewMetadata().withName(clusterName).withNamespace(namespace).endMetadata().withNewSpec().withNewKafka().withReplicas(3).endKafka().withNewZookeeper().withReplicas(3).endZookeeper().withNewEntityOperator().withNewUserOperator().endUserOperator().withNewTopicOperator().endTopicOperator().endEntityOperator().endSpec().build();
ResourceOperatorSupplier supplier = ResourceUtils.supplierWithMocks(false);
// Mock the CRD Operator for Kafka resources
CrdOperator mockKafkaOps = supplier.kafkaOperator;
when(mockKafkaOps.getAsync(eq(namespace), eq(clusterName))).thenReturn(Future.succeededFuture(kafka));
when(mockKafkaOps.get(eq(namespace), eq(clusterName))).thenReturn(kafka);
when(mockKafkaOps.updateStatusAsync(any(), any(Kafka.class))).thenReturn(Future.succeededFuture());
// Mock the operations for RoleBindings
RoleBindingOperator mockRoleBindingOps = supplier.roleBindingOperations;
// Capture the names of reconciled rolebindings and their patched state
ArgumentCaptor<String> roleBindingNameCaptor = ArgumentCaptor.forClass(String.class);
ArgumentCaptor<RoleBinding> roleBindingCaptor = ArgumentCaptor.forClass(RoleBinding.class);
when(mockRoleBindingOps.reconcile(any(), eq(namespace), roleBindingNameCaptor.capture(), roleBindingCaptor.capture())).thenReturn(Future.succeededFuture());
KafkaAssemblyOperatorRolesSubset kao = new KafkaAssemblyOperatorRolesSubset(vertx, new PlatformFeaturesAvailability(false, kubernetesVersion), certManager, passwordGenerator, supplier, configNamespaceRbacScope);
Checkpoint async = context.checkpoint();
kao.reconcile(new Reconciliation("test-trigger", Kafka.RESOURCE_KIND, namespace, clusterName)).onComplete(context.succeeding(v -> context.verify(() -> {
List<String> roleBindingNames = roleBindingNameCaptor.getAllValues();
List<RoleBinding> roleBindings = roleBindingCaptor.getAllValues();
assertThat(roleBindingNames, hasSize(2));
assertThat(roleBindings, hasSize(2));
// Check all RoleBindings, easier to index by order applied
assertThat(roleBindingNames.get(0), is("test-instance-entity-topic-operator-role"));
assertThat(roleBindings.get(0), hasRoleRef(new RoleRefBuilder().withApiGroup("rbac.authorization.k8s.io").withKind("Role").withName("test-instance-entity-operator").build()));
assertThat(roleBindingNames.get(1), is("test-instance-entity-user-operator-role"));
assertThat(roleBindings.get(1), hasRoleRef(new RoleRefBuilder().withApiGroup("rbac.authorization.k8s.io").withKind("Role").withName("test-instance-entity-operator").build()));
verify(supplier.clusterRoleBindingOperator, never()).reconcile(any(), anyString(), any());
async.flag();
})));
}
use of io.fabric8.agent.model.Feature in project strimzi by strimzi.
the class KafkaAssemblyOperatorRbacScopeTest method testRolesDeployedWhenNamespaceRbacScopeAndMultiWatchNamespace.
/**
* This test checks that when STRIMZI_RBAC_SCOPE feature is set to 'NAMESPACE', the cluster operator
* binds to ClusterRoles when it can't use Roles due to cross namespace permissions
*/
@Test
public void testRolesDeployedWhenNamespaceRbacScopeAndMultiWatchNamespace(VertxTestContext context) {
Kafka kafka = new KafkaBuilder().withNewMetadata().withName(clusterName).withNamespace(namespace).endMetadata().withNewSpec().withNewKafka().withReplicas(3).endKafka().withNewZookeeper().withReplicas(3).endZookeeper().withNewEntityOperator().withNewUserOperator().withWatchedNamespace("other-ns").endUserOperator().withNewTopicOperator().withWatchedNamespace("another-ns").endTopicOperator().endEntityOperator().endSpec().build();
ResourceOperatorSupplier supplier = ResourceUtils.supplierWithMocks(false);
// Mock the CRD Operator for Kafka resources
CrdOperator mockKafkaOps = supplier.kafkaOperator;
when(mockKafkaOps.getAsync(eq(namespace), eq(clusterName))).thenReturn(Future.succeededFuture(kafka));
when(mockKafkaOps.get(eq(namespace), eq(clusterName))).thenReturn(kafka);
when(mockKafkaOps.updateStatusAsync(any(), any(Kafka.class))).thenReturn(Future.succeededFuture());
// Mock the operations for Roles
RoleOperator mockRoleOps = supplier.roleOperations;
// Capture the names of reconciled Roles and their patched state
ArgumentCaptor<String> roleNameCaptor = ArgumentCaptor.forClass(String.class);
ArgumentCaptor<Role> roleCaptor = ArgumentCaptor.forClass(Role.class);
when(mockRoleOps.reconcile(any(), anyString(), roleNameCaptor.capture(), roleCaptor.capture())).thenReturn(Future.succeededFuture());
// Mock the operations for RoleBindings
RoleBindingOperator mockRoleBindingOps = supplier.roleBindingOperations;
// Capture the names of reconciled RoleBindings and their patched state
ArgumentCaptor<String> roleBindingNameCaptor = ArgumentCaptor.forClass(String.class);
ArgumentCaptor<RoleBinding> roleBindingCaptor = ArgumentCaptor.forClass(RoleBinding.class);
when(mockRoleBindingOps.reconcile(any(), anyString(), roleBindingNameCaptor.capture(), roleBindingCaptor.capture())).thenReturn(Future.succeededFuture());
KafkaAssemblyOperatorRolesSubset kao = new KafkaAssemblyOperatorRolesSubset(vertx, new PlatformFeaturesAvailability(false, kubernetesVersion), certManager, passwordGenerator, supplier, configNamespaceRbacScope);
Checkpoint async = context.checkpoint();
kao.reconcile(new Reconciliation("test-trigger", Kafka.RESOURCE_KIND, namespace, clusterName)).onComplete(context.succeeding(v -> context.verify(() -> {
List<String> roleBindingNames = roleBindingNameCaptor.getAllValues();
List<RoleBinding> roleBindings = roleBindingCaptor.getAllValues();
assertThat(roleBindingNames, hasSize(4));
assertThat(roleBindings, hasSize(4));
// Check all RoleBindings, easier to index by order applied
assertThat(roleBindingNames.get(0), is("test-instance-entity-topic-operator-role"));
assertThat(roleBindings.get(0).getMetadata().getNamespace(), is("another-ns"));
assertThat(roleBindings.get(0), hasRoleRef(new RoleRefBuilder().withApiGroup("rbac.authorization.k8s.io").withKind("Role").withName(EntityOperator.getRoleName(clusterName)).build()));
assertThat(roleBindingNames.get(1), is("test-instance-entity-topic-operator-role"));
assertThat(roleBindings.get(1).getMetadata().getNamespace(), is("test-ns"));
assertThat(roleBindings.get(1), hasRoleRef(new RoleRefBuilder().withApiGroup("rbac.authorization.k8s.io").withKind("Role").withName(EntityOperator.getRoleName(clusterName)).build()));
assertThat(roleBindingNames.get(2), is("test-instance-entity-user-operator-role"));
assertThat(roleBindings.get(2).getMetadata().getNamespace(), is("other-ns"));
assertThat(roleBindings.get(2), hasRoleRef(new RoleRefBuilder().withApiGroup("rbac.authorization.k8s.io").withKind("Role").withName(EntityOperator.getRoleName(clusterName)).build()));
assertThat(roleBindingNames.get(3), is("test-instance-entity-user-operator-role"));
assertThat(roleBindings.get(3).getMetadata().getNamespace(), is("test-ns"));
assertThat(roleBindings.get(3), hasRoleRef(new RoleRefBuilder().withApiGroup("rbac.authorization.k8s.io").withKind("Role").withName(EntityOperator.getRoleName(clusterName)).build()));
List<String> roleNames = roleNameCaptor.getAllValues();
List<Role> roles = roleCaptor.getAllValues();
assertThat(roleNames, hasSize(3));
assertThat(roles, hasSize(3));
// Check all Roles, easier to index by order applied
assertThat(roleNames.get(0), is("test-instance-entity-operator"));
assertThat(roles.get(0).getMetadata().getNamespace(), is("test-ns"));
assertThat(roleNames.get(1), is("test-instance-entity-operator"));
assertThat(roles.get(1).getMetadata().getNamespace(), is("other-ns"));
assertThat(roleNames.get(2), is("test-instance-entity-operator"));
assertThat(roles.get(2).getMetadata().getNamespace(), is("another-ns"));
async.flag();
})));
}
use of io.fabric8.agent.model.Feature in project strimzi by strimzi.
the class KafkaAssemblyOperatorRbacScopeTest method testRolesDeployedWhenClusterRbacScope.
/**
* This test checks that when STRIMZI_RBAC_SCOPE feature is set to 'CLUSTER', the cluster operator
* binds to ClusterRoles
*/
@Test
public void testRolesDeployedWhenClusterRbacScope(VertxTestContext context) {
Kafka kafka = new KafkaBuilder().withNewMetadata().withName(clusterName).withNamespace(namespace).endMetadata().withNewSpec().withNewKafka().withReplicas(3).endKafka().withNewZookeeper().withReplicas(3).endZookeeper().withNewEntityOperator().withNewUserOperator().endUserOperator().withNewTopicOperator().endTopicOperator().endEntityOperator().endSpec().build();
ResourceOperatorSupplier supplier = ResourceUtils.supplierWithMocks(false);
// Mock the CRD Operator for Kafka resources
CrdOperator mockKafkaOps = supplier.kafkaOperator;
when(mockKafkaOps.getAsync(eq(namespace), eq(clusterName))).thenReturn(Future.succeededFuture(kafka));
when(mockKafkaOps.get(eq(namespace), eq(clusterName))).thenReturn(kafka);
when(mockKafkaOps.updateStatusAsync(any(), any(Kafka.class))).thenReturn(Future.succeededFuture());
// Mock the operations for RoleBindings
RoleBindingOperator mockRoleBindingOps = supplier.roleBindingOperations;
// Capture the names of reconciled rolebindings and their patched state
ArgumentCaptor<String> roleBindingNameCaptor = ArgumentCaptor.forClass(String.class);
ArgumentCaptor<RoleBinding> roleBindingCaptor = ArgumentCaptor.forClass(RoleBinding.class);
when(mockRoleBindingOps.reconcile(any(), eq(namespace), roleBindingNameCaptor.capture(), roleBindingCaptor.capture())).thenReturn(Future.succeededFuture());
KafkaAssemblyOperatorRolesSubset kao = new KafkaAssemblyOperatorRolesSubset(vertx, new PlatformFeaturesAvailability(false, kubernetesVersion), certManager, passwordGenerator, supplier, config);
Checkpoint async = context.checkpoint();
kao.reconcile(new Reconciliation("test-trigger", Kafka.RESOURCE_KIND, namespace, clusterName)).onComplete(context.succeeding(v -> context.verify(() -> {
List<String> roleBindingNames = roleBindingNameCaptor.getAllValues();
List<RoleBinding> roleBindings = roleBindingCaptor.getAllValues();
assertThat(roleBindingNames, hasSize(2));
assertThat(roleBindings, hasSize(2));
// Check all RoleBindings, easier to index by order applied
assertThat(roleBindingNames.get(0), is("test-instance-entity-topic-operator-role"));
assertThat(roleBindings.get(0), hasRoleRef(new RoleRefBuilder().withApiGroup("rbac.authorization.k8s.io").withKind("Role").withName("test-instance-entity-operator").build()));
assertThat(roleBindingNames.get(1), is("test-instance-entity-user-operator-role"));
assertThat(roleBindings.get(1), hasRoleRef(new RoleRefBuilder().withApiGroup("rbac.authorization.k8s.io").withKind("Role").withName("test-instance-entity-operator").build()));
async.flag();
})));
}
Aggregations