Skip to content

Commit b98c83f

Browse files
Migrate asoctl to eris (#4458)
* Update go.mod * Update imports * go mod tidy * Tidy imports * Code gardening
1 parent 3bb9bf5 commit b98c83f

11 files changed

+82
-213
lines changed

v2/cmd/asoctl/cmd/clean-crds.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
package cmd
77

88
import (
9-
"github.com/pkg/errors"
9+
"github.com/rotisserie/eris"
1010
"github.com/spf13/cobra"
1111
v1 "k8s.io/apiextensions-apiserver/pkg/client/clientset/clientset/typed/apiextensions/v1"
1212
"sigs.k8s.io/controller-runtime/pkg/client"
@@ -28,19 +28,19 @@ func newCleanCRDsCommand() *cobra.Command {
2828
RunE: func(cmd *cobra.Command, args []string) error {
2929
cfg, err := config.GetConfig()
3030
if err != nil {
31-
return errors.Wrap(err, "unable to get Kubernetes config")
31+
return eris.Wrap(err, "unable to get Kubernetes config")
3232
}
3333

3434
ctx := cmd.Context()
3535

3636
apiExtClient, err := v1.NewForConfig(cfg)
3737
if err != nil {
38-
return errors.Wrap(err, "unable to create Kubernetes client")
38+
return eris.Wrap(err, "unable to create Kubernetes client")
3939
}
4040

4141
cl, err := client.New(cfg, client.Options{Scheme: api.CreateScheme()})
4242
if err != nil {
43-
return errors.Wrap(err, "unable to create Kubernetes client")
43+
return eris.Wrap(err, "unable to create Kubernetes client")
4444
}
4545

4646
return crd.NewCleaner(

v2/cmd/asoctl/cmd/export_template.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import (
1515
. "github.com/Azure/azure-service-operator/v2/internal/logging"
1616

1717
"github.com/go-logr/logr"
18-
"github.com/pkg/errors"
18+
"github.com/rotisserie/eris"
1919
"github.com/spf13/cobra"
2020
"k8s.io/apimachinery/pkg/runtime/schema"
2121

@@ -66,7 +66,7 @@ asoctl export template --version v2.6.0 --crd-pattern "resources.azure.com/*;con
6666
uri = options.source
6767
} else {
6868
if !expectedVersionRegex.MatchString(options.version) {
69-
return errors.New("specified version doesn't match expected format 'v#.#.#' (example: v2.6.0)")
69+
return eris.New("specified version doesn't match expected format 'v#.#.#' (example: v2.6.0)")
7070
}
7171

7272
uri = template.URIFromVersion(options.version)

v2/cmd/asoctl/cmd/import_azure_resource.go

+13-13
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import (
1414
"github.com/Azure/azure-sdk-for-go/sdk/azcore/cloud"
1515
"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
1616
"github.com/go-logr/logr"
17-
"github.com/pkg/errors"
17+
"github.com/rotisserie/eris"
1818
"github.com/spf13/cobra"
1919

2020
"github.com/Azure/azure-service-operator/v2/api"
@@ -122,13 +122,13 @@ func importAzureResource(
122122
) error {
123123
// Check we're being asked to do something ... anything ...
124124
if len(armIDs) == 0 {
125-
return errors.New("no ARM IDs provided")
125+
return eris.New("no ARM IDs provided")
126126
}
127127

128128
// Create an ARM client for requesting resources
129129
client, err := createARMClient(options)
130130
if err != nil {
131-
return errors.Wrapf(err, "failed to create ARM client")
131+
return eris.Wrapf(err, "failed to create ARM client")
132132
}
133133

134134
// Caution: the progress bar can deadlock if no bar is ever created, so make sure the gap between
@@ -146,7 +146,7 @@ func importAzureResource(
146146
for _, armID := range armIDs {
147147
err = importer.AddARMID(armID)
148148
if err != nil {
149-
return errors.Wrapf(err, "failed to add %q to import list", armID)
149+
return eris.Wrapf(err, "failed to add %q to import list", armID)
150150
}
151151
}
152152

@@ -163,7 +163,7 @@ func importAzureResource(
163163

164164
if err != nil {
165165
if result.Count() == 0 {
166-
return errors.Wrap(err, "failed to import any resources")
166+
return eris.Wrap(err, "failed to import any resources")
167167
}
168168

169169
log.Error(err, "Failed to import some resources.")
@@ -177,12 +177,12 @@ func importAzureResource(
177177

178178
err = configureImportedResources(options, result)
179179
if err != nil {
180-
return errors.Wrap(err, "failed to apply options to imported resources")
180+
return eris.Wrap(err, "failed to apply options to imported resources")
181181
}
182182

183183
err = writeResources(result, options, log, progressBar)
184184
if err != nil {
185-
return errors.Wrap(err, "failed to write resources")
185+
return eris.Wrap(err, "failed to write resources")
186186
}
187187

188188
return nil
@@ -192,7 +192,7 @@ func importAzureResource(
192192
func createARMClient(options *importAzureResourceOptions) (*genericarmclient.GenericClient, error) {
193193
creds, err := azidentity.NewDefaultAzureCredential(nil)
194194
if err != nil {
195-
return nil, errors.Wrap(err, "unable to get default Azure credential")
195+
return nil, eris.Wrap(err, "unable to get default Azure credential")
196196
}
197197

198198
clientOptions := &genericarmclient.GenericClientOptions{
@@ -217,15 +217,15 @@ func configureImportedResources(
217217
if len(options.labels) > 0 {
218218
err := result.AddLabels(options.labels)
219219
if err != nil {
220-
return errors.Wrap(err, "failed to add labels")
220+
return eris.Wrap(err, "failed to add labels")
221221
}
222222
}
223223

224224
// Apply annotations
225225
if len(options.annotations) > 0 {
226226
err := result.AddAnnotations(options.annotations)
227227
if err != nil {
228-
return errors.Wrap(err, "failed to add annotations")
228+
return eris.Wrap(err, "failed to add annotations")
229229
}
230230
}
231231

@@ -245,7 +245,7 @@ func writeResources(
245245
"file", file)
246246
err := result.SaveToSingleFile(file)
247247
if err != nil {
248-
return errors.Wrapf(err, "failed to write to file %s", file)
248+
return eris.Wrapf(err, "failed to write to file %s", file)
249249
}
250250

251251
return nil
@@ -258,7 +258,7 @@ func writeResources(
258258
"folder", folder)
259259
err := result.SaveToIndividualFilesInFolder(folder)
260260
if err != nil {
261-
return errors.Wrapf(err, "failed to write into folder %s", folder)
261+
return eris.Wrapf(err, "failed to write into folder %s", folder)
262262
}
263263

264264
return nil
@@ -267,7 +267,7 @@ func writeResources(
267267
// Write all the resources to stdout
268268
err := result.SaveToWriter(out)
269269
if err != nil {
270-
return errors.Wrapf(err, "failed to write to stdout")
270+
return eris.Wrapf(err, "failed to write to stdout")
271271
}
272272

273273
return nil

v2/cmd/asoctl/go.mod

+2-34
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ require (
1515
github.com/go-logr/logr v1.4.2
1616
github.com/go-logr/zerologr v1.2.3
1717
github.com/onsi/gomega v1.35.1
18-
github.com/pkg/errors v0.9.1
18+
github.com/rotisserie/eris v0.5.4
1919
github.com/rs/zerolog v1.33.0
2020
github.com/spf13/cobra v1.8.1
2121
github.com/vbauerster/mpb/v8 v8.8.3
@@ -50,25 +50,17 @@ require (
5050
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/storage/armstorage v1.6.0 // indirect
5151
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/subscription/armsubscription v1.2.0 // indirect
5252
github.com/AzureAD/microsoft-authentication-library-for-go v1.2.2 // indirect
53-
github.com/NYTimes/gziphandler v1.1.1 // indirect
5453
github.com/VividCortex/ewma v1.2.0 // indirect
5554
github.com/acarl005/stripansi v0.0.0-20180116102854-5a71ef0e047d // indirect
5655
github.com/antlr4-go/antlr/v4 v4.13.0 // indirect
57-
github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2 // indirect
5856
github.com/benbjohnson/clock v1.3.5 // indirect
5957
github.com/beorn7/perks v1.0.1 // indirect
60-
github.com/blang/semver/v4 v4.0.0 // indirect
61-
github.com/cenkalti/backoff/v4 v4.3.0 // indirect
6258
github.com/cespare/xxhash/v2 v2.3.0 // indirect
63-
github.com/coreos/go-semver v0.3.1 // indirect
64-
github.com/coreos/go-systemd/v22 v22.5.0 // indirect
6559
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
6660
github.com/emicklei/go-restful/v3 v3.12.1 // indirect
6761
github.com/evanphx/json-patch/v5 v5.9.0 // indirect
68-
github.com/felixge/httpsnoop v1.0.4 // indirect
6962
github.com/fsnotify/fsnotify v1.7.0 // indirect
7063
github.com/fxamacker/cbor/v2 v2.7.0 // indirect
71-
github.com/go-logr/stdr v1.2.2 // indirect
7264
github.com/go-openapi/jsonpointer v0.21.0 // indirect
7365
github.com/go-openapi/jsonreference v0.21.0 // indirect
7466
github.com/go-openapi/swag v0.23.0 // indirect
@@ -84,9 +76,6 @@ require (
8476
github.com/google/go-cmp v0.6.0 // indirect
8577
github.com/google/gofuzz v1.2.0 // indirect
8678
github.com/google/uuid v1.6.0 // indirect
87-
github.com/gorilla/websocket v1.5.0 // indirect
88-
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0 // indirect
89-
github.com/grpc-ecosystem/grpc-gateway/v2 v2.22.0 // indirect
9079
github.com/hbollon/go-edlib v1.6.0 // indirect
9180
github.com/imdario/mergo v0.3.16 // indirect
9281
github.com/inconshreveable/mousetrap v1.1.0 // indirect
@@ -104,12 +93,11 @@ require (
10493
github.com/mattn/go-isatty v0.0.20 // indirect
10594
github.com/mattn/go-runewidth v0.0.16 // indirect
10695
github.com/microsoft/go-mssqldb v1.7.2 // indirect
107-
github.com/moby/spdystream v0.4.0 // indirect
10896
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
10997
github.com/modern-go/reflect2 v1.0.2 // indirect
11098
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
111-
github.com/mxk/go-flowrate v0.0.0-20140419014527-cca7078d478f // indirect
11299
github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c // indirect
100+
github.com/pkg/errors v0.9.1 // indirect
113101
github.com/prometheus/client_golang v1.20.5 // indirect
114102
github.com/prometheus/client_model v0.6.1 // indirect
115103
github.com/prometheus/common v0.55.0 // indirect
@@ -120,20 +108,6 @@ require (
120108
github.com/spf13/pflag v1.0.5 // indirect
121109
github.com/stoewer/go-strcase v1.3.0 // indirect
122110
github.com/x448/float16 v0.8.4 // indirect
123-
go.etcd.io/etcd/api/v3 v3.5.14 // indirect
124-
go.etcd.io/etcd/client/pkg/v3 v3.5.14 // indirect
125-
go.etcd.io/etcd/client/v3 v3.5.14 // indirect
126-
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.53.0 // indirect
127-
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.54.0 // indirect
128-
go.opentelemetry.io/otel v1.29.0 // indirect
129-
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.29.0 // indirect
130-
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.29.0 // indirect
131-
go.opentelemetry.io/otel/metric v1.29.0 // indirect
132-
go.opentelemetry.io/otel/sdk v1.29.0 // indirect
133-
go.opentelemetry.io/otel/trace v1.29.0 // indirect
134-
go.opentelemetry.io/proto/otlp v1.3.1 // indirect
135-
go.uber.org/multierr v1.11.0 // indirect
136-
go.uber.org/zap v1.27.0 // indirect
137111
golang.org/x/crypto v0.29.0 // indirect
138112
golang.org/x/net v0.31.0 // indirect
139113
golang.org/x/oauth2 v0.22.0 // indirect
@@ -145,20 +119,14 @@ require (
145119
gomodules.xyz/jsonpatch/v2 v2.4.0 // indirect
146120
google.golang.org/genproto/googleapis/api v0.0.0-20240827150818-7e3bb234dfed // indirect
147121
google.golang.org/genproto/googleapis/rpc v0.0.0-20240827150818-7e3bb234dfed // indirect
148-
google.golang.org/grpc v1.65.0 // indirect
149122
google.golang.org/protobuf v1.35.1 // indirect
150123
gopkg.in/evanphx/json-patch.v4 v4.12.0 // indirect
151124
gopkg.in/inf.v0 v0.9.1 // indirect
152-
gopkg.in/natefinch/lumberjack.v2 v2.2.1 // indirect
153125
gopkg.in/yaml.v2 v2.4.0 // indirect
154126
gopkg.in/yaml.v3 v3.0.1 // indirect
155-
k8s.io/apiserver v0.31.2 // indirect
156-
k8s.io/component-base v0.31.2 // indirect
157127
k8s.io/klog/v2 v2.130.1 // indirect
158-
k8s.io/kms v0.31.2 // indirect
159128
k8s.io/kube-openapi v0.0.0-20240827152857-f7e401e7b4c2 // indirect
160129
k8s.io/utils v0.0.0-20240821151609-f90d01438635 // indirect
161-
sigs.k8s.io/apiserver-network-proxy/konnectivity-client v0.30.3 // indirect
162130
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
163131
sigs.k8s.io/structured-merge-diff/v4 v4.4.1 // indirect
164132
)

0 commit comments

Comments
 (0)