Skip to content

Commit

Permalink
Merge pull request #132 from kanisterio/sync
Browse files Browse the repository at this point in the history
Volume snapshot prep work;  TemplateParam Phases Doc updates
  • Loading branch information
tdmanv committed Oct 17, 2018
2 parents 9c1308a + e81331a commit bb7758f
Show file tree
Hide file tree
Showing 13 changed files with 916 additions and 28 deletions.
10 changes: 5 additions & 5 deletions docs/architecture.rst
Original file line number Diff line number Diff line change
Expand Up @@ -197,19 +197,19 @@ state, and the overall execution progress.
}
Unlike in the ActionSpec, the Artifacts in the ActionStatus are the rendered
output artifacts from the Blueprint. These are populated as soon as they are
rendered, but should only be considered valid once the action is complete.
output artifacts from the Blueprint. These are rendered and populated once the action is complete.


Each phase in the ActionStatus phases list contains the phase name of the
Blueprint phase and its state of execution.
Blueprint phase along with its state of execution and output.

.. code-block:: go
// Phase is subcomponent of an action.
type Phase struct {
Name string `json:"name"`
State State `json:"state"`
Name string `json:"name"`
State State `json:"state"`
Output map[string]interface{} `json:"output"`
}
.. _profiles:
Expand Down
2 changes: 1 addition & 1 deletion docs/functions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ implements the following go interface:
// Func allows custom actions to be executed.
type Func interface {
Name() string
Exec(ctx context.Context, args ...string) error
Exec(ctx context.Context, args ...string) (map[string]interface{}, error)
RequiredArgs() []string
}
Expand Down
32 changes: 32 additions & 0 deletions docs/templates.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ The TemplateParam struct is defined as:
Secrets map[string]v1.Secret
Time string
Options map[string]string
Phases map[string]*Phase
}
Rendering Templates
Expand Down Expand Up @@ -497,3 +498,34 @@ The Options can then be used in the Blueprint via templating:
"{{ .Options.podName }}"
Phases
------

Phases are used to capture information required or returned from Blueprint phases.
Currently, each phase contains a map of Secrets required to execute a phase,
or the Output map returned from the execution.

The definition is as follows:

.. code-block:: go
:linenos:
type Phase struct {
Secrets map[string]v1.Secret
Output map[string]interface{}
}
The phase parameters can be referenced by the phases following it,
or as output artifacts using templating.

For example, an output artifact can reference the output from a phase as follows:

.. code-block:: yaml
"{{ .Phases.phase-name.Output.key-name }}"

Similarly, a phase can use Secrets as arguments:

.. code-block:: yaml
"{{ .Phases.phase-name.Secrets.secret-name.Namespace }}"
3 changes: 3 additions & 0 deletions examples/picture-gallery-pvc-snapshot/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Walkthrough of Picture Gallery

