-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add run once option add custom config option
- Loading branch information
yacut
committed
Mar 6, 2021
1 parent
2f49cd9
commit 4bcfaf4
Showing
19 changed files
with
696 additions
and
391 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package config | ||
|
||
import ( | ||
"github.com/rs/zerolog/log" | ||
"k8s.io/client-go/kubernetes" | ||
"k8s.io/client-go/rest" | ||
"k8s.io/client-go/tools/clientcmd" | ||
metrics "k8s.io/metrics/pkg/client/clientset/versioned" | ||
|
||
agentclientset "github.com/iLert/ilert-kube-agent/pkg/client/clientset/versioned" | ||
) | ||
|
||
// SetKubeConfig override default kube config | ||
func (cfg *Config) SetKubeConfig(config *rest.Config) { | ||
cfg.KubeConfig = config | ||
} | ||
|
||
func (cfg *Config) initializeClients() { | ||
if cfg.KubeConfig == nil { | ||
config, err := clientcmd.BuildConfigFromFlags(cfg.Settings.Master, cfg.Settings.KubeConfig) | ||
if err != nil { | ||
log.Fatal().Err(err).Msg("Failed to build kubeconfig") | ||
} else { | ||
cfg.KubeConfig = config | ||
} | ||
|
||
if cfg.Settings.Insecure { | ||
config.Insecure = true | ||
} | ||
} | ||
|
||
if cfg.KubeClient == nil { | ||
kubeClient, err := kubernetes.NewForConfig(cfg.KubeConfig) | ||
if err != nil { | ||
log.Fatal().Err(err).Msg("Failed to create kube client") | ||
} else { | ||
cfg.KubeClient = kubeClient | ||
} | ||
} | ||
|
||
if cfg.AgentKubeClient == nil { | ||
agentKubeClient, err := agentclientset.NewForConfig(cfg.KubeConfig) | ||
if err != nil { | ||
log.Fatal().Err(err).Msg("Failed to create kube agent client") | ||
} else { | ||
cfg.AgentKubeClient = agentKubeClient | ||
} | ||
} | ||
|
||
if cfg.MetricsClient == nil { | ||
metricsClient, err := metrics.NewForConfig(cfg.KubeConfig) | ||
if err != nil { | ||
log.Fatal().Err(err).Msg("Failed to create metrics client") | ||
} else { | ||
cfg.MetricsClient = metricsClient | ||
} | ||
} | ||
} |
Oops, something went wrong.