Search in sources :

Example 26 with Binding

use of io.fabric8.kubernetes.api.model.Binding in project quarkus-operator-sdk by quarkiverse.

the class CsvManifestsBuilder method handleClusterPermissions.

private void handleClusterPermissions(List<ClusterRoleBinding> clusterRoleBindings, List<ClusterRole> clusterRoles, List<Role> roles, String defaultServiceAccountName, NamedInstallStrategyFluent.SpecNested<ClusterServiceVersionSpecFluent.InstallNested<ClusterServiceVersionFluent.SpecNested<ClusterServiceVersionBuilder>>> installSpec) {
    for (ClusterRoleBinding binding : clusterRoleBindings) {
        String serviceAccountName = findServiceAccountFromSubjects(binding.getSubjects(), defaultServiceAccountName);
        if (NO_SERVICE_ACCOUNT.equals(serviceAccountName)) {
            LOGGER.warnf("Cluster Role '%s' was not added because the service account is missing", binding.getRoleRef().getName());
            continue;
        }
        handleClusterPermission(findRules(binding.getRoleRef(), clusterRoles, roles), serviceAccountName, installSpec);
    }
}
Also used : ClusterRoleBinding(io.fabric8.kubernetes.api.model.rbac.ClusterRoleBinding)

Example 27 with Binding

use of io.fabric8.kubernetes.api.model.Binding in project yaks by citrusframework.

the class VerifyKameletBindingAction method doExecute.

@Override
public void doExecute(TestContext context) {
    String bindingName = context.replaceDynamicContentInString(name);
    CustomResourceDefinitionContext ctx = CamelKSupport.kameletBindingCRDContext(CamelKSettings.getKameletApiVersion());
    KameletBinding binding = getKubernetesClient().customResources(ctx, KameletBinding.class, KameletBindingList.class).inNamespace(namespace(context)).withName(bindingName).get();
    if (binding == null) {
        throw new ValidationException(String.format("Failed to retrieve KameletBinding '%s' in namespace '%s'", name, namespace(context)));
    }
    LOG.info("KamletBinding validation successful - All values OK!");
    if (LOG.isDebugEnabled()) {
        try {
            LOG.debug(KubernetesSupport.json().writeValueAsString(binding));
        } catch (JsonProcessingException e) {
            LOG.warn("Unable to dump KameletBinding data", e);
        }
    }
}
Also used : CustomResourceDefinitionContext(io.fabric8.kubernetes.client.dsl.base.CustomResourceDefinitionContext) ValidationException(com.consol.citrus.exceptions.ValidationException) KameletBindingList(org.citrusframework.yaks.camelk.model.KameletBindingList) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) KameletBinding(org.citrusframework.yaks.camelk.model.KameletBinding)

Example 28 with Binding

use of io.fabric8.kubernetes.api.model.Binding in project syndesis-qe by syndesisio.

the class OperatorValidationSteps method createPv.

@Given("create test persistent volumes with {string} storage class name")
public void createPv(String className) {
    // Create 3 PVs, two with higher capacity that will be used by meta and prometheus, because the binding of PV is FCFS,
    // so they theoretically can steal the test-pv from db
    // These volumes won't work, but they will be available to bind
    Map<String, Quantity> capacity = new HashMap<>();
    capacity.put("storage", new Quantity("3Gi"));
    if (!"".equals(className) && OpenShiftUtils.getInstance().storage().storageClasses().withName(className).get() == null) {
        log.info("Creating storage class " + className);
        OpenShiftUtils.getInstance().storage().storageClasses().createOrReplaceWithNew().withNewMetadata().withName(className).endMetadata().withProvisioner("kubernetes.io/cinder").done();
    }
    PersistentVolumeFluent.SpecNested<DoneablePersistentVolume> pv = OpenShiftUtils.getInstance().persistentVolumes().createOrReplaceWithNew().withNewMetadata().withName(TEST_PV_NAME).withLabels(TestUtils.map("operator", "test")).endMetadata().withNewSpec().withAccessModes("ReadOnlyMany", "ReadWriteOnce", "ReadWriteMany").withCapacity(capacity).withNewNfs().withNewServer("testServer").withNewPath("/testPath").endNfs();
    // The default storage class for OCP3 is empty, for OCP4 is "standard", so if the className is empty, we should use the default one
    if ("".equals(className)) {
        if (!OpenShiftUtils.isOpenshift3()) {
            if (OpenShiftUtils.isOSD()) {
                pv.withStorageClassName("gp2");
            } else {
                pv.withStorageClassName("standard");
            }
        }
    } else {
        pv.withStorageClassName(className);
    }
    pv.endSpec().done();
    capacity.put("storage", new Quantity("5Gi"));
    for (int i = 1; i < 3; i++) {
        pv = OpenShiftUtils.getInstance().persistentVolumes().createOrReplaceWithNew().withNewMetadata().withName(TEST_PV_NAME + "-" + i).endMetadata().withNewSpec().withAccessModes("ReadWriteOnce").withCapacity(capacity).withNewNfs().withNewServer("testServer").withNewPath("/testPath").endNfs();
        if (!OpenShiftUtils.isOpenshift3()) {
            // This should always be the default value despite the actual value of className - that is used only in "test-pv" intentionally
            if (OpenShiftUtils.isOSD()) {
                pv.withStorageClassName("gp2");
            } else {
                pv.withStorageClassName("standard");
            }
        }
        pv.endSpec().done();
    }
}
Also used : HashMap(java.util.HashMap) Quantity(io.fabric8.kubernetes.api.model.Quantity) DoneablePersistentVolume(io.fabric8.kubernetes.api.model.DoneablePersistentVolume) IntegrationsEndpoint(io.syndesis.qe.endpoint.IntegrationsEndpoint) PersistentVolumeFluent(io.fabric8.kubernetes.api.model.PersistentVolumeFluent) Given(io.cucumber.java.en.Given)

Example 29 with Binding

use of io.fabric8.kubernetes.api.model.Binding in project docker-maven-plugin by fabric8io.

the class VolumeBindingUtilTest method testResolveRelativeVolumePathContainingSlashes.

/**
 * The volume binding string: {@code src/test/docker:/path/to/container/mountpoint} is resolved, because {@code src/
 * test/docker} is considered a <em>relative path</em>.
 */
@Test
public void testResolveRelativeVolumePathContainingSlashes() throws Exception {
    String relativePath = "src" + SEP + "test" + SEP + "docker";
    String volumeString = format(BIND_STRING_FMT, relativePath, CONTAINER_PATH);
    // 'src/test/docker:/path/to/container/dir' to '/absolute/basedir/src/test/docker:/path/to/container/dir'
    String relativizedVolumeString = resolveRelativeVolumeBinding(ABS_BASEDIR, volumeString);
    String expectedBindingString = format(BIND_STRING_FMT, new File(ABS_BASEDIR, relativePath), CONTAINER_PATH);
    assertEquals(expectedBindingString, relativizedVolumeString);
}
Also used : PathTestUtil.createTmpFile(io.fabric8.maven.docker.util.PathTestUtil.createTmpFile) File(java.io.File) Test(org.junit.Test)

Example 30 with Binding

use of io.fabric8.kubernetes.api.model.Binding in project docker-maven-plugin by fabric8io.

the class VolumeBindingUtilTest method testResolveVolumeBindingsWithRunVolumeConfiguration.

/**
 * Insures that relative paths in the host portion of a volume binding string are properly resolved against a base
 * directory when present in a {@link RunVolumeConfiguration}.
 */
@Test
public void testResolveVolumeBindingsWithRunVolumeConfiguration() {
    RunVolumeConfiguration.Builder builder = new RunVolumeConfiguration.Builder();
    builder.bind(singletonList(format(BIND_STRING_FMT, RELATIVE_PATH, CONTAINER_PATH)));
    RunVolumeConfiguration volumeConfiguration = builder.build();
    // './rel:/path/to/container/dir' to '/absolute/basedir/rel:/path/to/container/dir'
    resolveRelativeVolumeBindings(ABS_BASEDIR, volumeConfiguration);
    String expectedBindingString = format(BIND_STRING_FMT, join("", ABS_BASEDIR.getAbsolutePath(), stripLeadingPeriod(RELATIVE_PATH)), CONTAINER_PATH);
    assertEquals(expectedBindingString, volumeConfiguration.getBind().get(0));
}
Also used : RunVolumeConfiguration(io.fabric8.maven.docker.config.RunVolumeConfiguration) Test(org.junit.Test)

Aggregations

IOException (java.io.IOException)11 List (java.util.List)11 Test (org.junit.jupiter.api.Test)11 RoleBinding (io.fabric8.kubernetes.api.model.rbac.RoleBinding)10 HasMetadata (io.fabric8.kubernetes.api.model.HasMetadata)8 ClusterRoleBinding (io.fabric8.kubernetes.api.model.rbac.ClusterRoleBinding)8 Subject (io.fabric8.kubernetes.api.model.rbac.Subject)8 ParallelTest (io.strimzi.test.annotations.ParallelTest)8 Arrays (java.util.Arrays)8 HashMap (java.util.HashMap)8 ServiceBinding (io.dekorate.servicebinding.model.ServiceBinding)7 File (java.io.File)7 Path (java.nio.file.Path)7 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)7 RoleRefBuilder (io.fabric8.kubernetes.api.model.rbac.RoleRefBuilder)6 SubjectBuilder (io.fabric8.kubernetes.api.model.rbac.SubjectBuilder)6 AppArtifact (io.quarkus.bootstrap.model.AppArtifact)6 Version (io.quarkus.builder.Version)6 ProdBuildResults (io.quarkus.test.ProdBuildResults)6 ProdModeTestResults (io.quarkus.test.ProdModeTestResults)6