|
| 1 | +package olmv1 |
| 2 | + |
| 3 | +import ( |
| 4 | + "fmt" |
| 5 | + "os" |
| 6 | + "text/tabwriter" |
| 7 | + "time" |
| 8 | + |
| 9 | + catalogdv1 "github.com/operator-framework/catalogd/api/v1" |
| 10 | + olmv1 "github.com/operator-framework/operator-controller/api/v1" |
| 11 | + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" |
| 12 | + "k8s.io/apimachinery/pkg/util/duration" |
| 13 | +) |
| 14 | + |
| 15 | +func printFormattedOperators(extensions ...olmv1.ClusterExtension) { |
| 16 | + tw := tabwriter.NewWriter(os.Stdout, 3, 4, 2, ' ', 0) |
| 17 | + _, _ = fmt.Fprint(tw, "NAME\tINSTALLED BUNDLE\tVERSION\tSOURCE TYPE\tINSTALLED\tPROGRESSING\tAGE\n") |
| 18 | + for _, ext := range extensions { |
| 19 | + |
| 20 | + age := time.Since(ext.CreationTimestamp.Time) |
| 21 | + _, _ = fmt.Fprintf(tw, "%s\t%s\t%s\t%s\t%s\t%s\t%s\n", |
| 22 | + ext.Name, |
| 23 | + ext.Status.Install.Bundle.Name, |
| 24 | + ext.Status.Install.Bundle.Version, |
| 25 | + ext.Spec.Source.SourceType, |
| 26 | + status(ext.Status.Conditions, olmv1.TypeInstalled), |
| 27 | + status(ext.Status.Conditions, olmv1.TypeProgressing), |
| 28 | + duration.HumanDuration(age), |
| 29 | + ) |
| 30 | + } |
| 31 | + _ = tw.Flush() |
| 32 | +} |
| 33 | + |
| 34 | +func printFormattedCatalogs(catalogs ...catalogdv1.ClusterCatalog) { |
| 35 | + tw := tabwriter.NewWriter(os.Stdout, 3, 4, 2, ' ', 0) |
| 36 | + _, _ = fmt.Fprint(tw, "NAME\tLASTUNPACKED\tSERVING\tAGE\n") |
| 37 | + for _, cat := range catalogs { |
| 38 | + |
| 39 | + age := time.Since(cat.CreationTimestamp.Time) |
| 40 | + lastUnpacked := time.Since(cat.Status.LastUnpacked.Time) |
| 41 | + _, _ = fmt.Fprintf(tw, "%s\t%s\t%s\t%s\n", |
| 42 | + cat.Name, |
| 43 | + duration.HumanDuration(lastUnpacked), |
| 44 | + status(cat.Status.Conditions, catalogdv1.TypeServing), |
| 45 | + duration.HumanDuration(age), |
| 46 | + ) |
| 47 | + } |
| 48 | + _ = tw.Flush() |
| 49 | +} |
| 50 | + |
| 51 | +func status(conditions []metav1.Condition, typ string) string { |
| 52 | + for _, condition := range conditions { |
| 53 | + if condition.Type == typ { |
| 54 | + return string(condition.Status) |
| 55 | + } |
| 56 | + } |
| 57 | + |
| 58 | + return "Unknown" |
| 59 | +} |
0 commit comments