當前位置: 首頁>>代碼示例>>Golang>>正文


Golang util.NewFactory函數代碼示例

本文整理匯總了Golang中k8s/io/kubernetes/pkg/kubectl/cmd/util.NewFactory函數的典型用法代碼示例。如果您正苦於以下問題:Golang NewFactory函數的具體用法?Golang NewFactory怎麽用?Golang NewFactory使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了NewFactory函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: applyAnsibleRC

func applyAnsibleRC(c *cli.Context) {
	args := c.Args()
	if len(args) < 1 {
		log.Die("Expected an argument!")
	}
	hosts := args[0]

	f := cmdutil.NewFactory(nil)
	if f == nil {
		log.Die("Failed to create Kuberentes client factory!")
	}
	kubeclient, _ := f.Client()
	if kubeclient == nil {
		log.Die("Failed to create Kuberentes client!")
	}
	ns, _, _ := f.DefaultNamespace()
	if len(ns) == 0 {
		ns = "default"
	}

	rcName, err := osExpandAndVerify(c, "rc")
	if err != nil {
		fail(err)
	}

	inventory, err := osExpandAndVerify(c, "inventory")
	if err != nil {
		fail(err)
	}
	_, err = ansible.UpdateAnsibleRC(inventory, hosts, kubeclient, ns, rcName)
	if err != nil {
		fail(err)
	}
}
開發者ID:jstrachan,項目名稱:kansible,代碼行數:34,代碼來源:gosupervise.go

示例2: TestNormalizationFuncGlobalExistence

func TestNormalizationFuncGlobalExistence(t *testing.T) {
	// This test can be safely deleted when we will not support multiple flag formats
	root := NewKubectlCommand(cmdutil.NewFactory(nil), os.Stdin, os.Stdout, os.Stderr)

	if root.Parent() != nil {
		t.Fatal("We expect the root command to be returned")
	}
	if root.GlobalNormalizationFunc() == nil {
		t.Fatal("We expect that root command has a global normalization function")
	}

	if reflect.ValueOf(root.GlobalNormalizationFunc()).Pointer() != reflect.ValueOf(root.Flags().GetNormalizeFunc()).Pointer() {
		t.Fatal("root command seems to have a wrong normalization function")
	}

	sub := root
	for sub.HasSubCommands() {
		sub = sub.Commands()[0]
	}

	// In case of failure of this test check this PR: spf13/cobra#110
	if reflect.ValueOf(sub.Flags().GetNormalizeFunc()).Pointer() != reflect.ValueOf(root.Flags().GetNormalizeFunc()).Pointer() {
		t.Fatal("child and root commands should have the same normalization functions")
	}
}
開發者ID:mataihang,項目名稱:kubernetes,代碼行數:25,代碼來源:cmd_test.go

示例3: main

func main() {
	cmds := &cobra.Command{
		Use:   "gofabric8",
		Short: "gofabric8 is used to validate & deploy fabric8 components on to your Kubernetes or OpenShift environment",
		Long: `gofabric8 is used to validate & deploy fabric8 components on to your Kubernetes or OpenShift environment
								Find more information at http://fabric8.io.`,
		Run: runHelp,
	}

	f := cmdutil.NewFactory(nil)
	f.BindFlags(cmds.PersistentFlags())

	cmds.PersistentFlags().StringP("version", "v", "latest", "fabric8 version")
	cmds.PersistentFlags().BoolP("yes", "y", false, "assume yes")

	cmds.AddCommand(commands.NewCmdValidate(f))
	cmds.AddCommand(commands.NewCmdDeploy(f))
	cmds.AddCommand(commands.NewCmdPull(f))
	cmds.AddCommand(commands.NewCmdRoutes(f))
	cmds.AddCommand(commands.NewCmdSecrets(f))
	cmds.AddCommand(commands.NewCmdVolume(f))
	cmds.AddCommand(commands.NewCmdVersion())

	cmds.Execute()
}
開發者ID:MarWestermann,項目名稱:gofabric8,代碼行數:25,代碼來源:gofabric8.go

示例4: walkPathForObjects

func walkPathForObjects(path string, fn resource.VisitorFunc) error {
	f := kubectl.NewFactory(nil)

	// todo: does "cacheDir" need to be parameterizable?
	schema, err := f.Validator(false, "")
	if err != nil {
		return err
	}

	mapper, typer := f.Object()
	result := resource.NewBuilder(mapper, typer, resource.DisabledClientForMapping{}, f.Decoder(true)).
		ContinueOnError().
		Schema(schema).
		FilenameParam(false, path).
		Flatten().
		Do()

	err = result.Err()
	if err != nil && !checkErrNoResources(err) {
		return err
	}

	err = result.Visit(fn)
	if err != nil {
		return err
	}
	return nil
}
開發者ID:redspread,項目名稱:spread,代碼行數:28,代碼來源:source.go

示例5: TestLocalAndDryRunFlags

