You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
k3s/pkg/server/context.go

70 lines
2.0 KiB

6 years ago
package server
import (
"context"
"github.com/rancher/helm-controller/pkg/generated/controllers/helm.cattle.io"
6 years ago
"github.com/rancher/k3s/pkg/generated/controllers/k3s.cattle.io"
"github.com/rancher/wrangler-api/pkg/generated/controllers/apps"
"github.com/rancher/wrangler-api/pkg/generated/controllers/batch"
"github.com/rancher/wrangler-api/pkg/generated/controllers/core"
"github.com/rancher/wrangler-api/pkg/generated/controllers/rbac"
6 years ago
"github.com/rancher/wrangler/pkg/apply"
"github.com/rancher/wrangler/pkg/crd"
"github.com/rancher/wrangler/pkg/start"
5 years ago
"k8s.io/client-go/kubernetes"
6 years ago
"k8s.io/client-go/rest"
5 years ago
"k8s.io/client-go/tools/clientcmd"
6 years ago
)
type Context struct {
K3s *k3s.Factory
Helm *helm.Factory
Batch *batch.Factory
6 years ago
Apps *apps.Factory
Auth *rbac.Factory
6 years ago
Core *core.Factory
K8s kubernetes.Interface
Apply apply.Apply
}
func (c *Context) Start(ctx context.Context) error {
return start.All(ctx, 5, c.K3s, c.Helm, c.Apps, c.Auth, c.Batch, c.Core)
6 years ago
}
func newContext(ctx context.Context, cfg string) (*Context, error) {
restConfig, err := clientcmd.BuildConfigFromFlags("", cfg)
if err != nil {
return nil, err
}
if err := crds(ctx, restConfig); err != nil {
return nil, err
}
k8s := kubernetes.NewForConfigOrDie(restConfig)
return &Context{
K3s: k3s.NewFactoryFromConfigOrDie(restConfig),
Helm: helm.NewFactoryFromConfigOrDie(restConfig),
6 years ago
K8s: k8s,
Auth: rbac.NewFactoryFromConfigOrDie(restConfig),
6 years ago
Apps: apps.NewFactoryFromConfigOrDie(restConfig),
Batch: batch.NewFactoryFromConfigOrDie(restConfig),
6 years ago
Core: core.NewFactoryFromConfigOrDie(restConfig),
Apply: apply.New(k8s, apply.NewClientFactory(restConfig)).WithDynamicLookup(),
6 years ago
}, nil
}
func crds(ctx context.Context, config *rest.Config) error {
factory, err := crd.NewFactoryFromClient(config)
if err != nil {
return err
}
factory.BatchCreateCRDs(ctx, crd.NamespacedTypes(
"Addon.k3s.cattle.io/v1",
"HelmChart.helm.cattle.io/v1")...)
6 years ago
return factory.BatchWait()
}