Add check for executor ref in phase helper

Relates-To: #365
Closes: #365

Change-Id: I95251a0ef49436d86f6f882bf23a91ceb1b1a952
This commit is contained in:
Kostiantyn Kalynovskyi 2020-10-12 12:00:48 -05:00
parent 3866d358b8
commit eddfc6338a
6 changed files with 34 additions and 4 deletions

View File

@ -38,8 +38,6 @@ type PhaseConfig struct {
// DefaultPhase can be used to safely unmarshal phase object without nil pointers
func DefaultPhase() *Phase {
return &Phase{
Config: PhaseConfig{
ExecutorRef: &corev1.ObjectReference{},
},
Config: PhaseConfig{},
}
}

View File

@ -51,3 +51,15 @@ func (e ErrDocumentEntrypointNotDefined) Error() string {
e.PhaseName,
e.PhaseNamespace)
}
// ErrExecutorRefNotDefined returned when phase has no entrypoint defined and phase needs it
type ErrExecutorRefNotDefined struct {
PhaseName string
PhaseNamespace string
}
func (e ErrExecutorRefNotDefined) Error() string {
return fmt.Sprintf("Phase name '%s', namespace '%s' must have executorRef field defined in config",
e.PhaseName,
e.PhaseNamespace)
}

View File

@ -182,6 +182,10 @@ func (helper *Helper) ExecutorDoc(phaseID ifc.ID) (document.Document, error) {
}
phaseConfig := phaseObj.Config
if phaseConfig.ExecutorRef == nil {
return nil, ErrExecutorRefNotDefined{PhaseName: phaseID.Name, PhaseNamespace: phaseID.Namespace}
}
// Searching executor configuration document referenced in
// phase configuration
refGVK := phaseConfig.ExecutorRef.GroupVersionKind()

View File

@ -194,7 +194,7 @@ func TestHelperListPhases(t *testing.T) {
}{
{
name: "Success phase list",
phaseLen: 3,
phaseLen: 4,
config: testConfig,
},
{
@ -372,6 +372,14 @@ func TestHelperExecutorDoc(t *testing.T) {
},
errContains: "no such file or directory",
},
{
name: "Error get phase without executor",
config: testConfig,
phaseID: ifc.ID{Name: "no_executor_phase"},
errContains: phase.ErrExecutorRefNotDefined{
PhaseName: "no_executor_phase",
}.Error(),
},
}
for _, test := range testCases {

View File

@ -7,3 +7,4 @@ resources:
- kubernetes_apply.yaml
- cluster_map.yaml
- phase_no_docentrypoint.yaml
- no_executor_phase.yaml

View File

@ -0,0 +1,7 @@
apiVersion: airshipit.org/v1alpha1
kind: Phase
metadata:
name: no_executor_phase
config:
documentEntryPoint: valid_site/phases