/
spec.go
85 lines (69 loc) · 1.71 KB
/
spec.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
package cluster
import (
"context"
infrastructurev1alpha3 "github.com/giantswarm/apiextensions/v3/pkg/apis/infrastructure/v1alpha3"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
capzv1alpha3 "sigs.k8s.io/cluster-api-provider-azure/api/v1alpha3"
capiv1alpha3 "sigs.k8s.io/cluster-api/api/v1alpha3"
)
type GetOptions struct {
Name string
Provider string
Namespace string
}
type PatchOptions struct {
PatchSpecs []PatchSpec
}
type PatchSpec struct {
Op string `json:"op"`
Path string `json:"path"`
Value interface{} `json:"value"`
}
// Interface represents the contract for the clusters service.
// Using this instead of a regular 'struct' makes mocking the
// service in tests much simpler.
type Interface interface {
Get(context.Context, GetOptions) (Resource, error)
Patch(context.Context, runtime.Object, PatchOptions) error
}
type Resource interface {
Object() runtime.Object
}
// Cluster abstracts away provider-specific
// node pool resources.
type Cluster struct {
Cluster *capiv1alpha3.Cluster
AWSCluster *infrastructurev1alpha3.AWSCluster
AzureCluster *capzv1alpha3.AzureCluster
}
func (n *Cluster) Object() runtime.Object {
if n.Cluster != nil {
return n.Cluster
}
return nil
}
// Collection wraps a list of clusters.
type Collection struct {
Items []Cluster
}
func (cc *Collection) Object() runtime.Object {
list := &metav1.List{
TypeMeta: metav1.TypeMeta{
Kind: "List",
APIVersion: "v1",
},
ListMeta: metav1.ListMeta{},
}
for _, item := range cc.Items {
obj := item.Object()
if obj == nil {
continue
}
raw := runtime.RawExtension{
Object: obj,
}
list.Items = append(list.Items, raw)
}
return list
}