generated from kyma-project/template-repository
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactored implementation to use interface
- Loading branch information
1 parent
bfb2bfe
commit ae6a8df
Showing
31 changed files
with
1,138 additions
and
312 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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,57 @@ | ||
package backupschedule | ||
|
||
import ( | ||
"context" | ||
cloudresourcesv1beta1 "github.com/kyma-project/cloud-manager/api/cloud-resources/v1beta1" | ||
"github.com/kyma-project/cloud-manager/pkg/composed" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"sigs.k8s.io/controller-runtime/pkg/client" | ||
"sort" | ||
) | ||
|
||
type backupImpl interface { | ||
emptySourceObject() composed.ObjWithConditions | ||
emptyBackupList() client.ObjectList | ||
toObjectSlice(list client.ObjectList) []client.Object | ||
getBackupObject(state *State, objectMeta *metav1.ObjectMeta) (client.Object, error) | ||
} | ||
|
||
func loadBackupImpl(ctx context.Context, st composed.State) (error, context.Context) { | ||
state := st.(*State) | ||
schedule := state.ObjAsBackupSchedule() | ||
logger := composed.LoggerFromCtx(ctx) | ||
|
||
logger.WithValues("BackupSchedule :", schedule.GetName()).Info("Load Provider Specific Implementation") | ||
|
||
if _, ok := schedule.(*cloudresourcesv1beta1.GcpNfsBackupSchedule); ok { | ||
state.backupImpl = &backupImplGcpNfs{} | ||
} else { | ||
return composed.UpdateStatus(schedule). | ||
SetExclusiveConditions(metav1.Condition{ | ||
Type: cloudresourcesv1beta1.ConditionTypeError, | ||
Status: metav1.ConditionTrue, | ||
Reason: cloudresourcesv1beta1.ReasonUnknownSchedule, | ||
Message: "Error identifying Schedule Provider", | ||
}). | ||
SuccessError(composed.StopWithRequeue). | ||
Run(ctx, state) | ||
} | ||
|
||
return nil, nil | ||
} | ||
|
||
func getListObjects(list client.ObjectList) []client.Object { | ||
var objects []client.Object | ||
|
||
//Retrieve List objects for specific type | ||
if x, ok := list.(*cloudresourcesv1beta1.GcpNfsVolumeList); ok { | ||
for _, item := range x.Items { | ||
objects = append(objects, &item) | ||
} | ||
} | ||
|
||
sort.Slice(objects, func(i, j int) bool { | ||
return objects[i].GetCreationTimestamp().Time.Before(objects[j].GetCreationTimestamp().Time) | ||
}) | ||
return objects | ||
} |
This file contains 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,50 @@ | ||
package backupschedule | ||
|
||
import ( | ||
"fmt" | ||
cloudresourcesv1beta1 "github.com/kyma-project/cloud-manager/api/cloud-resources/v1beta1" | ||
"github.com/kyma-project/cloud-manager/pkg/composed" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"sigs.k8s.io/controller-runtime/pkg/client" | ||
) | ||
|
||
type backupImplGcpNfs struct { | ||
} | ||
|
||
func (impl *backupImplGcpNfs) emptySourceObject() composed.ObjWithConditions { | ||
return &cloudresourcesv1beta1.GcpNfsVolume{} | ||
} | ||
|
||
func (impl *backupImplGcpNfs) emptyBackupList() client.ObjectList { | ||
return &cloudresourcesv1beta1.GcpNfsVolumeBackupList{} | ||
} | ||
func (impl *backupImplGcpNfs) toObjectSlice(list client.ObjectList) []client.Object { | ||
var objects []client.Object | ||
|
||
if x, ok := list.(*cloudresourcesv1beta1.GcpNfsVolumeList); ok { | ||
for _, item := range x.Items { | ||
objects = append(objects, &item) | ||
} | ||
} | ||
return objects | ||
} | ||
func (impl *backupImplGcpNfs) getBackupObject(state *State, objectMeta *metav1.ObjectMeta) (client.Object, error) { | ||
schedule := state.ObjAsBackupSchedule() | ||
x, ok := schedule.(*cloudresourcesv1beta1.GcpNfsBackupSchedule) | ||
if !ok { | ||
return nil, fmt.Errorf("provider %s not supported", state.Scope.Spec.Provider) | ||
} | ||
|
||
return &cloudresourcesv1beta1.GcpNfsVolumeBackup{ | ||
ObjectMeta: *objectMeta, | ||
Spec: cloudresourcesv1beta1.GcpNfsVolumeBackupSpec{ | ||
Location: x.Spec.Location, | ||
Source: cloudresourcesv1beta1.GcpNfsVolumeBackupSource{ | ||
Volume: cloudresourcesv1beta1.GcpNfsVolumeRef{ | ||
Name: schedule.GetSourceRef().Name, | ||
Namespace: schedule.GetSourceRef().Namespace, | ||
}, | ||
}, | ||
}, | ||
}, nil | ||
} |
This file contains 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 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 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 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
Oops, something went wrong.