-
Notifications
You must be signed in to change notification settings - Fork 63
/
strategy.go
54 lines (44 loc) · 1.57 KB
/
strategy.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// SPDX-License-Identifier: BSD-3-Clause
// Copyright (c) 2022, Unikraft GmbH and The KraftKit Authors.
// Licensed under the BSD-3-Clause License (the "License").
// You may not use this file except in compliance with the License.
package volume
import (
"context"
volumev1alpha1 "kraftkit.sh/api/volume/v1alpha1"
"kraftkit.sh/kconfig"
)
// NewStrategyConstructor is a prototype for the instantiation function of a
// platform driver implementation.
type NewStrategyConstructor[T any] func(context.Context, ...any) (T, error)
// strategies contains the map of registered strategies, whether provided as
// part from builtins and are host specific, or those that have been registered
// dynamically at runtime.
var strategies = make(map[string]*Strategy)
// DefaultStrategyName return the name of the default strategy of the platform.
func DefaultStrategyName() string {
return defaultStrategyName
}
// Strategy represents canonical reference of a machine driver and their
// platform.
type Strategy struct {
IsCompatible func(string, kconfig.KeyValueMap) (bool, error)
NewVolumeV1alpha1 NewStrategyConstructor[volumev1alpha1.VolumeService]
}
// Strategies returns the list of registered platform implementations.
func Strategies() map[string]*Strategy {
base := hostSupportedStrategies()
for name, driverInfo := range strategies {
base[name] = driverInfo
}
return base
}
// DriverNames returns the list of registered platform driver implementation
// names.
func DriverNames() []string {
ret := []string{}
for plat := range Strategies() {
ret = append(ret, plat)
}
return ret
}