-
-
Notifications
You must be signed in to change notification settings - Fork 8
/
provider.go
46 lines (40 loc) · 1.77 KB
/
provider.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
package provider
import (
"github.com/kobsio/kobs/pkg/api/clusters/cluster"
"github.com/kobsio/kobs/pkg/api/clusters/provider/incluster"
"github.com/kobsio/kobs/pkg/api/clusters/provider/kubeconfig"
"github.com/kobsio/kobs/pkg/log"
"go.uber.org/zap"
)
// Type is the type of the cluster provider. At the moment it is only possible to load clusters via the
// incluster configuration or a Kubeconfig file. It is planed to implement support GKE, EKS and AKS later, so that all
// clusters can be automatically added from a cloud provider.
type Type string
const (
// INCLUSTER is the type of the cluster provider, when kobs should be used for the cluster where it is running in.
INCLUSTER Type = "incluster"
// KUBECONFIG is the type of the cluster provider, when kobs should be used for all clusters in a given Kubeconfig
// file.
KUBECONFIG Type = "kubeconfig"
)
// Config is the provider configuration to get Kubernetes clusters from. The provider configuration only contains the
// provider type and a provider specific configuration.
type Config struct {
Provider Type `json:"provider"`
InCluster incluster.Config `json:"incluster"`
Kubeconfig kubeconfig.Config `json:"kubeconfig"`
}
// GetClusters returns all clusters for the given provider. When the provider field doesn't match our custom Type, we
// only log a warning instead of throwing an error. This allows kobs to start also, when one provided provider is
// invalid.
func GetClusters(config *Config) ([]*cluster.Cluster, error) {
switch config.Provider {
case INCLUSTER:
return incluster.GetCluster(&config.InCluster)
case KUBECONFIG:
return kubeconfig.GetClusters(&config.Kubeconfig)
default:
log.Warn(nil, "Invalid provider.", zap.String("provider", string(config.Provider)))
return nil, nil
}
}