Search in sources :

Example 11 with BackupConfigReview

use of io.stackgres.operator.common.BackupConfigReview in project stackgres by ongres.

the class BackupConfigSourceValidatorTest method givenNonExistentSecretAccountSecretForAzureBlobStorageCredentialsOnCreation_shouldFail.

@Test
void givenNonExistentSecretAccountSecretForAzureBlobStorageCredentialsOnCreation_shouldFail() throws ValidationFailed {
    final BackupConfigReview review = getEmptyReview();
    String namespace = review.getRequest().getObject().getMetadata().getNamespace();
    String accountName = "secret1";
    String accountKey = "key1";
    String accessKeyName = "secret2";
    String accessKeyKey = "key2";
    setAzureBlobCredentials(review, accountName, accountKey, accessKeyName, accessKeyKey);
    when(secretFinder.findByNameAndNamespace(accountName, namespace)).thenReturn(Optional.of(new SecretBuilder(secret).withData(ImmutableMap.of(accountKey, ResourceUtil.encodeSecret("account"))).build()));
    ValidationFailed ex = ValidationUtils.assertErrorType(ErrorType.INVALID_SECRET, () -> validator.validate(review));
    assertEquals("Invalid backup configuration, secret " + accessKeyName + " for accessKey of azureblob credentials not found", ex.getResult().getMessage());
    verify(secretFinder).findByNameAndNamespace(eq(accountName), eq(namespace));
}
Also used : SecretBuilder(io.fabric8.kubernetes.api.model.SecretBuilder) ValidationFailed(io.stackgres.operatorframework.admissionwebhook.validating.ValidationFailed) BackupConfigReview(io.stackgres.operator.common.BackupConfigReview) Test(org.junit.jupiter.api.Test)

Example 12 with BackupConfigReview

use of io.stackgres.operator.common.BackupConfigReview in project stackgres by ongres.

the class BackupConfigSourceValidatorTest method givenExistentSecretsAndKeysForGcsStorageCredentialsOnCreation_shouldNotFail.

@Test
void givenExistentSecretsAndKeysForGcsStorageCredentialsOnCreation_shouldNotFail() throws ValidationFailed {
    final BackupConfigReview review = getEmptyReview();
    String namespace = review.getRequest().getObject().getMetadata().getNamespace();
    String serviceAccountJsonKeyName = "secret1";
    String serviceAccountJsonKeyKey = "key1";
    setGcsCredentials(review, serviceAccountJsonKeyName, serviceAccountJsonKeyKey);
    when(secretFinder.findByNameAndNamespace(serviceAccountJsonKeyName, namespace)).thenReturn(Optional.of(new SecretBuilder(secret).withData(ImmutableMap.of(serviceAccountJsonKeyKey, ResourceUtil.encodeSecret("serviceAccountJsonKey"))).build()));
    validator.validate(review);
    verify(secretFinder).findByNameAndNamespace(eq(serviceAccountJsonKeyName), eq(namespace));
}
Also used : SecretBuilder(io.fabric8.kubernetes.api.model.SecretBuilder) BackupConfigReview(io.stackgres.operator.common.BackupConfigReview) Test(org.junit.jupiter.api.Test)

Example 13 with BackupConfigReview

use of io.stackgres.operator.common.BackupConfigReview in project stackgres by ongres.

the class BackupConfigDefaultValuesMutatorTest method givenConfWithAllDefaultsValuesSettledButNotDefaultStorage_shouldNotReturnAnyPatch.

@Test
public void givenConfWithAllDefaultsValuesSettledButNotDefaultStorage_shouldNotReturnAnyPatch() {
    BackupConfigReview review = getDefaultReview();
    review.getRequest().getObject().getSpec().getStorage().setType("s3");
    AwsS3Storage s3 = new AwsS3Storage();
    s3.setBucket(review.getRequest().getObject().getSpec().getStorage().getS3Compatible().getBucket());
    s3.setPath(review.getRequest().getObject().getSpec().getStorage().getS3Compatible().getPath());
    s3.setRegion(review.getRequest().getObject().getSpec().getStorage().getS3Compatible().getRegion());
    s3.setStorageClass(review.getRequest().getObject().getSpec().getStorage().getS3Compatible().getStorageClass());
    s3.setAwsCredentials(review.getRequest().getObject().getSpec().getStorage().getS3Compatible().getAwsCredentials());
    review.getRequest().getObject().getSpec().getStorage().setS3(s3);
    review.getRequest().getObject().getSpec().getStorage().setS3Compatible(null);
    List<JsonPatchOperation> operators = mutator.mutate(review);
    assertEquals(0, operators.size());
}
Also used : AwsS3Storage(io.stackgres.common.crd.storages.AwsS3Storage) BackupConfigReview(io.stackgres.operator.common.BackupConfigReview) JsonPatchOperation(com.github.fge.jsonpatch.JsonPatchOperation) DefaultValuesMutatorTest(io.stackgres.operator.mutation.DefaultValuesMutatorTest) Test(org.junit.jupiter.api.Test)

Example 14 with BackupConfigReview

use of io.stackgres.operator.common.BackupConfigReview in project stackgres by ongres.

the class BackupConfigDefaultValuesMutatorTest method getEmptyReview.

@Override
protected BackupConfigReview getEmptyReview() {
    BackupConfigReview backupConfigReview = JsonUtil.readFromJson("backupconfig_allow_request/create.json", BackupConfigReview.class);
    backupConfigReview.getRequest().getObject().setSpec(new StackGresBackupConfigSpec());
    return backupConfigReview;
}
Also used : StackGresBackupConfigSpec(io.stackgres.common.crd.sgbackupconfig.StackGresBackupConfigSpec) BackupConfigReview(io.stackgres.operator.common.BackupConfigReview)

Example 15 with BackupConfigReview

use of io.stackgres.operator.common.BackupConfigReview in project stackgres by ongres.

the class StorageValidatorTest method givenCreationWithoutVolumeProperties_shouldFail.

@Test
void givenCreationWithoutVolumeProperties_shouldFail() {
    BackupConfigReview review = JsonUtil.readFromJson("backupconfig_allow_request/invalid_creation_no_s3.json", BackupConfigReview.class);
    ValidationFailed ex = assertThrows(ValidationFailed.class, () -> {
        validator.validate(review);
    });
    String errorMessage = ex.getResult().getMessage();
    assertEquals("Invalid backup configuration," + " source s3 must be set when source type is s3", errorMessage);
}
Also used : ValidationFailed(io.stackgres.operatorframework.admissionwebhook.validating.ValidationFailed) BackupConfigReview(io.stackgres.operator.common.BackupConfigReview) Test(org.junit.jupiter.api.Test)

Aggregations

BackupConfigReview (io.stackgres.operator.common.BackupConfigReview)31 Test (org.junit.jupiter.api.Test)25 ValidationFailed (io.stackgres.operatorframework.admissionwebhook.validating.ValidationFailed)17 SecretBuilder (io.fabric8.kubernetes.api.model.SecretBuilder)14 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)6 ConstraintValidationTest (io.stackgres.operator.validation.ConstraintValidationTest)4 JsonPatchOperation (com.github.fge.jsonpatch.JsonPatchOperation)1 StackGresBackupConfigSpec (io.stackgres.common.crd.sgbackupconfig.StackGresBackupConfigSpec)1 AwsS3Storage (io.stackgres.common.crd.storages.AwsS3Storage)1 BackupStorage (io.stackgres.common.crd.storages.BackupStorage)1 DefaultValuesMutatorTest (io.stackgres.operator.mutation.DefaultValuesMutatorTest)1 Random (java.util.Random)1 EnumSource (org.junit.jupiter.params.provider.EnumSource)1 ValueSource (org.junit.jupiter.params.provider.ValueSource)1