kube-fetcher/cmd/fetcher/main.go

56 lines
1.7 KiB
Go

package main
import (
goflags "flag"
"github.com/spf13/cobra"
"k8s.io/klog/v2"
"os"
"time"
)
func main() {
klogFlags := goflags.NewFlagSet("", goflags.PanicOnError)
klog.InitFlags(klogFlags)
clientset := GetKubernetesConnection()
config := &Config{}
fetcher := NewFetcher(config, clientset)
cmd := &cobra.Command{
Use: "kube-fetcher",
Short: "Fetch images on a kubernetes node",
Long: `
Queries k8s for all running pods and makes sure that all
images referenced in pods are made available on the local k8s node and pinned
so they don't get garbage collected'`,
RunE: func(cmd *cobra.Command, args []string) error {
err := fetcher.pullAndPin()
//watcher := Watcher{}
//watcher.WatchPods(clientset, config.KubernetesNamespace)
return err
},
}
cmd.PersistentFlags().StringVar(&config.KubernetesNamespace, "kubernetes-namespace",
"", "Kubernetes containerdNamespace to inspect (default is all namespaces)")
cmd.PersistentFlags().StringVar(&config.SocketPath, "socket",
"/run/containerd/containerd.sock", "Containerd socket")
cmd.PersistentFlags().StringVar(&config.ContainerdNamespace, "containerd-namespace",
"k8s.io", "Containerd namespace to use")
cmd.PersistentFlags().StringVar(&config.Nodename, "nodename", "",
"Kubernetes node name the fetcher is running on, it will only fetch images running on other nodes")
cmd.PersistentFlags().DurationVar(&config.ReadyDuration, "ready-duration",
1*time.Hour, "Time a pod must be ready before its image will be fetched")
cmd.PersistentFlags().BoolVar(&config.includeControllerNodes, "include-controllers",
false, "Include controller nodes")
cmd.Flags().AddGoFlagSet(klogFlags)
err := cmd.Execute()
if err != nil {
klog.Errorf("Error: %v", err)
os.Exit(1)
}
}