diff options
| author | jannfis <jann@mistrust.net> | 2021-09-15 09:19:46 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-09-15 09:19:46 +0200 |
| commit | f2b1ae04cd34480ea4761207296b8a63a3584f8a (patch) | |
| tree | 0f189c276d651419903a1248a2dd878dfca87233 /cmd/util.go | |
| parent | 54cd9040acdfe42889bff709ec08bdfdb77a92b5 (diff) | |
refactor: Move CLI commands into their own files (#254)
Signed-off-by: jannfis <jann@mistrust.net>
Diffstat (limited to 'cmd/util.go')
| -rw-r--r-- | cmd/util.go | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/cmd/util.go b/cmd/util.go new file mode 100644 index 0000000..7b6a944 --- /dev/null +++ b/cmd/util.go @@ -0,0 +1,53 @@ +package main + +import ( + "context" + "fmt" + "path/filepath" + "time" + + "github.com/argoproj-labs/argocd-image-updater/pkg/kube" + "github.com/argoproj-labs/argocd-image-updater/pkg/log" +) + +func getPrintableInterval(interval time.Duration) string { + if interval == 0 { + return "once" + } else { + return interval.String() + } +} + +func getPrintableHealthPort(port int) string { + if port == 0 { + return "off" + } else { + return fmt.Sprintf("%d", port) + } +} + +func getKubeConfig(ctx context.Context, namespace string, kubeConfig string) (*kube.KubernetesClient, error) { + var fullKubeConfigPath string + var kubeClient *kube.KubernetesClient + var err error + + if kubeConfig != "" { + fullKubeConfigPath, err = filepath.Abs(kubeConfig) + if err != nil { + return nil, fmt.Errorf("cannot expand path %s: %v", kubeConfig, err) + } + } + + if fullKubeConfigPath != "" { + log.Debugf("Creating Kubernetes client from %s", fullKubeConfigPath) + } else { + log.Debugf("Creating in-cluster Kubernetes client") + } + + kubeClient, err = kube.NewKubernetesClientFromConfig(ctx, namespace, fullKubeConfigPath) + if err != nil { + return nil, err + } + + return kubeClient, nil +} |
