-
Notifications
You must be signed in to change notification settings - Fork 21
/
snapshot_helpers.go
103 lines (91 loc) · 2.9 KB
/
snapshot_helpers.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
package v1alpha1
import (
"fmt"
"path/filepath"
"github.com/kubedb/apimachinery/apis"
"github.com/pkg/errors"
apiextensions "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1"
crdutils "kmodules.xyz/client-go/apiextensions/v1beta1"
)
var _ apis.ResourceInfo = &Snapshot{}
func (s Snapshot) OffshootName() string {
return s.Name
}
func (s Snapshot) Location() (string, error) {
spec := s.Spec.Backend
if spec.S3 != nil {
return filepath.Join(spec.S3.Prefix, DatabaseNamePrefix, s.Namespace, s.Spec.DatabaseName), nil
} else if spec.GCS != nil {
return filepath.Join(spec.GCS.Prefix, DatabaseNamePrefix, s.Namespace, s.Spec.DatabaseName), nil
} else if spec.Azure != nil {
return filepath.Join(spec.Azure.Prefix, DatabaseNamePrefix, s.Namespace, s.Spec.DatabaseName), nil
} else if spec.Local != nil {
return filepath.Join(DatabaseNamePrefix, s.Namespace, s.Spec.DatabaseName), nil
} else if spec.Swift != nil {
return filepath.Join(spec.Swift.Prefix, DatabaseNamePrefix, s.Namespace, s.Spec.DatabaseName), nil
}
return "", errors.New("no storage provider is configured")
}
func (s Snapshot) ResourceShortCode() string {
return ResourceCodeSnapshot
}
func (s Snapshot) ResourceKind() string {
return ResourceKindSnapshot
}
func (s Snapshot) ResourceSingular() string {
return ResourceSingularSnapshot
}
func (s Snapshot) ResourcePlural() string {
return ResourcePluralSnapshot
}
func (s Snapshot) OSMSecretName() string {
return fmt.Sprintf("osm-%v", s.Name)
}
func (s Snapshot) CustomResourceDefinition() *apiextensions.CustomResourceDefinition {
return crdutils.NewCustomResourceDefinition(crdutils.Config{
Group: SchemeGroupVersion.Group,
Plural: ResourcePluralSnapshot,
Singular: ResourceSingularSnapshot,
Kind: ResourceKindSnapshot,
ShortNames: []string{ResourceCodeSnapshot},
Categories: []string{"datastore", "kubedb", "appscode", "all"},
ResourceScope: string(apiextensions.NamespaceScoped),
Versions: []apiextensions.CustomResourceDefinitionVersion{
{
Name: SchemeGroupVersion.Version,
Served: true,
Storage: true,
},
},
Labels: crdutils.Labels{
LabelsMap: map[string]string{"app": "kubedb"},
},
SpecDefinitionName: "github.com/kubedb/apimachinery/apis/kubedb/v1alpha1.Snapshot",
EnableValidation: true,
GetOpenAPIDefinitions: GetOpenAPIDefinitions,
EnableStatusSubresource: apis.EnableStatusSubresource,
AdditionalPrinterColumns: []apiextensions.CustomResourceColumnDefinition{
{
Name: "DatabaseName",
Type: "string",
JSONPath: ".spec.databaseName",
},
{
Name: "Status",
Type: "string",
JSONPath: ".status.phase",
},
{
Name: "Age",
Type: "date",
JSONPath: ".metadata.creationTimestamp",
},
},
}, apis.SetNameSchema)
}
func (s *Snapshot) SetDefaults() {
if s == nil {
return
}
// Add snapshot defaulting here
}