-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
76 lines (66 loc) · 2.32 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package main
import (
"context"
"flag"
"fmt"
"path/filepath"
"time"
"k8s.io/client-go/rest"
"k8s.io/client-go/tools/clientcmd"
"k8s.io/client-go/util/homedir"
"k8s.io/klog/v2"
klient "github.com/apoorvajagtap/trackPodCRD/pkg/client/clientset/versioned"
kInfFac "github.com/apoorvajagtap/trackPodCRD/pkg/client/informers/externalversions"
"github.com/apoorvajagtap/trackPodCRD/pkg/controller/pipelinerun"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/kubernetes"
)
func main() {
// find the kubeconfig file
var kubeconfig *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.Parse()
// Building config from flags might fail inside the pod,
// hence adding the code for usage of in-clusterconfig.
config, err := clientcmd.BuildConfigFromFlags("", *kubeconfig)
if err != nil {
klog.Errorf("Building config from flags failed, %s, trying to build inclusterconfig", err.Error())
// uses serviceAccount mounted inside the pod.
config, err = rest.InClusterConfig()
if err != nil {
klog.Errorf("error %s building inclusterconfig", err.Error())
}
}
// creating the clientset
klientset, err := klient.NewForConfig(config)
if err != nil {
klog.Errorf("getting klient set %s\n", err.Error())
}
// fmt.Println(klientset)
// Listing the existing trackpods.
tpods, err := klientset.AjV1().TrackPods("").List(context.Background(), metav1.ListOptions{})
if err != nil {
klog.Errorf("error while listing trackPods %s\n", err.Error())
}
fmt.Println(tpods)
// fmt.Printf("total trackPod sets: %d\n", len(tpods.Items))
client, err := kubernetes.NewForConfig(config)
if err != nil {
klog.Errorf("getting std client %s\n", err.Error())
}
infoFact := kInfFac.NewSharedInformerFactory(klientset, 20*time.Minute)
// infoFact :=
ch := make(chan struct{})
// c := trackpod.NewController(client, klientset, infoFact.Aj().V1().TrackPods())
pc := pipelinerun.NewController(client, klientset, infoFact.Aj().V1alpha1().PipelineRuns(), infoFact.Aj().V1alpha1().TaskRuns())
infoFact.Start(ch)
if err := pc.Run(ch); err != nil {
klog.Errorf("error running controller %s\n", err)
}
}