Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support an eventual phase for the blueprint actions #1297

Merged
merged 11 commits into from
Apr 11, 2022
Merged
5 changes: 5 additions & 0 deletions docs/architecture.rst
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ The definition of a ``BlueprintAction`` is:
InputArtifactNames []string `json:"inputArtifactNames"`
OutputArtifacts map[string]Artifact `json:"outputArtifacts"`
Phases []BlueprintPhase `json:"phases"`
DeferPhase *BlueprintPhase `json:"deferPhase,omitempty"`
}

- ``Kind`` represents the type of Kubernetes object this BlueprintAction is written for.
Expand All @@ -84,6 +85,10 @@ The definition of a ``BlueprintAction`` is:
to the ``BlueprintAction``.
- ``Phases`` is a required list of ``BlueprintPhases``. These phases are invoked
in order when executing this Action.
- ``DeferPhase`` is an optional ``BlueprintPhase`` invoked after the
execution of ``Phases`` defined above. A ``DeferPhase``, when specified,
is executed regardless of the statuses of the ``Phases``.
A ``DeferPhase`` can be used for cleanup operations at the end of an ``Action``.

.. code-block:: go
:linenos:
Expand Down
26 changes: 26 additions & 0 deletions docs/templates.rst
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ The TemplateParam struct is defined as:
Options map[string]string
Object map[string]interface{}
Phases map[string]*Phase
DeferPhase *Phase
PodOverride crv1alpha1.JSONMap
}

Expand Down Expand Up @@ -609,3 +610,28 @@ Similarly, a phase can use Secrets as arguments:
.. code-block:: go

"{{ .Phases.phase-name.Secrets.secret-name.Namespace }}"

DeferPhase
----------

``DeferPhase`` is used to capture information returned from the Blueprint's ``DeferPhase``
execution. The information is stored in the ``Phase`` struct that has the below
definition:

.. code-block:: go
:linenos:

type Phase struct {
Secrets map[string]v1.Secret
Output map[string]interface{}
}

Output artifact can be set as follows:

.. code-block:: go

"{{ .DeferPhase.Output.key-name }}"


Output artifacts that are set using ``DeferPhase`` can be consumed by other actions'
phases using the same way other output artifacts are consumed.
viveksinghggits marked this conversation as resolved.
Show resolved Hide resolved
54 changes: 54 additions & 0 deletions docs/tutorial.rst
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,60 @@ ConfigMap.
If you re-execute this Kanister Action, you'll be able to see the Artifact in the
ActionSet status.

If you use a ``DeferPhase``, below is how you can set the output artifact
from the output that is being generated from ``DeferPhase`` as shown below.

.. code-block:: yaml

cat <<EOF | kubectl apply -f -
apiVersion: cr.kanister.io/v1alpha1
kind: Blueprint
metadata:
name: time-log-bp
namespace: kanister
actions:
backup:
configMapNames:
- location
secretNames:
- aws
outputArtifacts:
timeLog:
keyValue:
path: '{{ .ConfigMaps.location.Data.path }}/time-log/'
deferPhaseArt:
keyValue:
time: "{{ .DeferPhase.Output.bkpCompletedTime }}"
phases:
- func: KubeExec
name: backupToS3
args:
namespace: "{{ .Deployment.Namespace }}"
pod: "{{ index .Deployment.Pods 0 }}"
container: test-container
command:
- sh
- -c
- |
echo "Main Phase"
deferPhase:
func: KubeTask
name: saveBackupTime
args:
image: ghcr.io/kanisterio/mysql-sidecar:0.74.0
namespace: "{{ .Deployment.Namespace }}"
command:
- sh
- -c
- |
echo "DeferPhase"
kando output bkpCompletedTime "10Minutes"
EOF


Output from the previous phases can also be used in the ``DeferPhase`` like it
is used in normal scenarios.

Input Artifacts
---------------

Expand Down
4 changes: 4 additions & 0 deletions pkg/apis/cr/v1alpha1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,9 @@ type ActionStatus struct {
Phases []Phase `json:"phases,omitempty"`
// Artifacts created by this phase.
Artifacts map[string]Artifact `json:"artifacts,omitempty"`
// DeferPhase is the phase that is executed at the end of an action
// irrespective of the status of other phases in the action
DeferPhase Phase `json:"deferPhase,omitempty"`
}

// State is the current state of a phase of execution.
Expand Down Expand Up @@ -194,6 +197,7 @@ type BlueprintAction struct {
InputArtifactNames []string `json:"inputArtifactNames,omitempty"`
OutputArtifacts map[string]Artifact `json:"outputArtifacts,omitempty"`
Phases []BlueprintPhase `json:"phases,omitempty"`
DeferPhase *BlueprintPhase `json:"deferPhase,omitempty"`
}

// BlueprintPhase is a an individual unit of execution.
Expand Down
5 changes: 5 additions & 0 deletions pkg/apis/cr/v1alpha1/zz_generated.deepcopy.go

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

Loading