Merge "Phase Validation: k8s applier package changes to support Phase Validation sub command"
This commit is contained in:
commit
c89a8c1949
0
pkg/k8s/applier/testdata/no_bundle/kustomization.yaml
vendored
Normal file
0
pkg/k8s/applier/testdata/no_bundle/kustomization.yaml
vendored
Normal file
@ -57,3 +57,20 @@ type ErrUnableParseProvider struct {
|
|||||||
func (e ErrUnableParseProvider) Error() string {
|
func (e ErrUnableParseProvider) Error() string {
|
||||||
return fmt.Sprintf("unable to parse name and version of '%s' type, '%s' provider", e.ProviderType, e.Provider)
|
return fmt.Sprintf("unable to parse name and version of '%s' type, '%s' provider", e.ProviderType, e.Provider)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ErrNilExecutorDoc returned when the executor document is nil
|
||||||
|
type ErrNilExecutorDoc struct {
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e ErrNilExecutorDoc) Error() string {
|
||||||
|
return "executor document is nil"
|
||||||
|
}
|
||||||
|
|
||||||
|
// ErrInvalidPhase is returned if the phase is invalid
|
||||||
|
type ErrInvalidPhase struct {
|
||||||
|
Reason string
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e ErrInvalidPhase) Error() string {
|
||||||
|
return fmt.Sprintf("invalid phase: %s", e.Reason)
|
||||||
|
}
|
||||||
|
@ -23,7 +23,6 @@ import (
|
|||||||
airshipv1 "opendev.org/airship/airshipctl/pkg/api/v1alpha1"
|
airshipv1 "opendev.org/airship/airshipctl/pkg/api/v1alpha1"
|
||||||
"opendev.org/airship/airshipctl/pkg/cluster/clustermap"
|
"opendev.org/airship/airshipctl/pkg/cluster/clustermap"
|
||||||
"opendev.org/airship/airshipctl/pkg/document"
|
"opendev.org/airship/airshipctl/pkg/document"
|
||||||
"opendev.org/airship/airshipctl/pkg/errors"
|
|
||||||
"opendev.org/airship/airshipctl/pkg/events"
|
"opendev.org/airship/airshipctl/pkg/events"
|
||||||
k8sapplier "opendev.org/airship/airshipctl/pkg/k8s/applier"
|
k8sapplier "opendev.org/airship/airshipctl/pkg/k8s/applier"
|
||||||
"opendev.org/airship/airshipctl/pkg/k8s/kubeconfig"
|
"opendev.org/airship/airshipctl/pkg/k8s/kubeconfig"
|
||||||
@ -125,7 +124,18 @@ func (e *KubeApplierExecutor) prepareApplier(ch chan events.Event) (*k8sapplier.
|
|||||||
|
|
||||||
// Validate document set
|
// Validate document set
|
||||||
func (e *KubeApplierExecutor) Validate() error {
|
func (e *KubeApplierExecutor) Validate() error {
|
||||||
return errors.ErrNotImplemented{}
|
if e.BundleName == "" {
|
||||||
|
return ErrInvalidPhase{Reason: "k8s applier BundleName is empty"}
|
||||||
|
}
|
||||||
|
docs, err := e.ExecutorBundle.GetAllDocuments()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if len(docs) == 0 {
|
||||||
|
return ErrInvalidPhase{Reason: "no executor documents in the bundle"}
|
||||||
|
}
|
||||||
|
// TODO: need to find if any other validation needs to be added
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Render document set
|
// Render document set
|
||||||
|
@ -254,3 +254,57 @@ func testKubeconfig(stringData string) kubeconfig.Interface {
|
|||||||
},
|
},
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestKubeApplierExecutor_Validate(t *testing.T) {
|
||||||
|
type fields struct {
|
||||||
|
BundleName string
|
||||||
|
path string
|
||||||
|
}
|
||||||
|
tests := []struct {
|
||||||
|
name string
|
||||||
|
fields fields
|
||||||
|
wantErr bool
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "Error empty BundleName",
|
||||||
|
fields: fields{
|
||||||
|
path: "../../k8s/applier/testdata/source_bundle",
|
||||||
|
},
|
||||||
|
wantErr: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Error no documents",
|
||||||
|
fields: fields{BundleName: "some name",
|
||||||
|
path: "../../k8s/applier/testdata/no_bundle",
|
||||||
|
},
|
||||||
|
wantErr: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Success case",
|
||||||
|
fields: fields{BundleName: "some name",
|
||||||
|
path: "../../k8s/applier/testdata/source_bundle",
|
||||||
|
},
|
||||||
|
wantErr: false,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
for _, test := range tests {
|
||||||
|
tt := test
|
||||||
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
execDoc, err := document.NewDocumentFromBytes([]byte(ValidExecutorDoc))
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.NotNil(t, execDoc)
|
||||||
|
|
||||||
|
e, err := executors.NewKubeApplierExecutor(ifc.ExecutorConfig{
|
||||||
|
BundleFactory: testBundleFactory(tt.fields.path),
|
||||||
|
PhaseName: tt.fields.BundleName,
|
||||||
|
ExecutorDocument: execDoc,
|
||||||
|
})
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.NotNil(t, e)
|
||||||
|
|
||||||
|
if err := e.Validate(); (err != nil) != tt.wantErr {
|
||||||
|
t.Errorf("KubeApplierExecutor.Validate() error = %v, wantErr %v", err, tt.wantErr)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user