Merge "Use cluster name as context in executors"
This commit is contained in:
commit
21e6bf7985
pkg
clusterctl/client
k8s
applier
client
kubectl
poller
utils
phase/apply
@ -145,6 +145,7 @@ func (c *ClusterctlExecutor) init(opts ifc.RunOptions, evtCh chan events.Event)
|
||||
}
|
||||
return
|
||||
}
|
||||
// Use cluster name as context in kubeconfig file
|
||||
err = c.Init(kubeConfigFile, c.clusterName)
|
||||
if err != nil {
|
||||
c.handleErr(err, evtCh)
|
||||
|
@ -33,7 +33,8 @@ import (
|
||||
|
||||
// ExecutorOptions provide a way to configure executor
|
||||
type ExecutorOptions struct {
|
||||
BundleName string
|
||||
BundleName string
|
||||
ClusterName string
|
||||
|
||||
ExecutorDocument document.Document
|
||||
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
|
||||
func registerExecutor(cfg ifc.ExecutorConfig) (ifc.Executor, error) {
|
||||
return NewExecutor(ExecutorOptions{
|
||||
ClusterName: cfg.ClusterName,
|
||||
BundleName: cfg.PhaseName,
|
||||
Helper: cfg.Helper,
|
||||
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
|
||||
e.cleanup = cleanup
|
||||
|
||||
factory := utils.FactoryFromKubeConfigPath(path)
|
||||
// Use cluster name as context in kubeconfig file
|
||||
factory := utils.FactoryFromKubeConfig(path, e.Options.ClusterName)
|
||||
streams := utils.Streams()
|
||||
return NewApplier(ch, factory, streams), bundle, nil
|
||||
}
|
||||
|
@ -65,7 +65,8 @@ func NewClient(cfg *config.Config) (Interface, error) {
|
||||
client := new(Client)
|
||||
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())
|
||||
client.kubectl = kubectl.NewKubectl(f).WithBufferDir(pathToBufferDir)
|
||||
|
@ -39,7 +39,7 @@ var (
|
||||
)
|
||||
|
||||
func TestNewKubectlFromKubeConfigPath(t *testing.T) {
|
||||
f := k8sutils.FactoryFromKubeConfigPath(kubeconfigPath)
|
||||
f := k8sutils.FactoryFromKubeConfig(kubeconfigPath, "")
|
||||
kctl := kubectl.NewKubectl(f).WithBufferDir("/tmp/.airship")
|
||||
|
||||
assert.NotNil(t, kctl.Factory)
|
||||
|
@ -30,7 +30,7 @@ import (
|
||||
func TestNewStatusPoller(t *testing.T) {
|
||||
airClient := fake.NewClient()
|
||||
|
||||
f := k8sutils.FactoryFromKubeConfigPath("testdata/kubeconfig.yaml")
|
||||
f := k8sutils.FactoryFromKubeConfig("testdata/kubeconfig.yaml", "")
|
||||
restConfig, err := f.ToRESTConfig()
|
||||
require.NoError(t, err)
|
||||
restMapper, err := f.ToRESTMapper()
|
||||
|
@ -28,11 +28,12 @@ import (
|
||||
"opendev.org/airship/airshipctl/pkg/document"
|
||||
)
|
||||
|
||||
// FactoryFromKubeConfigPath returns a factory with the
|
||||
// default Kubernetes resources for the given kube config path
|
||||
func FactoryFromKubeConfigPath(kp string) cmdutil.Factory {
|
||||
// FactoryFromKubeConfig returns a factory with the
|
||||
// default Kubernetes resources for the given kube config path and context
|
||||
func FactoryFromKubeConfig(path, context string) cmdutil.Factory {
|
||||
kf := genericclioptions.NewConfigFlags(false)
|
||||
kf.KubeConfig = &kp
|
||||
kf.KubeConfig = &path
|
||||
kf.Context = &context
|
||||
return cmdutil.NewFactory(kf)
|
||||
}
|
||||
|
||||
|
@ -29,7 +29,7 @@ import (
|
||||
func TestDefaultManifestFactory(t *testing.T) {
|
||||
bundle, err := document.NewBundleByPath("testdata/source_bundle")
|
||||
require.NoError(t, err)
|
||||
reader := DefaultManifestReaderFactory(false, bundle, FactoryFromKubeConfigPath("testdata/kubeconfig.yaml"))
|
||||
reader := DefaultManifestReaderFactory(false, bundle, FactoryFromKubeConfig("testdata/kubeconfig.yaml", ""))
|
||||
require.NotNil(t, reader)
|
||||
}
|
||||
|
||||
@ -64,7 +64,7 @@ func TestManifestBundleReader(t *testing.T) {
|
||||
for _, tt := range tests {
|
||||
tt := tt
|
||||
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 {
|
||||
reader.StreamReader.Reader = tt.reader
|
||||
}
|
||||
|
@ -42,7 +42,7 @@ type Options struct {
|
||||
|
||||
// Initialize Options with required field, such as Applier
|
||||
func (o *Options) Initialize(kubeConfigPath string) {
|
||||
f := utils.FactoryFromKubeConfigPath(kubeConfigPath)
|
||||
f := utils.FactoryFromKubeConfig(kubeConfigPath, "")
|
||||
streams := utils.Streams()
|
||||
o.EventChannel = make(chan events.Event)
|
||||
o.Applier = applier.NewApplier(o.EventChannel, f, streams)
|
||||
|
Loading…
x
Reference in New Issue
Block a user