This repository has been archived by the owner on Aug 25, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathhandler.go
102 lines (87 loc) · 2.95 KB
/
handler.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
// Copyright 2017 The quartermaster Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package storage
import (
"github.com/coreos/quartermaster/pkg/spec"
"github.com/lpabon/godbc"
"k8s.io/client-go/pkg/apis/extensions/v1beta1"
)
// StorageHandlerFuncs insulates the implementation from unsupported
// interface functions. Please see StorageType for documentation
type StorageHandlerFuncs struct {
StorageHandler interface{}
AddClusterFunc func(c *spec.StorageCluster) (*spec.StorageCluster, error)
UpdateClusterFunc func(old *spec.StorageCluster, new *spec.StorageCluster) error
DeleteClusterFunc func(c *spec.StorageCluster) error
MakeDeploymentFunc func(n *spec.StorageNode, old *v1beta1.Deployment) (*v1beta1.Deployment, error)
AddNodeFunc func(n *spec.StorageNode) (*spec.StorageNode, error)
UpdateNodeFunc func(n *spec.StorageNode) (*spec.StorageNode, error)
DeleteNodeFunc func(n *spec.StorageNode) error
InitFunc func() error
TypeFunc func() spec.StorageTypeIdentifier
}
func (s StorageHandlerFuncs) AddCluster(c *spec.StorageCluster) (*spec.StorageCluster, error) {
if s.AddClusterFunc != nil {
return s.AddClusterFunc(c)
}
return nil, nil
}
func (s StorageHandlerFuncs) UpdateCluster(old *spec.StorageCluster,
new *spec.StorageCluster) error {
if s.UpdateClusterFunc != nil {
return s.UpdateClusterFunc(old, new)
}
return nil
}
func (s StorageHandlerFuncs) DeleteCluster(c *spec.StorageCluster) error {
if s.DeleteClusterFunc != nil {
return s.DeleteClusterFunc(c)
}
return nil
}
func (s StorageHandlerFuncs) MakeDeployment(n *spec.StorageNode,
old *v1beta1.Deployment) (*v1beta1.Deployment, error) {
if s.MakeDeploymentFunc != nil {
return s.MakeDeploymentFunc(n, old)
}
return nil, nil
}
func (s StorageHandlerFuncs) AddNode(n *spec.StorageNode) (*spec.StorageNode, error) {
if s.AddNodeFunc != nil {
return s.AddNodeFunc(n)
}
return nil, nil
}
func (s StorageHandlerFuncs) UpdateNode(n *spec.StorageNode) (*spec.StorageNode, error) {
if s.UpdateNodeFunc != nil {
return s.UpdateNodeFunc(n)
}
return nil, nil
}
func (s StorageHandlerFuncs) DeleteNode(n *spec.StorageNode) error {
if s.DeleteNodeFunc != nil {
return s.DeleteNodeFunc(n)
}
return nil
}
func (s StorageHandlerFuncs) Init() error {
if s.InitFunc != nil {
return s.InitFunc()
}
return nil
}
func (s StorageHandlerFuncs) Type() spec.StorageTypeIdentifier {
godbc.Require(s.TypeFunc != nil, "Type() must be defined")
return s.TypeFunc()
}