mirror of
https://github.com/onepanelio/onepanel.git
synced 2025-09-27 10:02:10 +08:00
82 lines
2.0 KiB
Go
82 lines
2.0 KiB
Go
package v1
|
|
|
|
import (
|
|
sq "github.com/Masterminds/squirrel"
|
|
argoprojv1alpha1 "github.com/argoproj/argo/pkg/client/clientset/versioned/typed/workflow/v1alpha1"
|
|
"github.com/jmoiron/sqlx"
|
|
"github.com/onepanelio/core/pkg/util/s3"
|
|
log "github.com/sirupsen/logrus"
|
|
"k8s.io/client-go/kubernetes"
|
|
"k8s.io/client-go/rest"
|
|
"k8s.io/client-go/tools/clientcmd"
|
|
)
|
|
|
|
type Config = rest.Config
|
|
|
|
type DB = sqlx.DB
|
|
|
|
var sb = sq.StatementBuilder.PlaceholderFormat(sq.Dollar)
|
|
|
|
type Client struct {
|
|
kubernetes.Interface
|
|
argoprojV1alpha1 argoprojv1alpha1.ArgoprojV1alpha1Interface
|
|
*DB
|
|
systemConfig map[string]string // cache of SystemConfig
|
|
}
|
|
|
|
func (c *Client) ArgoprojV1alpha1() argoprojv1alpha1.ArgoprojV1alpha1Interface {
|
|
return c.argoprojV1alpha1
|
|
}
|
|
|
|
func NewConfig() (config *Config) {
|
|
config, err := clientcmd.NewNonInteractiveDeferredLoadingClientConfig(
|
|
clientcmd.NewDefaultClientConfigLoadingRules(), &clientcmd.ConfigOverrides{}).ClientConfig()
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
return
|
|
}
|
|
|
|
func NewClient(config *Config, db *sqlx.DB) (client *Client, err error) {
|
|
if config.BearerToken != "" {
|
|
config.BearerTokenFile = ""
|
|
config.Username = ""
|
|
config.Password = ""
|
|
config.CertData = nil
|
|
config.CertFile = ""
|
|
}
|
|
|
|
kubeClient, err := kubernetes.NewForConfig(config)
|
|
if err != nil {
|
|
return
|
|
}
|
|
|
|
argoClient, err := argoprojv1alpha1.NewForConfig(config)
|
|
if err != nil {
|
|
return
|
|
}
|
|
|
|
return &Client{Interface: kubeClient, argoprojV1alpha1: argoClient, DB: db}, nil
|
|
}
|
|
|
|
func (c *Client) GetS3Client(namespace string, config *ArtifactRepositoryS3Config) (s3Client *s3.Client, err error) {
|
|
s3Client, err = s3.NewClient(s3.Config{
|
|
Endpoint: config.Endpoint,
|
|
Region: config.Region,
|
|
AccessKey: config.AccessKey,
|
|
SecretKey: config.Secretkey,
|
|
InSecure: config.Insecure,
|
|
})
|
|
if err != nil {
|
|
log.WithFields(log.Fields{
|
|
"Namespace": namespace,
|
|
"ConfigMap": config,
|
|
"Error": err.Error(),
|
|
}).Error("getS3Client failed when initializing a new S3 client.")
|
|
return
|
|
}
|
|
|
|
return
|
|
}
|