Skip to content
Merged
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 @@ -231,6 +231,7 @@ protected void sanitizeState(R actual, R desired, Map<String, Object> actualMap)
}
}

@SuppressWarnings("unchecked")
private static void sanitizeVolumeClaimTemplates(
Map<String, Object> actualMap, StatefulSetSpec actualSpec, StatefulSetSpec desiredSpec) {
int claims = desiredSpec.getVolumeClaimTemplates().size();
Expand All @@ -251,6 +252,18 @@ private static void sanitizeVolumeClaimTemplates(
.map(Map.class::cast)
.ifPresent(m -> m.remove("status"));
}
var desiredResources = claim.getSpec().getResources();
var actualResources = actualSpec.getVolumeClaimTemplates().get(i).getSpec().getResources();
if (desiredResources != null && actualResources != null) {
Optional.ofNullable(
GenericKubernetesResource.get(
actualMap, "spec", "volumeClaimTemplates", i, "spec", "resources", "requests"))
.map(Map.class::cast)
.ifPresent(
m ->
QuantitySanitizer.sanitizeQuantities(
m, actualResources.getRequests(), desiredResources.getRequests()));
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,8 @@ void withFinalizer() {
strings = {
"sample-sts-volumeclaimtemplates-desired.yaml",
"sample-sts-volumeclaimtemplates-desired-with-status.yaml",
"sample-sts-volumeclaimtemplates-desired-with-volumemode.yaml"
"sample-sts-volumeclaimtemplates-desired-with-volumemode.yaml",
"sample-sts-volumeclaimtemplates-desired-with-equivalent-storage.yaml"
})
void testSanitizeState_statefulSetWithVolumeClaims(String desiredResourceFileName) {
var desiredStatefulSet = loadResource(desiredResourceFileName, StatefulSet.class);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#
# Copyright Java Operator SDK Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

# desired StatefulSet with a VolumeClaimTemplate with a numerically equal, non-canonical storage quantity
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: "test"
spec:
replicas: 1
selector:
matchLabels:
app: test-app
serviceName: "nginx-service"
template:
metadata:
labels:
app: test-app
spec:
containers:
- name: nginx
image: nginx:1.17.0
ports:
- containerPort: 80
volumeMounts:
- name: persistent-storage
mountPath: /usr/share/nginx/html
volumeClaimTemplates:
- metadata:
name: persistent-storage
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 1024Mi
storageClassName: standard
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package io.javaoperatorsdk.operator.dependent.statefulsetdesiredsanitizer;

import io.fabric8.kubernetes.api.model.ObjectMetaBuilder;
import io.fabric8.kubernetes.api.model.Quantity;
import io.fabric8.kubernetes.api.model.apps.StatefulSet;
import io.javaoperatorsdk.operator.ReconcilerUtilsInternal;
import io.javaoperatorsdk.operator.api.reconciler.Context;
Expand All @@ -39,6 +40,15 @@ protected StatefulSet desired(
.withName(primary.getMetadata().getName())
.withNamespace(primary.getMetadata().getNamespace())
.build());
// the API server stores 1024Mi as 1Gi
template
.getSpec()
.getVolumeClaimTemplates()
.get(0)
.getSpec()
.getResources()
.getRequests()
.put("storage", new Quantity("1024Mi"));
return template;
}

Expand Down
Loading