Hold reference to VFSContext from Factory

This commit is contained in:
John Gardiner Myers 2023-01-05 17:48:12 -08:00
parent 60a2e153a9
commit 64903eb166
5 changed files with 18 additions and 9 deletions

View File

@ -33,7 +33,6 @@ import (
"k8s.io/kops/pkg/kubemanifest"
"k8s.io/kops/upup/pkg/fi/cloudup"
"k8s.io/kops/util/pkg/text"
"k8s.io/kops/util/pkg/vfs"
"k8s.io/kubectl/pkg/util/i18n"
"k8s.io/kubectl/pkg/util/templates"
)
@ -102,6 +101,8 @@ func RunCreate(ctx context.Context, f *util.Factory, out io.Writer, c *CreateOpt
return err
}
vfsContext := f.VFSContext()
clusterName := ""
// var cSpec = false
var sb bytes.Buffer
@ -118,7 +119,7 @@ func RunCreate(ctx context.Context, f *util.Factory, out io.Writer, c *CreateOpt
return err
}
} else {
contents, err = vfs.Context.ReadFile(f)
contents, err = vfsContext.ReadFile(f)
if err != nil {
return fmt.Errorf("error reading file %q: %v", f, err)
}

View File

@ -28,7 +28,6 @@ import (
kopsapi "k8s.io/kops/pkg/apis/kops"
"k8s.io/kops/pkg/kopscodecs"
"k8s.io/kops/util/pkg/text"
"k8s.io/kops/util/pkg/vfs"
"k8s.io/kubectl/pkg/util/i18n"
"k8s.io/kubectl/pkg/util/templates"
)
@ -91,7 +90,7 @@ func RunDelete(ctx context.Context, factory *util.Factory, out io.Writer, d *Del
return fmt.Errorf("reading from stdin: %v", err)
}
} else {
contents, err = vfs.Context.ReadFile(f)
contents, err = factory.VFSContext().ReadFile(f)
if err != nil {
return fmt.Errorf("reading file %q: %v", f, err)
}

View File

@ -30,7 +30,6 @@ import (
"k8s.io/kops/pkg/kopscodecs"
"k8s.io/kops/upup/pkg/fi/cloudup"
"k8s.io/kops/util/pkg/text"
"k8s.io/kops/util/pkg/vfs"
"k8s.io/kubectl/pkg/util/i18n"
"k8s.io/kubectl/pkg/util/templates"
)
@ -90,6 +89,8 @@ func RunReplace(ctx context.Context, f *util.Factory, out io.Writer, c *ReplaceO
return err
}
vfsContext := f.VFSContext()
for _, f := range c.Filenames {
var contents []byte
if f == "-" {
@ -98,7 +99,7 @@ func RunReplace(ctx context.Context, f *util.Factory, out io.Writer, c *ReplaceO
return err
}
} else {
contents, err = vfs.Context.ReadFile(f)
contents, err = vfsContext.ReadFile(f)
if err != nil {
return fmt.Errorf("error reading file %q: %v", f, err)
}

View File

@ -51,6 +51,7 @@ type Factory struct {
kubernetesClient kubernetes.Interface
certManagerClient certmanager.Interface
vfsContext *vfs.VFSContext
cachedRESTConfig *rest.Config
dynamicClient dynamic.Interface
@ -119,7 +120,7 @@ func (f *Factory) KopsClient() (simple.Clientset, error) {
KopsClient: kopsClient.Kops(),
}
} else {
basePath, err := vfs.Context.BuildVfsPath(registryPath)
basePath, err := f.VFSContext().BuildVfsPath(registryPath)
if err != nil {
return nil, fmt.Errorf("error building path for %q: %v", registryPath, err)
}
@ -221,3 +222,11 @@ func (f *Factory) RESTMapper() (*restmapper.DeferredDiscoveryRESTMapper, error)
return f.restMapper, nil
}
func (f *Factory) VFSContext() *vfs.VFSContext {
if f.vfsContext == nil {
// TODO vfs.NewVFSContext()
f.vfsContext = vfs.Context
}
return f.vfsContext
}

View File

@ -25,7 +25,6 @@ import (
"k8s.io/kops"
"k8s.io/kops/cmd/kops/util"
"k8s.io/kops/pkg/apis/kops/registry"
"k8s.io/kops/util/pkg/vfs"
"k8s.io/kubectl/pkg/util/i18n"
"k8s.io/kubectl/pkg/util/templates"
)
@ -116,7 +115,7 @@ func serverVersion(f *util.Factory, options *VersionOptions) string {
if err != nil {
return "could not fetch cluster"
}
configBase, err := vfs.Context.BuildVfsPath(cluster.Spec.ConfigBase)
configBase, err := f.VFSContext().BuildVfsPath(cluster.Spec.ConfigBase)
if err != nil {
return "could not talk to vfs"
}