This repository has been archived by the owner on Jan 11, 2024. It is now read-only.
/
addon.go
159 lines (142 loc) · 4.7 KB
/
addon.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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
package clientset
// import (
// "encoding/json"
// "errors"
// platform "kolihub.io/koli/pkg/apis/core/v1alpha1"
// metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
// "k8s.io/apimachinery/pkg/runtime"
// "k8s.io/apimachinery/pkg/types"
// "k8s.io/apimachinery/pkg/watch"
// "k8s.io/client-go/rest"
// )
// // AddonGetter has a method to return an AddonInterface.
// // A group's client should implement this interface.
// type AddonGetter interface {
// Addon(namespace string) AddonInterface
// }
// // AddonInterface has methods to work with Addon resources.
// type AddonInterface interface {
// List(opts *metav1.ListOptions) (*platform.AddonList, error)
// Get(name string) (*platform.Addon, error)
// Delete(name string, options *metav1.DeleteOptions) error
// Create(data *platform.Addon) (*platform.Addon, error)
// Update(data *platform.Addon) (*platform.Addon, error)
// Watch(opts *metav1.ListOptions) (watch.Interface, error)
// }
// // addon implements AddonInterface
// type addon struct {
// client rest.Interface
// namespace string
// resource *metav1.APIResource
// }
// // Get gets the resource with the specified name.
// func (a *addon) Get(name string) (*platform.Addon, error) {
// addon := &platform.Addon{}
// err := a.client.Get().
// NamespaceIfScoped(a.namespace, a.resource.Namespaced).
// Resource(a.resource.Name).
// Name(name).
// Do().
// Into(addon)
// return addon, err
// }
// // List returns a list of objects for this resource.
// func (a *addon) List(opts *metav1.ListOptions) (*platform.AddonList, error) {
// addonList := &platform.AddonList{}
// err := a.client.Get().
// NamespaceIfScoped(a.namespace, a.resource.Namespaced).
// Resource(a.resource.Name).
// FieldsSelectorParam(nil).
// // VersionedParams(opts, scheme.ParameterCodec). // TODO: test this option
// Do().
// Into(addonList)
// return addonList, err
// }
// // Delete deletes the resource with the specified name.
// func (a *addon) Delete(name string, opts *metav1.DeleteOptions) error {
// return a.client.Delete().
// NamespaceIfScoped(a.namespace, a.resource.Namespaced).
// Resource(a.resource.Name).
// Name(name).
// // TODO: https://github.com/kubernetes/kubernetes/issues/37278
// // error: no kind "DeleteOptions" is registered for version "<3PR>"
// // Body(opts).
// Do().
// Error()
// }
// // Create creates the provided resource.
// func (a *addon) Create(data *platform.Addon) (*platform.Addon, error) {
// addon := &platform.Addon{}
// err := a.client.Post().
// NamespaceIfScoped(a.namespace, a.resource.Namespaced).
// Resource(a.resource.Name).
// Body(data).
// Do().
// Into(addon)
// return addon, err
// }
// // Update updates the provided resource.
// func (a *addon) Update(data *platform.Addon) (*platform.Addon, error) {
// addon := &platform.Addon{}
// if len(data.GetName()) == 0 {
// return data, errors.New("object missing name")
// }
// err := a.client.Put().
// NamespaceIfScoped(a.namespace, a.resource.Namespaced).
// Resource(a.resource.Name).
// Name(data.GetName()).
// Body(data).
// Do().
// Into(addon)
// return addon, err
// }
// // Watch returns a watch.Interface that watches the resource.
// func (a *addon) Watch(opts *metav1.ListOptions) (watch.Interface, error) {
// // TODO: Using Watch method gives the following error on creation and deletion of resources:
// // expected type X, but watch event object had type *runtime.Unstructured
// stream, err := a.client.Get().
// Prefix("watch").
// NamespaceIfScoped(a.namespace, a.resource.Namespaced).
// Resource(a.resource.Name).
// VersionedParams(opts, metav1.ParameterCodec).
// Stream()
// if err != nil {
// return nil, err
// }
// return watch.NewStreamWatcher(&addonDecoder{
// dec: json.NewDecoder(stream),
// close: stream.Close,
// }), nil
// }
// // Patch updates the provided resource
// func (a *addon) Patch(name string, pt types.PatchType, data []byte) (*platform.Addon, error) {
// addon := &platform.Addon{}
// err := a.client.Patch(pt).
// NamespaceIfScoped(a.namespace, a.resource.Namespaced).
// Resource(a.resource.Name).
// Name(name).
// Body(data).
// Do().
// Into(addon)
// return addon, err
// }
// // addonDecoder provides a decoder for watching addon resources
// type addonDecoder struct {
// dec *json.Decoder
// close func() error
// }
// // Close decoder
// func (d *addonDecoder) Close() {
// d.close()
// }
// // Decode data
// func (d *addonDecoder) Decode() (watch.EventType, runtime.Object, error) {
// var e struct {
// Type watch.EventType
// Object platform.Addon
// }
// if err := d.dec.Decode(&e); err != nil {
// return watch.Error, nil, err
// }
// return e.Type, &e.Object, nil
// }