Skip to content

Commit 1c1a6f1

Browse files
author
lamai93
committed
Added event when pvc is resized. Added log if the user tries to shrink a volume.
1 parent 80ba00b commit 1c1a6f1

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

pkg/deployment/resources/pvc_inspector.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,16 +85,21 @@ func (r *Resources) InspectPVCs(ctx context.Context) (util.Interval, error) {
8585
groupSpec := spec.GetServerGroupSpec(group)
8686
if requestedSize, ok := groupSpec.Resources.Requests[apiv1.ResourceStorage]; ok {
8787
if volumeSize, ok := p.Spec.Resources.Requests[apiv1.ResourceStorage]; ok {
88-
if volumeSize.Cmp(requestedSize) < 0 {
88+
cmp := volumeSize.Cmp(requestedSize)
89+
if cmp < 0 {
8990
// Size of the volume is smaller than the requested size
9091
// Update the pvc with the request size
9192
p.Spec.Resources.Requests[apiv1.ResourceStorage] = requestedSize
9293

93-
log.Debug().Str("pvc-capacity", volumeSize.String()).Str("requested", requestedSize.String()).Msg("PVC capacity differes - updating")
94+
log.Debug().Str("pvc-capacity", volumeSize.String()).Str("requested", requestedSize.String()).Msg("PVC capacity differs - updating")
9495
kube := r.context.GetKubeCli()
9596
if _, err := kube.CoreV1().PersistentVolumeClaims(r.context.GetNamespace()).Update(&p); err != nil {
9697
log.Error().Err(err).Msg("Failed to update pvc")
9798
}
99+
r.context.CreateEvent(k8sutil.NewPVCResizedEvent(r.context.GetAPIObject(), p.Name))
100+
} else if cmp > 0 {
101+
log.Error().Str("server-group", group.AsRole()).Str("pvc-storage-size", volumeSize.String()).Str("requested-size", requestedSize.String()).
102+
Msg("Volume size should not shrink")
98103
}
99104
}
100105
}

pkg/util/k8sutil/events.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,15 @@ func NewDowntimeNotAllowedEvent(apiObject APIObject, operation string) *Event {
193193
return event
194194
}
195195

196+
// NewPVCResizedEvent creates an event indicating that a PVC has been resized
197+
func NewPVCResizedEvent(apiObject APIObject, pvcname string) *Event {
198+
event := newDeploymentEvent(apiObject)
199+
event.Type = v1.EventTypeNormal
200+
event.Reason = "PVC Resized"
201+
event.Message = fmt.Sprintf("The persistent volume claim %s has been resized", pvcname)
202+
return event
203+
}
204+
196205
// NewUpgradeNotAllowedEvent creates an event indicating that an upgrade (or downgrade) is not allowed.
197206
func NewUpgradeNotAllowedEvent(apiObject APIObject,
198207
fromVersion, toVersion driver.Version,

0 commit comments

Comments
 (0)