@@ -7,11 +7,11 @@ import (
7
7
"strings"
8
8
"time"
9
9
10
- "github.com/golang/glog"
11
10
"k8s.io/apimachinery/pkg/api/errors"
12
11
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
13
12
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
14
13
"k8s.io/apimachinery/pkg/util/wait"
14
+ "k8s.io/klog"
15
15
)
16
16
17
17
// CustomResourceList represents a list of custom resource objects that will
@@ -25,7 +25,7 @@ type CustomResourceList struct {
25
25
26
26
// GetCustomResource returns the custom resource as *unstructured.Unstructured by the given name.
27
27
func (c * Client ) GetCustomResource (apiGroup , version , namespace , resourcePlural , resourceName string ) (* unstructured.Unstructured , error ) {
28
- glog .V (4 ).Infof ("[GET CUSTOM RESOURCE]: %s:%s" , namespace , resourceName )
28
+ klog .V (4 ).Infof ("[GET CUSTOM RESOURCE]: %s:%s" , namespace , resourceName )
29
29
var object unstructured.Unstructured
30
30
31
31
b , err := c .GetCustomResourceRaw (apiGroup , version , namespace , resourcePlural , resourceName )
@@ -41,17 +41,17 @@ func (c *Client) GetCustomResource(apiGroup, version, namespace, resourcePlural,
41
41
42
42
// GetCustomResourceRaw returns the custom resource's raw body data by the given name.
43
43
func (c * Client ) GetCustomResourceRaw (apiGroup , version , namespace , resourcePlural , resourceName string ) ([]byte , error ) {
44
- glog .V (4 ).Infof ("[GET CUSTOM RESOURCE RAW]: %s:%s" , namespace , resourceName )
44
+ klog .V (4 ).Infof ("[GET CUSTOM RESOURCE RAW]: %s:%s" , namespace , resourceName )
45
45
httpRestClient := c .extInterface .ApiextensionsV1beta1 ().RESTClient ()
46
46
uri := customResourceURI (apiGroup , version , namespace , resourcePlural , resourceName )
47
- glog .V (4 ).Infof ("[GET]: %s" , uri )
47
+ klog .V (4 ).Infof ("[GET]: %s" , uri )
48
48
49
49
return httpRestClient .Get ().RequestURI (uri ).DoRaw ()
50
50
}
51
51
52
52
// CreateCustomResource creates the custom resource.
53
53
func (c * Client ) CreateCustomResource (item * unstructured.Unstructured ) error {
54
- glog .V (4 ).Infof ("[CREATE CUSTOM RESOURCE]: %s:%s" , item .GetNamespace (), item .GetName ())
54
+ klog .V (4 ).Infof ("[CREATE CUSTOM RESOURCE]: %s:%s" , item .GetNamespace (), item .GetName ())
55
55
kind := item .GetKind ()
56
56
namespace := item .GetNamespace ()
57
57
apiVersion := item .GetAPIVersion ()
@@ -70,20 +70,20 @@ func (c *Client) CreateCustomResource(item *unstructured.Unstructured) error {
70
70
71
71
// CreateCustomResourceRaw creates the raw bytes of the custom resource.
72
72
func (c * Client ) CreateCustomResourceRaw (apiGroup , version , namespace , kind string , data []byte ) error {
73
- glog .V (4 ).Infof ("[CREATE CUSTOM RESOURCE RAW]: %s:%s" , namespace , kind )
73
+ klog .V (4 ).Infof ("[CREATE CUSTOM RESOURCE RAW]: %s:%s" , namespace , kind )
74
74
var statusCode int
75
75
76
76
httpRestClient := c .extInterface .ApiextensionsV1beta1 ().RESTClient ()
77
77
uri := customResourceDefinitionURI (apiGroup , version , namespace , kind )
78
- glog .V (4 ).Infof ("[POST]: %s" , uri )
78
+ klog .V (4 ).Infof ("[POST]: %s" , uri )
79
79
result := httpRestClient .Post ().RequestURI (uri ).Body (data ).Do ()
80
80
81
81
if result .Error () != nil {
82
82
return result .Error ()
83
83
}
84
84
85
85
result .StatusCode (& statusCode )
86
- glog .V (4 ).Infof ("Written %s, status: %d" , uri , statusCode )
86
+ klog .V (4 ).Infof ("Written %s, status: %d" , uri , statusCode )
87
87
88
88
if statusCode != 201 {
89
89
return fmt .Errorf ("unexpected status code %d, expecting 201" , statusCode )
@@ -94,7 +94,7 @@ func (c *Client) CreateCustomResourceRaw(apiGroup, version, namespace, kind stri
94
94
// CreateCustomResourceRawIfNotFound creates the raw bytes of the custom resource if it doesn't exist.
95
95
// It also returns a boolean to indicate whether a new custom resource is created.
96
96
func (c * Client ) CreateCustomResourceRawIfNotFound (apiGroup , version , namespace , kind , name string , data []byte ) (bool , error ) {
97
- glog .V (4 ).Infof ("[CREATE CUSTOM RESOURCE RAW if not found]: %s:%s" , namespace , name )
97
+ klog .V (4 ).Infof ("[CREATE CUSTOM RESOURCE RAW if not found]: %s:%s" , namespace , name )
98
98
_ , err := c .GetCustomResource (apiGroup , version , namespace , kind , name )
99
99
if err == nil {
100
100
return false , nil
@@ -112,7 +112,7 @@ func (c *Client) CreateCustomResourceRawIfNotFound(apiGroup, version, namespace,
112
112
// UpdateCustomResource updates the custom resource.
113
113
// To do an atomic update, use AtomicModifyCustomResource().
114
114
func (c * Client ) UpdateCustomResource (item * unstructured.Unstructured ) error {
115
- glog .V (4 ).Infof ("[UPDATE CUSTOM RESOURCE]: %s:%s" , item .GetNamespace (), item .GetName ())
115
+ klog .V (4 ).Infof ("[UPDATE CUSTOM RESOURCE]: %s:%s" , item .GetNamespace (), item .GetName ())
116
116
kind := item .GetKind ()
117
117
name := item .GetName ()
118
118
namespace := item .GetNamespace ()
@@ -132,20 +132,20 @@ func (c *Client) UpdateCustomResource(item *unstructured.Unstructured) error {
132
132
133
133
// UpdateCustomResourceRaw updates the thirdparty resource with the raw data.
134
134
func (c * Client ) UpdateCustomResourceRaw (apiGroup , version , namespace , resourcePlural , resourceName string , data []byte ) error {
135
- glog .V (4 ).Infof ("[UPDATE CUSTOM RESOURCE RAW]: %s:%s" , namespace , resourceName )
135
+ klog .V (4 ).Infof ("[UPDATE CUSTOM RESOURCE RAW]: %s:%s" , namespace , resourceName )
136
136
var statusCode int
137
137
138
138
httpRestClient := c .extInterface .ApiextensionsV1beta1 ().RESTClient ()
139
139
uri := customResourceURI (apiGroup , version , namespace , resourcePlural , resourceName )
140
- glog .V (4 ).Infof ("[PUT]: %s" , uri )
140
+ klog .V (4 ).Infof ("[PUT]: %s" , uri )
141
141
result := httpRestClient .Put ().RequestURI (uri ).Body (data ).Do ()
142
142
143
143
if result .Error () != nil {
144
144
return result .Error ()
145
145
}
146
146
147
147
result .StatusCode (& statusCode )
148
- glog .V (4 ).Infof ("Updated %s, status: %d" , uri , statusCode )
148
+ klog .V (4 ).Infof ("Updated %s, status: %d" , uri , statusCode )
149
149
150
150
if statusCode != 200 {
151
151
return fmt .Errorf ("unexpected status code %d, expecting 200" , statusCode )
@@ -156,7 +156,7 @@ func (c *Client) UpdateCustomResourceRaw(apiGroup, version, namespace, resourceP
156
156
// CreateOrUpdateCustomeResourceRaw creates the custom resource if it doesn't exist.
157
157
// If the custom resource exists, it updates the existing one.
158
158
func (c * Client ) CreateOrUpdateCustomeResourceRaw (apiGroup , version , namespace , resourcePlural , resourceName string , data []byte ) error {
159
- glog .V (4 ).Infof ("[CREATE OR UPDATE UPDATE CUSTOM RESOURCE RAW]: %s:%s" , namespace , resourceName )
159
+ klog .V (4 ).Infof ("[CREATE OR UPDATE UPDATE CUSTOM RESOURCE RAW]: %s:%s" , namespace , resourceName )
160
160
old , err := c .GetCustomResourceRaw (apiGroup , version , namespace , resourcePlural , resourceName )
161
161
if err != nil {
162
162
if ! errors .IsNotFound (err ) {
@@ -186,11 +186,11 @@ func (c *Client) CreateOrUpdateCustomeResourceRaw(apiGroup, version, namespace,
186
186
187
187
// DeleteCustomResource deletes the with the given name.
188
188
func (c * Client ) DeleteCustomResource (apiGroup , version , namespace , resourcePlural , resourceName string ) error {
189
- glog .V (4 ).Infof ("[DELETE CUSTOM RESOURCE]: %s:%s" , namespace , resourceName )
189
+ klog .V (4 ).Infof ("[DELETE CUSTOM RESOURCE]: %s:%s" , namespace , resourceName )
190
190
httpRestClient := c .extInterface .ApiextensionsV1beta1 ().RESTClient ()
191
191
uri := customResourceURI (apiGroup , version , namespace , resourcePlural , resourceName )
192
192
193
- glog .V (4 ).Infof ("[DELETE]: %s" , uri )
193
+ klog .V (4 ).Infof ("[DELETE]: %s" , uri )
194
194
_ , err := httpRestClient .Delete ().RequestURI (uri ).DoRaw ()
195
195
return err
196
196
}
@@ -201,31 +201,31 @@ type CustomResourceModifier func(*unstructured.Unstructured, interface{}) error
201
201
// AtomicModifyCustomResource gets the custom resource, modifies it and writes it back.
202
202
// If it's modified by other writers, we will retry until it succeeds.
203
203
func (c * Client ) AtomicModifyCustomResource (apiGroup , version , namespace , resourcePlural , resourceName string , f CustomResourceModifier , data interface {}) error {
204
- glog .V (4 ).Infof ("[ATOMIC MODIFY CUSTOM RESOURCE]: %s:%s" , namespace , resourceName )
204
+ klog .V (4 ).Infof ("[ATOMIC MODIFY CUSTOM RESOURCE]: %s:%s" , namespace , resourceName )
205
205
return wait .PollInfinite (time .Second , func () (bool , error ) {
206
206
var customResource unstructured.Unstructured
207
207
b , err := c .GetCustomResourceRaw (apiGroup , version , namespace , resourcePlural , resourceName )
208
208
if err != nil {
209
- glog .Errorf ("Failed to get CUSTOM RESOURCE %q, kind:%q: %v" , resourceName , resourcePlural , err )
209
+ klog .Errorf ("Failed to get CUSTOM RESOURCE %q, kind:%q: %v" , resourceName , resourcePlural , err )
210
210
return false , err
211
211
}
212
212
213
213
if err := json .Unmarshal (b , & customResource ); err != nil {
214
- glog .Errorf ("Failed to unmarshal CUSTOM RESOURCE %q, kind:%q: %v" , resourceName , resourcePlural , err )
214
+ klog .Errorf ("Failed to unmarshal CUSTOM RESOURCE %q, kind:%q: %v" , resourceName , resourcePlural , err )
215
215
return false , err
216
216
}
217
217
218
218
if err := f (& customResource , data ); err != nil {
219
- glog .Errorf ("Failed to modify the CUSTOM RESOURCE %q, kind:%q: %v" , resourceName , resourcePlural , err )
219
+ klog .Errorf ("Failed to modify the CUSTOM RESOURCE %q, kind:%q: %v" , resourceName , resourcePlural , err )
220
220
return false , err
221
221
}
222
222
223
223
if err := c .UpdateCustomResource (& customResource ); err != nil {
224
224
if errors .IsConflict (err ) {
225
- glog .Errorf ("Failed to update CUSTOM RESOURCE %q, kind:%q: %v, will retry" , resourceName , resourcePlural , err )
225
+ klog .Errorf ("Failed to update CUSTOM RESOURCE %q, kind:%q: %v, will retry" , resourceName , resourcePlural , err )
226
226
return false , nil
227
227
}
228
- glog .Errorf ("Failed to update CUSTOM RESOURCE %q, kind:%q: %v" , resourceName , resourcePlural , err )
228
+ klog .Errorf ("Failed to update CUSTOM RESOURCE %q, kind:%q: %v" , resourceName , resourcePlural , err )
229
229
return false , err
230
230
}
231
231
@@ -273,13 +273,13 @@ func customResourceDefinitionURI(apiGroup, version, namespace, resourcePlural st
273
273
274
274
// ListCustomResource lists all custom resources for the given namespace.
275
275
func (c * Client ) ListCustomResource (apiGroup , version , namespace , resourcePlural string ) (* CustomResourceList , error ) {
276
- glog .V (4 ).Infof ("LIST CUSTOM RESOURCE]: %s" , resourcePlural )
276
+ klog .V (4 ).Infof ("LIST CUSTOM RESOURCE]: %s" , resourcePlural )
277
277
278
278
var crList CustomResourceList
279
279
280
280
httpRestClient := c .extInterface .ApiextensionsV1beta1 ().RESTClient ()
281
281
uri := customResourceDefinitionURI (apiGroup , version , namespace , resourcePlural )
282
- glog .V (4 ).Infof ("[GET]: %s" , uri )
282
+ klog .V (4 ).Infof ("[GET]: %s" , uri )
283
283
bytes , err := httpRestClient .Get ().RequestURI (uri ).DoRaw ()
284
284
if err != nil {
285
285
return nil , fmt .Errorf ("failed to get custom resource list: %v" , err )
0 commit comments