// Run runs the designed image
514832
func Run(ctx context.Context, buildOpts *provision.BuildOptions, containerOpts *provision.ContainerOptions) (stdout string, stderr string, err error) {
	var client *docker.Client
	var container *docker.Container
	var machine *iaas.Machine
	done := make(chan struct{})
	go func(ctx context.Context, done chan struct{}) {
		client, err = provision.FnClient("", "")
		if err != nil {
			done <- struct{}{}
			return
		}

		if buildOpts.Iaas != nil {
			client, machine, err = ProvideMachine(ctx, buildOpts.Iaas)
			if err != nil {
				done <- struct{}{}
				return
			}
		}

		container, err = PrepareContainer(ctx, client, buildOpts, containerOpts)
		if err != nil {
			done <- struct{}{}
			return
		}

		var buffout *bytes.Buffer
		var bufferr *bytes.Buffer

		buffout, bufferr, err = provision.FnRun(client, container.ID, buildOpts.StdIN)
		stdout = buffout.String()
		stderr = bufferr.String()
		done <- struct{}{}
	}(ctx, done)
	select {
	case <-ctx.Done():
		log.Errorf("trying to destroy container %v\n", ctx.Err())
	case <-done:
		log.Debugln("trying to destroy container process done")
	}
	if machine != nil {
		log.Debugf("trying to delete machine ID:%v\n", machine.ID)
		deleteErr := buildOpts.Iaas.DeleteMachine()
		if deleteErr != nil {
			err = fmt.Errorf("error trying to delete machine %v", deleteErr)
		}
		return
	}
	if client != nil && container != nil {
		for killAttempt := 0; killAttempt < 3; killAttempt++ {
			if killAttempt > 0 {
				<-time.After(time.Duration(3) * time.Second)
			}
			_, err = provision.FnFindContainerByID(client, container.ID)
			if err != nil {
				if err == provision.ErrContainerNotFound {
					err = nil
				}
				return
			}
			if container.State.Running {
				log.Debugf("destroying container ID:%v, attempt:%v\n", container.ID, killAttempt+1)
				err = client.KillContainer(docker.KillContainerOptions{ID: container.ID})
				if err != nil {
					log.Errorf("error trying to kill container %v, %v, attempt:%v\n", container.ID, err.Error(), killAttempt+1)
				}
			}
			err = client.RemoveContainer(docker.RemoveContainerOptions{
				ID:    container.ID,
				Force: true,
			})
			if err != nil {
				log.Errorf("error trying to remove container %v, %v, attempt:%v\n", container.ID, err.Error(), killAttempt+1)
			}
		}
		err = fmt.Errorf("unable to kill container %v", container.ID)
	}
	return
}
1032540
func (o *MustGatherOptions) Run(rsyncCmd *cobra.Command) error {
	if len(o.Image) == 0 {
		return fmt.Errorf("missing an image")
	}

	var err error

	// create namespace
	ns, err := o.Client.CoreV1().Namespaces().Create(&corev1.Namespace{
		ObjectMeta: metav1.ObjectMeta{
			GenerateName: "openshift-must-gather-",
			Labels: map[string]string{
				"openshift.io/run-level": "0",
			},
			Annotations: map[string]string{
				"oc.openshift.io/command": "oc adm must-gather",
			},
		},
	})
	if err != nil {
		return err
	}
	o.PrinterCreated.PrintObj(ns, o.Out)
	if !o.Keep {
		defer func() {
			if err := o.Client.CoreV1().Namespaces().Delete(ns.Name, nil); err != nil {
				fmt.Printf("%v", err)
				return
			}
			o.PrinterDeleted.PrintObj(ns, o.Out)
		}()
	}

	clusterRoleBinding, err := o.Client.RbacV1().ClusterRoleBindings().Create(o.newClusterRoleBinding(ns.Name))
	if err != nil {
		return err
	}
	o.PrinterCreated.PrintObj(clusterRoleBinding, o.Out)
	if !o.Keep {
		defer func() {
			if err := o.Client.RbacV1().ClusterRoleBindings().Delete(clusterRoleBinding.Name, &metav1.DeleteOptions{}); err != nil {
				fmt.Printf("%v", err)
				return
			}
			o.PrinterDeleted.PrintObj(clusterRoleBinding, o.Out)
		}()
	}

	// create pod
	pod, err := o.Client.CoreV1().Pods(ns.Name).Create(o.newPod(o.NodeName))
	if err != nil {
		return err
	}

	// wait for pod to be running (gather has completed)
	if err := o.waitForPodRunning(pod); err != nil {
		return err
	}

	// copy the gathered files into the local destination dir
	err = o.copyFilesFromPod(pod)
	return err
}
939355
func (u *UIDMonitor) Run(ctx context.Context) error {

	if err := u.proc.config.IsComplete(); err != nil {
		return fmt.Errorf("uid: %s", err)
	}

	return u.Resync(ctx)
}
1068675
func (c *Copier) Run() {
	for src, w := range c.srcs {
		c.copyJobs.Add(1)
		go c.copySrc(src, w)
	}
}
421616
func (*ExecRunner) Run(cmd string) error {
	glog.Infoln("Run:", cmd)
	c := exec.Command("/bin/bash", "-c", cmd)
	if err := c.Run(); err != nil {
		return errors.Wrapf(err, "running command: %s", cmd)
	}
	return nil
}
46883
func (darwin *darwinRecord) Run(e Executable) (string, error) {
	runAction := "Running " + darwin.description + ":"
	e.Run()
	return runAction + " completed.", nil
}
153353
func (cmd *CheckCommand) Run(_ context.Context) error {
	for _, path := range cmd.Paths {
		switch filepath.Ext(path) {
		case "":
			if err := cmd.checkBitmapFile(path); err != nil {
				return errors.Wrap(err, "checking bitmap")
			}

		case ".cache":
			if err := cmd.checkCacheFile(path); err != nil {
				return errors.Wrap(err, "checking cache")
			}

		case ".snapshotting":
			if err := cmd.checkSnapshotFile(path); err != nil {
				return errors.Wrap(err, "checking snapshot")
			}
		}
	}

	return nil
}
942981
func (c *ImageStreamController) Run(workers int, stopCh <-chan struct{}) {
	defer utilruntime.HandleCrash()
	defer c.queue.ShutDown()

	klog.Infof("Starting image stream controller")

	// Wait for the stream store to sync before starting any work in this controller.
	if !cache.WaitForCacheSync(stopCh, c.listerSynced) {
		utilruntime.HandleError(fmt.Errorf("timed out waiting for caches to sync"))
		return
	}

	for i := 0; i < workers; i++ {
		go wait.Until(c.worker, time.Second, stopCh)
	}

	metrics.InitializeImportCollector(false, c.importCounter.Collect)

	<-stopCh
	klog.Infof("Shutting down image stream controller")
}
676319
func (c *AddDRACCmd) Run(app subcommands.Application, args []string, env subcommands.Env) int {
	ctx := cli.GetContext(app, c, env)
	// TODO(smut): Validate required fields client-side.
	req := &crimson.CreateDRACRequest{
		Drac: &c.drac,
	}
	client := getClient(ctx)
	resp, err := client.CreateDRAC(ctx, req)
	if err != nil {
		errors.Log(ctx, err)
		return 1
	}
	printDRACs(c.f.tsv, resp)
	return 0
}
121998
func (linux *systemDRecord) Run(e Executable) (string, error) {
	runAction := "Running " + linux.description + ":"
	e.Run()
	return runAction + " completed.", nil
}
798808
func (c *addImageMetadataCommand) Run(ctx *cmd.Context) (err error) {
	api, err := getImageMetadataAddAPI(c)
	if err != nil {
		return err
	}
	defer api.Close()

	m := c.constructMetadataParam()
	if err := api.Save([]params.CloudImageMetadata{m}); err != nil {
		return errors.Trace(err)
	}
	return nil
}
1171163
func (o ViewOptions) Run() error {
	config, err := o.loadConfig()
	if err != nil {
		return err
	}

	if o.Minify {
		if len(o.Context) > 0 {
			config.CurrentContext = o.Context
		}
		if err := clientcmdapi.MinifyConfig(config); err != nil {
			return err
		}
	}

	if o.Flatten {
		if err := clientcmdapi.FlattenConfig(config); err != nil {
			return err
		}
	} else if !o.RawByteData {
		clientcmdapi.ShortenConfig(config)
	}

	convertedObj, err := latest.Scheme.ConvertToVersion(config, latest.ExternalVersion)
	if err != nil {
		return err
	}

	return o.PrintObject(convertedObj, o.Out)
}
1079728
func (c *CmdGitMdget) Run() error {
	cli, err := GetGitClient(c.G())
	ctx := context.Background()
	if err != nil {
		return err
	}

	var res []keybase1.GitRepoResult
	if len(c.folder) > 0 {
		folder, err := ParseTLF(c.folder)
		if err != nil {
			return err
		}
		res, err = cli.GetGitMetadata(ctx, folder)
		if err != nil {
			return err
		}
	} else {
		res, err = cli.GetAllGitMetadata(ctx)
		if err != nil {
			return err
		}
	}

	jsonStr, err := json.MarshalIndent(res, "", "    ")
	if err != nil {
		return err
	}

	fmt.Println(string(jsonStr))
	return nil
}
50319
func (c *CmdGitMddel) Run() error {
	cli, err := GetGitClient(c.G())
	if err != nil {
		return err
	}

	folder, err := ParseTLF(c.folder)
	if err != nil {
		return err
	}

	return cli.DeleteGitMetadata(context.Background(), keybase1.DeleteGitMetadataArg{
		Folder:   folder,
		RepoName: keybase1.GitRepoName(c.repoName),
	})
}
1023290
func (b *Buffer) Run(gen func(chan<- func() error)) <-chan error {
	return b.runThen(gen, nil)
}
1246987
func Run(c *Config) {
	if c != nil {
		SetUp(c)
	}

	err := ircConn.Connect(config.Server)
	if err != nil {
		log.Fatal(err)
	}
	ircConn.Loop()
}
127484
func (c *AddMachineCmd) Run(app subcommands.Application, args []string, env subcommands.Env) int {
	ctx := cli.GetContext(app, c, env)
	// TODO(smut): Validate required fields client-side.
	req := &crimson.CreateMachineRequest{
		Machine: &c.machine,
	}
	client := getClient(ctx)
	resp, err := client.CreateMachine(ctx, req)
	if err != nil {
		errors.Log(ctx, err)
		return 1
	}
	printMachines(c.f.tsv, resp)
	return 0
}