mirror of https://github.com/kubernetes/kops.git
Move SecretStore to CloudupSubContext
This commit is contained in:
parent
c65224a15a
commit
f5fb91c858
|
@ -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] {
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue