-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
59 lines (50 loc) · 1.48 KB
/
main.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
package main
import (
"flag"
"fmt"
"path/filepath"
"github.com/bryant-rh/k8sutil/history"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/tools/clientcmd"
"k8s.io/client-go/util/homedir"
)
func main() {
var (
kubeconfig *string
kind string
namespace string
name string
)
if home := homedir.HomeDir(); home != "" {
kubeconfig = flag.String("kubeconfig", filepath.Join(home, ".kube", "config"), "(optional) absolute path to the kubeconfig file")
} else {
kubeconfig = flag.String("kubeconfig", "", "absolute path to the kubeconfig file")
}
flag.StringVar(&kind, "kind", "Deployment", "The resource kind you want to view")
flag.StringVar(&namespace, "namespace", metav1.NamespaceDefault, "The resource namespace")
flag.StringVar(&name, "name", "", "The resource name")
flag.Parse()
// use the current context in kubeconfig
config, err := clientcmd.BuildConfigFromFlags("", *kubeconfig)
if err != nil {
panic(err.Error())
}
client, err := kubernetes.NewForConfig(config)
if err != nil {
panic(err.Error())
}
viewer := history.ViewerFor(client, schema.GroupKind{Group: "apps", Kind: kind})
latest, olds, err := viewer.ViewHistory(namespace, name)
if err != nil {
panic(err.Error())
}
fmt.Printf("New Revision: %d\n", latest[0].Revision)
for _, o := range olds {
fmt.Printf("Old Revision: %d\n", o.Revision)
}
}
func intToPointer(i int) *int {
return &i
}