Skip to content

Commit

Permalink
feat: add labels to the volume identify the k8s usage
Browse files Browse the repository at this point in the history
  • Loading branch information
mrsimonemms committed Dec 20, 2024
1 parent b8a9f15 commit 32a0fea
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
10 changes: 10 additions & 0 deletions internal/api/volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,16 @@ func (s *VolumeService) Attach(ctx context.Context, volume *csi.Volume, server *
return volumes.ErrAttached
}

if _, _, err := s.client.Volume.Update(ctx, hcloudVolume, hcloud.VolumeUpdateOpts{Labels: volume.Labels}); err != nil {
s.logger.Info(
"failed to update labels on volume",
"volume-id", volume.ID,
"server-id", server.ID,
"err", err,
)
return err
}

action, _, err := s.client.Volume.Attach(ctx, hcloudVolume, hcloudServer)
if err != nil {
s.logger.Info(
Expand Down
1 change: 1 addition & 0 deletions internal/csi/volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ type Volume struct {
ID int64
Name string
Size int // GB
Labels map[string]string
Location string
LinuxDevice string
Server *Server
Expand Down
4 changes: 3 additions & 1 deletion internal/driver/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,9 @@ func (s *ControllerService) ControllerPublishVolume(ctx context.Context, req *pr
return nil, status.Error(codes.InvalidArgument, "readonly volumes are not supported")
}

volume := &csi.Volume{ID: volumeID}
volume := &csi.Volume{ID: volumeID, Labels: map[string]string{
"hello": "world",
}}
server := &csi.Server{ID: serverID}

if err := s.volumeService.Attach(ctx, volume, server); err != nil {
Expand Down

0 comments on commit 32a0fea

Please sign in to comment.