-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Attila Mészáros <csviri@gmail.com>
- Loading branch information
Showing
9 changed files
with
206 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
src/test/java/io/csviri/operator/glue/GlueLabelSelectorTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package io.csviri.operator.glue; | ||
|
||
|
||
import java.util.Map; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import io.csviri.operator.glue.customresource.glue.Glue; | ||
import io.fabric8.kubernetes.api.model.ConfigMap; | ||
import io.quarkus.test.junit.QuarkusTest; | ||
import io.quarkus.test.junit.QuarkusTestProfile; | ||
import io.quarkus.test.junit.TestProfile; | ||
|
||
import static io.csviri.operator.glue.TestUtils.INITIAL_RECONCILE_WAIT_TIMEOUT; | ||
import static io.csviri.operator.glue.reconciler.glue.GlueReconciler.GLUE_RECONCILER_NAME; | ||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.awaitility.Awaitility.await; | ||
|
||
@QuarkusTest | ||
@TestProfile(GlueLabelSelectorTest.LabelSelectorTestProfile.class) | ||
public class GlueLabelSelectorTest extends TestBase { | ||
|
||
|
||
public static final String LABEL_KEY = "test-glue"; | ||
public static final String LABEL_VALUE = "true"; | ||
|
||
@Test | ||
void testLabelSelectorHandling() { | ||
Glue glue = | ||
TestUtils.loadResoureFlow("/glue/SimpleGlue.yaml"); | ||
glue = create(glue); | ||
|
||
await().pollDelay(INITIAL_RECONCILE_WAIT_TIMEOUT).untilAsserted(() -> { | ||
assertThat(get(ConfigMap.class, "simple-glue-configmap")).isNull(); | ||
}); | ||
|
||
glue.getMetadata().getLabels().put(LABEL_KEY, LABEL_VALUE); | ||
update(glue); | ||
|
||
await().untilAsserted(() -> { | ||
assertThat(get(ConfigMap.class, "simple-glue-configmap")).isNotNull(); | ||
}); | ||
} | ||
|
||
public static class LabelSelectorTestProfile implements QuarkusTestProfile { | ||
|
||
@Override | ||
public Map<String, String> getConfigOverrides() { | ||
return Map.of("quarkus.operator-sdk.controllers." + GLUE_RECONCILER_NAME + ".selector", | ||
LABEL_KEY + "=" + LABEL_VALUE); | ||
} | ||
} | ||
|
||
} |
80 changes: 80 additions & 0 deletions
80
src/test/java/io/csviri/operator/glue/GlueOperatorLabelSelectorTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
package io.csviri.operator.glue; | ||
|
||
import java.util.Map; | ||
|
||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import io.csviri.operator.glue.customresource.TestCustomResource; | ||
import io.csviri.operator.glue.customresource.TestCustomResource2; | ||
import io.csviri.operator.glue.customresource.glue.Glue; | ||
import io.csviri.operator.glue.reconciler.operator.GlueOperatorReconciler; | ||
import io.fabric8.kubernetes.api.model.ConfigMap; | ||
import io.quarkus.test.junit.QuarkusTest; | ||
import io.quarkus.test.junit.QuarkusTestProfile; | ||
import io.quarkus.test.junit.TestProfile; | ||
|
||
import static io.csviri.operator.glue.TestUtils.INITIAL_RECONCILE_WAIT_TIMEOUT; | ||
import static io.csviri.operator.glue.reconciler.glue.GlueReconciler.GLUE_RECONCILER_NAME; | ||
import static io.csviri.operator.glue.reconciler.operator.GlueOperatorReconciler.GLUE_OPERATOR_RECONCILER_NAME; | ||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.awaitility.Awaitility.await; | ||
|
||
@QuarkusTest | ||
@TestProfile(GlueOperatorLabelSelectorTest.GlueOperatorLabelSelectorTestProfile.class) | ||
public class GlueOperatorLabelSelectorTest extends TestBase { | ||
|
||
public static final String GLUE_OPERATOR_LABEL_KEY = "test-glue-operator"; | ||
public static final String GLUE_LABEL_KEY = "test-glue"; | ||
public static final String LABEL_VALUE = "true"; | ||
|
||
@BeforeEach | ||
void applyCRD() { | ||
TestUtils.applyTestCrd(client, TestCustomResource.class, TestCustomResource2.class); | ||
} | ||
|
||
@Test | ||
void testGlueOperatorLabelSelector() { | ||
var go = create(TestUtils | ||
.loadResourceFlowOperator("/glueoperator/SimpleGlueOperator.yaml")); | ||
|
||
var testCR = create(TestData.testCustomResource()); | ||
|
||
await().pollDelay(INITIAL_RECONCILE_WAIT_TIMEOUT).untilAsserted(() -> { | ||
assertThat(get(ConfigMap.class, testCR.getMetadata().getName())).isNull(); | ||
}); | ||
|
||
go.getMetadata().getLabels().put(GLUE_OPERATOR_LABEL_KEY, LABEL_VALUE); | ||
update(go); | ||
|
||
await().untilAsserted(() -> { | ||
assertThat(get(ConfigMap.class, testCR.getMetadata().getName())).isNotNull(); | ||
var glue = get(Glue.class, GlueOperatorReconciler.glueName(testCR.getMetadata().getName(), | ||
testCR.getKind())); | ||
assertThat(glue).isNotNull(); | ||
assertThat(glue.getMetadata().getLabels()).containsEntry(GLUE_LABEL_KEY, LABEL_VALUE); | ||
}); | ||
|
||
// explicit cleanup, so there are no exception in the logs because of namespace marked for | ||
// deletion | ||
delete(testCR); | ||
await().untilAsserted(() -> { | ||
var glue = get(Glue.class, GlueOperatorReconciler.glueName(testCR.getMetadata().getName(), | ||
testCR.getKind())); | ||
assertThat(glue).isNull(); | ||
}); | ||
delete(go); | ||
} | ||
|
||
public static class GlueOperatorLabelSelectorTestProfile implements QuarkusTestProfile { | ||
|
||
@Override | ||
public Map<String, String> getConfigOverrides() { | ||
return Map.of("quarkus.operator-sdk.controllers." + GLUE_RECONCILER_NAME + ".selector", | ||
GLUE_LABEL_KEY + "=" + LABEL_VALUE, | ||
"quarkus.operator-sdk.controllers." + GLUE_OPERATOR_RECONCILER_NAME + ".selector", | ||
GLUE_OPERATOR_LABEL_KEY + "=" + LABEL_VALUE); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package io.csviri.operator.glue; | ||
|
||
import io.csviri.operator.glue.customresource.TestCustomResource; | ||
import io.csviri.operator.glue.customresource.TestCustomResource2; | ||
import io.csviri.operator.glue.customresource.TestCustomResourceSpec; | ||
import io.fabric8.kubernetes.api.model.ObjectMetaBuilder; | ||
|
||
public class TestData { | ||
|
||
public static final String TEST_RESOURCE_VALUE = "val"; | ||
public static final String TEST_RESOURCE_PREFIX = "testcr"; | ||
public static final String TEST_RESOURCE2_PREFIX = "testcr2"; | ||
|
||
public static TestCustomResource testCustomResource() { | ||
return testCustomResource(1); | ||
} | ||
|
||
public static TestCustomResource testCustomResource(int index) { | ||
var res = new TestCustomResource(); | ||
res.setMetadata(new ObjectMetaBuilder() | ||
.withName(TEST_RESOURCE_PREFIX + index) | ||
.build()); | ||
res.setSpec(new TestCustomResourceSpec()); | ||
res.getSpec().setValue(TEST_RESOURCE_VALUE + index); | ||
return res; | ||
} | ||
|
||
public static TestCustomResource2 testCustomResource2(int index) { | ||
var res = new TestCustomResource2(); | ||
res.setMetadata(new ObjectMetaBuilder() | ||
.withName(TEST_RESOURCE2_PREFIX + index) | ||
.build()); | ||
res.setSpec(new TestCustomResourceSpec()); | ||
res.getSpec().setValue(TEST_RESOURCE_VALUE + index); | ||
return res; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
quarkus.log.category."io.csviri.operator.glue".level=DEBUG | ||
quarkus.kubernetes-client.devservices.flavor=kind | ||
quarkus.kubernetes-client.devservices.flavor=kind | ||
#quarkus.operator-sdk.controllers.glue.selector=testglue=true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# Invalid GLUE, presents resources with non-unique name | ||
apiVersion: io.csviri.operator.glue/v1beta1 | ||
kind: Glue | ||
metadata: | ||
name: simple-glue | ||
spec: | ||
childResources: | ||
- name: configMap | ||
resource: | ||
apiVersion: v1 | ||
kind: ConfigMap | ||
metadata: | ||
name: simple-glue-configmap | ||
data: | ||
key: "value1" |
File renamed without changes.