The blueprint for this application is in progress. Once it is ready, we will be able to take PVC screenshots, restore PVCs and delete the backup data.
17 changes: 17 additions & 0 deletions examples/picture-gallery-pvc-snapshot/backup-actionset.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
apiVersion: cr.kanister.io/v1alpha1
kind: ActionSet
metadata:
generateName: pic-gal-pvc-snapshot-
namespace: kanister
spec:
actions:
- name: backup
blueprint: picture-gallery
object:
kind: Deployment
name: picture-gallery
namespace: default
profile:
kind: Profile
name: default-profile
namespace: kanister
51 changes: 51 additions & 0 deletions examples/picture-gallery-pvc-snapshot/blueprint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
apiVersion: cr.kanister.io/v1alpha1
kind: Blueprint
metadata:
name: picture-gallery
namespace: kanister
actions:
backup:
type: Deployment
outputArtifacts:
backupLocation:
keyValue:
path: "{{ .Phases.backupVolume.Output.backupLocation }}"
phases:
- func: CreateVolumeSnapshot
name: backupVolume
args:
namespace: "{{ .Deployment.Namespace }}"
restore:
type: Deployment
inputArtifactNames:
- backupLocation
phases:
- func: ScaleWorkload
name: shutdownPod
args:
namespace: "{{ .Deployment.Namespace }}"
name: "{{ .Deployment.Name }}"
kind: Deployment
replicas: 0
- func: CreateVolumeFromSnapshot
name: restoreVolume
args:
namespace: "{{ .Deployment.Namespace }}"
snapshots: "{{ .ArtifactsIn.backupLocation.KeyValue.path }}"
- func: ScaleWorkload
name: bringupPod
args:
namespace: "{{ .Deployment.Namespace }}"
name: "{{ .Deployment.Name }}"
kind: Deployment
replicas: 1
delete:
type: Deployment
inputArtifactNames:
- backupLocation
phases:
- func: DeleteVolumeSnapshot
name: deleteVolumeSnapshot
args:
namespace: "{{ .Deployment.Namespace }}"
snapshots: "{{ .ArtifactsIn.backupLocation.KeyValue.path }}"
122 changes: 122 additions & 0 deletions examples/picture-gallery-pvc-snapshot/picture-gallery-deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
apiVersion: v1
kind: Service
metadata:
name: picture-gallery
labels:
app: picture-gallery
spec:
ports:
- port: 80
selector:
app: picture-gallery
tier: frontend
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: pic-gal-php-cfg
labels:
app: picture-gallery
contains: php-config
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 1Gi
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: pic-gal-pics
labels:
app: picture-gallery
contains: uploaded-pictures
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 2Gi
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: pic-gal-mysql
labels:
app: picture-gallery
contains: mysql-dbs
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 1Gi
---
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: picture-gallery
labels:
app: picture-gallery
spec:
strategy:
type: Recreate
selector:
matchLabels:
app: picture-gallery
template:
metadata:
labels:
app: picture-gallery
tier: frontend
spec:
containers:
- image: kastenio/picturegallery:70307e
livenessProbe:
httpGet:
path: /
port: 80
scheme: HTTP
initialDelaySeconds: 30
timeoutSeconds: 5
name: picture-gallery
ports:
- containerPort: 80
name: picture-gallery
volumeMounts:
- name: pic-gal-php-cfg
mountPath: /data
- name: pic-gal-pic
mountPath: /uploads
- name: pic-gal-mysql
mountPath: /mysql
volumes:
- name: pic-gal-php-cfg
persistentVolumeClaim:
claimName: pic-gal-php-cfg
- name: pic-gal-pic
persistentVolumeClaim:
claimName: pic-gal-pics
- name: pic-gal-mysql
persistentVolumeClaim:
claimName: pic-gal-mysql
---
kind: Ingress
apiVersion: extensions/v1beta1
#creating ingress for picture-gallery
#is accessible by cluster.domainname/picture-gallery
metadata:
name: picture-gallery
annotations:
kubernetes.io/ingress.class: "nginx"
nginx.ingress.kubernetes.io/ssl-redirect: "false"
nginx.ingress.kubernetes.io/proxy-body-size: "100m"
spec:
rules:
- http:
paths:
- path: /picture-gallery
backend:
serviceName: picture-gallery
servicePort: 80
22 changes: 15 additions & 7 deletions pkg/function/copy_volume_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,15 @@ import (
)

const (
kanisterToolsImage = "kanisterio/kanister-tools:0.12.0"
copyVolumeDataMountPoint = "/mnt/vol_data/%s"
copyVolumeDataJobPrefix = "copy-vol-data-"
CopyVolumeDataNamespaceArg = "namespace"
CopyVolumeDataVolumeArg = "volume"
CopyVolumeDataArtifactPrefixArg = "dataArtifactPrefix"
kanisterToolsImage = "kanisterio/kanister-tools:0.12.0"
copyVolumeDataMountPoint = "/mnt/vol_data/%s"
copyVolumeDataJobPrefix = "copy-vol-data-"
CopyVolumeDataNamespaceArg = "namespace"
CopyVolumeDataVolumeArg = "volume"
CopyVolumeDataArtifactPrefixArg = "dataArtifactPrefix"
CopyVolumeDataOutputBackupID = "backupID"
CopyVolumeDataOutputBackupRoot = "backupRoot"
CopyVolumeDataOutputBackupArtifactLocation = "backupArtifactLocation"
)

func init() {
Expand Down Expand Up @@ -70,7 +73,12 @@ func copyVolumeData(ctx context.Context, cli kubernetes.Interface, tp param.Temp
if err != nil {
return nil, errors.Wrapf(err, "Failed to create and upload backup")
}
return map[string]interface{}{"backupID": backupIdentifier}, nil
return map[string]interface{}{
CopyVolumeDataOutputBackupID: backupIdentifier,
CopyVolumeDataOutputBackupRoot: mountPoint,
CopyVolumeDataOutputBackupArtifactLocation: targetPath,
},
nil
}

func (*copyVolumeDataFunc) Exec(ctx context.Context, tp param.TemplateParams, args map[string]interface{}) (map[string]interface{}, error) {
Expand Down
Loading

0 comments on commit bb7758f

Please sign in to comment.