Updated executor definition to introduce a status interface
Change-Id: Ib95cb2f6464b2d15ba7378e9b40a13899d273ba3 Signed-off-by: bijayasharma <vetbijaya@gmail.com> Relates-To: #409 Closes: #409
This commit is contained in:
parent
2351051ffd
commit
044b636a57
@ -178,6 +178,21 @@ func (p *phase) Render(w io.Writer, executorRender bool, options ifc.RenderOptio
|
||||
return rendered.Write(w)
|
||||
}
|
||||
|
||||
// Status returns the status of the given phase
|
||||
func (p *phase) Status() (ifc.PhaseStatus, error) {
|
||||
executor, err := p.Executor()
|
||||
if err != nil {
|
||||
return ifc.PhaseStatus{}, err
|
||||
}
|
||||
|
||||
sts, err := executor.Status()
|
||||
if err != nil {
|
||||
return ifc.PhaseStatus{}, err
|
||||
}
|
||||
|
||||
return ifc.PhaseStatus{ExecutorStatus: sts}, err
|
||||
}
|
||||
|
||||
// DocumentRoot root that holds all the documents associated with the phase
|
||||
func (p *phase) DocumentRoot() (string, error) {
|
||||
relativePath := p.apiObj.Config.DocumentEntryPoint
|
||||
|
@ -208,6 +208,10 @@ func TestPhaseValidate(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func (e fakeExecutor) Status() (ifc.ExecutorStatus, error) {
|
||||
return ifc.ExecutorStatus{}, nil
|
||||
}
|
||||
|
||||
// TODO develop tests, when we add phase object validation
|
||||
func TestClientByAPIObj(t *testing.T) {
|
||||
helper, err := phase.NewHelper(testConfig(t))
|
||||
|
@ -21,6 +21,7 @@ import (
|
||||
|
||||
"opendev.org/airship/airshipctl/pkg/api/v1alpha1"
|
||||
airshipv1 "opendev.org/airship/airshipctl/pkg/api/v1alpha1"
|
||||
"opendev.org/airship/airshipctl/pkg/errors"
|
||||
"opendev.org/airship/airshipctl/pkg/events"
|
||||
"opendev.org/airship/airshipctl/pkg/inventory"
|
||||
inventoryifc "opendev.org/airship/airshipctl/pkg/inventory/ifc"
|
||||
@ -140,3 +141,8 @@ func toCommandOptions(i inventoryifc.Inventory,
|
||||
Timeout: timeout,
|
||||
}
|
||||
}
|
||||
|
||||
// Status returns the status of the given phase
|
||||
func (e *BaremetalManagerExecutor) Status() (ifc.ExecutorStatus, error) {
|
||||
return ifc.ExecutorStatus{}, errors.ErrNotImplemented{What: BMHManager}
|
||||
}
|
||||
|
@ -24,6 +24,7 @@ import (
|
||||
"opendev.org/airship/airshipctl/pkg/cluster/clustermap"
|
||||
"opendev.org/airship/airshipctl/pkg/clusterctl/client"
|
||||
"opendev.org/airship/airshipctl/pkg/document"
|
||||
"opendev.org/airship/airshipctl/pkg/errors"
|
||||
airerrors "opendev.org/airship/airshipctl/pkg/errors"
|
||||
"opendev.org/airship/airshipctl/pkg/events"
|
||||
"opendev.org/airship/airshipctl/pkg/k8s/kubeconfig"
|
||||
@ -231,3 +232,8 @@ func (c *ClusterctlExecutor) Render(w io.Writer, ro ifc.RenderOptions) error {
|
||||
}
|
||||
return filtered.Write(w)
|
||||
}
|
||||
|
||||
// Status returns the status of the given phase
|
||||
func (c *ClusterctlExecutor) Status() (ifc.ExecutorStatus, error) {
|
||||
return ifc.ExecutorStatus{}, errors.ErrNotImplemented{What: Clusterctl}
|
||||
}
|
||||
|
@ -199,3 +199,8 @@ func (c *ContainerExecutor) setConfig() error {
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Status returns the status of the given phase
|
||||
func (c *ContainerExecutor) Status() (ifc.ExecutorStatus, error) {
|
||||
return ifc.ExecutorStatus{}, errors.ErrNotImplemented{What: GenericContainer}
|
||||
}
|
||||
|
@ -140,3 +140,8 @@ func (c *EphemeralExecutor) Render(w io.Writer, _ ifc.RenderOptions) error {
|
||||
log.Print("Ephemeral Executor Render() will be implemented later.")
|
||||
return nil
|
||||
}
|
||||
|
||||
// Status returns the status of the given phase
|
||||
func (c *EphemeralExecutor) Status() (ifc.ExecutorStatus, error) {
|
||||
return ifc.ExecutorStatus{}, errors.ErrNotImplemented{What: Ephemeral}
|
||||
}
|
||||
|
@ -19,6 +19,10 @@ import (
|
||||
"time"
|
||||
|
||||
"sigs.k8s.io/cli-utils/pkg/common"
|
||||
"sigs.k8s.io/cli-utils/pkg/kstatus/polling/aggregator"
|
||||
"sigs.k8s.io/cli-utils/pkg/kstatus/polling/event"
|
||||
"sigs.k8s.io/cli-utils/pkg/kstatus/status"
|
||||
"sigs.k8s.io/cli-utils/pkg/provider"
|
||||
|
||||
airshipv1 "opendev.org/airship/airshipctl/pkg/api/v1alpha1"
|
||||
"opendev.org/airship/airshipctl/pkg/cluster/clustermap"
|
||||
@ -146,3 +150,43 @@ func (e *KubeApplierExecutor) Render(w io.Writer, o ifc.RenderOptions) error {
|
||||
}
|
||||
return bundle.Write(w)
|
||||
}
|
||||
|
||||
// Status returns the status of the given phase
|
||||
func (e *KubeApplierExecutor) Status() (sts ifc.ExecutorStatus, err error) {
|
||||
var ctx string
|
||||
ctx, err = e.clusterMap.ClusterKubeconfigContext(e.clusterName)
|
||||
if err != nil {
|
||||
return sts, err
|
||||
}
|
||||
log.Debug("Getting kubeconfig file information from kubeconfig provider")
|
||||
path, _, err := e.kubeconfig.GetFile()
|
||||
if err != nil {
|
||||
return sts, err
|
||||
}
|
||||
|
||||
cf := provider.NewProvider(utils.FactoryFromKubeConfig(path, ctx))
|
||||
rm, err := cf.Factory().ToRESTMapper()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
r := utils.DefaultManifestReaderFactory(false, e.ExecutorBundle, rm)
|
||||
infos, err := r.Read()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
var resSts event.ResourceStatuses
|
||||
|
||||
for _, info := range infos {
|
||||
s, sErr := status.Compute(info)
|
||||
if sErr != nil {
|
||||
return
|
||||
}
|
||||
st := &event.ResourceStatus{
|
||||
Status: s.Status,
|
||||
}
|
||||
resSts = append(resSts, st)
|
||||
}
|
||||
_ = aggregator.AggregateStatus(resSts, status.CurrentStatus)
|
||||
return ifc.ExecutorStatus{}, err
|
||||
}
|
||||
|
@ -30,8 +30,12 @@ type Executor interface {
|
||||
Run(chan events.Event, RunOptions)
|
||||
Render(io.Writer, RenderOptions) error
|
||||
Validate() error
|
||||
Status() (ExecutorStatus, error)
|
||||
}
|
||||
|
||||
// ExecutorStatus is a struct which defines the status
|
||||
type ExecutorStatus struct{}
|
||||
|
||||
// RunOptions holds options for run method
|
||||
type RunOptions struct {
|
||||
DryRun bool
|
||||
|
@ -29,6 +29,12 @@ type Phase interface {
|
||||
Details() (string, error)
|
||||
Executor() (Executor, error)
|
||||
Render(io.Writer, bool, RenderOptions) error
|
||||
Status() (PhaseStatus, error)
|
||||
}
|
||||
|
||||
// PhaseStatus is a struct which defines status of phase
|
||||
type PhaseStatus struct {
|
||||
ExecutorStatus ExecutorStatus
|
||||
}
|
||||
|
||||
// Plan provides a way to interact with phase plans
|
||||
|
Loading…
Reference in New Issue
Block a user