Merge "Updated executor definition to introduce a status interface"
This commit is contained in:
commit
a39d547981
@ -177,6 +177,21 @@ func (p *phase) Render(w io.Writer, executorRender bool, options ifc.RenderOptio
|
|||||||
return rendered.Write(w)
|
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
|
// DocumentRoot root that holds all the documents associated with the phase
|
||||||
func (p *phase) DocumentRoot() (string, error) {
|
func (p *phase) DocumentRoot() (string, error) {
|
||||||
relativePath := p.apiObj.Config.DocumentEntryPoint
|
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
|
// TODO develop tests, when we add phase object validation
|
||||||
func TestClientByAPIObj(t *testing.T) {
|
func TestClientByAPIObj(t *testing.T) {
|
||||||
helper, err := phase.NewHelper(testConfig(t))
|
helper, err := phase.NewHelper(testConfig(t))
|
||||||
|
@ -21,6 +21,7 @@ import (
|
|||||||
|
|
||||||
"opendev.org/airship/airshipctl/pkg/api/v1alpha1"
|
"opendev.org/airship/airshipctl/pkg/api/v1alpha1"
|
||||||
airshipv1 "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/events"
|
||||||
"opendev.org/airship/airshipctl/pkg/inventory"
|
"opendev.org/airship/airshipctl/pkg/inventory"
|
||||||
inventoryifc "opendev.org/airship/airshipctl/pkg/inventory/ifc"
|
inventoryifc "opendev.org/airship/airshipctl/pkg/inventory/ifc"
|
||||||
@ -140,3 +141,8 @@ func toCommandOptions(i inventoryifc.Inventory,
|
|||||||
Timeout: timeout,
|
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/cluster/clustermap"
|
||||||
"opendev.org/airship/airshipctl/pkg/clusterctl/client"
|
"opendev.org/airship/airshipctl/pkg/clusterctl/client"
|
||||||
"opendev.org/airship/airshipctl/pkg/document"
|
"opendev.org/airship/airshipctl/pkg/document"
|
||||||
|
"opendev.org/airship/airshipctl/pkg/errors"
|
||||||
airerrors "opendev.org/airship/airshipctl/pkg/errors"
|
airerrors "opendev.org/airship/airshipctl/pkg/errors"
|
||||||
"opendev.org/airship/airshipctl/pkg/events"
|
"opendev.org/airship/airshipctl/pkg/events"
|
||||||
"opendev.org/airship/airshipctl/pkg/k8s/kubeconfig"
|
"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)
|
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
|
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.")
|
log.Print("Ephemeral Executor Render() will be implemented later.")
|
||||||
return nil
|
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"
|
"time"
|
||||||
|
|
||||||
"sigs.k8s.io/cli-utils/pkg/common"
|
"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"
|
airshipv1 "opendev.org/airship/airshipctl/pkg/api/v1alpha1"
|
||||||
"opendev.org/airship/airshipctl/pkg/cluster/clustermap"
|
"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)
|
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)
|
Run(chan events.Event, RunOptions)
|
||||||
Render(io.Writer, RenderOptions) error
|
Render(io.Writer, RenderOptions) error
|
||||||
Validate() error
|
Validate() error
|
||||||
|
Status() (ExecutorStatus, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ExecutorStatus is a struct which defines the status
|
||||||
|
type ExecutorStatus struct{}
|
||||||
|
|
||||||
// RunOptions holds options for run method
|
// RunOptions holds options for run method
|
||||||
type RunOptions struct {
|
type RunOptions struct {
|
||||||
DryRun bool
|
DryRun bool
|
||||||
|
@ -29,6 +29,12 @@ type Phase interface {
|
|||||||
Details() (string, error)
|
Details() (string, error)
|
||||||
Executor() (Executor, error)
|
Executor() (Executor, error)
|
||||||
Render(io.Writer, bool, RenderOptions) 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
|
// Plan provides a way to interact with phase plans
|
||||||
|
Loading…
x
Reference in New Issue
Block a user