Skip to content

Commit

Permalink
Merge pull request #136 from kanisterio/sync
Browse files Browse the repository at this point in the history
Bump Kanister version to 0.13.0; Object Store enhancements; BackupData: Capture and return SnapshotID from logs
  • Loading branch information
SupriyaKasten authored Oct 31, 2018
2 parents 3f31121 + fae9b97 commit ee7479b
Show file tree
Hide file tree
Showing 31 changed files with 104 additions and 78 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ found [here](https://hub.kubeapps.com/charts/stable/kanister-operator) and can
be installed by specifying the `stable` chart prefix.

```bash
helm install --name myrelease --namespace kanister stable/kanister-operator --set image.tag=0.12.0
helm install --name myrelease --namespace kanister stable/kanister-operator --set image.tag=0.13.0
```

> **Warning**: The Kanister chart found in `stable` may be behind the one in
Expand Down
2 changes: 1 addition & 1 deletion docker/postgres-kanister-tools/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ RUN apk -v --update add --no-cache python py-pip groff less && \
apk -v --purge del py-pip && \
rm -f /var/cache/apk/*

COPY --from=kanisterio/kanister-tools:0.12.0 /usr/local/bin/kando /usr/local/bin/kando
COPY --from=kanisterio/kanister-tools:0.13.0 /usr/local/bin/kando /usr/local/bin/kando

CMD ["tail", "-f", "/dev/null"]
2 changes: 1 addition & 1 deletion docs/functions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ Example:
args:
namespace: "{{ .Deployment.Namespace }}"
pod: "{{ index .Deployment.Pods 0 }}"
image: kanisterio/kanister-tools:0.12.0
image: kanisterio/kanister-tools:0.13.0
backupArtifactPrefix: s3-bucket/path/artifactPrefix
backupIdentifier: "{{ .Time }}"
Expand Down
2 changes: 1 addition & 1 deletion docs/helm.rst
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ You also need to install the Kanister controller

.. code-block:: console
$ helm install --name myrelease --namespace kanister kanister/kanister-operator --set image.tag=0.12.0
$ helm install --name myrelease --namespace kanister kanister/kanister-operator --set image.tag=0.13.0
Kanister-Enabled Applications
=============================
Expand Down
2 changes: 1 addition & 1 deletion docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ and backup to an AWS S3 bucket.
helm repo add kanister http://charts.kanister.io
# Install the Kanister Controller
helm install --name myrelease --namespace kanister kanister/kanister-operator --set image.tag=0.12.0
helm install --name myrelease --namespace kanister kanister/kanister-operator --set image.tag=0.13.0
# Install MySQL and configure its Kanister Blueprint.
# Also create a Profile CR that can be used in ActionSets
Expand Down
2 changes: 1 addition & 1 deletion docs/install.rst
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ This will install the Kanister controller in the `kanister` namespace
$ helm repo add kanister https://charts.kanister.io/
# Install the Kanister operator controller using helm
$ helm install --name myrelease --namespace kanister kanister/kanister-operator --set image.tag=0.12.0
$ helm install --name myrelease --namespace kanister kanister/kanister-operator --set image.tag=0.13.0
Building and Deploying from Source
Expand Down
2 changes: 1 addition & 1 deletion docs/tooling.rst
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ These tools, especially `kando` are meant to be invoked inside containers via
Blueprints. Although suggest using the released image when possible, we've also
made it simple to add these tools to your container.
The released image, `kanisterio/kanister-tools:0.12.0`, is hosted by
The released image, `kanisterio/kanister-tools:0.13.0`, is hosted by
`dockerhub <https://cloud.docker.com/swarm/kanisterio/repository/docker/kanisterio/kanister-tools/general>`_.
The Dockerfile for this image is in the
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

FROM kanisterio/kanister-tools:0.12.0
FROM kanisterio/kanister-tools:0.13.0
MAINTAINER Supriya Kharade <supriya@kasten.io>

COPY esdump-setup.sh /esdump-setup.sh
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ actions:
name: takeDataSnapshot
args:
namespace: "{{ .StatefulSet.Namespace }}"
image: "kanisterio/es-sidecar:0.12.0"
image: "kanisterio/es-sidecar:0.13.0"
command:
- bash
- -o
Expand All @@ -37,7 +37,7 @@ actions:
name: restoreSnapshots
args:
namespace: "{{ .StatefulSet.Namespace }}"
image: "kanisterio/es-sidecar:0.12.0"
image: "kanisterio/es-sidecar:0.13.0"
command:
- bash
- -o
Expand All @@ -63,7 +63,7 @@ actions:
name: deleteSnapshots
args:
namespace: "{{ .StatefulSet.Namespace }}"
image: "kanisterio/es-sidecar:0.12.0"
image: "kanisterio/es-sidecar:0.13.0"
command:
- bash
- -o
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ ADD . /kanister

RUN /kanister/install.sh && rm -rf /kanister && rm -rf /tmp && mkdir /tmp

COPY --from=kanisterio/kanister-tools:0.12.0 /usr/local/bin/kando /usr/local/bin/kando
COPY --from=kanisterio/kanister-tools:0.13.0 /usr/local/bin/kando /usr/local/bin/kando

CMD ["tail", "-f", "/dev/null"]
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ spec:
mountPath: /data/db
containers:
- name: kanister-sidecar
image: kanisterio/mongo-sidecar:0.12.0
image: kanisterio/mongo-sidecar:0.13.0
imagePullPolicy: Always
env:
{{- if .Values.auth.enabled }}
Expand Down
2 changes: 1 addition & 1 deletion examples/helm/kanister/kanister-mysql/image/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ ADD . /kanister

RUN /kanister/install.sh && rm -rf /kanister && rm -rf /tmp && mkdir /tmp

COPY --from=kanisterio/kanister-tools:0.12.0 /usr/local/bin/kando /usr/local/bin/kando
COPY --from=kanisterio/kanister-tools:0.13.0 /usr/local/bin/kando /usr/local/bin/kando

CMD ["tail", "-f", "/dev/null"]
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ spec:
mountPath: /etc/mysql/conf.d
{{- end }}
- name: kanister-sidecar
image: kanisterio/mysql-sidecar:0.12.0
image: kanisterio/mysql-sidecar:0.13.0
imagePullPolicy: Always
env:
{{- if .Values.mysqlAllowEmptyPassword }}
Expand Down
2 changes: 1 addition & 1 deletion examples/time-log/blueprint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ actions:
args:
namespace: "{{ .Deployment.Namespace }}"
pod: "{{ index .Deployment.Pods 0 }}"
image: kanisterio/kanister-tools:0.12.0
image: kanisterio/kanister-tools:0.13.0
backupArtifactPrefix: "{{ .ArtifactsIn.timeLog.KeyValue.path }}"
backupIdentifier: "{{ .ArtifactsIn.backupIdentifier.KeyValue.id }}"
- func: ScaleWorkload
Expand Down
2 changes: 1 addition & 1 deletion examples/time-log/time-logger-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ spec:
spec:
containers:
- name: test-container
image: kanisterio/kanister-tools:0.12.0
image: kanisterio/kanister-tools:0.13.0
command: ["sh", "-c"]
args: ["while true; do for x in $(seq 1200); do date >> /var/log/time.log; sleep 1; done; truncate /var/log/time.log --size 0; done"]
volumeMounts:
Expand Down
2 changes: 1 addition & 1 deletion helm/kanister-operator/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# Declare variables to be passed into your templates.
image:
repository: kanisterio/controller
tag: 0.12.0
tag: 0.13.0
pullPolicy: IfNotPresent
rbac:
create: true
Expand Down
21 changes: 21 additions & 0 deletions pkg/function/backup_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package function

import (
"context"
"regexp"

"github.com/pkg/errors"

Expand Down Expand Up @@ -52,6 +53,22 @@ func validateProfile(profile *param.Profile) error {
return nil
}

func getSnapshotIDFromLog(output string) string {
if output == "" {
return ""
}
logs := regexp.MustCompile("[\n]").Split(output, -1)
for _, l := range logs {
// Log should contain "snapshot ABC123 saved"
pattern := regexp.MustCompile(`snapshot\s(.*?)\ssaved$`)
match := pattern.FindAllStringSubmatch(l, 1)
if match != nil {
return match[0][1]
}
}
return ""
}

func (*backupDataFunc) Exec(ctx context.Context, tp param.TemplateParams, args map[string]interface{}) (map[string]interface{}, error) {
var namespace, pod, container, includePath, backupArtifactPrefix, backupIdentifier, encryptionKey string
var err error
Expand Down Expand Up @@ -97,6 +114,10 @@ func (*backupDataFunc) Exec(ctx context.Context, tp param.TemplateParams, args m
if err != nil {
return nil, errors.Wrapf(err, "Failed to create and upload backup")
}
// Get the snapshot ID from log
if snapID := getSnapshotIDFromLog(stdout); snapID != "" {
return map[string]interface{}{"snapshotID": snapID}, nil
}
return nil, nil
}

Expand Down
21 changes: 18 additions & 3 deletions pkg/function/backup_data_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ import (
"github.com/kanisterio/kanister/pkg/param"
)

type ValidateProfileSuite struct {
type BackupDataSuite struct {
}

var _ = Suite(&ValidateProfileSuite{})
var _ = Suite(&BackupDataSuite{})

func newValidProfile() *param.Profile {
return &param.Profile{
Expand Down Expand Up @@ -56,7 +56,7 @@ func newInvalidProfile() *param.Profile {
}
}

func (s *ValidateProfileSuite) TestValidateProfile(c *C) {
func (s *BackupDataSuite) TestValidateProfile(c *C) {
testCases := []struct {
name string
profile *param.Profile
Expand All @@ -71,3 +71,18 @@ func (s *ValidateProfileSuite) TestValidateProfile(c *C) {
c.Check(err, tc.errChecker, Commentf("Test %s Failed", tc.name))
}
}

func (s *BackupDataSuite) TestGetSnapshotID(c *C) {
for _, tc := range []struct {
log string
expected string
}{
{"snapshot 1a2b3c4d saved", "1a2b3c4d"},
{"snapshot 123abcd", ""},
{"Invalid message", ""},
{"snapshot abc123\n saved", ""},
} {
id := getSnapshotIDFromLog(tc.log)
c.Check(id, Equals, tc.expected, Commentf("Failed for log: %s", tc.log))
}
}
2 changes: 1 addition & 1 deletion pkg/function/copy_volume_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
)

const (
kanisterToolsImage = "kanisterio/kanister-tools:0.12.0"
kanisterToolsImage = "kanisterio/kanister-tools:0.13.0"
copyVolumeDataMountPoint = "/mnt/vol_data/%s"
copyVolumeDataJobPrefix = "copy-vol-data-"
CopyVolumeDataNamespaceArg = "namespace"
Expand Down
9 changes: 6 additions & 3 deletions pkg/function/data_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func newRestoreDataBlueprint(pvc string) *crv1alpha1.Blueprint {
Func: "RestoreData",
Args: map[string]interface{}{
RestoreDataNamespaceArg: "{{ .StatefulSet.Namespace }}",
RestoreDataImageArg: "kanisterio/kanister-tools:0.12.0",
RestoreDataImageArg: "kanisterio/kanister-tools:0.13.0",
RestoreDataBackupArtifactPrefixArg: "{{ .Profile.Location.S3Compliant.Bucket }}/{{ .Profile.Location.S3Compliant.Prefix }}",
RestoreDataRestorePathArg: "/",
RestoreDataBackupIdentifierArg: "{{ .Time }}",
Expand Down Expand Up @@ -176,7 +176,10 @@ func (s *DataSuite) TestBackupRestoreData(c *C) {
phases, err := kanister.GetPhases(bp, actionName, *tp)
c.Assert(err, IsNil)
for _, p := range phases {
_, err = p.Exec(context.Background(), bp, actionName, *tp)
out, err := p.Exec(context.Background(), bp, actionName, *tp)
if out != nil {
c.Assert(out["snapshotID"], NotNil)
}
c.Assert(err, IsNil)
}
}
Expand Down Expand Up @@ -222,7 +225,7 @@ func newCopyDataTestBlueprint() crv1alpha1.Blueprint {
Func: "RestoreData",
Args: map[string]interface{}{
RestoreDataNamespaceArg: "{{ .PVC.Namespace }}",
RestoreDataImageArg: "kanisterio/kanister-tools:0.12.0",
RestoreDataImageArg: "kanisterio/kanister-tools:0.13.0",
RestoreDataBackupArtifactPrefixArg: fmt.Sprintf("{{ .Options.%s }}", CopyVolumeDataOutputBackupArtifactLocation),
RestoreDataBackupIdentifierArg: fmt.Sprintf("{{ .Options.%s }}", CopyVolumeDataOutputBackupID),
RestoreDataVolsArg: map[string]string{
Expand Down
2 changes: 1 addition & 1 deletion pkg/function/delete_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func (*deleteDataFunc) Exec(ctx context.Context, tp param.TemplateParams, args m
// Generate delete command
cmd := generateDeleteCommand(artifact, tp.Profile)
// Use KubeTask to delete the artifact
return nil, kubeTask(ctx, namespace, "kanisterio/kanister-tools:0.12.0", cmd)
return nil, kubeTask(ctx, namespace, "kanisterio/kanister-tools:0.13.0", cmd)
}

func (*deleteDataFunc) RequiredArgs() []string {
Expand Down
10 changes: 5 additions & 5 deletions pkg/function/kube_exec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,11 +157,11 @@ func (s *KubeExecTest) TestParseLogAndCreateOutput(c *C) {
errChecker Checker
outChecker Checker
}{
{"###Phase-output###: {\"key\":\"version\",\"value\":\"0.12.0\"}", map[string]interface{}{"version": "0.12.0"}, IsNil, NotNil},
{"###Phase-output###: {\"key\":\"version\",\"value\":\"0.12.0\"}\n###Phase-output###: {\"key\":\"path\",\"value\":\"/backup/path\"}",
map[string]interface{}{"version": "0.12.0", "path": "/backup/path"}, IsNil, NotNil},
{"Random message ###Phase-output###: {\"key\":\"version\",\"value\":\"0.12.0\"}", map[string]interface{}{"version": "0.12.0"}, IsNil, NotNil},
{"Random message with newline \n###Phase-output###: {\"key\":\"version\",\"value\":\"0.12.0\"}", map[string]interface{}{"version": "0.12.0"}, IsNil, NotNil},
{"###Phase-output###: {\"key\":\"version\",\"value\":\"0.13.0\"}", map[string]interface{}{"version": "0.13.0"}, IsNil, NotNil},
{"###Phase-output###: {\"key\":\"version\",\"value\":\"0.13.0\"}\n###Phase-output###: {\"key\":\"path\",\"value\":\"/backup/path\"}",
map[string]interface{}{"version": "0.13.0", "path": "/backup/path"}, IsNil, NotNil},
{"Random message ###Phase-output###: {\"key\":\"version\",\"value\":\"0.13.0\"}", map[string]interface{}{"version": "0.13.0"}, IsNil, NotNil},
{"Random message with newline \n###Phase-output###: {\"key\":\"version\",\"value\":\"0.13.0\"}", map[string]interface{}{"version": "0.13.0"}, IsNil, NotNil},
{"###Phase-output###: Invalid message", nil, NotNil, IsNil},
{"Random message", nil, IsNil, IsNil},
} {
Expand Down
4 changes: 2 additions & 2 deletions pkg/kube/pod_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func (s *PodSuite) TestPod(c *C) {
pod, err := CreatePod(ctx, s.cli, &PodOptions{
Namespace: s.namespace,
GenerateName: "test-",
Image: "kanisterio/kanister-tools:0.12.0",
Image: "kanisterio/kanister-tools:0.13.0",
Command: []string{"sh", "-c", "tail -f /dev/null"},
})
c.Assert(err, IsNil)
Expand All @@ -76,7 +76,7 @@ func (s *PodSuite) TestPodWithVolumes(c *C) {
pod, err := CreatePod(ctx, cli, &PodOptions{
Namespace: s.namespace,
GenerateName: "test-",
Image: "kanisterio/kanister-tools:0.12.0",
Image: "kanisterio/kanister-tools:0.13.0",
Command: []string{"sh", "-c", "tail -f /dev/null"},
Volumes: vols,
})
Expand Down
7 changes: 6 additions & 1 deletion pkg/objectstore/aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package objectstore

import (
"context"
"strings"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/awserr"
Expand All @@ -14,6 +15,7 @@ import (
const (
bucketNotFound = "NotFound"
noSuchBucket = s3.ErrCodeNoSuchBucket
gcsS3NotFound = "not found"
)

func config(region string) *aws.Config {
Expand All @@ -25,11 +27,14 @@ func config(region string) *aws.Config {
}

func isBucketNotFoundError(err error) bool {
if err == nil {
return false
}
if awsErr, ok := errors.Cause(err).(awserr.Error); ok {
code := awsErr.Code()
return code == bucketNotFound || code == noSuchBucket
}
return false
return strings.Contains(err.Error(), gcsS3NotFound)
}

func GetS3BucketRegion(ctx context.Context, bucketName, regionHint string) (string, error) {
Expand Down
Loading

0 comments on commit ee7479b

Please sign in to comment.