Skip to content
This repository has been archived by the owner on Mar 28, 2020. It is now read-only.

Commit

Permalink
refactoring and address comment
Browse files Browse the repository at this point in the history
  • Loading branch information
Jingtao Ren committed Jan 25, 2018
1 parent daaea5d commit ec07d43
Show file tree
Hide file tree
Showing 9 changed files with 57 additions and 40 deletions.
6 changes: 1 addition & 5 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,7 @@

[[constraint]]
name = "golang.org/x/time"

[[constraint]]
name = "github.com/Azure/azure-sdk-for-go"
version = "v11.3.0-beta"
4 changes: 2 additions & 2 deletions pkg/backup/reader/abs_reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ type absReader struct {
abs *storage.BlobStorageClient
}

// NewABSReader return a Reader implementation to read a file from ABS in the form of absReader
func NewABSReader(abs *storage.BlobStorageClient) Reader {
return &absReader{abs}
}
Expand All @@ -53,6 +54,5 @@ func (absr *absReader) Open(path string) (io.ReadCloser, error) {
}

blob := containerRef.GetBlobReference(key)
getBlobOpts := &storage.GetBlobOptions{}
return blob.Get(getBlobOpts)
return blob.Get(&storage.GetBlobOptions{})
}
12 changes: 5 additions & 7 deletions pkg/backup/writer/abs_writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ import (
"fmt"
"io"

"github.com/Azure/azure-sdk-for-go/storage"
"github.com/coreos/etcd-operator/pkg/backup/util"

"github.com/Azure/azure-sdk-for-go/storage"
"github.com/pborman/uuid"
)

