This repository has been archived by the owner on Dec 11, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 13
/
resource.go
70 lines (58 loc) · 1.55 KB
/
resource.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
package serviceaccount
import (
"github.com/giantswarm/microerror"
"github.com/giantswarm/micrologger"
corev1 "k8s.io/api/core/v1"
"k8s.io/client-go/kubernetes"
)
const (
// Name is the identifier of the resource.
Name = "serviceaccount"
)
// Config represents the configuration used to create a new cloud config resource.
type Config struct {
// Dependencies.
K8sClient kubernetes.Interface
Logger micrologger.Logger
}
// DefaultConfig provides a default configuration to create a new config map
// resource by best effort.
func DefaultConfig() Config {
return Config{
K8sClient: nil,
Logger: nil,
}
}
// Resource implements the config map resource.
type Resource struct {
// Dependencies.
k8sClient kubernetes.Interface
logger micrologger.Logger
}
// New creates a new configured config map resource.
func New(config Config) (*Resource, error) {
if config.K8sClient == nil {
return nil, microerror.Maskf(invalidConfigError, "config.K8sClient must not be empty")
}
if config.Logger == nil {
return nil, microerror.Maskf(invalidConfigError, "config.Logger must not be empty")
}
newService := &Resource{
k8sClient: config.K8sClient,
logger: config.Logger,
}
return newService, nil
}
func (r *Resource) Name() string {
return Name
}
func toServiceAccount(v interface{}) (*corev1.ServiceAccount, error) {
if v == nil {
return nil, nil
}
serviceAccount, ok := v.(*corev1.ServiceAccount)
if !ok {
return nil, microerror.Maskf(wrongTypeError, "expected '%T', got '%T'", corev1.ServiceAccount{}, v)
}
return serviceAccount, nil
}