This repository has been archived by the owner on Nov 14, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 15
/
clients.go
52 lines (45 loc) · 1.88 KB
/
clients.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package clients
import (
"context"
"github.com/rancher/os2/pkg/generated/controllers/fleet.cattle.io"
fleetcontrollers "github.com/rancher/os2/pkg/generated/controllers/fleet.cattle.io/v1alpha1"
"github.com/rancher/os2/pkg/generated/controllers/management.cattle.io"
ranchercontrollers "github.com/rancher/os2/pkg/generated/controllers/management.cattle.io/v3"
"github.com/rancher/os2/pkg/generated/controllers/provisioning.cattle.io"
provcontrollers "github.com/rancher/os2/pkg/generated/controllers/provisioning.cattle.io/v1"
"github.com/rancher/os2/pkg/generated/controllers/rancheros.cattle.io"
oscontrollers "github.com/rancher/os2/pkg/generated/controllers/rancheros.cattle.io/v1"
"github.com/rancher/wrangler/pkg/clients"
"github.com/rancher/wrangler/pkg/generic"
"k8s.io/client-go/rest"
)
const (
// SystemNamespace Default namespace for rancher system objects
SystemNamespace = "cattle-system"
)
type Clients struct {
*clients.Clients
Fleet fleetcontrollers.Interface
OS oscontrollers.Interface
Rancher ranchercontrollers.Interface
Provisioning provcontrollers.Interface
}
func NewFromConfig(restConfig *rest.Config) (*Clients, error) {
c, err := clients.NewFromConfig(restConfig, nil)
if err != nil {
return nil, err
}
opts := &generic.FactoryOptions{
SharedControllerFactory: c.SharedControllerFactory,
}
return &Clients{
Clients: c,
Fleet: fleet.NewFactoryFromConfigWithOptionsOrDie(restConfig, opts).Fleet().V1alpha1(),
OS: rancheros.NewFactoryFromConfigWithOptionsOrDie(restConfig, opts).Rancheros().V1(),
Rancher: management.NewFactoryFromConfigWithOptionsOrDie(restConfig, opts).Management().V3(),
Provisioning: provisioning.NewFactoryFromConfigWithOptionsOrDie(restConfig, opts).Provisioning().V1(),
}, nil
}
func (c *Clients) Start(ctx context.Context) error {
return c.SharedControllerFactory.Start(ctx, 5)
}