Expand All @@ -38,7 +39,7 @@ func NewABSWriter(abs *storage.BlobStorageClient) Writer {

const (
// AzureBlobBlockChunkLimitInBytes 100MiB is the limit
AzureBlobBlockChunkLimitInBytes = 104857600
AzureBlobBlockChunkLimitInBytes = 100 * 1024 * 1024
)

// Write writes the backup file to the given abs path, "<abs-container-name>/<key>".
Expand All @@ -59,9 +60,7 @@ func (absw *absWriter) Write(path string, r io.Reader) (int64, error) {
}

blob := containerRef.GetBlobReference(key)
putBlobOpts := storage.PutBlobOptions{}

err = blob.CreateBlockBlob(&putBlobOpts)
err = blob.CreateBlockBlob(&storage.PutBlobOptions{})
if err != nil {
return 0, err
}
Expand Down Expand Up @@ -92,8 +91,7 @@ func (absw *absWriter) Write(path string, r io.Reader) (int64, error) {
return 0, err
}

getBlobOpts := &storage.GetBlobOptions{}
_, err = blob.Get(getBlobOpts)
_, err = blob.Get(&storage.GetBlobOptions{})
if err != nil {
return 0, err
}
Expand Down
14 changes: 2 additions & 12 deletions pkg/controller/backup-operator/abs_backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,10 @@ import (
"github.com/coreos/etcd-operator/pkg/backup"
"github.com/coreos/etcd-operator/pkg/backup/writer"
"github.com/coreos/etcd-operator/pkg/util/azureutil/absfactory"
"github.com/coreos/etcd-operator/pkg/util/etcdutil"
"github.com/coreos/etcd-operator/pkg/util/k8sutil"

"k8s.io/client-go/kubernetes"
)

// TODO: replace this with generic backend interface for other options (PV, Azure)
// handleABS saves etcd cluster's backup to specificed ABS path.
func handleABS(kubecli kubernetes.Interface, s *api.ABSBackupSource, endpoints []string, clientTLSSecret, namespace string) (*api.BackupStatus, error) {
cli, err := absfactory.NewClientFromSecret(kubecli, namespace, s.ABSSecret)
Expand All @@ -37,15 +34,8 @@ func handleABS(kubecli kubernetes.Interface, s *api.ABSBackupSource, endpoints [
}

var tlsConfig *tls.Config
if len(clientTLSSecret) != 0 {
d, err := k8sutil.GetTLSDataFromSecret(kubecli, namespace, clientTLSSecret)
if err != nil {
return nil, fmt.Errorf("failed to get TLS data from secret (%v): %v", clientTLSSecret, err)
}
tlsConfig, err = etcdutil.NewTLSConfig(d.CertData, d.KeyData, d.CAData)
if err != nil {
return nil, fmt.Errorf("failed to constructs tls config: %v", err)
}
if tlsConfig, err = generateTLSConfig(kubecli, clientTLSSecret, namespace); err != nil {
return nil, err
}

bm := backup.NewBackupManagerFromWriter(kubecli, writer.NewABSWriter(cli.ABS), tlsConfig, endpoints, namespace)
Expand Down
13 changes: 2 additions & 11 deletions pkg/controller/backup-operator/s3_backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ import (
"github.com/coreos/etcd-operator/pkg/backup"
"github.com/coreos/etcd-operator/pkg/backup/writer"
"github.com/coreos/etcd-operator/pkg/util/awsutil/s3factory"
"github.com/coreos/etcd-operator/pkg/util/etcdutil"
"github.com/coreos/etcd-operator/pkg/util/k8sutil"

"k8s.io/client-go/kubernetes"
)
Expand All @@ -38,15 +36,8 @@ func handleS3(kubecli kubernetes.Interface, s *api.S3BackupSource, endpoints []s
defer cli.Close()

var tlsConfig *tls.Config
if len(clientTLSSecret) != 0 {
d, err := k8sutil.GetTLSDataFromSecret(kubecli, namespace, clientTLSSecret)
if err != nil {
return nil, fmt.Errorf("failed to get TLS data from secret (%v): %v", clientTLSSecret, err)
}
tlsConfig, err = etcdutil.NewTLSConfig(d.CertData, d.KeyData, d.CAData)
if err != nil {
return nil, fmt.Errorf("failed to constructs tls config: %v", err)
}
if tlsConfig, err = generateTLSConfig(kubecli, clientTLSSecret, namespace); err != nil {
return nil, err
}

bm := backup.NewBackupManagerFromWriter(kubecli, writer.NewS3Writer(cli.S3), tlsConfig, endpoints, namespace)
Expand Down
38 changes: 38 additions & 0 deletions pkg/controller/backup-operator/util.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// Copyright 2017 The etcd-operator Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package controller

import (
"crypto/tls"
"fmt"

"github.com/coreos/etcd-operator/pkg/util/etcdutil"
"github.com/coreos/etcd-operator/pkg/util/k8sutil"
)

func generateTLSConfig(kubecli kubernetes.Interface, clientTLSSecret, namespace string) (*tls.Config, error) {
var tlsConfig *tls.Config
if len(clientTLSSecret) != 0 {
d, err := k8sutil.GetTLSDataFromSecret(kubecli, namespace, clientTLSSecret)
if err != nil {
return nil, fmt.Errorf("failed to get TLS data from secret (%v): %v", clientTLSSecret, err)
}
tlsConfig, err = etcdutil.NewTLSConfig(d.CertData, d.KeyData, d.CAData)
if err != nil {
return nil, fmt.Errorf("failed to constructs tls config: %v", err)
}
}
return tlsConfig, nil
}
4 changes: 1 addition & 3 deletions pkg/util/azureutil/absfactory/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ func NewClientFromSecret(kubecli kubernetes.Interface, namespace, absSecret stri
}
}()

w = &ABSClient{}
se, err := kubecli.CoreV1().Secrets(namespace).Get(absSecret, metav1.GetOptions{})
if err != nil {
return nil, fmt.Errorf("failed to get k8s secret: %v", err)
Expand All @@ -58,6 +57,5 @@ func NewClientFromSecret(kubecli kubernetes.Interface, namespace, absSecret stri
}

abs := bc.GetBlobService()
w.ABS = &abs
return w, nil
return &ABSClient{ABS: &abs}, nil
}
2 changes: 2 additions & 0 deletions test/pod/test-pod-templ.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ spec:
value: <TEST_S3_BUCKET>
- name: TEST_AWS_SECRET
value: <TEST_AWS_SECRET>
- name: TEST_ABS_SECRET
value: <TEST_ABS_SECRET>
- name: PARALLEL_TEST
value: "true"
- name: UPGRADE_TEST_SELECTOR
Expand Down

0 comments on commit ec07d43

Please sign in to comment.