Stop using CurrentContextEntryPoint in remote pkg

Note this commit doesn't refactor remote package, it is only created
to shift from using CurrentContextEntryPoint function, which would
in turn allow us to refactor config package and get rid of cluster
types in airship config.

Relates-To: #349
Relates-To: #246
Relates-To: #265

Change-Id: I1c941c8ade3497b9911fb126465aa85c25567431
This commit is contained in:
Kostiantyn Kalynovskyi 2020-09-21 21:07:47 -05:00
parent 1eba48d8cd
commit 2b30dd0d71
13 changed files with 77 additions and 11 deletions

View File

@ -21,6 +21,8 @@ import (
"opendev.org/airship/airshipctl/pkg/config" "opendev.org/airship/airshipctl/pkg/config"
"opendev.org/airship/airshipctl/pkg/document" "opendev.org/airship/airshipctl/pkg/document"
"opendev.org/airship/airshipctl/pkg/log" "opendev.org/airship/airshipctl/pkg/log"
"opendev.org/airship/airshipctl/pkg/phase"
"opendev.org/airship/airshipctl/pkg/phase/ifc"
"opendev.org/airship/airshipctl/pkg/remote/power" "opendev.org/airship/airshipctl/pkg/remote/power"
"opendev.org/airship/airshipctl/pkg/remote/redfish" "opendev.org/airship/airshipctl/pkg/remote/redfish"
redfishdell "opendev.org/airship/airshipctl/pkg/remote/redfish/vendors/dell" redfishdell "opendev.org/airship/airshipctl/pkg/remote/redfish/vendors/dell"
@ -115,7 +117,7 @@ func ByName(name string) HostSelector {
// NewManager provides a manager that exposes the capability to perform remote direct functionality and other // NewManager provides a manager that exposes the capability to perform remote direct functionality and other
// out-of-band management on multiple hosts. // out-of-band management on multiple hosts.
func NewManager(cfg *config.Config, phase string, hosts ...HostSelector) (*Manager, error) { func NewManager(cfg *config.Config, phaseName string, hosts ...HostSelector) (*Manager, error) {
managementCfg, err := cfg.CurrentContextManagementConfig() managementCfg, err := cfg.CurrentContextManagementConfig()
if err != nil { if err != nil {
return nil, err return nil, err
@ -125,12 +127,18 @@ func NewManager(cfg *config.Config, phase string, hosts ...HostSelector) (*Manag
return nil, err return nil, err
} }
entrypoint, err := cfg.CurrentContextEntryPoint(phase) helper, err := phase.NewHelper(cfg)
if err != nil { if err != nil {
return nil, err return nil, err
} }
docBundle, err := document.NewBundleByPath(entrypoint) phaseClient := phase.NewClient(helper)
phase, err := phaseClient.PhaseByID(ifc.ID{Name: phaseName})
if err != nil {
return nil, err
}
docBundle, err := document.NewBundleByPath(phase.DocumentRoot())
if err != nil { if err != nil {
return nil, err return nil, err
} }

View File

@ -56,8 +56,8 @@ func withTestDataPath(path string) Configuration {
if err != nil { if err != nil {
panic(fmt.Sprintf("Unable to initialize management tests. Current Context error %q", err)) panic(fmt.Sprintf("Unable to initialize management tests. Current Context error %q", err))
} }
manifest.TargetPath = fmt.Sprintf("testdata/%s", path) manifest.TargetPath = fmt.Sprintf("testdata/%s", path)
manifest.MetadataPath = "metadata.yaml"
} }
} }
@ -108,6 +108,9 @@ func TestNewManagerMultipleSelectorsNoMatch(t *testing.T) {
manager, err := NewManager(settings, config.BootstrapPhase, ByName("master-2"), manager, err := NewManager(settings, config.BootstrapPhase, ByName("master-2"),
ByLabel(document.EphemeralHostSelector)) ByLabel(document.EphemeralHostSelector))
// Must return ErrNoHostsFound here, without check for specific error, test can panic
require.Equal(t, ErrNoHostsFound{}, err)
require.Equal(t, 0, len(manager.Hosts)) require.Equal(t, 0, len(manager.Hosts))
assert.Error(t, err) assert.Error(t, err)
} }

View File

@ -19,17 +19,25 @@ import (
"opendev.org/airship/airshipctl/pkg/config" "opendev.org/airship/airshipctl/pkg/config"
"opendev.org/airship/airshipctl/pkg/document" "opendev.org/airship/airshipctl/pkg/document"
"opendev.org/airship/airshipctl/pkg/log" "opendev.org/airship/airshipctl/pkg/log"
"opendev.org/airship/airshipctl/pkg/phase"
"opendev.org/airship/airshipctl/pkg/phase/ifc"
"opendev.org/airship/airshipctl/pkg/remote/power" "opendev.org/airship/airshipctl/pkg/remote/power"
) )
// DoRemoteDirect bootstraps the ephemeral node. // DoRemoteDirect bootstraps the ephemeral node.
func (b baremetalHost) DoRemoteDirect(cfg *config.Config) error { func (b baremetalHost) DoRemoteDirect(cfg *config.Config) error {
root, err := cfg.CurrentContextEntryPoint(config.BootstrapPhase) helper, err := phase.NewHelper(cfg)
if err != nil { if err != nil {
return err return err
} }
docBundle, err := document.NewBundleByPath(root) phaseClient := phase.NewClient(helper)
phase, err := phaseClient.PhaseByID(ifc.ID{Name: config.BootstrapPhase})
if err != nil {
return err
}
docBundle, err := document.NewBundleByPath(phase.DocumentRoot())
if err != nil { if err != nil {
return err return err
} }

View File

@ -1,3 +1,4 @@
resources: resources:
- baremetal.yaml - baremetal.yaml
- remote_direct_configuration.yaml - remote_direct_configuration.yaml
- phase.yaml

View File

@ -0,0 +1,12 @@
---
apiVersion: airshipit.org/v1alpha1
kind: Phase
metadata:
name: bootstrap
clusterName: ephemeral-cluster
config:
executorRef:
apiVersion: airshipit.org/v1alpha1
kind: KubernetesApply
name: kubernetes-apply
documentEntryPoint: manifests/site/test-site/ephemeral/bootstrap

View File

@ -0,0 +1,2 @@
phase:
path: manifests/site/test-site/ephemeral/bootstrap

View File

@ -0,0 +1,2 @@
phase:
path: emptyurl/manifests/site/test-site/ephemeral/bootstrap

View File

@ -1,3 +1,4 @@
resources: resources:
- baremetal.yaml - baremetal.yaml
- remote_direct_configuration.yaml - remote_direct_configuration.yaml
- phase.yaml

View File

@ -0,0 +1,12 @@
---
apiVersion: airshipit.org/v1alpha1
kind: Phase
metadata:
name: bootstrap
clusterName: ephemeral-cluster
config:
executorRef:
apiVersion: airshipit.org/v1alpha1
kind: KubernetesApply
name: kubernetes-apply
documentEntryPoint: manifests/site/test-site/ephemeral/bootstrap

View File

@ -0,0 +1,2 @@
phase:
path: manifests/site/test-site/ephemeral/bootstrap

View File

@ -1,2 +1,3 @@
resources: resources:
- baremetal.yaml - baremetal.yaml
- phase.yaml

View File

@ -0,0 +1,12 @@
---
apiVersion: airshipit.org/v1alpha1
kind: Phase
metadata:
name: bootstrap
clusterName: ephemeral-cluster
config:
executorRef:
apiVersion: airshipit.org/v1alpha1
kind: KubernetesApply
name: kubernetes-apply
documentEntryPoint: manifests/site/test-site/ephemeral/bootstrap

View File

@ -0,0 +1,2 @@
phase:
path: manifests/site/test-site/ephemeral/bootstrap