-
Notifications
You must be signed in to change notification settings - Fork 0
/
namespaces.go
72 lines (63 loc) · 1.7 KB
/
namespaces.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/*
* *******************************************************************************
* * Copyright (c) 2023 Datasance Teknoloji A.S.
* *
* * This program and the accompanying materials are made available under the
* * terms of the Eclipse Public License v. 2.0 which is available at
* * http://www.eclipse.org/legal/epl-2.0
* *
* * SPDX-License-Identifier: EPL-2.0
* *******************************************************************************
*
*/
package get
import (
"github.com/datasance/potctl/internal/config"
rsc "github.com/datasance/potctl/internal/resource"
"github.com/datasance/potctl/pkg/util"
)
type namespaceExecutor struct {
}
func newNamespaceExecutor() *namespaceExecutor {
n := &namespaceExecutor{}
return n
}
func (exe *namespaceExecutor) GetName() string {
return ""
}
func (exe *namespaceExecutor) Execute() error {
namespacesNames := config.GetNamespaces()
namespaces := make([]*rsc.Namespace, len(namespacesNames))
for idx, n := range namespacesNames {
ns, err := config.GetNamespace(n)
if err != nil {
return err
}
namespaces[idx] = ns
}
// Generate table and headers
table := make([][]string, len(namespaces))
headers := []string{"NAMESPACE", "AGE"}
table[0] = append(table[0], headers...)
// Populate rows
for idx, ns := range namespaces {
age, err := util.ElapsedUTC(ns.Created, util.NowUTC())
if err != nil {
age = "-"
}
row := []string{
ns.Name,
age,
}
if ns.Name == config.GetDefaultNamespaceName() {
row[0] = ns.Name + "*"
prepend := [][]string{table[0]}
table = append(prepend, table...)
table[1] = row
} else {
table[idx+1] = append(table[idx+1], row...)
}
}
// Print the table
return print(table)
}