Merge "Use cluster name as context in executors"
This commit is contained in:
commit
21e6bf7985
@ -145,6 +145,7 @@ func (c *ClusterctlExecutor) init(opts ifc.RunOptions, evtCh chan events.Event)
|
|||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
// Use cluster name as context in kubeconfig file
|
||||||
err = c.Init(kubeConfigFile, c.clusterName)
|
err = c.Init(kubeConfigFile, c.clusterName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.handleErr(err, evtCh)
|
c.handleErr(err, evtCh)
|
||||||
|
@ -34,6 +34,7 @@ import (
|
|||||||
// ExecutorOptions provide a way to configure executor
|
// ExecutorOptions provide a way to configure executor
|
||||||
type ExecutorOptions struct {
|
type ExecutorOptions struct {
|
||||||
BundleName string
|
BundleName string
|
||||||
|
ClusterName string
|
||||||
|
|
||||||
ExecutorDocument document.Document
|
ExecutorDocument document.Document
|
||||||
ExecutorBundle document.Bundle
|
ExecutorBundle document.Bundle
|
||||||
@ -57,6 +58,7 @@ func RegisterExecutor(registry map[schema.GroupVersionKind]ifc.ExecutorFactory)
|
|||||||
// registerExecutor is here so that executor in theory can be used outside phases
|
// registerExecutor is here so that executor in theory can be used outside phases
|
||||||
func registerExecutor(cfg ifc.ExecutorConfig) (ifc.Executor, error) {
|
func registerExecutor(cfg ifc.ExecutorConfig) (ifc.Executor, error) {
|
||||||
return NewExecutor(ExecutorOptions{
|
return NewExecutor(ExecutorOptions{
|
||||||
|
ClusterName: cfg.ClusterName,
|
||||||
BundleName: cfg.PhaseName,
|
BundleName: cfg.PhaseName,
|
||||||
Helper: cfg.Helper,
|
Helper: cfg.Helper,
|
||||||
ExecutorBundle: cfg.ExecutorBundle,
|
ExecutorBundle: cfg.ExecutorBundle,
|
||||||
@ -125,8 +127,8 @@ func (e *Executor) prepareApplier(ch chan events.Event) (*Applier, document.Bund
|
|||||||
}
|
}
|
||||||
// set up cleanup only if all calls up to here were successful
|
// set up cleanup only if all calls up to here were successful
|
||||||
e.cleanup = cleanup
|
e.cleanup = cleanup
|
||||||
|
// Use cluster name as context in kubeconfig file
|
||||||
factory := utils.FactoryFromKubeConfigPath(path)
|
factory := utils.FactoryFromKubeConfig(path, e.Options.ClusterName)
|
||||||
streams := utils.Streams()
|
streams := utils.Streams()
|
||||||
return NewApplier(ch, factory, streams), bundle, nil
|
return NewApplier(ch, factory, streams), bundle, nil
|
||||||
}
|
}
|
||||||
|
@ -65,7 +65,8 @@ func NewClient(cfg *config.Config) (Interface, error) {
|
|||||||
client := new(Client)
|
client := new(Client)
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
f := k8sutils.FactoryFromKubeConfigPath(cfg.KubeConfigPath())
|
// TODO add support for kubeconfig context, for now use current context
|
||||||
|
f := k8sutils.FactoryFromKubeConfig(cfg.KubeConfigPath(), "")
|
||||||
|
|
||||||
pathToBufferDir := filepath.Dir(cfg.LoadedConfigPath())
|
pathToBufferDir := filepath.Dir(cfg.LoadedConfigPath())
|
||||||
client.kubectl = kubectl.NewKubectl(f).WithBufferDir(pathToBufferDir)
|
client.kubectl = kubectl.NewKubectl(f).WithBufferDir(pathToBufferDir)
|
||||||
|
@ -39,7 +39,7 @@ var (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func TestNewKubectlFromKubeConfigPath(t *testing.T) {
|
func TestNewKubectlFromKubeConfigPath(t *testing.T) {
|
||||||
f := k8sutils.FactoryFromKubeConfigPath(kubeconfigPath)
|
f := k8sutils.FactoryFromKubeConfig(kubeconfigPath, "")
|
||||||
kctl := kubectl.NewKubectl(f).WithBufferDir("/tmp/.airship")
|
kctl := kubectl.NewKubectl(f).WithBufferDir("/tmp/.airship")
|
||||||
|
|
||||||
assert.NotNil(t, kctl.Factory)
|
assert.NotNil(t, kctl.Factory)
|
||||||
|
@ -30,7 +30,7 @@ import (
|
|||||||
func TestNewStatusPoller(t *testing.T) {
|
func TestNewStatusPoller(t *testing.T) {
|
||||||
airClient := fake.NewClient()
|
airClient := fake.NewClient()
|
||||||
|
|
||||||
f := k8sutils.FactoryFromKubeConfigPath("testdata/kubeconfig.yaml")
|
f := k8sutils.FactoryFromKubeConfig("testdata/kubeconfig.yaml", "")
|
||||||
restConfig, err := f.ToRESTConfig()
|
restConfig, err := f.ToRESTConfig()
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
restMapper, err := f.ToRESTMapper()
|
restMapper, err := f.ToRESTMapper()
|
||||||
|
@ -28,11 +28,12 @@ import (
|
|||||||
"opendev.org/airship/airshipctl/pkg/document"
|
"opendev.org/airship/airshipctl/pkg/document"
|
||||||
)
|
)
|
||||||
|
|
||||||
// FactoryFromKubeConfigPath returns a factory with the
|
// FactoryFromKubeConfig returns a factory with the
|
||||||
// default Kubernetes resources for the given kube config path
|
// default Kubernetes resources for the given kube config path and context
|
||||||
func FactoryFromKubeConfigPath(kp string) cmdutil.Factory {
|
func FactoryFromKubeConfig(path, context string) cmdutil.Factory {
|
||||||
kf := genericclioptions.NewConfigFlags(false)
|
kf := genericclioptions.NewConfigFlags(false)
|
||||||
kf.KubeConfig = &kp
|
kf.KubeConfig = &path
|
||||||
|
kf.Context = &context
|
||||||
return cmdutil.NewFactory(kf)
|
return cmdutil.NewFactory(kf)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -29,7 +29,7 @@ import (
|
|||||||
func TestDefaultManifestFactory(t *testing.T) {
|
func TestDefaultManifestFactory(t *testing.T) {
|
||||||
bundle, err := document.NewBundleByPath("testdata/source_bundle")
|
bundle, err := document.NewBundleByPath("testdata/source_bundle")
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
reader := DefaultManifestReaderFactory(false, bundle, FactoryFromKubeConfigPath("testdata/kubeconfig.yaml"))
|
reader := DefaultManifestReaderFactory(false, bundle, FactoryFromKubeConfig("testdata/kubeconfig.yaml", ""))
|
||||||
require.NotNil(t, reader)
|
require.NotNil(t, reader)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -64,7 +64,7 @@ func TestManifestBundleReader(t *testing.T) {
|
|||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
tt := tt
|
tt := tt
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
reader := NewManifestBundleReader(false, bundle, FactoryFromKubeConfigPath("testdata/kubeconfig.yaml"))
|
reader := NewManifestBundleReader(false, bundle, FactoryFromKubeConfig("testdata/kubeconfig.yaml", ""))
|
||||||
if tt.reader != nil {
|
if tt.reader != nil {
|
||||||
reader.StreamReader.Reader = tt.reader
|
reader.StreamReader.Reader = tt.reader
|
||||||
}
|
}
|
||||||
|
@ -42,7 +42,7 @@ type Options struct {
|
|||||||
|
|
||||||
// Initialize Options with required field, such as Applier
|
// Initialize Options with required field, such as Applier
|
||||||
func (o *Options) Initialize(kubeConfigPath string) {
|
func (o *Options) Initialize(kubeConfigPath string) {
|
||||||
f := utils.FactoryFromKubeConfigPath(kubeConfigPath)
|
f := utils.FactoryFromKubeConfig(kubeConfigPath, "")
|
||||||
streams := utils.Streams()
|
streams := utils.Streams()
|
||||||
o.EventChannel = make(chan events.Event)
|
o.EventChannel = make(chan events.Event)
|
||||||
o.Applier = applier.NewApplier(o.EventChannel, f, streams)
|
o.Applier = applier.NewApplier(o.EventChannel, f, streams)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user