49 lines
1.4 KiB
Go
49 lines
1.4 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)
|
|
|
|
fetcher := Fetcher{}
|
|
|
|
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()
|
|
return err
|
|
},
|
|
}
|
|
|
|
cmd.PersistentFlags().StringVar(&fetcher.KubernetesNamespace, "kubernetes-namespace",
|
|
"", "Kubernetes containerdNamespace to inspect (default is all namespaces)")
|
|
cmd.PersistentFlags().StringVar(&fetcher.SocketPath, "socket",
|
|
"/run/containerd/containerd.sock", "Containerd socket")
|
|
cmd.PersistentFlags().StringVar(&fetcher.ContainerdNamespace, "containerd-namespace",
|
|
"k8s.io", "Containerd namespace to use")
|
|
cmd.PersistentFlags().StringVar(&fetcher.Nodename, "nodename", "",
|
|
"Kubernetes node name the fetcher is running on, it will only fetch images running on other nodes")
|
|
cmd.PersistentFlags().DurationVar(&fetcher.ReadyDuration, "ready-duration",
|
|
1*time.Hour, "Time a pod must be ready before its image will be fetched")
|
|
cmd.Flags().AddGoFlagSet(klogFlags)
|
|
|
|
err := cmd.Execute()
|
|
if err != nil {
|
|
klog.Errorf("Error: %v", err)
|
|
os.Exit(1)
|
|
}
|
|
|
|
}
|