Merge "Add check for executor ref in phase helper"
This commit is contained in:
commit
0f287089d9
@ -38,8 +38,6 @@ type PhaseConfig struct {
|
|||||||
// DefaultPhase can be used to safely unmarshal phase object without nil pointers
|
// DefaultPhase can be used to safely unmarshal phase object without nil pointers
|
||||||
func DefaultPhase() *Phase {
|
func DefaultPhase() *Phase {
|
||||||
return &Phase{
|
return &Phase{
|
||||||
Config: PhaseConfig{
|
Config: PhaseConfig{},
|
||||||
ExecutorRef: &corev1.ObjectReference{},
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -51,3 +51,15 @@ func (e ErrDocumentEntrypointNotDefined) Error() string {
|
|||||||
e.PhaseName,
|
e.PhaseName,
|
||||||
e.PhaseNamespace)
|
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)
|
||||||
|
}
|
||||||
|
@ -186,6 +186,10 @@ func (helper *Helper) ExecutorDoc(phaseID ifc.ID) (document.Document, error) {
|
|||||||
}
|
}
|
||||||
phaseConfig := phaseObj.Config
|
phaseConfig := phaseObj.Config
|
||||||
|
|
||||||
|
if phaseConfig.ExecutorRef == nil {
|
||||||
|
return nil, ErrExecutorRefNotDefined{PhaseName: phaseID.Name, PhaseNamespace: phaseID.Namespace}
|
||||||
|
}
|
||||||
|
|
||||||
// Searching executor configuration document referenced in
|
// Searching executor configuration document referenced in
|
||||||
// phase configuration
|
// phase configuration
|
||||||
refGVK := phaseConfig.ExecutorRef.GroupVersionKind()
|
refGVK := phaseConfig.ExecutorRef.GroupVersionKind()
|
||||||
|
@ -194,7 +194,7 @@ func TestHelperListPhases(t *testing.T) {
|
|||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
name: "Success phase list",
|
name: "Success phase list",
|
||||||
phaseLen: 3,
|
phaseLen: 4,
|
||||||
config: testConfig,
|
config: testConfig,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -372,6 +372,14 @@ func TestHelperExecutorDoc(t *testing.T) {
|
|||||||
},
|
},
|
||||||
errContains: "no such file or directory",
|
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 {
|
for _, test := range testCases {
|
||||||
|
@ -7,3 +7,4 @@ resources:
|
|||||||
- kubernetes_apply.yaml
|
- kubernetes_apply.yaml
|
||||||
- cluster_map.yaml
|
- cluster_map.yaml
|
||||||
- phase_no_docentrypoint.yaml
|
- phase_no_docentrypoint.yaml
|
||||||
|
- no_executor_phase.yaml
|
||||||
|
7
pkg/phase/testdata/valid_site/phases/no_executor_phase.yaml
vendored
Normal file
7
pkg/phase/testdata/valid_site/phases/no_executor_phase.yaml
vendored
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
apiVersion: airshipit.org/v1alpha1
|
||||||
|
kind: Phase
|
||||||
|
metadata:
|
||||||
|
name: no_executor_phase
|
||||||
|
config:
|
||||||
|
documentEntryPoint: valid_site/phases
|
||||||
|
|
Loading…
Reference in New Issue
Block a user