func TestLocalAndDryRunFlags(t *testing.T) {
	out := &bytes.Buffer{}
	errout := &bytes.Buffer{}
	f := clientcmdutil.NewFactory(nil)
	setCmd := NewCmdSet(f, out, errout)
	ensureLocalAndDryRunFlagsOnChildren(t, setCmd, "")
}
開發者ID:alex-mohr,項目名稱:kubernetes,代碼行數:7,代碼來源:set_test.go

示例6: main

func main() {
	// use os.Args instead of "flags" because "flags" will mess up the man pages!
	path := "docs/man/man1"
	if len(os.Args) == 2 {
		path = os.Args[1]
	} else if len(os.Args) > 2 {
		fmt.Fprintf(os.Stderr, "usage: %s [output directory]\n", os.Args[0])
		os.Exit(1)
	}

	outDir, err := genutils.OutDir(path)
	if err != nil {
		fmt.Fprintf(os.Stderr, "failed to get output directory: %v\n", err)
		os.Exit(1)
	}

	// Set environment variables used by kubectl so the output is consistent,
	// regardless of where we run.
	os.Setenv("HOME", "/home/username")
	//TODO os.Stdin should really be something like ioutil.Discard, but a Reader
	kubectl := cmd.NewKubectlCommand(cmdutil.NewFactory(nil), os.Stdin, ioutil.Discard, ioutil.Discard)
	genMarkdown(kubectl, "", outDir)
	for _, c := range kubectl.Commands() {
		genMarkdown(c, "kubectl", outDir)
	}
}
開發者ID:johndmulhausen,項目名稱:kubernetes,代碼行數:26,代碼來源:gen_kubectl_man.go

示例7: DeployAppFromFile

// DeployAppFromFile deploys an app based on the given yaml or json file.
func DeployAppFromFile(spec *AppDeploymentFromFileSpec,
	createObjectFromInfoFn createObjectFromInfo, clientConfig clientcmd.ClientConfig) (bool, error) {
	const emptyCacheDir = ""
	validate := spec.Validate

	factory := cmdutil.NewFactory(clientConfig)
	schema, err := factory.Validator(validate, emptyCacheDir)
	if err != nil {
		return false, err
	}

	mapper, typer := factory.Object(false)
	reader := strings.NewReader(spec.Content)

	r := kubectlResource.NewBuilder(mapper, typer, kubectlResource.ClientMapperFunc(factory.ClientForMapping), factory.Decoder(true)).
		Schema(schema).
		NamespaceParam(api.NamespaceDefault).DefaultNamespace().
		Stream(reader, spec.Name).
		Flatten().
		Do()

	deployedResourcesCount := 0

	err = r.Visit(func(info *kubectlResource.Info, err error) error {
		isDeployed, err := createObjectFromInfoFn(info)
		if isDeployed {
			deployedResourcesCount++
			log.Printf("%s is deployed", info.Name)
		}
		return err
	})

	return deployedResourcesCount > 0, err
}
開發者ID:digitalfishpond,項目名稱:dashboard,代碼行數:35,代碼來源:deploymentdeploy.go

示例8: DeployAppFromFile

// Deploys an app based on the given yaml or json file.
func DeployAppFromFile(spec *AppDeploymentFromFileSpec, createObjectFromInfoFn createObjectFromInfo) error {
	const (
		validate      = true
		emptyCacheDir = ""
	)

	factory := cmdutil.NewFactory(nil)
	schema, err := factory.Validator(validate, emptyCacheDir)
	if err != nil {
		return err
	}

	mapper, typer := factory.Object()
	reader := strings.NewReader(spec.Content)

	r := kubectlResource.NewBuilder(mapper, typer, kubectlResource.ClientMapperFunc(factory.ClientForMapping), factory.Decoder(true)).
		Schema(schema).
		NamespaceParam(api.NamespaceDefault).DefaultNamespace().
		Stream(reader, spec.Name).
		Flatten().
		Do()

	return r.Visit(func(info *kubectlResource.Info, err error) error {
		err = createObjectFromInfoFn(info)
		if err != nil {
			return err
		}
		log.Printf("%s is deployed", info.Name)
		return nil
	})
}
開發者ID:luxas,項目名稱:dashboard,代碼行數:32,代碼來源:deploy.go

示例9: New

// New create a new Client
func New(config clientcmd.ClientConfig) *Client {
	return &Client{
		Factory:        cmdutil.NewFactory(config),
		Validate:       true,
		SchemaCacheDir: clientcmd.RecommendedSchemaFile,
	}
}
開發者ID:kubernetes,項目名稱:helm,代碼行數:8,代碼來源:client.go

示例10: Run

func Run() error {
	logs.InitLogs()
	defer logs.FlushLogs()

	cmd := kubefed.NewKubeFedCommand(cmdutil.NewFactory(nil), os.Stdin, os.Stdout, os.Stderr)
	return cmd.Execute()
}
開發者ID:eljefedelrodeodeljefe,項目名稱:kubernetes,代碼行數:7,代碼來源:kubefed.go

示例11: NewAPIFactory

