Skip to content

Commit 8ccea5a

Browse files
authored
initial (#2562)
Signed-off-by: grokspawn <jordan@nimblewidget.com>
1 parent eea6f95 commit 8ccea5a

2 files changed

Lines changed: 34 additions & 3 deletions

File tree

cmd/catalogd/main.go

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ import (
3737
clientgoscheme "k8s.io/client-go/kubernetes/scheme"
3838
"k8s.io/client-go/metadata"
3939
_ "k8s.io/client-go/plugin/pkg/client/auth"
40+
"k8s.io/client-go/rest"
41+
"k8s.io/client-go/tools/clientcmd"
4042
"k8s.io/klog/v2"
4143
"k8s.io/utils/ptr"
4244
ctrl "sigs.k8s.io/controller-runtime"
@@ -95,6 +97,7 @@ type config struct {
9597
webhookPort int
9698
pullCasDir string
9799
globalPullSecret string
100+
kubeconfig string
98101
// Generated config
99102
globalPullSecretKey *k8stypes.NamespacedName
100103
}
@@ -136,6 +139,7 @@ func init() {
136139
flags.IntVar(&cfg.webhookPort, "webhook-server-port", 9443, "Webhook server port")
137140
flags.StringVar(&cfg.pullCasDir, "pull-cas-dir", "", "The directory of TLS certificate authorities to use for verifying HTTPS connections to image registries.")
138141
flags.StringVar(&cfg.globalPullSecret, "global-pull-secret", "", "Global pull secret (<namespace>/<name>)")
142+
flags.StringVar(&cfg.kubeconfig, "kubeconfig", "", "Path to kubeconfig file for API server access. Uses in-cluster config if empty.")
139143

140144
// adds version subcommand
141145
catalogdCmd.AddCommand(versionCommand)
@@ -273,8 +277,20 @@ func run(ctx context.Context) error {
273277
return err
274278
}
275279

276-
// Create manager
277-
mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{
280+
// Create manager with kubeconfig support for non-default kubeconfig
281+
var restConfig *rest.Config
282+
if cfg.kubeconfig != "" {
283+
setupLog.Info("loading kubeconfig from file", "path", cfg.kubeconfig)
284+
restConfig, err = clientcmd.BuildConfigFromFlags("", cfg.kubeconfig)
285+
if err != nil {
286+
setupLog.Error(err, "unable to load kubeconfig")
287+
return err
288+
}
289+
} else {
290+
restConfig = ctrl.GetConfigOrDie()
291+
}
292+
293+
mgr, err := ctrl.NewManager(restConfig, ctrl.Options{
278294
Scheme: scheme,
279295
Metrics: metricsServerOptions,
280296
PprofBindAddress: cfg.pprofAddr,

cmd/operator-controller/main.go

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ import (
4040
"k8s.io/client-go/discovery/cached/memory"
4141
corev1client "k8s.io/client-go/kubernetes/typed/core/v1"
4242
_ "k8s.io/client-go/plugin/pkg/client/auth"
43+
"k8s.io/client-go/rest"
44+
"k8s.io/client-go/tools/clientcmd"
4345
"k8s.io/klog/v2"
4446
"k8s.io/utils/ptr"
4547
"pkg.package-operator.run/boxcutter/managedcache"
@@ -104,6 +106,7 @@ type config struct {
104106
catalogdCasDir string
105107
pullCasDir string
106108
globalPullSecret string
109+
kubeconfig string
107110
}
108111

109112
type reconcilerConfigurator interface {
@@ -183,6 +186,7 @@ func init() {
183186
flags.StringVar(&cfg.cachePath, "cache-path", "/var/cache", "The local directory path used for filesystem based caching")
184187
flags.StringVar(&cfg.systemNamespace, "system-namespace", "", "Configures the namespace that gets used to deploy system resources.")
185188
flags.StringVar(&cfg.globalPullSecret, "global-pull-secret", "", "The <namespace>/<name> of the global pull secret that is going to be used to pull bundle images.")
189+
flags.StringVar(&cfg.kubeconfig, "kubeconfig", "", "Path to kubeconfig file for API server access. Uses in-cluster config if empty.")
186190

187191
//adds version sub command
188192
operatorControllerCmd.AddCommand(versionCommand)
@@ -324,7 +328,18 @@ func run() error {
324328
"Metrics will not be served since the TLS certificate and key file are not provided.")
325329
}
326330

327-
restConfig := ctrl.GetConfigOrDie()
331+
// Load REST config with kubeconfig support for non-default kubeconfig
332+
var restConfig *rest.Config
333+
if cfg.kubeconfig != "" {
334+
setupLog.Info("loading kubeconfig from file", "path", cfg.kubeconfig)
335+
restConfig, err = clientcmd.BuildConfigFromFlags("", cfg.kubeconfig)
336+
if err != nil {
337+
setupLog.Error(err, "unable to load kubeconfig")
338+
return err
339+
}
340+
} else {
341+
restConfig = ctrl.GetConfigOrDie()
342+
}
328343
mgr, err := ctrl.NewManager(restConfig, ctrl.Options{
329344
Scheme: scheme.Scheme,
330345
Metrics: metricsServerOptions,

0 commit comments

Comments
 (0)