Skip to content

[WIP] Add test for direct.go #157

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -450,11 +450,9 @@ github.com/mailru/easyjson v0.7.0 h1:aizVhC/NAAcKWb+5QsU1iNOZb4Yws5UO2I+aIprQITM
github.com/mailru/easyjson v0.7.0/go.mod h1:KAzv3t3aY1NaHWoQz1+4F1ccyAH66Jk7yos7ldAVICs=
github.com/matoous/godox v0.0.0-20190911065817-5d6d842e92eb/go.mod h1:1BELzlh859Sh1c6+90blK8lbYy0kwQf1bYlBhBysy1s=
github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU=
github.com/mattn/go-colorable v0.1.4 h1:snbPLB8fVfU9iwbbo30TPtbLRzwWu6aJS6Xh4eaaviA=
github.com/mattn/go-colorable v0.1.4/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE=
github.com/mattn/go-isatty v0.0.3/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4=
github.com/mattn/go-isatty v0.0.4/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4=
github.com/mattn/go-isatty v0.0.8 h1:HLtExJ+uU2HOZ+wI0Tt5DtUDrx8yhUqDcp7fYERX4CE=
github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
github.com/mattn/go-runewidth v0.0.2/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU=
github.com/mattn/goveralls v0.0.2/go.mod h1:8d1ZMHsd7fW6IRPKQh46F2WRpyib5/X4FOpevwGNQEw=
Expand Down
64 changes: 61 additions & 3 deletions pkg/patterns/declarative/pkg/applier/direct.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package applier

import (
"context"
//"io/ioutil"
"os"
"strings"

Expand All @@ -14,11 +15,14 @@ import (
)

type DirectApplier struct {
a apply.ApplyOptions
a apply.ApplyOptions
ConfigFlags genericclioptions.RESTClientGetter
}

func NewDirectApplier() *DirectApplier {
return &DirectApplier{}
return &DirectApplier{
ConfigFlags: genericclioptions.NewConfigFlags(true).WithDeprecatedPasswordFlag(),
}
}

func (d *DirectApplier) Apply(ctx context.Context,
Expand All @@ -32,7 +36,7 @@ func (d *DirectApplier) Apply(ctx context.Context,
Out: os.Stdout,
ErrOut: os.Stderr,
}
restClient := genericclioptions.NewConfigFlags(true).WithDeprecatedPasswordFlag()
restClient := d.ConfigFlags
ioReader := strings.NewReader(manifest)

b := resource.NewBuilder(restClient)
Expand All @@ -56,3 +60,57 @@ func (d *DirectApplier) Apply(ctx context.Context,

return applyOpts.Run()
}

//func (d *DirectApplier) Apply(ctx context.Context,
// namespace string,
// manifest string,
// validate bool,
// extraArgs ...string,
//) error {
//
// tmpFile, err := ioutil.TempFile("", "tmp-manifest-*.yaml")
// if err != nil {
// return err
// }
// tmpFile.Write([]byte(manifest))
// tmpFile.Close()
// defer os.Remove(tmpFile.Name())
// ioStreams := genericclioptions.IOStreams{
// In: tmpFile,
// Out: os.Stdout,
// ErrOut: os.Stderr,
// }
// restClient := d.ConfigFlags
// f := cmdutil.NewFactory(restClient)
// schema, err := f.Validator(validate)
// if err != nil {
// return err
// }
// applyOpts := apply.NewApplyOptions(ioStreams)
//
// applyOpts.DynamicClient, err = f.DynamicClient()
// if err != nil {
// return err
// }
// applyOpts.DeleteOptions, _ = applyOpts.DeleteFlags.ToOptions(applyOpts.DynamicClient, applyOpts.IOStreams)
//
// applyOpts.Namespace, applyOpts.EnforceNamespace, err = f.ToRawKubeConfigLoader().Namespace()
// if namespace != "" {
// applyOpts.Namespace = namespace
// //applyOpts.EnforceNamespace = true
// }
// applyOpts.Validator = schema
// applyOpts.Builder = f.NewBuilder()
// applyOpts.Mapper, err = f.ToRESTMapper()
// applyOpts.ToPrinter = func(operation string) (printers.ResourcePrinter, error) {
// applyOpts.PrintFlags.NamePrintFlags.Operation = operation
// cmdutil.PrintFlagsWithDryRunStrategy(applyOpts.PrintFlags, applyOpts.DryRunStrategy)
// return applyOpts.PrintFlags.ToPrinter()
// }
// applyOpts.DeleteOptions = &cmdDelete.DeleteOptions{
// IOStreams: ioStreams,
// }
// applyOpts.DeleteOptions.Filenames = []string{tmpFile.Name()}
//
// return applyOpts.Run()
//}
Loading