func NewAPIFactory() (cmdutil.Factory, *TestFactory, runtime.Codec, runtime.NegotiatedSerializer) {
	t := &TestFactory{
		Validator: validation.NullSchema{},
	}
	rf := cmdutil.NewFactory(nil)
	return &fakeAPIFactory{
		Factory: rf,
		tf:      t,
	}, t, testapi.Default.Codec(), testapi.Default.NegotiatedSerializer()
}
開發者ID:nak3,項目名稱:kubernetes,代碼行數:10,代碼來源:fake.go

示例12: NewAPIFactory

func NewAPIFactory() (*cmdutil.Factory, *testFactory, runtime.Codec) {
	t := &testFactory{
		Validator: validation.NullSchema{},
	}
	generators := map[string]kubectl.Generator{
		"run/v1":       kubectl.BasicReplicationController{},
		"run-pod/v1":   kubectl.BasicPod{},
		"service/v1":   kubectl.ServiceGeneratorV1{},
		"service/v2":   kubectl.ServiceGeneratorV2{},
		"service/test": testServiceGenerator{},
	}
	f := &cmdutil.Factory{
		Object: func() (meta.RESTMapper, runtime.ObjectTyper) {
			return testapi.Default.RESTMapper(), api.Scheme
		},
		Client: func() (*client.Client, error) {
			// Swap out the HTTP client out of the client with the fake's version.
			fakeClient := t.Client.(*fake.RESTClient)
			c := client.NewOrDie(t.ClientConfig)
			c.Client = fakeClient.Client
			return c, t.Err
		},
		RESTClient: func(*meta.RESTMapping) (resource.RESTClient, error) {
			return t.Client, t.Err
		},
		Describer: func(*meta.RESTMapping) (kubectl.Describer, error) {
			return t.Describer, t.Err
		},
		Printer: func(mapping *meta.RESTMapping, noHeaders, withNamespace bool, wide bool, showAll bool, columnLabels []string) (kubectl.ResourcePrinter, error) {
			return t.Printer, t.Err
		},
		Validator: func(validate bool, cacheDir string) (validation.Schema, error) {
			return t.Validator, t.Err
		},
		DefaultNamespace: func() (string, bool, error) {
			return t.Namespace, false, t.Err
		},
		ClientConfig: func() (*client.Config, error) {
			return t.ClientConfig, t.Err
		},
		CanBeExposed: func(kind string) error {
			if kind != "ReplicationController" && kind != "Service" && kind != "Pod" {
				return fmt.Errorf("invalid resource provided: %v, only a replication controller, service or pod is accepted", kind)
			}
			return nil
		},
		Generator: func(name string) (kubectl.Generator, bool) {
			generator, ok := generators[name]
			return generator, ok
		},
	}
	rf := cmdutil.NewFactory(nil)
	f.PodSelectorForObject = rf.PodSelectorForObject
	return f, t, testapi.Default.Codec()
}
開發者ID:alfred-huangjian,項目名稱:kubernetes,代碼行數:55,代碼來源:cmd_test.go

示例13: Run

func Run() error {
	logs.InitLogs()
	defer logs.FlushLogs()

	// We do not want these flags to show up in --help
	pflag.CommandLine.MarkHidden("google-json-key")
	pflag.CommandLine.MarkHidden("log-flush-frequency")

	cmd := cmd.NewKubeadmCommand(cmdutil.NewFactory(nil), os.Stdin, os.Stdout, os.Stderr)
	return cmd.Execute()
}
開發者ID:ConnorDoyle,項目名稱:kubernetes,代碼行數:11,代碼來源:kubeadm.go

示例14: HostFactory

func (a *adminConfig) HostFactory(host, kubeconfigPath string) cmdutil.Factory {
	loadingRules := *a.pathOptions.LoadingRules
	loadingRules.Precedence = a.pathOptions.GetLoadingPrecedence()
	loadingRules.ExplicitPath = kubeconfigPath
	overrides := &clientcmd.ConfigOverrides{
		CurrentContext: host,
	}

	hostClientConfig := clientcmd.NewNonInteractiveDeferredLoadingClientConfig(&loadingRules, overrides)

	return cmdutil.NewFactory(hostClientConfig)
}
開發者ID:eljefedelrodeodeljefe,項目名稱:kubernetes,代碼行數:12,代碼來源:util.go

示例15: AddFlags

func AddFlags(fs *pflag.FlagSet, kubectlSubCmd string) {
	cmd := cmd.NewKubectlCommand(cmdutil.NewFactory(nil), os.Stdin, os.Stdout, os.Stderr)
	fs.AddFlagSet(cmd.LocalFlags())
	if kubectlSubCmd == "" {
		return
	}
	for _, child := range cmd.Commands() {
		if child.Name() == kubectlSubCmd {
			fs.AddFlagSet(child.LocalFlags())
			return
		}
	}
}
開發者ID:tanen01,項目名稱:kubernetes,代碼行數:13,代碼來源:kubectl.go


注:本文中的k8s/io/kubernetes/pkg/kubectl/cmd/util.NewFactory函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。