From f5fb91c8586ed9f2bd5abfad4293e988415005eb Mon Sep 17 00:00:00 2001 From: John Gardiner Myers Date: Tue, 20 Dec 2022 09:03:16 -0800 Subject: [PATCH] Move SecretStore to CloudupSubContext --- upup/pkg/fi/context.go | 18 +++++++++--------- upup/pkg/fi/fitasks/mirrorsecrets.go | 4 ++-- upup/pkg/fi/fitasks/secret.go | 4 ++-- upup/pkg/fi/nodeup/command.go | 2 +- 4 files changed, 14 insertions(+), 14 deletions(-) diff --git a/upup/pkg/fi/context.go b/upup/pkg/fi/context.go index 4aa38e2cb1..b8a2249f4a 100644 --- a/upup/pkg/fi/context.go +++ b/upup/pkg/fi/context.go @@ -33,9 +33,8 @@ import ( type Context[T SubContext] struct { ctx context.Context - Target Target[T] - Keystore Keystore - SecretStore SecretStore + Target Target[T] + Keystore Keystore CheckExisting bool @@ -58,6 +57,7 @@ type CloudupSubContext struct { Cluster *kops.Cluster // TODO: Few places use this. They could instead get it from the cluster spec. ClusterConfigBase vfs.Path + SecretStore SecretStore } type InstallSubContext struct{} type NodeupSubContext struct { @@ -75,12 +75,11 @@ type Warning[T SubContext] struct { Message string } -func newContext[T SubContext](ctx context.Context, target Target[T], keystore Keystore, secretStore SecretStore, checkExisting bool, sub T, tasks map[string]Task[T]) (*Context[T], error) { +func newContext[T SubContext](ctx context.Context, target Target[T], keystore Keystore, checkExisting bool, sub T, tasks map[string]Task[T]) (*Context[T], error) { c := &Context[T]{ ctx: ctx, Target: target, Keystore: keystore, - SecretStore: secretStore, CheckExisting: checkExisting, tasks: tasks, T: sub, @@ -91,14 +90,14 @@ func newContext[T SubContext](ctx context.Context, target Target[T], keystore Ke func NewInstallContext(ctx context.Context, target InstallTarget, tasks map[string]InstallTask) (*InstallContext, error) { sub := InstallSubContext{} - return newContext[InstallSubContext](ctx, target, nil, nil, true, sub, tasks) + return newContext[InstallSubContext](ctx, target, nil, true, sub, tasks) } -func NewNodeupContext(ctx context.Context, target NodeupTarget, keystore Keystore, secretStore SecretStore, checkExisting bool, bootConfig *nodeup.BootConfig, nodeupConfig *nodeup.Config, tasks map[string]NodeupTask) (*NodeupContext, error) { +func NewNodeupContext(ctx context.Context, target NodeupTarget, keystore Keystore, checkExisting bool, bootConfig *nodeup.BootConfig, nodeupConfig *nodeup.Config, tasks map[string]NodeupTask) (*NodeupContext, error) { sub := NodeupSubContext{ BootConfig: bootConfig, NodeupConfig: nodeupConfig, } - return newContext[NodeupSubContext](ctx, target, keystore, secretStore, checkExisting, sub, tasks) + return newContext[NodeupSubContext](ctx, target, keystore, 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) { @@ -106,8 +105,9 @@ func NewCloudupContext(ctx context.Context, target CloudupTarget, cluster *kops. Cloud: cloud, Cluster: cluster, ClusterConfigBase: clusterConfigBase, + SecretStore: secretStore, } - return newContext[CloudupSubContext](ctx, target, keystore, secretStore, checkExisting, sub, tasks) + return newContext[CloudupSubContext](ctx, target, keystore, checkExisting, sub, tasks) } func (c *Context[T]) AllTasks() map[string]Task[T] { diff --git a/upup/pkg/fi/fitasks/mirrorsecrets.go b/upup/pkg/fi/fitasks/mirrorsecrets.go index 3d9ddeefa2..5cf176fcd4 100644 --- a/upup/pkg/fi/fitasks/mirrorsecrets.go +++ b/upup/pkg/fi/fitasks/mirrorsecrets.go @@ -46,7 +46,7 @@ func (e *MirrorSecrets) GetDependencies(tasks map[string]fi.CloudupTask) []fi.Cl // Find implements fi.Task::Find func (e *MirrorSecrets) Find(c *fi.CloudupContext) (*MirrorSecrets, error) { - if vfsSecretStore, ok := c.SecretStore.(*secrets.VFSSecretStore); ok { + if vfsSecretStore, ok := c.T.SecretStore.(*secrets.VFSSecretStore); ok { if vfsSecretStore.VFSPath().Path() == e.MirrorPath.Path() { return e, nil } @@ -74,6 +74,6 @@ func (s *MirrorSecrets) CheckChanges(a, e, changes *MirrorSecrets) error { // Render implements fi.Task::Render func (_ *MirrorSecrets) Render(c *fi.CloudupContext, a, e, changes *MirrorSecrets) error { - secrets := c.SecretStore + secrets := c.T.SecretStore return secrets.MirrorTo(e.MirrorPath) } diff --git a/upup/pkg/fi/fitasks/secret.go b/upup/pkg/fi/fitasks/secret.go index b6f3ad271a..33b02e9004 100644 --- a/upup/pkg/fi/fitasks/secret.go +++ b/upup/pkg/fi/fitasks/secret.go @@ -36,7 +36,7 @@ func (e *Secret) CheckExisting(c *fi.CloudupContext) bool { } func (e *Secret) Find(c *fi.CloudupContext) (*Secret, error) { - secrets := c.SecretStore + secrets := c.T.SecretStore name := fi.ValueOf(e.Name) if name == "" { @@ -80,7 +80,7 @@ func (_ *Secret) Render(c *fi.CloudupContext, a, e, changes *Secret) error { return fi.RequiredField("Name") } - secrets := c.SecretStore + secrets := c.T.SecretStore secret, err := fi.CreateSecret() if err != nil { diff --git a/upup/pkg/fi/nodeup/command.go b/upup/pkg/fi/nodeup/command.go index 109704d01a..4e44624b8f 100644 --- a/upup/pkg/fi/nodeup/command.go +++ b/upup/pkg/fi/nodeup/command.go @@ -379,7 +379,7 @@ func (c *NodeUpCommand) Run(out io.Writer) error { return fmt.Errorf("unsupported target type %q", c.Target) } - context, err := fi.NewNodeupContext(ctx, target, keyStore, secretStore, checkExisting, &bootConfig, &nodeupConfig, taskMap) + context, err := fi.NewNodeupContext(ctx, target, keyStore, checkExisting, &bootConfig, &nodeupConfig, taskMap) if err != nil { klog.Exitf("error building context: %v", err) }