@@ -15,7 +15,7 @@ import (
15
15
16
16
"github.com/Azure/azure-sdk-for-go/sdk/azcore"
17
17
"github.com/go-logr/logr"
18
- "github.com/pkg/errors "
18
+ "github.com/rotisserie/eris "
19
19
"sigs.k8s.io/controller-runtime/pkg/conversion"
20
20
21
21
compute "github.com/Azure/azure-service-operator/v2/api/compute/v1api20220301/storage"
@@ -70,7 +70,7 @@ func (e *VirtualMachineScaleSetExtension) ModifyARMResource(
70
70
) (genruntime.ARMResource , error ) {
71
71
typedObj , ok := obj .(* compute.VirtualMachineScaleSet )
72
72
if ! ok {
73
- return nil , errors .Errorf ("cannot run on unknown resource type %T, expected *compute.VirtualMachineScaleSet" , obj )
73
+ return nil , eris .Errorf ("cannot run on unknown resource type %T, expected *compute.VirtualMachineScaleSet" , obj )
74
74
}
75
75
76
76
// Type assert that we are the hub type. This will fail to compile if
@@ -85,7 +85,7 @@ func (e *VirtualMachineScaleSetExtension) ModifyARMResource(
85
85
86
86
apiVersion , err := genruntime .GetAPIVersion (typedObj , kubeClient .Scheme ())
87
87
if err != nil {
88
- return nil , errors .Wrapf (err , "error getting api version for resource %s while getting status" , obj .GetName ())
88
+ return nil , eris .Wrapf (err , "error getting api version for resource %s while getting status" , obj .GetName ())
89
89
}
90
90
91
91
// Get the raw resource
@@ -94,15 +94,15 @@ func (e *VirtualMachineScaleSetExtension) ModifyARMResource(
94
94
if err != nil {
95
95
// If the error is NotFound, the resource we're trying to Create doesn't exist and so no modification is needed
96
96
var responseError * azcore.ResponseError
97
- if errors .As (err , & responseError ) && responseError .StatusCode == http .StatusNotFound {
97
+ if eris .As (err , & responseError ) && responseError .StatusCode == http .StatusNotFound {
98
98
return armObj , nil
99
99
}
100
- return nil , errors .Wrapf (err , "getting resource with ID: %q" , resourceID )
100
+ return nil , eris .Wrapf (err , "getting resource with ID: %q" , resourceID )
101
101
}
102
102
103
103
azureExtensions , err := getRawChildCollection (raw , rawChildCollectionPath ... )
104
104
if err != nil {
105
- return nil , errors .Wrapf (err , "failed to get VMSS Extensions" )
105
+ return nil , eris .Wrapf (err , "failed to get VMSS Extensions" )
106
106
}
107
107
108
108
// If the child collection is not defined, We return the arm object as is here.
@@ -115,7 +115,7 @@ func (e *VirtualMachineScaleSetExtension) ModifyARMResource(
115
115
116
116
err = setChildCollection (armObj .Spec (), azureExtensions , childCollectionPathARM ... )
117
117
if err != nil {
118
- return nil , errors .Wrapf (err , "failed to set VMSS Extensions" )
118
+ return nil , eris .Wrapf (err , "failed to set VMSS Extensions" )
119
119
}
120
120
121
121
return armObj , nil
@@ -130,7 +130,7 @@ func getExactParentRecursively(parentValue reflect.Value, childFieldName []strin
130
130
fieldName := childFieldName [i ]
131
131
field := parentValue .FieldByName (fieldName )
132
132
if ! field .IsValid () {
133
- return reflect.Value {}, errors .Errorf ("couldn't find %s field" , fieldName )
133
+ return reflect.Value {}, eris .Errorf ("couldn't find %s field" , fieldName )
134
134
}
135
135
136
136
propertiesValue := reflect .Indirect (field )
@@ -147,15 +147,15 @@ func getExactParentRecursively(parentValue reflect.Value, childFieldName []strin
147
147
func getChildCollectionField (parent any , fieldPath []string ) (ret reflect.Value , err error ) {
148
148
defer func () {
149
149
if x := recover (); x != nil {
150
- err = errors .Errorf ("caught panic: %s" , x )
150
+ err = eris .Errorf ("caught panic: %s" , x )
151
151
}
152
152
}()
153
153
154
154
// Here be dragons
155
155
parentValue := reflect .ValueOf (parent )
156
156
parentValue = reflect .Indirect (parentValue )
157
157
if ! parentValue .IsValid () {
158
- return reflect.Value {}, errors .Errorf ("cannot assign to nil parent" )
158
+ return reflect.Value {}, eris .Errorf ("cannot assign to nil parent" )
159
159
}
160
160
161
161
exactParent , err := getExactParentRecursively (parentValue , fieldPath , 0 )
@@ -166,11 +166,11 @@ func getChildCollectionField(parent any, fieldPath []string) (ret reflect.Value,
166
166
childFieldName := fieldPath [len (fieldPath )- 1 ]
167
167
childField := exactParent .FieldByName (childFieldName )
168
168
if ! childField .IsValid () {
169
- return reflect.Value {}, errors .Errorf ("couldn't find %q field" , fieldPath )
169
+ return reflect.Value {}, eris .Errorf ("couldn't find %q field" , fieldPath )
170
170
}
171
171
172
172
if childField .Type ().Kind () != reflect .Slice {
173
- return reflect.Value {}, errors .Errorf ("%q field was not of kind Slice" , fieldPath )
173
+ return reflect.Value {}, eris .Errorf ("%q field was not of kind Slice" , fieldPath )
174
174
}
175
175
176
176
return childField , nil
@@ -192,7 +192,7 @@ func getRawExactParentRecursively(parent map[string]any, fieldSlice []string, i
192
192
193
193
propsMap , ok := props .(map [string ]any )
194
194
if ! ok {
195
- return nil , errors .Errorf ("%s field wasn't a map" , prop )
195
+ return nil , eris .Errorf ("%s field wasn't a map" , prop )
196
196
}
197
197
198
198
return getRawExactParentRecursively (propsMap , fieldSlice , i + 1 )
@@ -211,12 +211,12 @@ func getRawChildCollection(parent map[string]any, fieldSlice ...string) ([]any,
211
211
childFieldName := fieldSlice [len (fieldSlice )- 1 ]
212
212
childField , ok := exactParent [childFieldName ]
213
213
if ! ok {
214
- return nil , errors .Errorf ("couldn't find %q field" , fieldSlice )
214
+ return nil , eris .Errorf ("couldn't find %q field" , fieldSlice )
215
215
}
216
216
217
217
childSlice , ok := childField .([]any )
218
218
if ! ok {
219
- return nil , errors .Errorf ("%q field wasn't a slice" , fieldSlice )
219
+ return nil , eris .Errorf ("%q field wasn't a slice" , fieldSlice )
220
220
}
221
221
222
222
return childSlice , nil
@@ -225,7 +225,7 @@ func getRawChildCollection(parent map[string]any, fieldSlice ...string) ([]any,
225
225
func setChildCollection (parent genruntime.ARMResourceSpec , childCollectionFromAzure []any , childFieldPath ... string ) (err error ) {
226
226
defer func () {
227
227
if x := recover (); x != nil {
228
- err = errors .Errorf ("caught panic: %s" , x )
228
+ err = eris .Errorf ("caught panic: %s" , x )
229
229
}
230
230
}()
231
231
@@ -256,12 +256,12 @@ func setChildCollection(parent genruntime.ARMResourceSpec, childCollectionFromAz
256
256
func fuzzySetResource (resource any , embeddedResource reflect.Value ) error {
257
257
resourceJSON , err := json .Marshal (resource )
258
258
if err != nil {
259
- return errors .Wrap (err , "failed to marshal resource JSON" )
259
+ return eris .Wrap (err , "failed to marshal resource JSON" )
260
260
}
261
261
262
262
err = json .Unmarshal (resourceJSON , embeddedResource .Interface ())
263
263
if err != nil {
264
- return errors .Wrap (err , "failed to unmarshal resource JSON" )
264
+ return eris .Wrap (err , "failed to unmarshal resource JSON" )
265
265
}
266
266
267
267
// TODO: Can't do a trivial fuzzyEqualityComparison here because we don't know which fields are readonly
@@ -288,7 +288,7 @@ func mergeExtensions(extensionField reflect.Value, azureExtensionsSlice reflect.
288
288
azureExtension := azureExtensionsSlice .Index (i )
289
289
newExtensionName , err := getNameField (azureExtension )
290
290
if err != nil {
291
- return reflect.Value {}, errors .Wrapf (err , "failed to get name for new extension" )
291
+ return reflect.Value {}, eris .Wrapf (err , "failed to get name for new extension" )
292
292
}
293
293
foundExistingExtension := false
294
294
@@ -297,7 +297,7 @@ func mergeExtensions(extensionField reflect.Value, azureExtensionsSlice reflect.
297
297
var existingName reflect.Value
298
298
existingName , err = getNameField (existingExtension )
299
299
if err != nil {
300
- return reflect.Value {}, errors .Wrapf (err , "failed to get name for existing extension" )
300
+ return reflect.Value {}, eris .Wrapf (err , "failed to get name for existing extension" )
301
301
}
302
302
303
303
if existingName .String () == newExtensionName .String () {
@@ -317,13 +317,13 @@ func mergeExtensions(extensionField reflect.Value, azureExtensionsSlice reflect.
317
317
func getNameField (natValue reflect.Value ) (ret reflect.Value , err error ) {
318
318
defer func () {
319
319
if x := recover (); x != nil {
320
- err = errors .Errorf ("caught panic: %s" , x )
320
+ err = eris .Errorf ("caught panic: %s" , x )
321
321
}
322
322
}()
323
323
324
324
nameField := natValue .FieldByName ("Name" )
325
325
if ! nameField .IsValid () {
326
- return nameField , errors .Errorf ("couldn't find name field" )
326
+ return nameField , eris .Errorf ("couldn't find name field" )
327
327
}
328
328
329
329
nameField = reflect .Indirect (nameField )
0 commit comments