Skip to content

Commit

Permalink
Clean-up.
Browse files Browse the repository at this point in the history
  • Loading branch information
udhos committed Dec 26, 2023
1 parent 8ab19b4 commit 98e0181
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 32 deletions.
4 changes: 3 additions & 1 deletion kubegroup/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ type Options struct {
// from the PodLabelKey key).
PodLabelValue string

// KubeEngine sets a plugable kube client. If unspecified, defaults to DefaultEngine.
// You can plug in a mocked client like KubeBogus for testing.
Engine KubeEngine

// Cooldown sets interval between retries. If unspecified defaults to 5 seconds.
Expand Down Expand Up @@ -96,7 +98,7 @@ func fatalf(format string, v ...any) {
log.Fatalf("FATAL: "+format, v...)
}

// DefaultEngine defines default kube engine.
// DefaultEngine defines default kube client engine.
var DefaultEngine = NewKubeReal()

func defaultOptions(options Options) Options {
Expand Down
31 changes: 0 additions & 31 deletions kubegroup/kube.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (
)

type kubeClient struct {
//clientset *kubernetes.Clientset
inCluster bool
podCache *podInfo
options Options
Expand All @@ -32,25 +31,6 @@ func newKubeClient(options Options) (kubeClient, error) {
options: options,
}

/*
config, errConfig := rest.InClusterConfig()
if errConfig != nil {
options.Errorf("running OUT-OF-CLUSTER: %v", errConfig)
return kc, nil
}
options.Debugf("running IN-CLUSTER")
kc.inCluster = true
clientset, errClientset := kubernetes.NewForConfig(config)
if errClientset != nil {
options.Errorf("kube clientset error: %v", errClientset)
return kc, errClientset
}
kc.clientset = clientset
*/

inCluster, errInit := options.Engine.initClient(options)

kc.inCluster = inCluster
Expand All @@ -73,14 +53,12 @@ func (k *kubeClient) getPod() (*corev1.Pod, error) {
return nil, errors.New("missing pod name")
}

//namespace, errNs := findMyNamespace()
namespace, errNs := k.options.Engine.findMyNamespace()
if errNs != nil {
k.options.Errorf("getPod: could not find pod='%s' namespace: %v", podName, errNs)
return nil, errNs
}

//pod, errPod := k.clientset.CoreV1().Pods(namespace).Get(context.TODO(), podName, metav1.GetOptions{})
pod, errPod := k.options.Engine.getPod(namespace, podName)
if errPod != nil {
k.options.Errorf("getPod: could not find pod name='%s': %v", podName, errPod)
Expand All @@ -89,13 +67,6 @@ func (k *kubeClient) getPod() (*corev1.Pod, error) {
return pod, errPod
}

/*
func findMyNamespace() (string, error) {
buf, err := os.ReadFile("/var/run/secrets/kubernetes.io/serviceaccount/namespace")
return string(buf), err
}
*/

func isPodReady(pod *corev1.Pod) bool {
for _, condition := range pod.Status.Conditions {
if condition.Type == corev1.PodReady && condition.Status == corev1.ConditionTrue {
Expand Down Expand Up @@ -187,7 +158,6 @@ func (k *kubeClient) getPodTable() (map[string]string, error) {
return nil, errInfo
}

//pods, errList := k.clientset.CoreV1().Pods(podInfo.namespace).List(context.TODO(), podInfo.listOptions)
pods, errList := k.options.Engine.listPods(podInfo.namespace, podInfo.listOptions)
if errList != nil {
k.options.Errorf("%s: list pods: %v", me, errList)
Expand Down Expand Up @@ -257,7 +227,6 @@ func (k *kubeClient) watchOnce(out chan<- podAddress, info *podInfo, table map[s

myPodName := info.name

//watcher, errWatch := k.clientset.CoreV1().Pods(info.namespace).Watch(context.TODO(), info.listOptions)
watcher, errWatch := k.options.Engine.watchPods(info.namespace, info.listOptions)
if errWatch != nil {
k.options.Errorf("%s: watch: %v", me, errWatch)
Expand Down

0 comments on commit 98e0181

Please sign in to comment.