Esempio n. 1
0
// RunNewApplication contains all the necessary functionality for the OpenShift cli new-app command
func RunNewApplication(fullName string, f *clientcmd.Factory, out io.Writer, c *cobra.Command, args []string, config *newcmd.AppConfig) error {
	if err := setupAppConfig(f, c, args, config); err != nil {
		return err
	}

	if config.AsSearch {
		result, err := config.RunSearch(out, c.Out())
		if err != nil {
			return handleRunError(c, err)
		}

		if len(cmdutil.GetFlagString(c, "output")) != 0 {
			return f.Factory.PrintObject(c, result.List, out)
		}

		return printHumanReadableSearchResult(result, out, fullName)
	}
	if err := setAppConfigLabels(c, config); err != nil {
		return err
	}
	result, err := config.RunAll(out, c.Out())
	if err != nil {
		return handleRunError(c, err)
	}
	if err := setLabels(config.Labels, result); err != nil {
		return err
	}
	if len(cmdutil.GetFlagString(c, "output")) != 0 {
		return f.Factory.PrintObject(c, result.List, out)
	}
	if err := createObjects(f, out, result); err != nil {
		return err
	}

	hasMissingRepo := false
	for _, item := range result.List.Items {
		switch t := item.(type) {
		case *kapi.Service:
			portMappings := "."
			if len(t.Spec.Ports) > 0 {
				portMappings = fmt.Sprintf(" with port mappings %s.", describeServicePorts(t.Spec))
			}
			fmt.Fprintf(c.Out(), "Service %q created at %s%s\n", t.Name, t.Spec.ClusterIP, portMappings)
		case *buildapi.BuildConfig:
			fmt.Fprintf(c.Out(), "A build was created - you can run `%s start-build %s` to start it.\n", fullName, t.Name)
		case *imageapi.ImageStream:
			if len(t.Status.DockerImageRepository) == 0 {
				if hasMissingRepo {
					continue
				}
				hasMissingRepo = true
				fmt.Fprintf(c.Out(), "WARNING: We created an image stream %q, but it does not look like a Docker registry has been integrated with the server. Automatic builds and deployments depend on that integration to detect new images and will not function properly.\n", t.Name)
			}
		}
	}
	fmt.Fprintf(c.Out(), "Run '%s status' to view your app.\n", fullName)

	return nil
}