Skip to content

Commit

Permalink
Merge pull request #4 from Rickyf115/master
Browse files Browse the repository at this point in the history
updating golang deps
  • Loading branch information
rmb938 committed May 2, 2024
2 parents bf2739e + 4011c0e commit d89121d
Show file tree
Hide file tree
Showing 9 changed files with 300 additions and 369 deletions.
4 changes: 2 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ version: 2
jobs:
build:
docker:
- image: circleci/golang:1.14
- image: cimg/go:1.22.2
steps:
- checkout
- run:
Expand Down Expand Up @@ -35,7 +35,7 @@ jobs:

publish-image:
docker:
- image: circleci/golang:1.14
- image: cimg/go:1.22.2
steps:
- checkout
- run:
Expand Down
76 changes: 64 additions & 12 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,17 +1,69 @@
module github.com/rmb938/kubeadm-backup

go 1.14
go 1.22

require (
cloud.google.com/go/storage v1.5.0
github.com/go-logr/logr v0.1.0
github.com/go-logr/zapr v0.1.1
github.com/minio/minio-go/v6 v6.0.52
github.com/pkg/errors v0.8.1
github.com/prometheus/client_golang v1.10.0
go.etcd.io/etcd v0.0.0-20200401174654-e694b7bb0875
go.uber.org/zap v1.14.1
golang.org/x/oauth2 v0.0.0-20191202225959-858c2ad4c8b6
google.golang.org/api v0.15.0
gopkg.in/yaml.v2 v2.2.2
cloud.google.com/go/storage v1.40.0
github.com/go-logr/logr v1.4.1
github.com/go-logr/zapr v1.3.0
github.com/minio/minio-go/v6 v6.0.57
github.com/prometheus/client_golang v1.19.0
go.etcd.io/etcd/client/v3 v3.5.13
go.uber.org/zap v1.27.0
golang.org/x/oauth2 v0.19.0
google.golang.org/api v0.177.0
gopkg.in/yaml.v2 v2.4.0
)

require (
cloud.google.com/go v0.112.2 // indirect
cloud.google.com/go/auth v0.3.0 // indirect
cloud.google.com/go/auth/oauth2adapt v0.2.2 // indirect
cloud.google.com/go/compute/metadata v0.3.0 // indirect
cloud.google.com/go/iam v1.1.8 // indirect
github.com/beorn7/perks v1.0.1 // 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/felixge/httpsnoop v1.0.4 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/protobuf v1.5.4 // indirect
github.com/google/s2a-go v0.1.7 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/googleapis/enterprise-certificate-proxy v0.3.2 // indirect
github.com/googleapis/gax-go/v2 v2.12.3 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/klauspost/cpuid/v2 v2.2.7 // indirect
github.com/minio/md5-simd v1.1.2 // indirect
github.com/minio/sha256-simd v1.0.1 // indirect
github.com/mitchellh/go-homedir v1.1.0 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/prometheus/client_model v0.6.1 // indirect
github.com/prometheus/common v0.53.0 // indirect
github.com/prometheus/procfs v0.14.0 // indirect
go.etcd.io/etcd/api/v3 v3.5.13 // indirect
go.etcd.io/etcd/client/pkg/v3 v3.5.13 // indirect
go.opencensus.io v0.24.0 // indirect
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.51.0 // indirect
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.51.0 // indirect
go.opentelemetry.io/otel v1.26.0 // indirect
go.opentelemetry.io/otel/metric v1.26.0 // indirect
go.opentelemetry.io/otel/sdk v1.26.0 // indirect
go.opentelemetry.io/otel/trace v1.26.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
golang.org/x/crypto v0.22.0 // indirect
golang.org/x/net v0.24.0 // indirect
golang.org/x/sync v0.7.0 // indirect
golang.org/x/sys v0.19.0 // indirect
golang.org/x/text v0.14.0 // indirect
golang.org/x/time v0.5.0 // indirect
google.golang.org/genproto v0.0.0-20240429193739-8cf5692501f6 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20240429193739-8cf5692501f6 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240429193739-8cf5692501f6 // indirect
google.golang.org/grpc v1.63.2 // indirect
google.golang.org/protobuf v1.34.0 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
)
504 changes: 194 additions & 310 deletions go.sum

Large diffs are not rendered by default.

