Move ClusterConfigBase into CloudupSubContext

This commit is contained in:
John Gardiner Myers 2022-12-18 13:17:21 -08:00
parent 7fcd55737a
commit 0aba1a24b9
5 changed files with 29 additions and 28 deletions

View File

@ -28,7 +28,6 @@ import (
"k8s.io/kops/upup/pkg/fi/nodeup/local"
"k8s.io/kops/upup/pkg/fi/nodeup/nodetasks"
"k8s.io/kops/util/pkg/distributions"
"k8s.io/kops/util/pkg/vfs"
)
type Installation struct {
@ -65,7 +64,6 @@ func (i *Installation) Run() error {
klog.Infof("No package task found; won't update packages")
}
var configBase vfs.Path
var cloud fi.Cloud
var keyStore fi.Keystore
var secretStore fi.SecretStore
@ -75,7 +73,7 @@ func (i *Installation) Run() error {
}
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 {
return fmt.Errorf("error building context: %v", err)
}

View File

@ -58,7 +58,7 @@ func (e *LoadBalancer) IsForAPIServer() bool {
func (v *LoadBalancer) FindAddresses(c *fi.CloudupContext) ([]string, error) {
// 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
}

View File

@ -32,12 +32,11 @@ import (
type Context[T SubContext] struct {
ctx context.Context
Target Target[T]
Cloud Cloud
Cluster *kops.Cluster
Keystore Keystore
SecretStore SecretStore
ClusterConfigBase vfs.Path
Target Target[T]
Cloud Cloud
Cluster *kops.Cluster
Keystore Keystore
SecretStore SecretStore
CheckExisting bool
@ -54,7 +53,10 @@ type SubContext interface {
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{}
func (c *Context[T]) Context() context.Context {
@ -67,31 +69,32 @@ type Warning[T SubContext] struct {
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]{
ctx: ctx,
Cloud: cloud,
Cluster: cluster,
Target: target,
Keystore: keystore,
SecretStore: secretStore,
ClusterConfigBase: clusterConfigBase,
CheckExisting: checkExisting,
tasks: tasks,
T: sub,
ctx: ctx,
Cloud: cloud,
Cluster: cluster,
Target: target,
Keystore: keystore,
SecretStore: secretStore,
CheckExisting: checkExisting,
tasks: tasks,
T: sub,
}
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{}
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) {
sub := CloudupSubContext{}
return NewContext[CloudupSubContext](ctx, target, cluster, cloud, keystore, secretStore, clusterConfigBase, checkExisting, sub, tasks)
sub := CloudupSubContext{
ClusterConfigBase: clusterConfigBase,
}
return NewContext[CloudupSubContext](ctx, target, cluster, cloud, keystore, secretStore, checkExisting, sub, tasks)
}
func (c *Context[T]) AllTasks() map[string]Task[T] {

View File

@ -186,7 +186,7 @@ func getBasePath(c *fi.CloudupContext, e *ManagedFile) (vfs.Path, error) {
return p, nil
}
return c.ClusterConfigBase, nil
return c.T.ClusterConfigBase, nil
}
// RenderTerraform is responsible for rendering the terraform json.

View File

@ -384,7 +384,7 @@ func (c *NodeUpCommand) Run(out io.Writer) error {
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 {
klog.Exitf("error building context: %v", err)
}