/
kubernetes.go
99 lines (81 loc) · 2.82 KB
/
kubernetes.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
package kubernetes
import (
"errors"
"github.com/armory/spinnaker-operator/pkg/accounts/account"
"github.com/armory/spinnaker-operator/pkg/apis/spinnaker/interfaces"
"strings"
)
// Kubernetes accounts have a deeper integration than other accounts.
// When read from Spinnaker settings, they support `kubeconfigFile`, `kubeconfigContents`, or oauth via `oauth2l`.
// When read from the CRD, user can reference a Kubernetes secret, pass the kubeconfig file inlined,
// reference a secret (s3, gcs...), or pass provider options to make the kubeconfig on the fly.
const (
KubeconfigFileSettings = "kubeconfigFile"
KubeconfigFileContentSettings = "kubeconfigContents"
UseServiceAccount = "serviceAccount"
)
var TypesFactory interfaces.TypesFactory
type AccountType struct{}
func (k *AccountType) GetType() interfaces.AccountType {
return interfaces.KubernetesAccountType
}
func (k *AccountType) GetAccountsKey() string {
return "kubernetes.accounts"
}
func (k *AccountType) GetConfigAccountsKey() string {
return "providers.kubernetes.accounts"
}
func (k *AccountType) GetServices() []string {
return []string{"clouddriver"}
}
func (k *AccountType) newAccount() *Account {
return &Account{
Env: Env{},
}
}
func (k *AccountType) GetValidationSettings(spinsvc interfaces.SpinnakerService) *interfaces.ValidationSetting {
v := spinsvc.GetSpinnakerValidation()
for n, s := range v.Providers {
if strings.ToLower(n) == strings.ToLower(string(interfaces.KubernetesAccountType)) {
return &s
}
}
return v.GetValidationSettings()
}
type Env struct {
Namespaces []string `json:"namespaces,omitempty"`
OmitNamespaces []string `json:"omitNamespaces,omitempty"`
Kinds []string `json:"kinds,omitempty"`
OmitKinds []string `json:"omitKinds,omitempty"`
CustomResources []CustomKubernetesResource `json:"customResources,omitempty"`
}
type CustomKubernetesResource struct {
KubernetesKind string `json:"kubernetesKind,omitempty"`
SpinnakerKind string `json:"spinnakerKind,omitEmpty"`
Versioned bool `json:"versioned,omitempty"`
}
type Account struct {
*account.BaseAccount
Name string `json:"name,omitempty"`
Auth *interfaces.KubernetesAuth
Env Env `json:"env,omitempty"`
Settings interfaces.FreeForm `json:"settings,omitempty"`
}
func (k *Account) GetType() interfaces.AccountType {
return interfaces.KubernetesAccountType
}
func (k *Account) GetName() string {
return k.Name
}
func (k *Account) GetSettings() *interfaces.FreeForm {
return &k.Settings
}
func (k *Account) validateFormat() error {
if k.Name == "" {
return errors.New("Spinnaker account must have a name")
}
return nil
}
func (k *Account) NewValidator() account.AccountValidator {
return &kubernetesAccountValidator{account: k}
}