24 changes: 11 additions & 13 deletions pkg/backup/backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ import (
"path"
"time"

"github.com/pkg/errors"

"github.com/rmb938/kubeadm-backup/pkg/blob"
"github.com/rmb938/kubeadm-backup/pkg/etcd"
)
Expand Down Expand Up @@ -42,21 +40,21 @@ func (b *backup) Take() error {
defer syncCTXCancel()
err := b.etcdClient.Sync(syncCTX)
if err != nil {
return errors.Wrap(err, "error syncing etcd endpoints")
return fmt.Errorf("error syncing etcd endpoints: %w", err)
}

// take etcd snapshot
snapshotCTX, snapshotCTXCancel := context.WithTimeout(context.Background(), 2*time.Minute)
defer snapshotCTXCancel()
snapshotReader, err := b.etcdClient.Snapshot(snapshotCTX)
if err != nil {
return errors.Wrap(err, "error trying to snapshot etcd")
return fmt.Errorf("error trying to snapshot etcd: %w", err)
}
defer snapshotReader.Close()
// write snapshot to buffer, tar header needs a size
snapshotBytesBuff := &bytes.Buffer{}
if _, err := io.Copy(snapshotBytesBuff, snapshotReader); err != nil {
return errors.Wrap(err, "error copying etcd snapshot data to a buffer")
return fmt.Errorf("error copying etcd snapshot data to a buffer: %w", err)
}

// create backup buff, gzip and tar writers
Expand All @@ -73,23 +71,23 @@ func (b *backup) Take() error {
}
err = tarWriter.WriteHeader(snapshotHdr)
if err != nil {
return errors.Wrap(err, "error writing etcd snapshot header to tar")
return fmt.Errorf("error writing etcd snapshot header to tar: %w", err)
}
if _, err = io.Copy(tarWriter, snapshotBytesBuff); err != nil {
return errors.Wrap(err, "error writing etcd snapshot data to tar")
return fmt.Errorf("error writing etcd snapshot data to tar: %w", err)
}

// backup pki
for _, pkiFile := range pkiFiles {
pkiFilePath := path.Join(b.kubeadmPKIDirectory, pkiFile)
f, err := os.Open(pkiFilePath)
if err != nil {
return errors.Wrapf(err, "error opening pki file %s", pkiFilePath)
return fmt.Errorf("error opening pki file %s: %w", pkiFilePath, err)
}

stat, err := f.Stat()
if err != nil {
return errors.Wrapf(err, "error stat pki file %s", pkiFilePath)
return fmt.Errorf("error stat pki file %s: %w", pkiFilePath, err)
}

pkiFileHeader := &tar.Header{
Expand All @@ -101,23 +99,23 @@ func (b *backup) Take() error {

err = tarWriter.WriteHeader(pkiFileHeader)
if err != nil {
return errors.Wrapf(err, "error writing pki file %s header to tar", pkiFile)
return fmt.Errorf("error writing pki file %s header to tar %w", pkiFile, err)
}

if _, err = io.Copy(tarWriter, f); err != nil {
return errors.Wrapf(err, "error writing pki file %s to tar", pkiFile)
return fmt.Errorf("error writing pki file %s to tar: %w", pkiFile, err)
}
}

// close everything
err = tarWriter.Close()
if err != nil {
return errors.Wrap(err, "error closing tar")
return fmt.Errorf("error closing tar: %w", err)
}

err = gzipWriter.Close()
if err != nil {
return errors.Wrap(err, "error closing gzip")
return fmt.Errorf("error closing gzip: %w", err)
}

// create backup
Expand Down
12 changes: 6 additions & 6 deletions pkg/backup/timer.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ package backup

import (
"context"
"github.com/prometheus/client_golang/prometheus"
"github.com/rmb938/kubeadm-backup/pkg/metrics"
"fmt"
"time"

"github.com/pkg/errors"
"github.com/prometheus/client_golang/prometheus"
"github.com/rmb938/kubeadm-backup/pkg/metrics"

"github.com/go-logr/logr"

Expand Down Expand Up @@ -113,7 +113,7 @@ func (bt *backupTimer) cleanBackups() error {

objectTime, err := time.Parse(time.RFC3339Nano, objectName[7:len(objectName)-7])
if err != nil {
return errors.Wrapf(err, "error parsing backup time for object %s", objectName)
return fmt.Errorf("error parsing backup time for object %s: %w", objectName, err)
}

now := time.Now()
Expand All @@ -125,13 +125,13 @@ func (bt *backupTimer) cleanBackups() error {
defer deleteCancel()
err = bt.blobClient.Delete(deleteCTX, objectName)
if err != nil {
return errors.Wrapf(err, "error deleting old backup taken at %v", objectTime.Format(time.RFC3339Nano))
return fmt.Errorf("error deleting old backup taken at %v: %w", objectTime.Format(time.RFC3339Nano), err)
}

bt.log.Info("Deleted old backup", "backup-time", objectTime.Format(time.RFC3339Nano))
}
default:
return errors.Errorf("Unknown type from objects channel: %T", objInterface)
return fmt.Errorf("Unknown type from objects channel: %T", objInterface)
}
}

Expand Down
16 changes: 8 additions & 8 deletions pkg/blob/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ package blob

import (
"context"
"io/ioutil"
"fmt"
"os"
"strings"

"github.com/pkg/errors"
"gopkg.in/yaml.v2"

"github.com/rmb938/kubeadm-backup/pkg/blob/gcs"
Expand All @@ -27,19 +27,19 @@ type BlobStorageConfig struct {
func CreateBlobClientFromConfig(configFilePath string) (BlobClient, error) {
blobStorageConfig := &BlobStorageConfig{}

rawConfig, err := ioutil.ReadFile(configFilePath)
rawConfig, err := os.ReadFile(configFilePath)
if err != nil {
return nil, errors.Wrapf(err, "error reading blob storage config file %s", configFilePath)
return nil, fmt.Errorf("error reading blob storage config file %s: %w", configFilePath, err)
}

err = yaml.UnmarshalStrict(rawConfig, blobStorageConfig)
if err != nil {
return nil, errors.Wrap(err, "error unmarshaling blob storage config")
return nil, fmt.Errorf("error unmarshaling blob storage config: %w", err)
}

config, err := yaml.Marshal(blobStorageConfig.Config)
if err != nil {
return nil, errors.Wrap(err, "error marshaling content of blob storage config")
return nil, fmt.Errorf("error marshaling content of blob storage config: %w", err)
}

var client BlobClient
Expand All @@ -49,11 +49,11 @@ func CreateBlobClientFromConfig(configFilePath string) (BlobClient, error) {
case string(S3):
client, err = s3.NewBlobClient(config)
default:
return nil, errors.Errorf("blob storage config with type %s not supported", blobStorageConfig.Type)
return nil, fmt.Errorf("blob storage config with type %s not supported: %w", blobStorageConfig.Type, err)
}

if err != nil {
return nil, errors.Wrapf(err, "failed to create blob client %s", blobStorageConfig.Type)
return nil, fmt.Errorf("failed to create blob client %s: %w", blobStorageConfig.Type, err)
}

return client, nil
Expand Down
15 changes: 7 additions & 8 deletions pkg/blob/gcs/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"runtime"

"cloud.google.com/go/storage"
"github.com/pkg/errors"
"golang.org/x/oauth2/google"
"google.golang.org/api/iterator"
"google.golang.org/api/option"
Expand All @@ -30,24 +29,24 @@ func NewBlobClient(ctx context.Context, rawConfig []byte) (*blobClient, error) {
config := &blobStorageConfig{}
err := yaml.Unmarshal(rawConfig, config)
if err != nil {
return nil, errors.Wrap(err, "error parsing gcs blob storage config")
return nil, fmt.Errorf("error parsing gcs blob storage config: %w", err)
}

if config.Bucket == "" {
return nil, errors.New("missing gcs bucket name in blob storage config")
return nil, fmt.Errorf("missing gcs bucket name in blob storage config: %w", err)
}

if len(config.ServiceAccount) > 0 {
credentials, err := google.CredentialsFromJSON(ctx, []byte(config.ServiceAccount), storage.ScopeFullControl)
if err != nil {
return nil, errors.Wrap(err, "failed to create credentials from JSON")
return nil, fmt.Errorf("failed to create credentials from JSON: %w", err)
}

opts = append(opts, option.WithCredentials(credentials))
} else {
credentials, err := google.FindDefaultCredentials(ctx, storage.ScopeFullControl)
if err != nil {
return nil, errors.Wrap(err, "failed to find default credentials")
return nil, fmt.Errorf("failed to find default credentials: %w", err)
}

opts = append(opts, option.WithCredentials(credentials))
Expand All @@ -58,7 +57,7 @@ func NewBlobClient(ctx context.Context, rawConfig []byte) (*blobClient, error) {

gcsClient, err := storage.NewClient(context.Background(), opts...)
if err != nil {
return nil, errors.Wrap(err, "error creating gcs client")
return nil, fmt.Errorf("error creating gcs client: %w", err)
}

bc := &blobClient{
Expand All @@ -75,12 +74,12 @@ func (bc *blobClient) Create(ctx context.Context, objectName string, reader io.R

_, err := io.Copy(objWriter, reader)
if err != nil {
return errors.Wrapf(err, "error writing object %s to bucket %s", objectName, bc.config.Bucket)
return fmt.Errorf("error writing object %s to bucket %s: %w", objectName, bc.config.Bucket, err)
}

err = objWriter.Close()
if err != nil {
return errors.Wrapf(err, "error closing object writer")
return fmt.Errorf("error closing object writer: %w", err)
}

return nil
Expand Down
5 changes: 2 additions & 3 deletions pkg/blob/s3/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (

"github.com/minio/minio-go/v6"
"github.com/minio/minio-go/v6/pkg/credentials"
"github.com/pkg/errors"
"gopkg.in/yaml.v2"
)

Expand Down Expand Up @@ -48,7 +47,7 @@ func NewBlobClient(rawConfig []byte) (*blobClient, error) {
config := &defaultConfig
err := yaml.Unmarshal(rawConfig, config)
if err != nil {
return nil, errors.Wrap(err, "error parsing s3 blob storage config")
return nil, fmt.Errorf("error parsing s3 blob storage config: %w", err)
}

var chain []credentials.Provider
Expand All @@ -75,7 +74,7 @@ func NewBlobClient(rawConfig []byte) (*blobClient, error) {

minioClient, err := minio.NewWithCredentials(config.Endpoint, credentials.NewChainCredentials(chain), !config.Insecure, "")
if err != nil {
return nil, errors.Wrap(err, "error creating s3 client")
return nil, fmt.Errorf("error creating s3 client: %w", err)
}

minioClient.SetAppInfo("kube-baremetal", fmt.Sprintf("%s (%s)", "0.0.1", runtime.Version()))
Expand Down
Loading

0 comments on commit d89121d

Please sign in to comment.