Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose bundle data from bundle image #94

Merged
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 2 additions & 24 deletions pkg/appregistry/appregistry.go
Original file line number Diff line number Diff line change
@@ -5,10 +5,8 @@ import (

"github.com/sirupsen/logrus"
utilerrors "k8s.io/apimachinery/pkg/util/errors"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/rest"
"k8s.io/client-go/tools/clientcmd"

"github.com/operator-framework/operator-registry/pkg/client"
"github.com/operator-framework/operator-registry/pkg/registry"
)

@@ -19,7 +17,7 @@ import (
// downloadPath specifies the folder where the downloaded nested bundle(s) will
// be stored.
func NewLoader(kubeconfig string, dbName string, downloadPath string, logger *logrus.Entry) (*AppregistryLoader, error) {
kubeClient, err := NewKubeClient(kubeconfig, logger)
kubeClient, err := client.NewKubeClient(kubeconfig, logger.Logger)
if err != nil {
return nil, err
}
@@ -104,23 +102,3 @@ func (a *AppregistryLoader) Load(csvSources []string, csvPackages string) (regis

return store, utilerrors.NewAggregate(errs)
}

func NewKubeClient(kubeconfig string, logger *logrus.Entry) (clientset *kubernetes.Clientset, err error) {
var config *rest.Config

if kubeconfig != "" {
logger.Infof("Loading kube client config from path %q", kubeconfig)
config, err = clientcmd.BuildConfigFromFlags("", kubeconfig)
} else {
logger.Infof("Using in-cluster kube client config")
config, err = rest.InClusterConfig()
}

if err != nil {
err = fmt.Errorf("Cannot load config for REST client: %v", err)
return
}

clientset, err = kubernetes.NewForConfig(config)
return
}
35 changes: 35 additions & 0 deletions pkg/client/kubeclient.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package client

import (
"fmt"
"os"

"github.com/sirupsen/logrus"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/rest"
"k8s.io/client-go/tools/clientcmd"
)

func NewKubeClient(kubeconfig string, logger *logrus.Logger) (clientset *kubernetes.Clientset, err error) {
var config *rest.Config

if overrideConfig := os.Getenv(clientcmd.RecommendedConfigPathEnvVar); overrideConfig != "" {
kubeconfig = overrideConfig
}

if kubeconfig != "" {
logger.Infof("Loading kube client config from path %q", kubeconfig)
config, err = clientcmd.BuildConfigFromFlags("", kubeconfig)
} else {
logger.Infof("Using in-cluster kube client config")
config, err = rest.InClusterConfig()
}

if err != nil {
err = fmt.Errorf("Cannot load config for REST client: %v", err)
return
}

clientset, err = kubernetes.NewForConfig(config)
return
}