func RunHistory(f *cmdutil.Factory, cmd *cobra.Command, out io.Writer, args []string, options *HistoryOptions) error { if len(args) == 0 && len(options.Filenames) == 0 { return cmdutil.UsageError(cmd, "Required resource not specified.") } revisionDetail := cmdutil.GetFlagInt64(cmd, "revision") mapper, typer := f.Object(false) cmdNamespace, enforceNamespace, err := f.DefaultNamespace() if err != nil { return err } r := resource.NewBuilder(mapper, typer, resource.ClientMapperFunc(f.ClientForMapping), f.Decoder(true)). NamespaceParam(cmdNamespace).DefaultNamespace(). FilenameParam(enforceNamespace, options.Recursive, options.Filenames...). ResourceTypeOrNameArgs(true, args...). ContinueOnError(). Latest(). Flatten(). Do() err = r.Err() if err != nil { return err } err = r.Visit(func(info *resource.Info, err error) error { if err != nil { return err } mapping := info.ResourceMapping() historyViewer, err := f.HistoryViewer(mapping) if err != nil { return err } historyInfo, err := historyViewer.History(info.Namespace, info.Name) if err != nil { return err } if revisionDetail > 0 { // Print details of a specific revision template, ok := historyInfo.RevisionToTemplate[revisionDetail] if !ok { return fmt.Errorf("unable to find revision %d of %s %q", revisionDetail, mapping.Resource, info.Name) } fmt.Fprintf(out, "%s %q revision %d\n", mapping.Resource, info.Name, revisionDetail) kubectl.DescribePodTemplate(template, out) } else { // Print all revisions formattedOutput, printErr := kubectl.PrintRolloutHistory(historyInfo, mapping.Resource, info.Name) if printErr != nil { return printErr } fmt.Fprintf(out, "%s\n", formattedOutput) } return nil }) return err }
func printDeploymentConfigSpec(kc kclient.Interface, dc deployapi.DeploymentConfig, w *tabwriter.Writer) error { spec := dc.Spec // Selector formatString(w, "Selector", formatLabels(spec.Selector)) // Replicas test := "" if spec.Test { test = " (test, will be scaled down between deployments)" } formatString(w, "Replicas", fmt.Sprintf("%d%s", spec.Replicas, test)) // Autoscaling info printAutoscalingInfo(deployapi.Resource("DeploymentConfig"), dc.Namespace, dc.Name, kc, w) // Triggers printTriggers(spec.Triggers, w) // Strategy formatString(w, "Strategy", spec.Strategy.Type) printStrategy(spec.Strategy, " ", w) if dc.Spec.MinReadySeconds > 0 { formatString(w, "MinReadySeconds", fmt.Sprintf("%d", spec.MinReadySeconds)) } // Pod template fmt.Fprintf(w, "Template:\n") kctl.DescribePodTemplate(spec.Template, w) return nil }
// ViewHistory returns a description of all the history it can find for a deployment config. func (h *DeploymentConfigHistoryViewer) ViewHistory(namespace, name string, revision int64) (string, error) { opts := kapi.ListOptions{LabelSelector: deployutil.ConfigSelector(name)} deploymentList, err := h.rn.ReplicationControllers(namespace).List(opts) if err != nil { return "", err } if len(deploymentList.Items) == 0 { return "No rollout history found.", nil } items := deploymentList.Items history := make([]*kapi.ReplicationController, 0, len(items)) for i := range items { history = append(history, &items[i]) } // Print details of a specific revision if revision > 0 { var desired *kapi.PodTemplateSpec // We could use a binary search here but brute-force is always faster to write for i := range history { rc := history[i] if deployutil.DeploymentVersionFor(rc) == revision { desired = rc.Spec.Template break } } if desired == nil { return "", fmt.Errorf("unable to find the specified revision") } buf := bytes.NewBuffer([]byte{}) kubectl.DescribePodTemplate(desired, buf) return buf.String(), nil } sort.Sort(deployutil.ByLatestVersionAsc(history)) return tabbedString(func(out *tabwriter.Writer) error { fmt.Fprintf(out, "REVISION\tSTATUS\tCAUSE\n") for i := range history { rc := history[i] rev := deployutil.DeploymentVersionFor(rc) status := deployutil.DeploymentStatusFor(rc) cause := rc.Annotations[deployapi.DeploymentStatusReasonAnnotation] if len(cause) == 0 { cause = "<unknown>" } fmt.Fprintf(out, "%d\t%s\t%s\n", rev, status, cause) } return nil }) }
func printDeploymentConfigSpec(spec deployapi.DeploymentConfigSpec, w *tabwriter.Writer) error { // Selector formatString(w, "Selector", formatLabels(spec.Selector)) // Replicas test := "" if spec.Test { test = " (test, will be scaled down between deployments)" } formatString(w, "Replicas", fmt.Sprintf("%d%s", spec.Replicas, test)) // Triggers printTriggers(spec.Triggers, w) // Strategy formatString(w, "Strategy", spec.Strategy.Type) printStrategy(spec.Strategy, w) // Pod template fmt.Fprintf(w, "Template:\n") kctl.DescribePodTemplate(spec.Template, w) return nil }