Move SecretStore to CloudupSubContext

This commit is contained in:
John Gardiner Myers 2022-12-20 09:03:16 -08:00
parent c65224a15a
commit f5fb91c858
4 changed files with 14 additions and 14 deletions

View File

@ -33,9 +33,8 @@ import (
type Context[T SubContext] struct { type Context[T SubContext] struct {
ctx context.Context ctx context.Context
Target Target[T] Target Target[T]
Keystore Keystore Keystore Keystore
SecretStore SecretStore
CheckExisting bool CheckExisting bool
@ -58,6 +57,7 @@ type CloudupSubContext struct {
Cluster *kops.Cluster Cluster *kops.Cluster
// TODO: Few places use this. They could instead get it from the cluster spec. // TODO: Few places use this. They could instead get it from the cluster spec.
ClusterConfigBase vfs.Path ClusterConfigBase vfs.Path
SecretStore SecretStore
} }
type InstallSubContext struct{} type InstallSubContext struct{}
type NodeupSubContext struct { type NodeupSubContext struct {
@ -75,12 +75,11 @@ type Warning[T SubContext] struct {
Message string 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]{ c := &Context[T]{
ctx: ctx, ctx: ctx,
Target: target, Target: target,
Keystore: keystore, Keystore: keystore,
SecretStore: secretStore,
CheckExisting: checkExisting, CheckExisting: checkExisting,
tasks: tasks, tasks: tasks,
T: sub, 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) { func NewInstallContext(ctx context.Context, target InstallTarget, tasks map[string]InstallTask) (*InstallContext, error) {
sub := InstallSubContext{} 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{ sub := NodeupSubContext{
BootConfig: bootConfig, BootConfig: bootConfig,
NodeupConfig: nodeupConfig, 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) { 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, Cloud: cloud,
Cluster: cluster, Cluster: cluster,
ClusterConfigBase: clusterConfigBase, 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] { func (c *Context[T]) AllTasks() map[string]Task[T] {

View File

@ -46,7 +46,7 @@ func (e *MirrorSecrets) GetDependencies(tasks map[string]fi.CloudupTask) []fi.Cl
// Find implements fi.Task::Find // Find implements fi.Task::Find
func (e *MirrorSecrets) Find(c *fi.CloudupContext) (*MirrorSecrets, error) { 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() { if vfsSecretStore.VFSPath().Path() == e.MirrorPath.Path() {
return e, nil return e, nil
} }
@ -74,6 +74,6 @@ func (s *MirrorSecrets) CheckChanges(a, e, changes *MirrorSecrets) error {
// Render implements fi.Task::Render // Render implements fi.Task::Render
func (_ *MirrorSecrets) Render(c *fi.CloudupContext, a, e, changes *MirrorSecrets) error { func (_ *MirrorSecrets) Render(c *fi.CloudupContext, a, e, changes *MirrorSecrets) error {
secrets := c.SecretStore secrets := c.T.SecretStore
return secrets.MirrorTo(e.MirrorPath) return secrets.MirrorTo(e.MirrorPath)
} }

View File

@ -36,7 +36,7 @@ func (e *Secret) CheckExisting(c *fi.CloudupContext) bool {
} }
func (e *Secret) Find(c *fi.CloudupContext) (*Secret, error) { func (e *Secret) Find(c *fi.CloudupContext) (*Secret, error) {
secrets := c.SecretStore secrets := c.T.SecretStore
name := fi.ValueOf(e.Name) name := fi.ValueOf(e.Name)
if name == "" { if name == "" {
@ -80,7 +80,7 @@ func (_ *Secret) Render(c *fi.CloudupContext, a, e, changes *Secret) error {
return fi.RequiredField("Name") return fi.RequiredField("Name")
} }
secrets := c.SecretStore secrets := c.T.SecretStore
secret, err := fi.CreateSecret() secret, err := fi.CreateSecret()
if err != nil { if err != nil {

View File

@ -379,7 +379,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, keyStore, secretStore, checkExisting, &bootConfig, &nodeupConfig, taskMap) context, err := fi.NewNodeupContext(ctx, target, keyStore, checkExisting, &bootConfig, &nodeupConfig, taskMap)
if err != nil { if err != nil {
klog.Exitf("error building context: %v", err) klog.Exitf("error building context: %v", err)
} }