Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

reproduce ssa issue with persistentVolumeClaimRetentionPolicy #2037

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ private static void fillResultsAndTraverseFurther(Map<String, Object> result,
Object managedFieldValue) {
var emptyMapValue = new HashMap<String, Object>();
result.put(keyInActual, emptyMapValue);
var actualMapValue = actualMap.get(keyInActual);
var actualMapValue = actualMap.getOrDefault(keyInActual, Map.of());
log.debug("key: {} actual map value: {} managedFieldValue: {}", keyInActual,
actualMapValue, managedFieldValue);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package io.javaoperatorsdk.operator;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

import io.fabric8.kubernetes.api.model.ObjectMetaBuilder;
import io.fabric8.kubernetes.api.model.apps.StatefulSet;
import io.javaoperatorsdk.operator.junit.LocallyRunOperatorExtension;
import io.javaoperatorsdk.operator.sample.ssastatefulsetmatcherissue.SSAStatefulSetMatcherIssueCustomResource;
import io.javaoperatorsdk.operator.sample.ssastatefulsetmatcherissue.SSAStatefulSetMatcherIssueReconciler;

import static org.assertj.core.api.Assertions.assertThat;
import static org.awaitility.Awaitility.await;

public class SSAStatefulSetMatcherIssueIT {

public static final String TEST_1 = "test1";
@RegisterExtension
LocallyRunOperatorExtension extension =
LocallyRunOperatorExtension.builder()
.withReconciler(new SSAStatefulSetMatcherIssueReconciler())
.build();

@Test
void testSSAMatcher() {
extension.create(testResource());


await().untilAsserted(() -> {
var statefulSet = extension.get(StatefulSet.class, TEST_1);
assertThat(statefulSet).isNotNull();
});

System.out.println("ok");
}

SSAStatefulSetMatcherIssueCustomResource testResource() {
var res = new SSAStatefulSetMatcherIssueCustomResource();
res.setMetadata(new ObjectMetaBuilder()
.withName(TEST_1)
.build());
return res;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package io.javaoperatorsdk.operator.sample.ssastatefulsetmatcherissue;

import io.fabric8.kubernetes.api.model.Namespaced;
import io.fabric8.kubernetes.client.CustomResource;
import io.fabric8.kubernetes.model.annotation.Group;
import io.fabric8.kubernetes.model.annotation.Version;

@Group("sample.javaoperatorsdk")
@Version("v1")
public class SSAStatefulSetMatcherIssueCustomResource
extends CustomResource<Void, Void>
implements Namespaced {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package io.javaoperatorsdk.operator.sample.ssastatefulsetmatcherissue;

import io.javaoperatorsdk.operator.api.reconciler.Context;
import io.javaoperatorsdk.operator.api.reconciler.ControllerConfiguration;
import io.javaoperatorsdk.operator.api.reconciler.Reconciler;
import io.javaoperatorsdk.operator.api.reconciler.UpdateControl;
import io.javaoperatorsdk.operator.api.reconciler.dependent.Dependent;

@ControllerConfiguration(dependents = {@Dependent(type = StatefulSetDependentResource.class)})
public class SSAStatefulSetMatcherIssueReconciler
implements Reconciler<SSAStatefulSetMatcherIssueCustomResource> {

@Override
public UpdateControl<SSAStatefulSetMatcherIssueCustomResource> reconcile(
SSAStatefulSetMatcherIssueCustomResource resource,
Context<SSAStatefulSetMatcherIssueCustomResource> context) throws Exception {
return UpdateControl.noUpdate();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package io.javaoperatorsdk.operator.sample.ssastatefulsetmatcherissue;

import io.fabric8.kubernetes.api.model.ObjectMetaBuilder;
import io.fabric8.kubernetes.api.model.apps.StatefulSet;
import io.javaoperatorsdk.operator.ReconcilerUtils;
import io.javaoperatorsdk.operator.api.reconciler.Context;
import io.javaoperatorsdk.operator.processing.dependent.kubernetes.CRUDKubernetesDependentResource;

public class StatefulSetDependentResource
extends CRUDKubernetesDependentResource<StatefulSet, SSAStatefulSetMatcherIssueCustomResource> {

public StatefulSetDependentResource() {

super(StatefulSet.class);
}

@Override
protected StatefulSet desired(SSAStatefulSetMatcherIssueCustomResource primary,
Context<SSAStatefulSetMatcherIssueCustomResource> context) {
var template =
ReconcilerUtils.loadYaml(StatefulSet.class, getClass(), "statefulset_fixed_full.yaml");
template.setMetadata(new ObjectMetaBuilder()
.withName(primary.getMetadata().getName())
.withNamespace(primary.getMetadata().getNamespace())
.build());
return template;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: web
spec:
persistentVolumeClaimRetentionPolicy:
whenDeleted: "Retain"
whenScaled: "Delete"
selector:
matchLabels:
app: nginx # has to match .spec.template.metadata.labels
serviceName: "nginx"
replicas: 1
minReadySeconds: 10 # by default is 0
template:
metadata:
labels:
app: nginx # has to match .spec.selector.matchLabels
spec:
terminationGracePeriodSeconds: 10
containers:
- name: nginx
image: registry.k8s.io/nginx-slim:0.8
ports:
- containerPort: 80
name: web
volumeMounts:
- name: www
mountPath: /usr/share/nginx/html
volumeClaimTemplates:
- metadata:
name: www
spec:
accessModes: [ "ReadWriteOnce" ]
storageClassName: "my-storage-class"
resources:
requests:
storage: 1Gi
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: web
spec:
selector:
matchLabels:
app: nginx # has to match .spec.template.metadata.labels
serviceName: "nginx"
replicas: 1
minReadySeconds: 10 # by default is 0
template:
metadata:
labels:
app: nginx # has to match .spec.selector.matchLabels
spec:
terminationGracePeriodSeconds: 10
containers:
- name: nginx
image: registry.k8s.io/nginx-slim:0.8
ports:
- containerPort: 80
name: web
volumeMounts:
- name: www
mountPath: /usr/share/nginx/html
volumeClaimTemplates:
- metadata:
name: www
spec:
accessModes: [ "ReadWriteOnce" ]
storageClassName: "my-storage-class"
volumeMode: Filesystem
resources:
requests:
storage: 1Gi
status:
phase: pending