-
Notifications
You must be signed in to change notification settings - Fork 10
Implement VolumeSnapshot
IRI methods in volume poollet & broker
#1388
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
Open
sujeet01
wants to merge
2
commits into
ironcore-dev:main
Choose a base branch
from
opensovereigncloud:osc/feat/volumesnapshot-iri-implementation
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
// SPDX-FileCopyrightText: 2025 SAP SE or an SAP affiliate company and IronCore contributors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package server | ||
|
||
import ( | ||
"fmt" | ||
|
||
storagev1alpha1 "github.com/ironcore-dev/ironcore/api/storage/v1alpha1" | ||
"github.com/ironcore-dev/ironcore/broker/volumebroker/apiutils" | ||
iri "github.com/ironcore-dev/ironcore/iri/apis/volume/v1alpha1" | ||
) | ||
|
||
func (s *Server) convertIronCoreVolumeSnapshot(ironcoreVolumeSnapshot *storagev1alpha1.VolumeSnapshot) (*iri.VolumeSnapshot, error) { | ||
metadata, err := apiutils.GetObjectMetadata(ironcoreVolumeSnapshot) | ||
if err != nil { | ||
return nil, fmt.Errorf("error getting object metadata: %w", err) | ||
} | ||
|
||
var volumeID string | ||
if ironcoreVolumeSnapshot.Spec.VolumeRef != nil { | ||
volumeID = ironcoreVolumeSnapshot.Spec.VolumeRef.Name | ||
} | ||
|
||
state, err := s.convertIronCoreVolumeSnapshotState(ironcoreVolumeSnapshot.Status.State) | ||
if err != nil { | ||
return nil, fmt.Errorf("error converting volume snapshot state: %w", err) | ||
} | ||
|
||
iriVolumeSnapshot := &iri.VolumeSnapshot{ | ||
Metadata: metadata, | ||
Spec: &iri.VolumeSnapshotSpec{ | ||
VolumeId: volumeID, | ||
}, | ||
Status: &iri.VolumeSnapshotStatus{ | ||
State: state, | ||
}, | ||
} | ||
|
||
if ironcoreVolumeSnapshot.Status.Size != nil { | ||
iriVolumeSnapshot.Status.Size = ironcoreVolumeSnapshot.Status.Size.Value() | ||
} | ||
|
||
return iriVolumeSnapshot, nil | ||
} | ||
|
||
var ironcoreVolumeSnapshotStateToIRIState = map[storagev1alpha1.VolumeSnapshotState]iri.VolumeSnapshotState{ | ||
storagev1alpha1.VolumeSnapshotStatePending: iri.VolumeSnapshotState_VOLUME_SNAPSHOT_PENDING, | ||
storagev1alpha1.VolumeSnapshotStateReady: iri.VolumeSnapshotState_VOLUME_SNAPSHOT_READY, | ||
storagev1alpha1.VolumeSnapshotStateFailed: iri.VolumeSnapshotState_VOLUME_SNAPSHOT_FAILED, | ||
} | ||
|
||
func (s *Server) convertIronCoreVolumeSnapshotState(state storagev1alpha1.VolumeSnapshotState) (iri.VolumeSnapshotState, error) { | ||
if state, ok := ironcoreVolumeSnapshotStateToIRIState[state]; ok { | ||
return state, nil | ||
} | ||
return 0, fmt.Errorf("unknown ironcore volume snapshot state %q", state) | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
// SPDX-FileCopyrightText: 2025 SAP SE or an SAP affiliate company and IronCore contributors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package server | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/go-logr/logr" | ||
storagev1alpha1 "github.com/ironcore-dev/ironcore/api/storage/v1alpha1" | ||
brokerutils "github.com/ironcore-dev/ironcore/broker/common/utils" | ||
volumebrokerv1alpha1 "github.com/ironcore-dev/ironcore/broker/volumebroker/api/v1alpha1" | ||
"github.com/ironcore-dev/ironcore/broker/volumebroker/apiutils" | ||
iri "github.com/ironcore-dev/ironcore/iri/apis/volume/v1alpha1" | ||
volumepoolletv1alpha1 "github.com/ironcore-dev/ironcore/poollet/volumepoollet/api/v1alpha1" | ||
utilsmaps "github.com/ironcore-dev/ironcore/utils/maps" | ||
"google.golang.org/grpc/codes" | ||
"google.golang.org/grpc/status" | ||
corev1 "k8s.io/api/core/v1" | ||
apierrors "k8s.io/apimachinery/pkg/api/errors" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"sigs.k8s.io/controller-runtime/pkg/client" | ||
) | ||
|
||
func (s *Server) getIronCoreVolumeSnapshotConfig(ctx context.Context, volumeSnapshot *iri.VolumeSnapshot) (*storagev1alpha1.VolumeSnapshot, error) { | ||
volumeID := volumeSnapshot.Spec.VolumeId | ||
if volumeID == "" { | ||
return nil, status.Errorf(codes.InvalidArgument, "volume ID is required") | ||
} | ||
|
||
volume := &storagev1alpha1.Volume{} | ||
if err := s.getManagedAndCreated(ctx, volumeID, volume); err != nil { | ||
if apierrors.IsNotFound(err) { | ||
return nil, status.Errorf(codes.NotFound, "volume with ID %s not found", volumeID) | ||
} | ||
return nil, fmt.Errorf("error getting volume %s: %w", volumeID, err) | ||
} | ||
|
||
labels := brokerutils.PrepareDownwardAPILabels( | ||
volumeSnapshot.Metadata.Labels, | ||
s.brokerDownwardAPILabels, | ||
volumepoolletv1alpha1.VolumeSnapshotDownwardAPIPrefix, | ||
) | ||
|
||
ironcoreVolumeSnapshot := &storagev1alpha1.VolumeSnapshot{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Namespace: s.namespace, | ||
Name: s.idGen.Generate(), | ||
Labels: utilsmaps.AppendMap(labels, map[string]string{ | ||
volumebrokerv1alpha1.ManagerLabel: volumebrokerv1alpha1.VolumeBrokerManager, | ||
}), | ||
Annotations: volumeSnapshot.Metadata.Annotations, | ||
}, | ||
Spec: storagev1alpha1.VolumeSnapshotSpec{ | ||
VolumeRef: &corev1.LocalObjectReference{ | ||
Name: volume.Name, | ||
}, | ||
}, | ||
} | ||
|
||
if err := apiutils.SetObjectMetadata(ironcoreVolumeSnapshot, volumeSnapshot.Metadata); err != nil { | ||
return nil, err | ||
} | ||
|
||
return ironcoreVolumeSnapshot, nil | ||
} | ||
|
||
func (s *Server) createIronCoreVolumeSnapshot(ctx context.Context, log logr.Logger, volumeSnapshot *storagev1alpha1.VolumeSnapshot) (retErr error) { | ||
c, cleanup := s.setupCleaner(ctx, log, &retErr) | ||
defer cleanup() | ||
|
||
log.V(1).Info("Creating ironcore volume snapshot") | ||
if err := s.client.Create(ctx, volumeSnapshot); err != nil { | ||
return fmt.Errorf("error creating ironcore volume snapshot: %w", err) | ||
} | ||
c.Add(func(ctx context.Context) error { | ||
if err := s.client.Delete(ctx, volumeSnapshot); client.IgnoreNotFound(err) != nil { | ||
return fmt.Errorf("error deleting ironcore volume snapshot: %w", err) | ||
} | ||
return nil | ||
}) | ||
|
||
log.V(1).Info("Patching ironcore volume snapshot as created") | ||
if err := apiutils.PatchCreated(ctx, s.client, volumeSnapshot); err != nil { | ||
return fmt.Errorf("error patching ironcore volume snapshot as created: %w", err) | ||
} | ||
|
||
// Reset cleaner since everything from now on operates on a consistent volume snapshot | ||
c.Reset() | ||
|
||
return nil | ||
} | ||
|
||
func (s *Server) CreateVolumeSnapshot(ctx context.Context, req *iri.CreateVolumeSnapshotRequest) (res *iri.CreateVolumeSnapshotResponse, retErr error) { | ||
log := s.loggerFrom(ctx) | ||
|
||
log.V(1).Info("Getting volume snapshot configuration") | ||
ironcoreVolumeSnapshot, err := s.getIronCoreVolumeSnapshotConfig(ctx, req.VolumeSnapshot) | ||
if err != nil { | ||
return nil, fmt.Errorf("error getting ironcore volume snapshot config: %w", err) | ||
} | ||
|
||
if err := s.createIronCoreVolumeSnapshot(ctx, log, ironcoreVolumeSnapshot); err != nil { | ||
return nil, fmt.Errorf("error creating ironcore volume snapshot: %w", err) | ||
} | ||
|
||
v, err := s.convertIronCoreVolumeSnapshot(ironcoreVolumeSnapshot) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return &iri.CreateVolumeSnapshotResponse{ | ||
VolumeSnapshot: v, | ||
}, nil | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.