diff --git a/cmd/cl-adm/cmd/create/create_peer.go b/cmd/cl-adm/cmd/create/create_peer.go index 2b259cc92..514bd1907 100644 --- a/cmd/cl-adm/cmd/create/create_peer.go +++ b/cmd/cl-adm/cmd/create/create_peer.go @@ -113,7 +113,7 @@ func (o *PeerOptions) createGWCTL() error { // Run the 'create peer' subcommand. func (o *PeerOptions) Run() error { if _, err := idna.Lookup.ToASCII(o.Name); err != nil { - return fmt.Errorf("peer name is not a valid DNS name: %v", err) + return fmt.Errorf("peer name is not a valid DNS name: %w", err) } if err := verifyNotExists(o.Name); err != nil { diff --git a/cmd/cl-adm/templates/docker.go b/cmd/cl-adm/templates/docker.go index 14aae699e..0523d1991 100644 --- a/cmd/cl-adm/templates/docker.go +++ b/cmd/cl-adm/templates/docker.go @@ -74,7 +74,7 @@ func CreateDockerRunScripts(args map[string]interface{}, outDir string) error { var dockerRunScript bytes.Buffer t := template.Must(template.New("").Parse(dockerRunTemplate)) if err := t.Execute(&dockerRunScript, args); err != nil { - return fmt.Errorf("cannot create docker run script off template: %v", err) + return fmt.Errorf("cannot create docker run script off template: %w", err) } outPath := filepath.Join(outDir, config.DockerRunFile) diff --git a/cmd/cl-adm/templates/k8s.go b/cmd/cl-adm/templates/k8s.go index c9a5c9d47..6a23006a2 100644 --- a/cmd/cl-adm/templates/k8s.go +++ b/cmd/cl-adm/templates/k8s.go @@ -269,7 +269,7 @@ func CreateK8SConfig(args map[string]interface{}, outDir string) error { var k8sConfig bytes.Buffer t := template.Must(template.New("").Parse(k8sTemplate)) if err := t.Execute(&k8sConfig, args); err != nil { - return fmt.Errorf("cannot create k8s configuration off template: %v", err) + return fmt.Errorf("cannot create k8s configuration off template: %w", err) } outPath := filepath.Join(outDir, config.K8SYamlFile) diff --git a/cmd/cl-dataplane/app/envoy.go b/cmd/cl-dataplane/app/envoy.go index 093b4975f..e2a2335e5 100644 --- a/cmd/cl-dataplane/app/envoy.go +++ b/cmd/cl-dataplane/app/envoy.go @@ -69,7 +69,7 @@ func (o *Options) runEnvoy(peerName, dataplaneID string) error { var envoyConf bytes.Buffer t := template.Must(template.New("").Parse(envoyConfigurationTemplate)) if err := t.Execute(&envoyConf, envoyConfArgs); err != nil { - return fmt.Errorf("cannot create Envoy configuration off template: %v", err) + return fmt.Errorf("cannot create Envoy configuration off template: %w", err) } args := []string{ diff --git a/cmd/cl-dataplane/app/server.go b/cmd/cl-dataplane/app/server.go index 8f1059c2a..bd3409200 100644 --- a/cmd/cl-dataplane/app/server.go +++ b/cmd/cl-dataplane/app/server.go @@ -69,7 +69,7 @@ func (o *Options) Run() error { if o.LogFile != "" { f, err := os.OpenFile(o.LogFile, os.O_APPEND|os.O_CREATE|os.O_RDWR, 0666) if err != nil { - return fmt.Errorf("unable to open log file: %v", err) + return fmt.Errorf("unable to open log file: %w", err) } defer func() { @@ -84,7 +84,7 @@ func (o *Options) Run() error { // set log level logLevel, err := log.ParseLevel(o.LogLevel) if err != nil { - return fmt.Errorf("unable to set log level: %v", err) + return fmt.Errorf("unable to set log level: %w", err) } log.SetLevel(logLevel) diff --git a/cmd/cl-go-dataplane/app/server.go b/cmd/cl-go-dataplane/app/server.go index 6171a561a..8ec26fee1 100644 --- a/cmd/cl-go-dataplane/app/server.go +++ b/cmd/cl-go-dataplane/app/server.go @@ -92,7 +92,7 @@ func (o *Options) runGoDataplane(peerName, dataplaneID string, parsedCertData *u tlsConfig := parsedCertData.ClientConfig(cpapi.GRPCServerName(peerName)) xdsClient := dpclient.NewXDSClient(dataplane, controlplaneTarget, tlsConfig) err := xdsClient.Run() - return fmt.Errorf("xDS Client stopped: %v", err) + return fmt.Errorf("xDS Client stopped: %w", err) } // Run the dataplane. @@ -101,7 +101,7 @@ func (o *Options) Run() error { if o.LogFile != "" { f, err := os.OpenFile(o.LogFile, os.O_APPEND|os.O_CREATE|os.O_RDWR, 0666) if err != nil { - return fmt.Errorf("unable to open log file: %v", err) + return fmt.Errorf("unable to open log file: %w", err) } defer func() { @@ -116,7 +116,7 @@ func (o *Options) Run() error { // set log level logLevel, err := log.ParseLevel(o.LogLevel) if err != nil { - return fmt.Errorf("unable to set log level: %v", err) + return fmt.Errorf("unable to set log level: %w", err) } log.SetLevel(logLevel) diff --git a/cmd/gwctl/subcommand/gwctl.go b/cmd/gwctl/subcommand/gwctl.go index 2e3f1d70b..6602b2e41 100644 --- a/cmd/gwctl/subcommand/gwctl.go +++ b/cmd/gwctl/subcommand/gwctl.go @@ -122,7 +122,7 @@ func (o *stateGetOptions) run() error { sJSON, err := json.MarshalIndent(d, "", " ") if err != nil { - return fmt.Errorf("error: %v", err.Error()) + return fmt.Errorf("error: %w", err) } fmt.Println(string(sJSON)) @@ -166,11 +166,11 @@ func (o *allGetOptions) run() error { fmt.Printf("%s:\n", name) d, err := o.List() if err != nil { - return fmt.Errorf("error: %v", err.Error()) + return fmt.Errorf("error: %w", err) } sJSON, err := json.Marshal(d) if err != nil { - return fmt.Errorf("error: %v", err.Error()) + return fmt.Errorf("error: %w", err) } fmt.Println(string(sJSON)) } diff --git a/pkg/controlplane/authz.go b/pkg/controlplane/authz.go index cc34f57c7..1fa710186 100644 --- a/pkg/controlplane/authz.go +++ b/pkg/controlplane/authz.go @@ -105,7 +105,7 @@ func (cp *Instance) AuthorizeEgress(req *EgressAuthorizationRequest) (*EgressAut serverResp, err := client.Authorize(&api.AuthorizationRequest{Service: req.Import}) if err != nil { - return nil, fmt.Errorf("unable to get access token from peer: %v", err) + return nil, fmt.Errorf("unable to get access token from peer: %w", err) } resp := &EgressAuthorizationResponse{ @@ -152,13 +152,13 @@ func (cp *Instance) AuthorizeIngress(req *IngressAuthorizationRequest) (*Ingress Claim(api.ExportNameJWTClaim, export.Name). Build() if err != nil { - return nil, fmt.Errorf("unable to generate access token: %v", err) + return nil, fmt.Errorf("unable to generate access token: %w", err) } // sign access token signed, err := jwt.Sign(token, jwtSignatureAlgorithm, cp.jwkSignKey) if err != nil { - return nil, fmt.Errorf("unable to sign access token: %v", err) + return nil, fmt.Errorf("unable to sign access token: %w", err) } resp.AccessToken = string(signed) diff --git a/pkg/controlplane/client.go b/pkg/controlplane/client.go index 27cb5fcf4..ab32cc159 100644 --- a/pkg/controlplane/client.go +++ b/pkg/controlplane/client.go @@ -61,7 +61,7 @@ type remoteServerAuthorizationResponse struct { func (c *client) Authorize(req *api.AuthorizationRequest) (*remoteServerAuthorizationResponse, error) { body, err := json.Marshal(req) if err != nil { - return nil, fmt.Errorf("unable to serialize authorization request: %v", err) + return nil, fmt.Errorf("unable to serialize authorization request: %w", err) } var serverResp *jsonapi.Response @@ -96,7 +96,7 @@ func (c *client) Authorize(req *api.AuthorizationRequest) (*remoteServerAuthoriz var authResp api.AuthorizationResponse if err := json.Unmarshal(serverResp.Body, &authResp); err != nil { - return nil, fmt.Errorf("unable to parse server response: %v", err) + return nil, fmt.Errorf("unable to parse server response: %w", err) } resp.Allowed = true diff --git a/pkg/controlplane/instance.go b/pkg/controlplane/instance.go index ec5ec0ca7..64fd3e6fd 100644 --- a/pkg/controlplane/instance.go +++ b/pkg/controlplane/instance.go @@ -273,7 +273,7 @@ func (cp *Instance) CreateImport(imp *cpstore.Import) error { port, err := cp.ports.Lease(imp.Port) if err != nil { - return fmt.Errorf("cannot generate listening port: %v", err) + return fmt.Errorf("cannot generate listening port: %w", err) } imp.Port = port @@ -483,7 +483,7 @@ func (cp *Instance) GetXDSListenerManager() cache.Cache { func (cp *Instance) init() error { // generate the JWK key if err := cp.generateJWK(); err != nil { - return fmt.Errorf("unable to generate JWK key: %v", err) + return fmt.Errorf("unable to generate JWK key: %w", err) } // add peers @@ -533,17 +533,17 @@ func (cp *Instance) generateJWK() error { // generate RSA key-pair rsaKey, err := rsa.GenerateKey(rand.Reader, 2048) if err != nil { - return fmt.Errorf("unable to generate RSA keys: %v", err) + return fmt.Errorf("unable to generate RSA keys: %w", err) } jwkSignKey, err := jwk.New(rsaKey) if err != nil { - return fmt.Errorf("unable to create JWK signing key: %v", err) + return fmt.Errorf("unable to create JWK signing key: %w", err) } jwkVerifyKey, err := jwk.New(rsaKey.PublicKey) if err != nil { - return fmt.Errorf("unable to create JWK verifing key: %v", err) + return fmt.Errorf("unable to create JWK verifing key: %w", err) } cp.jwkSignKey = jwkSignKey @@ -557,19 +557,19 @@ func NewInstance(peerTLS *util.ParsedCertData, storeManager store.Manager, platf peers, err := cpstore.NewPeers(storeManager) if err != nil { - return nil, fmt.Errorf("cannot load peers from store: %v", err) + return nil, fmt.Errorf("cannot load peers from store: %w", err) } logger.Infof("Loaded %d peers.", peers.Len()) exports, err := cpstore.NewExports(storeManager) if err != nil { - return nil, fmt.Errorf("cannot load exports from store: %v", err) + return nil, fmt.Errorf("cannot load exports from store: %w", err) } logger.Infof("Loaded %d exports.", exports.Len()) imports, err := cpstore.NewImports(storeManager) if err != nil { - return nil, fmt.Errorf("cannot load imports from store: %v", err) + return nil, fmt.Errorf("cannot load imports from store: %w", err) } logger.Infof("Loaded %d imports.", imports.Len()) @@ -581,7 +581,7 @@ func NewInstance(peerTLS *util.ParsedCertData, storeManager store.Manager, platf policies, err := cpstore.NewAccessPolicies(storeManager) if err != nil { - return nil, fmt.Errorf("cannot load access policies from store: %v", err) + return nil, fmt.Errorf("cannot load access policies from store: %w", err) } logger.Infof("Loaded %d access policies.", policies.Len()) diff --git a/pkg/controlplane/server/controller.go b/pkg/controlplane/server/controller.go index cb64b6260..59d36dee0 100644 --- a/pkg/controlplane/server/controller.go +++ b/pkg/controlplane/server/controller.go @@ -52,7 +52,7 @@ func (c *Controller) Run() error { // start server listeners for listenAddress, server := range c.servers { if err := server.Listen(listenAddress); err != nil { - return fmt.Errorf("unable to create listener for server '%s' on %s: %v", + return fmt.Errorf("unable to create listener for server '%s' on %s: %w", server.Name(), listenAddress, err) } } @@ -121,7 +121,7 @@ func (c *Controller) Run() error { for server, err := range c.errors { if err != nil { errs = append(errs, fmt.Errorf( - "error running server '%s': %v", server.Name(), err)) + "error running server '%s': %w", server.Name(), err)) } } return errors.Join(errs...) @@ -135,7 +135,7 @@ func (c *Controller) Stop() error { for _, server := range c.servers { if err := server.Stop(); err != nil { errs = append(errs, fmt.Errorf( - "unable to stop server '%s': %v", server.Name(), err)) + "unable to stop server '%s': %w", server.Name(), err)) } } @@ -150,7 +150,7 @@ func (c *Controller) GracefulStop() error { for _, server := range c.servers { if err := server.GracefulStop(); err != nil { errs = append(errs, fmt.Errorf( - "unable to gracefully stop server '%s': %v", server.Name(), err)) + "unable to gracefully stop server '%s': %w", server.Name(), err)) } } diff --git a/pkg/controlplane/server/http/api.go b/pkg/controlplane/server/http/api.go index bdce82120..a5c6d9c74 100644 --- a/pkg/controlplane/server/http/api.go +++ b/pkg/controlplane/server/http/api.go @@ -65,7 +65,7 @@ type peerHandler struct { func (h *peerHandler) Decode(data []byte) (any, error) { var peer api.Peer if err := json.Unmarshal(data, &peer); err != nil { - return nil, fmt.Errorf("cannot decode peer: %v", err) + return nil, fmt.Errorf("cannot decode peer: %w", err) } if peer.Name == "" { @@ -134,7 +134,7 @@ type exportHandler struct { func (h *exportHandler) Decode(data []byte) (any, error) { var export api.Export if err := json.Unmarshal(data, &export); err != nil { - return nil, fmt.Errorf("cannot decode export: %v", err) + return nil, fmt.Errorf("cannot decode export: %w", err) } if export.Name == "" { @@ -201,7 +201,7 @@ type importHandler struct { func (h *importHandler) Decode(data []byte) (any, error) { var imp api.Import if err := json.Unmarshal(data, &imp); err != nil { - return nil, fmt.Errorf("cannot decode import: %v", err) + return nil, fmt.Errorf("cannot decode import: %w", err) } if imp.Name == "" { @@ -274,7 +274,7 @@ type bindingHandler struct { func (h *bindingHandler) Decode(data []byte) (any, error) { var binding api.Binding if err := json.Unmarshal(data, &binding); err != nil { - return nil, fmt.Errorf("cannot decode binding: %v", err) + return nil, fmt.Errorf("cannot decode binding: %w", err) } if binding.Spec.Import == "" { @@ -329,7 +329,7 @@ type accessPolicyHandler struct { func (h *accessPolicyHandler) Decode(data []byte) (any, error) { var policy api.Policy if err := json.Unmarshal(data, &policy); err != nil { - return nil, fmt.Errorf("cannot decode access policy: %v", err) + return nil, fmt.Errorf("cannot decode access policy: %w", err) } if len(policy.Spec.Blob) == 0 { diff --git a/pkg/dataplane/client/xds.go b/pkg/dataplane/client/xds.go index dbfd0a029..3bf2cd1f8 100644 --- a/pkg/dataplane/client/xds.go +++ b/pkg/dataplane/client/xds.go @@ -95,7 +95,7 @@ func (x *XDSClient) Run() error { for resource, err := range x.errors { if err != nil { errs = append(errs, fmt.Errorf( - "error running fetcher '%s': %v", resource, err)) + "error running fetcher '%s': %w", resource, err)) } } diff --git a/pkg/dataplane/server/server.go b/pkg/dataplane/server/server.go index 6f79a4315..f982c73f1 100644 --- a/pkg/dataplane/server/server.go +++ b/pkg/dataplane/server/server.go @@ -50,7 +50,7 @@ func (d *Dataplane) StartSNIServer(dataplaneServerAddress string) error { d.logger.Infof("SNI proxy starting at %s.", dataplaneListenAddress) err := sniProxy.Listen(dataplaneListenAddress) if err != nil { - return fmt.Errorf("unable to create listener for server on %s: %v", + return fmt.Errorf("unable to create listener for server on %s: %w", dataplaneListenAddress, err) } return sniProxy.Serve() @@ -129,16 +129,16 @@ func (d *Dataplane) hijackConn(w http.ResponseWriter) (net.Conn, error) { // Hijack the connection peerConn, _, err := hj.Hijack() if err != nil { - return nil, fmt.Errorf("hijacking failed: %v", err) + return nil, fmt.Errorf("hijacking failed: %w", err) } if err = peerConn.SetDeadline(time.Time{}); err != nil { - return nil, fmt.Errorf("failed to clear deadlines on connection: %v", err) + return nil, fmt.Errorf("failed to clear deadlines on connection: %w", err) } if _, err := peerConn.Write([]byte{}); err != nil { _ = peerConn.Close() // close the connection ignoring errors - return nil, fmt.Errorf("failed to write to connection: %v", err) + return nil, fmt.Errorf("failed to write to connection: %w", err) } fmt.Fprintf(peerConn, "HTTP/1.1 200 OK\r\nContent-Type: text/plain\r\n\r\n") diff --git a/pkg/store/kv/bolt/store.go b/pkg/store/kv/bolt/store.go index 02914c0f8..25a194cb7 100644 --- a/pkg/store/kv/bolt/store.go +++ b/pkg/store/kv/bolt/store.go @@ -106,7 +106,7 @@ func Open(path string) (*Store, error) { // open db, err := bbolt.Open(path, 0666, nil) if err != nil { - return nil, fmt.Errorf("unable to open store: %v", err) + return nil, fmt.Errorf("unable to open store: %w", err) } // create the single bucket we use (if does not exist) @@ -115,7 +115,7 @@ func Open(path string) (*Store, error) { return err }) if err != nil { - return nil, fmt.Errorf("unable to create bucket: %v", err) + return nil, fmt.Errorf("unable to create bucket: %w", err) } return &Store{ diff --git a/pkg/store/kv/store.go b/pkg/store/kv/store.go index 317f34371..315fda695 100644 --- a/pkg/store/kv/store.go +++ b/pkg/store/kv/store.go @@ -46,7 +46,7 @@ func (s *ObjectStore) Create(name string, value any) error { // serialize encoded, err := json.Marshal(value) if err != nil { - return fmt.Errorf("unable to serialize object: %v", err) + return fmt.Errorf("unable to serialize object: %w", err) } // persist to store @@ -69,13 +69,13 @@ func (s *ObjectStore) Update(name string, mutator func(any) any) error { // de-serialize old value decoded := reflect.New(s.objectType).Interface() if err := json.Unmarshal(value, decoded); err != nil { - return nil, fmt.Errorf("unable to decode value for object '%s': %v", name, err) + return nil, fmt.Errorf("unable to decode value for object '%s': %w", name, err) } // serialize mutated value encoded, err := json.Marshal(mutator(decoded)) if err != nil { - return nil, fmt.Errorf("unable to serialize mutated object '%s': %v", name, err) + return nil, fmt.Errorf("unable to serialize mutated object '%s': %w", name, err) } return encoded, nil @@ -106,7 +106,7 @@ func (s *ObjectStore) GetAll() ([]any, error) { decoded := reflect.New(s.objectType).Interface() if err := json.Unmarshal(value, decoded); err != nil { - return fmt.Errorf("unable to decode object for key %v: %v", key, err) + return fmt.Errorf("unable to decode object for key %v: %w", key, err) } objects = append(objects, decoded) diff --git a/pkg/util/jsonapi/client.go b/pkg/util/jsonapi/client.go index a23059ece..d4c86ddf0 100644 --- a/pkg/util/jsonapi/client.go +++ b/pkg/util/jsonapi/client.go @@ -73,7 +73,7 @@ func (c *Client) do(method, path string, body []byte) (*Response, error) { req, err := http.NewRequest(method, c.serverURL+path, bytes.NewBuffer(body)) if err != nil { - return nil, fmt.Errorf("unable to create http request: %v", err) + return nil, fmt.Errorf("unable to create http request: %w", err) } if body != nil { @@ -82,7 +82,7 @@ func (c *Client) do(method, path string, body []byte) (*Response, error) { resp, err := c.client.Do(req) if err != nil { - return nil, fmt.Errorf("unable to perform http request: %v", err) + return nil, fmt.Errorf("unable to perform http request: %w", err) } defer func() { @@ -93,7 +93,7 @@ func (c *Client) do(method, path string, body []byte) (*Response, error) { body, err = io.ReadAll(resp.Body) if err != nil { - return nil, fmt.Errorf("unable to read response body: %v", err) + return nil, fmt.Errorf("unable to read response body: %w", err) } requestLogger.WithField("body-length", len(body)).Debugf("Received response: %d.", resp.StatusCode) diff --git a/pkg/util/log/log.go b/pkg/util/log/log.go index 6beedf153..759a76fd1 100644 --- a/pkg/util/log/log.go +++ b/pkg/util/log/log.go @@ -39,7 +39,7 @@ func SetLog(logLevel string, logFileName string) (*os.File, error) { f, err := os.OpenFile(logFileFullPath, os.O_APPEND|os.O_CREATE|os.O_RDWR, 0600) fmt.Printf("Creating log file: %v\n", logFileFullPath) if err != nil { - return nil, fmt.Errorf("error opening log file: %v", err.Error()) + return nil, fmt.Errorf("error opening log file: %w", err) } // assign it to the standard logger logrus.SetOutput(f) diff --git a/pkg/util/rest/client.go b/pkg/util/rest/client.go index 461bf36f4..3f072637e 100644 --- a/pkg/util/rest/client.go +++ b/pkg/util/rest/client.go @@ -46,12 +46,12 @@ type Client struct { func (c *Client) Create(object any) error { encoded, err := json.Marshal(object) if err != nil { - return fmt.Errorf("unable to encode object: %v", err) + return fmt.Errorf("unable to encode object: %w", err) } resp, err := c.client.Post(c.basePath, encoded) if err != nil { - return fmt.Errorf("unable to create object: %v", err) + return fmt.Errorf("unable to create object: %w", err) } if resp.Status != http.StatusCreated { @@ -66,12 +66,12 @@ func (c *Client) Create(object any) error { func (c *Client) Update(object any) error { encoded, err := json.Marshal(object) if err != nil { - return fmt.Errorf("unable to encode object: %v", err) + return fmt.Errorf("unable to encode object: %w", err) } resp, err := c.client.Put(c.basePath, encoded) if err != nil { - return fmt.Errorf("unable to update object: %v", err) + return fmt.Errorf("unable to update object: %w", err) } if resp.Status != http.StatusNoContent { @@ -86,7 +86,7 @@ func (c *Client) Update(object any) error { func (c *Client) Get(name string) (any, error) { resp, err := c.client.Get(c.basePath + "/" + name) if err != nil { - return nil, fmt.Errorf("unable to get object: %v", err) + return nil, fmt.Errorf("unable to get object: %w", err) } if resp.Status != http.StatusOK { @@ -96,7 +96,7 @@ func (c *Client) Get(name string) (any, error) { decoded := reflect.New(c.objectType).Interface() if err := json.Unmarshal(resp.Body, decoded); err != nil { - return nil, fmt.Errorf("unable to decode object %v: %v", decoded, err) + return nil, fmt.Errorf("unable to decode object %v: %w", decoded, err) } return decoded, nil @@ -114,14 +114,14 @@ func (c *Client) Delete(object any) error { // delete by object encoded, err := json.Marshal(object) if err != nil { - return fmt.Errorf("cannot encode object: %v", err) + return fmt.Errorf("cannot encode object: %w", err) } body = encoded } resp, err := c.client.Delete(path, body) if err != nil { - return fmt.Errorf("unable to delete object: %v", err) + return fmt.Errorf("unable to delete object: %w", err) } if resp.Status != http.StatusNoContent { @@ -136,7 +136,7 @@ func (c *Client) Delete(object any) error { func (c *Client) List() (any, error) { resp, err := c.client.Get(c.basePath) if err != nil { - return nil, fmt.Errorf("unable to list objects: %v", err) + return nil, fmt.Errorf("unable to list objects: %w", err) } if resp.Status != http.StatusOK { @@ -146,7 +146,7 @@ func (c *Client) List() (any, error) { decoded := reflect.New(c.listType).Interface() if err := json.Unmarshal(resp.Body, decoded); err != nil { - return nil, fmt.Errorf("unable to decode object list %v: %v", decoded, err) + return nil, fmt.Errorf("unable to decode object list %v: %w", decoded, err) } return decoded, nil diff --git a/pkg/util/tls.go b/pkg/util/tls.go index 3a911ea4d..49aec3cfa 100644 --- a/pkg/util/tls.go +++ b/pkg/util/tls.go @@ -24,22 +24,22 @@ import ( func ParseTLSFiles(ca, cert, key string) (*ParsedCertData, error) { rawCA, err := os.ReadFile(ca) if err != nil { - return nil, fmt.Errorf("unable to read CA file '%s': %v", ca, err) + return nil, fmt.Errorf("unable to read CA file '%s': %w", ca, err) } rawCertificate, err := os.ReadFile(cert) if err != nil { - return nil, fmt.Errorf("unable to read certificate file: %v", err) + return nil, fmt.Errorf("unable to read certificate file: %w", err) } rawPrivateKey, err := os.ReadFile(key) if err != nil { - return nil, fmt.Errorf("unable to read private key file: %v", err) + return nil, fmt.Errorf("unable to read private key file: %w", err) } certificate, err := tls.X509KeyPair(rawCertificate, rawPrivateKey) if err != nil { - return nil, fmt.Errorf("unable to parse certificate keypair: %v", err) + return nil, fmt.Errorf("unable to parse certificate keypair: %w", err) } caCertPool := x509.NewCertPool() @@ -49,7 +49,7 @@ func ParseTLSFiles(ca, cert, key string) (*ParsedCertData, error) { x509cert, err := x509.ParseCertificate(certificate.Certificate[0]) if err != nil { - return nil, fmt.Errorf("unable to parse x509 certificate: %v", err) + return nil, fmt.Errorf("unable to parse x509 certificate: %w", err) } return &ParsedCertData{ diff --git a/tests/e2e/utils/kind.go b/tests/e2e/utils/kind.go index 517c1bd71..6fba6ddbe 100644 --- a/tests/e2e/utils/kind.go +++ b/tests/e2e/utils/kind.go @@ -36,12 +36,12 @@ func createClientset() (*kubernetes.Clientset, error) { if err != nil { log.Errorf("failed to create Kubernetes API client: %v", err) - return nil, fmt.Errorf("failed to create Kubernetes API client: %v", err) + return nil, fmt.Errorf("failed to create Kubernetes API client: %w", err) } clientset, err := kubernetes.NewForConfig(config) if err != nil { log.Errorf("failed to create Kubernetes API client: %v", err) - return nil, fmt.Errorf("failed to create Kubernetes API client: %v", err) + return nil, fmt.Errorf("failed to create Kubernetes API client: %w", err) } return clientset, nil } @@ -51,7 +51,7 @@ func IsPodReady(name string) error { namespace := "default" clientset, err := createClientset() if err != nil { - return fmt.Errorf("failed to create Kubernetes API client: %v", err) + return fmt.Errorf("failed to create Kubernetes API client: %w", err) } listOptions := metav1.ListOptions{