Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
Signed-off-by: Attila Mészáros <csviri@gmail.com>
  • Loading branch information
csviri committed May 3, 2024
1 parent e580b7c commit 3b86da9
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ public class Parent {

private String apiVersion;
private String kind;
private boolean clusterScoped = false;
private String labelSelector;


public Parent() {}

public Parent(String apiVersion, String kind) {
Expand Down Expand Up @@ -41,19 +43,27 @@ public void setLabelSelector(String labelSelector) {
this.labelSelector = labelSelector;
}

public boolean isClusterScoped() {
return clusterScoped;
}

public void setClusterScoped(boolean clusterScoped) {
this.clusterScoped = clusterScoped;
}

@Override
public boolean equals(Object o) {
if (this == o)
return true;
if (o == null || getClass() != o.getClass())
return false;
Parent parent = (Parent) o;
return Objects.equals(apiVersion, parent.apiVersion) && Objects.equals(kind, parent.kind)
&& Objects.equals(labelSelector, parent.labelSelector);
return clusterScoped == parent.clusterScoped && Objects.equals(apiVersion, parent.apiVersion)
&& Objects.equals(kind, parent.kind) && Objects.equals(labelSelector, parent.labelSelector);
}

@Override
public int hashCode() {
return Objects.hash(apiVersion, kind, labelSelector);
return Objects.hash(apiVersion, kind, clusterScoped, labelSelector);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,9 @@ private Glue createGlue(GenericKubernetesResource targetParentResource,
parentRelatedSpec.setKind(parent.getKind());
parentRelatedSpec.setResourceNames(List.of(targetParentResource.getMetadata().getName()));
parentRelatedSpec.setNamespace(targetParentResource.getMetadata().getNamespace());
parentRelatedSpec.setClusterScoped(glueOperator.getSpec().getParent().isClusterScoped());

glue.getSpec().getRelatedResources().add(parentRelatedSpec);

glue.addOwnerReference(targetParentResource);
return glue;
}
Expand Down
18 changes: 13 additions & 5 deletions src/test/java/io/csviri/operator/glue/GlueOperatorTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import java.util.stream.IntStream;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;

import io.csviri.operator.glue.customresource.TestCustomResource;
Expand Down Expand Up @@ -191,8 +190,6 @@ void parentWithLabelSelector() {
});
}


@Disabled
@Test
void secretCopySample() {
var secret = TestUtils.load("/sample/secretcopy/secret-to-copy.yaml", Secret.class);
Expand All @@ -205,12 +202,23 @@ void secretCopySample() {
var namespaces = client.namespaces().list().getItems();
namespaces.forEach(ns -> {
var copiedSecret =
client.secrets().inNamespace(ns.getMetadata().getName()).withName("copied-secret");
client.secrets().inNamespace(ns.getMetadata().getName()).withName("copied-secret")
.get();
assertThat(copiedSecret).isNotNull();
assertThat(copiedSecret.getData().get("shared-password"))
.isEqualTo(secret.getData().get("password"));
});
});


delete(go);
await().untilAsserted(() -> {
var namespaces = client.namespaces().list().getItems();
namespaces.forEach(ns -> {
var copiedSecret =
client.secrets().inNamespace(ns.getMetadata().getName()).withName("copied-secret");
assertThat(copiedSecret).isNull();
});
});
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ spec:
kind: Namespace
glueMetadata:
name: copied-secret-glue
namespace: {parent.metadata.name}
namespace: "{parent.metadata.name}"
childResources:
- name: secret
resource:
Expand All @@ -23,4 +23,5 @@ spec:
- name: sharedsecret
apiVersion: v1
kind: Secret
namespace: default
resourceNames: [ "secret-to-copy" ]

0 comments on commit 3b86da9

Please sign in to comment.