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 2b53691 commit b61134b
Show file tree
Hide file tree
Showing 10 changed files with 71 additions and 39 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.

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

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

[[constraint]]
name = "github.com/Azure/azure-sdk-for-go"
version = "v11.3.0-beta"

[[constraint]]
name = "github.com/Azure/go-autorest"
version = "v9.6.0"

[[constraint]]
name = "github.com/dgrijalva/jwt-go"

[[constraint]]
name = "github.com/satori/uuid"
version = "v1.1.0"

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
13 changes: 2 additions & 11 deletions pkg/controller/backup-operator/abs_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/azureutil/absfactory"
"github.com/coreos/etcd-operator/pkg/util/etcdutil"
"github.com/coreos/etcd-operator/pkg/util/k8sutil"

"k8s.io/client-go/kubernetes"
)
Expand All @@ -37,15 +35,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/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ The [test-pod-tmpl.yaml](./test-pod-tmpl.yaml) can be used to define the test-po
- `OPERATOR_IMAGE` is the etcd-operator image used for testing
- `TEST_S3_BUCKET` is the S3 bucket name used for testing
- `TEST_AWS_SECRET` is the secret name containing the aws credentials/config files.
- `TEST_ABS_SECRET` is the secret name containing the abs credentials
- `E2E_TEST_SELECTOR` selects which e2e tests to run. Leave empty to run all tests.
- `UPGRADE_TEST_SELECTOR` selects which upgrade tests to run. Leave empty to run all tests.
- `PASSES` are the test passes to run (e2e, e2eslow, e2esh). See [hack/test](../../hack/test)
Expand All @@ -35,6 +36,7 @@ sed -e "s|<POD_NAME>|e2e-testing|g" \
-e "s|<E2E_TEST_SELECTOR>||g" \
-e "s|<TEST_S3_BUCKET>|my-bucket|g" \
-e "s|<TEST_AWS_SECRET>|aws-secret|g" \
-e "s|<TEST_ABS_SECRET>|abs-secret|g" \
-e "s|<UPGRADE_TEST_SELECTOR>||g" \
-e "s|<UPGRADE_FROM>|quay.io/coreos/etcd-operator:latest|g" \
-e "s|<UPGRADE_TO>|quay.io/coreos/etcd-operator:dev|g" \
Expand Down
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 b61134b

Please sign in to comment.