mirror of https://github.com/kubernetes/kops.git
Move ClusterConfigBase into CloudupSubContext
This commit is contained in:
parent
7fcd55737a
commit
0aba1a24b9
|
@ -28,7 +28,6 @@ import (
|
||||||
"k8s.io/kops/upup/pkg/fi/nodeup/local"
|
"k8s.io/kops/upup/pkg/fi/nodeup/local"
|
||||||
"k8s.io/kops/upup/pkg/fi/nodeup/nodetasks"
|
"k8s.io/kops/upup/pkg/fi/nodeup/nodetasks"
|
||||||
"k8s.io/kops/util/pkg/distributions"
|
"k8s.io/kops/util/pkg/distributions"
|
||||||
"k8s.io/kops/util/pkg/vfs"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type Installation struct {
|
type Installation struct {
|
||||||
|
@ -65,7 +64,6 @@ func (i *Installation) Run() error {
|
||||||
klog.Infof("No package task found; won't update packages")
|
klog.Infof("No package task found; won't update packages")
|
||||||
}
|
}
|
||||||
|
|
||||||
var configBase vfs.Path
|
|
||||||
var cloud fi.Cloud
|
var cloud fi.Cloud
|
||||||
var keyStore fi.Keystore
|
var keyStore fi.Keystore
|
||||||
var secretStore fi.SecretStore
|
var secretStore fi.SecretStore
|
||||||
|
@ -75,7 +73,7 @@ func (i *Installation) Run() error {
|
||||||
}
|
}
|
||||||
|
|
||||||
checkExisting := true
|
checkExisting := true
|
||||||
context, err := fi.NewNodeupContext(ctx, target, nil, cloud, keyStore, secretStore, configBase, checkExisting, tasks)
|
context, err := fi.NewNodeupContext(ctx, target, nil, cloud, keyStore, secretStore, checkExisting, tasks)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("error building context: %v", err)
|
return fmt.Errorf("error building context: %v", err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -58,7 +58,7 @@ func (e *LoadBalancer) IsForAPIServer() bool {
|
||||||
|
|
||||||
func (v *LoadBalancer) FindAddresses(c *fi.CloudupContext) ([]string, error) {
|
func (v *LoadBalancer) FindAddresses(c *fi.CloudupContext) ([]string, error) {
|
||||||
// TODO(hakman): Use mock to handle this more gracefully
|
// TODO(hakman): Use mock to handle this more gracefully
|
||||||
if strings.HasPrefix(c.ClusterConfigBase.Path(), "memfs://tests/") {
|
if strings.HasPrefix(c.T.ClusterConfigBase.Path(), "memfs://tests/") {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -37,7 +37,6 @@ type Context[T SubContext] struct {
|
||||||
Cluster *kops.Cluster
|
Cluster *kops.Cluster
|
||||||
Keystore Keystore
|
Keystore Keystore
|
||||||
SecretStore SecretStore
|
SecretStore SecretStore
|
||||||
ClusterConfigBase vfs.Path
|
|
||||||
|
|
||||||
CheckExisting bool
|
CheckExisting bool
|
||||||
|
|
||||||
|
@ -54,7 +53,10 @@ type SubContext interface {
|
||||||
CloudupSubContext | NodeupSubContext
|
CloudupSubContext | NodeupSubContext
|
||||||
}
|
}
|
||||||
|
|
||||||
type CloudupSubContext struct{}
|
type CloudupSubContext struct {
|
||||||
|
// TODO: Few places use this. They could instead get it from the cluster spec.
|
||||||
|
ClusterConfigBase vfs.Path
|
||||||
|
}
|
||||||
type NodeupSubContext struct{}
|
type NodeupSubContext struct{}
|
||||||
|
|
||||||
func (c *Context[T]) Context() context.Context {
|
func (c *Context[T]) Context() context.Context {
|
||||||
|
@ -67,7 +69,7 @@ type Warning[T SubContext] struct {
|
||||||
Message string
|
Message string
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewContext[T SubContext](ctx context.Context, target Target[T], cluster *kops.Cluster, cloud Cloud, keystore Keystore, secretStore SecretStore, clusterConfigBase vfs.Path, checkExisting bool, sub T, tasks map[string]Task[T]) (*Context[T], error) {
|
func NewContext[T SubContext](ctx context.Context, target Target[T], cluster *kops.Cluster, cloud Cloud, keystore Keystore, secretStore SecretStore, checkExisting bool, sub T, tasks map[string]Task[T]) (*Context[T], error) {
|
||||||
c := &Context[T]{
|
c := &Context[T]{
|
||||||
ctx: ctx,
|
ctx: ctx,
|
||||||
Cloud: cloud,
|
Cloud: cloud,
|
||||||
|
@ -75,7 +77,6 @@ func NewContext[T SubContext](ctx context.Context, target Target[T], cluster *ko
|
||||||
Target: target,
|
Target: target,
|
||||||
Keystore: keystore,
|
Keystore: keystore,
|
||||||
SecretStore: secretStore,
|
SecretStore: secretStore,
|
||||||
ClusterConfigBase: clusterConfigBase,
|
|
||||||
CheckExisting: checkExisting,
|
CheckExisting: checkExisting,
|
||||||
tasks: tasks,
|
tasks: tasks,
|
||||||
T: sub,
|
T: sub,
|
||||||
|
@ -84,14 +85,16 @@ func NewContext[T SubContext](ctx context.Context, target Target[T], cluster *ko
|
||||||
return c, nil
|
return c, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewNodeupContext(ctx context.Context, target NodeupTarget, cluster *kops.Cluster, cloud Cloud, keystore Keystore, secretStore SecretStore, clusterConfigBase vfs.Path, checkExisting bool, tasks map[string]NodeupTask) (*NodeupContext, error) {
|
func NewNodeupContext(ctx context.Context, target NodeupTarget, cluster *kops.Cluster, cloud Cloud, keystore Keystore, secretStore SecretStore, checkExisting bool, tasks map[string]NodeupTask) (*NodeupContext, error) {
|
||||||
sub := NodeupSubContext{}
|
sub := NodeupSubContext{}
|
||||||
return NewContext[NodeupSubContext](ctx, target, cluster, cloud, keystore, secretStore, clusterConfigBase, checkExisting, sub, tasks)
|
return NewContext[NodeupSubContext](ctx, target, cluster, cloud, keystore, secretStore, checkExisting, sub, tasks)
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewCloudupContext(ctx context.Context, target CloudupTarget, cluster *kops.Cluster, cloud Cloud, keystore Keystore, secretStore SecretStore, clusterConfigBase vfs.Path, checkExisting bool, tasks map[string]CloudupTask) (*CloudupContext, error) {
|
func NewCloudupContext(ctx context.Context, target CloudupTarget, cluster *kops.Cluster, cloud Cloud, keystore Keystore, secretStore SecretStore, clusterConfigBase vfs.Path, checkExisting bool, tasks map[string]CloudupTask) (*CloudupContext, error) {
|
||||||
sub := CloudupSubContext{}
|
sub := CloudupSubContext{
|
||||||
return NewContext[CloudupSubContext](ctx, target, cluster, cloud, keystore, secretStore, clusterConfigBase, checkExisting, sub, tasks)
|
ClusterConfigBase: clusterConfigBase,
|
||||||
|
}
|
||||||
|
return NewContext[CloudupSubContext](ctx, target, cluster, cloud, keystore, secretStore, checkExisting, sub, tasks)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Context[T]) AllTasks() map[string]Task[T] {
|
func (c *Context[T]) AllTasks() map[string]Task[T] {
|
||||||
|
|
|
@ -186,7 +186,7 @@ func getBasePath(c *fi.CloudupContext, e *ManagedFile) (vfs.Path, error) {
|
||||||
return p, nil
|
return p, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
return c.ClusterConfigBase, nil
|
return c.T.ClusterConfigBase, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// RenderTerraform is responsible for rendering the terraform json.
|
// RenderTerraform is responsible for rendering the terraform json.
|
||||||
|
|
|
@ -384,7 +384,7 @@ func (c *NodeUpCommand) Run(out io.Writer) error {
|
||||||
return fmt.Errorf("unsupported target type %q", c.Target)
|
return fmt.Errorf("unsupported target type %q", c.Target)
|
||||||
}
|
}
|
||||||
|
|
||||||
context, err := fi.NewNodeupContext(ctx, target, c.cluster, cloud, keyStore, secretStore, configBase, checkExisting, taskMap)
|
context, err := fi.NewNodeupContext(ctx, target, c.cluster, cloud, keyStore, secretStore, checkExisting, taskMap)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
klog.Exitf("error building context: %v", err)
|
klog.Exitf("error building context: %v", err)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue