Skip to content

Commit

Permalink
Migrate asoctl to eris (#4458)
Browse files Browse the repository at this point in the history
* Update go.mod

* Update imports

* go mod tidy

* Tidy imports

* Code gardening
  • Loading branch information
theunrepentantgeek authored Nov 22, 2024
1 parent 3bb9bf5 commit b98c83f
Show file tree
Hide file tree
Showing 11 changed files with 82 additions and 213 deletions.
8 changes: 4 additions & 4 deletions v2/cmd/asoctl/cmd/clean-crds.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
package cmd

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

ctx := cmd.Context()

apiExtClient, err := v1.NewForConfig(cfg)
if err != nil {
return errors.Wrap(err, "unable to create Kubernetes client")
return eris.Wrap(err, "unable to create Kubernetes client")
}

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

return crd.NewCleaner(
Expand Down
4 changes: 2 additions & 2 deletions v2/cmd/asoctl/cmd/export_template.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
. "github.com/Azure/azure-service-operator/v2/internal/logging"

"github.com/go-logr/logr"
"github.com/pkg/errors"
"github.com/rotisserie/eris"
"github.com/spf13/cobra"
"k8s.io/apimachinery/pkg/runtime/schema"

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

uri = template.URIFromVersion(options.version)
Expand Down
26 changes: 13 additions & 13 deletions v2/cmd/asoctl/cmd/import_azure_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
"github.com/Azure/azure-sdk-for-go/sdk/azcore/cloud"
"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
"github.com/go-logr/logr"
"github.com/pkg/errors"
"github.com/rotisserie/eris"
"github.com/spf13/cobra"

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

// Create an ARM client for requesting resources
client, err := createARMClient(options)
if err != nil {
return errors.Wrapf(err, "failed to create ARM client")
return eris.Wrapf(err, "failed to create ARM client")
}

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

Expand All @@ -163,7 +163,7 @@ func importAzureResource(

if err != nil {
if result.Count() == 0 {
return errors.Wrap(err, "failed to import any resources")
return eris.Wrap(err, "failed to import any resources")
}

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

err = configureImportedResources(options, result)
if err != nil {
return errors.Wrap(err, "failed to apply options to imported resources")
return eris.Wrap(err, "failed to apply options to imported resources")
}

err = writeResources(result, options, log, progressBar)
if err != nil {
return errors.Wrap(err, "failed to write resources")
return eris.Wrap(err, "failed to write resources")
}

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

clientOptions := &genericarmclient.GenericClientOptions{
Expand All @@ -217,15 +217,15 @@ func configureImportedResources(
if len(options.labels) > 0 {
err := result.AddLabels(options.labels)
if err != nil {
return errors.Wrap(err, "failed to add labels")
return eris.Wrap(err, "failed to add labels")
}
}

// Apply annotations
if len(options.annotations) > 0 {
err := result.AddAnnotations(options.annotations)
if err != nil {
return errors.Wrap(err, "failed to add annotations")
return eris.Wrap(err, "failed to add annotations")
}
}

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

return nil
Expand All @@ -258,7 +258,7 @@ func writeResources(
"folder", folder)
err := result.SaveToIndividualFilesInFolder(folder)
if err != nil {
return errors.Wrapf(err, "failed to write into folder %s", folder)
return eris.Wrapf(err, "failed to write into folder %s", folder)
}

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

return nil
Expand Down
36 changes: 2 additions & 34 deletions v2/cmd/asoctl/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ require (
github.com/go-logr/logr v1.4.2
github.com/go-logr/zerologr v1.2.3
github.com/onsi/gomega v1.35.1
github.com/pkg/errors v0.9.1
github.com/rotisserie/eris v0.5.4
github.com/rs/zerolog v1.33.0
github.com/spf13/cobra v1.8.1
github.com/vbauerster/mpb/v8 v8.8.3
Expand Down Expand Up @@ -50,25 +50,17 @@ require (
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/storage/armstorage v1.6.0 // indirect
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/subscription/armsubscription v1.2.0 // indirect
github.com/AzureAD/microsoft-authentication-library-for-go v1.2.2 // indirect
github.com/NYTimes/gziphandler v1.1.1 // indirect
github.com/VividCortex/ewma v1.2.0 // indirect
github.com/acarl005/stripansi v0.0.0-20180116102854-5a71ef0e047d // indirect
github.com/antlr4-go/antlr/v4 v4.13.0 // indirect
github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2 // indirect
github.com/benbjohnson/clock v1.3.5 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/blang/semver/v4 v4.0.0 // indirect
github.com/cenkalti/backoff/v4 v4.3.0 // indirect
github.com/cespare/xxhash/v2 v2.3.0 // indirect
github.com/coreos/go-semver v0.3.1 // indirect
github.com/coreos/go-systemd/v22 v22.5.0 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/emicklei/go-restful/v3 v3.12.1 // indirect
github.com/evanphx/json-patch/v5 v5.9.0 // indirect
github.com/felixge/httpsnoop v1.0.4 // indirect
github.com/fsnotify/fsnotify v1.7.0 // indirect
github.com/fxamacker/cbor/v2 v2.7.0 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/go-openapi/jsonpointer v0.21.0 // indirect
github.com/go-openapi/jsonreference v0.21.0 // indirect
github.com/go-openapi/swag v0.23.0 // indirect
Expand All @@ -84,9 +76,6 @@ require (
github.com/google/go-cmp v0.6.0 // indirect
github.com/google/gofuzz v1.2.0 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/gorilla/websocket v1.5.0 // indirect
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.22.0 // indirect
github.com/hbollon/go-edlib v1.6.0 // indirect
github.com/imdario/mergo v0.3.16 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
Expand All @@ -104,12 +93,11 @@ require (
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mattn/go-runewidth v0.0.16 // indirect
github.com/microsoft/go-mssqldb v1.7.2 // indirect
github.com/moby/spdystream v0.4.0 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/mxk/go-flowrate v0.0.0-20140419014527-cca7078d478f // indirect
github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/prometheus/client_golang v1.20.5 // indirect
github.com/prometheus/client_model v0.6.1 // indirect
github.com/prometheus/common v0.55.0 // indirect
Expand All @@ -120,20 +108,6 @@ require (
github.com/spf13/pflag v1.0.5 // indirect
github.com/stoewer/go-strcase v1.3.0 // indirect
github.com/x448/float16 v0.8.4 // indirect
go.etcd.io/etcd/api/v3 v3.5.14 // indirect
go.etcd.io/etcd/client/pkg/v3 v3.5.14 // indirect
go.etcd.io/etcd/client/v3 v3.5.14 // indirect
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.53.0 // indirect
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.54.0 // indirect
go.opentelemetry.io/otel v1.29.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.29.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.29.0 // indirect
go.opentelemetry.io/otel/metric v1.29.0 // indirect
go.opentelemetry.io/otel/sdk v1.29.0 // indirect
go.opentelemetry.io/otel/trace v1.29.0 // indirect
go.opentelemetry.io/proto/otlp v1.3.1 // indirect
go.uber.org/multierr v1.11.0 // indirect
go.uber.org/zap v1.27.0 // indirect
golang.org/x/crypto v0.29.0 // indirect
golang.org/x/net v0.31.0 // indirect
golang.org/x/oauth2 v0.22.0 // indirect
Expand All @@ -145,20 +119,14 @@ require (
gomodules.xyz/jsonpatch/v2 v2.4.0 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20240827150818-7e3bb234dfed // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240827150818-7e3bb234dfed // indirect
google.golang.org/grpc v1.65.0 // indirect
google.golang.org/protobuf v1.35.1 // indirect
gopkg.in/evanphx/json-patch.v4 v4.12.0 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/natefinch/lumberjack.v2 v2.2.1 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
k8s.io/apiserver v0.31.2 // indirect
k8s.io/component-base v0.31.2 // indirect
k8s.io/klog/v2 v2.130.1 // indirect
k8s.io/kms v0.31.2 // indirect
k8s.io/kube-openapi v0.0.0-20240827152857-f7e401e7b4c2 // indirect
k8s.io/utils v0.0.0-20240821151609-f90d01438635 // indirect
sigs.k8s.io/apiserver-network-proxy/konnectivity-client v0.30.3 // indirect
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.4.1 // indirect
)
Loading

0 comments on commit b98c83f

Please sign in to comment.