Skip to content

Commit

Permalink
Enhance vleg by comparing volume state
Browse files Browse the repository at this point in the history
  • Loading branch information
adracus committed Nov 15, 2022
1 parent 7632f3b commit 43e1ba7
Show file tree
Hide file tree
Showing 4 changed files with 134 additions and 77 deletions.
184 changes: 110 additions & 74 deletions ori/apis/storage/v1alpha1/api.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions ori/apis/storage/v1alpha1/api.proto
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,9 @@ message VolumeConfig {
message Volume {
string id = 1;
VolumeMetadata metadata = 2;
map<string, string> annotations = 3;
map<string, string> labels = 4;
VolumeState state = 3;
map<string, string> annotations = 4;
map<string, string> labels = 5;
}

message VolumeClassCapabilities {
Expand Down
20 changes: 19 additions & 1 deletion volumepoollet/vleg/generic.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ type genericVolumeMetadata struct {
type genericVolume struct {
id string
metadata genericVolumeMetadata
state ori.VolumeState
}

func (g genericVolume) key() string { //nolint:unused
Expand Down Expand Up @@ -102,6 +103,7 @@ func (g *Generic) list(ctx context.Context) ([]*genericVolume, error) {
namespace: volume.Metadata.Namespace,
name: volume.Metadata.Name,
},
state: volume.State,
}
}

Expand Down Expand Up @@ -139,14 +141,30 @@ func (g *Generic) Start(ctx context.Context) error {
return nil
}

func oriVolumeStateToVolumeLifecycleEventType(state ori.VolumeState) VolumeLifecycleEventType {
switch state {
case ori.VolumeState_VOLUME_AVAILABLE:
return VolumeAvailable
case ori.VolumeState_VOLUME_ERROR:
return VolumeError
case ori.VolumeState_VOLUME_PENDING:
return VolumePending
default:
panic(fmt.Sprintf("unrecognized volume state %d", state))
}
}

func (g *Generic) inferEvents(id string, metadata VolumeLifecycleEventMetadata, oldVolume, newVolume *genericVolume) []*VolumeLifecycleEvent {
switch {
case oldVolume == nil && newVolume != nil:
return []*VolumeLifecycleEvent{{ID: id, Metadata: metadata, Type: VolumeAvailable}}
return []*VolumeLifecycleEvent{{ID: id, Metadata: metadata, Type: oriVolumeStateToVolumeLifecycleEventType(newVolume.state)}}
case oldVolume != nil && newVolume == nil:
return []*VolumeLifecycleEvent{{ID: id, Metadata: metadata, Type: VolumeRemoved}}
case oldVolume != nil && newVolume != nil:
var events []*VolumeLifecycleEvent
if oldVolume.state != newVolume.state {
events = append(events, &VolumeLifecycleEvent{ID: id, Metadata: metadata, Type: oriVolumeStateToVolumeLifecycleEventType(newVolume.state)})
}
return events
default:
panic("unhandled case")
Expand Down
2 changes: 2 additions & 0 deletions volumepoollet/vleg/mleg.go → volumepoollet/vleg/vleg.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ import (
type VolumeLifecycleEventType string

const (
VolumePending VolumeLifecycleEventType = "VolumePending"
VolumeAvailable VolumeLifecycleEventType = "VolumeAvailable"
VolumeError VolumeLifecycleEventType = "VolumeError"
VolumeRemoved VolumeLifecycleEventType = "VolumeRemoved"
)

Expand Down

0 comments on commit 43e1ba7

Please sign in to comment.