This repository has been archived by the owner on Nov 30, 2023. It is now read-only.
/
resource.go
78 lines (65 loc) · 2.13 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
71
72
73
74
75
76
77
78
package azureconfig
import (
"github.com/giantswarm/microerror"
"github.com/giantswarm/micrologger"
"sigs.k8s.io/controller-runtime/pkg/client"
v5client "github.com/giantswarm/azure-operator/v6/client"
)
const (
Name = "azureconfig"
)
type CalicoConfig struct {
CIDRSize int
MTU int
Subnet string
}
type Config struct {
CtrlClient client.Client
Logger micrologger.Logger
APIServerSecurePort int
Calico CalicoConfig
ClientFactory v5client.OrganizationFactory
ClusterIPRange string
EtcdPrefix string
ManagementClusterResourceGroup string
VnetMaskSize int
}
type Resource struct {
ctrlClient client.Client
logger micrologger.Logger
apiServerSecurePort int
calico CalicoConfig
clientFactory v5client.OrganizationFactory
clusterIPRange string
etcdPrefix string
managementClusterResourceGroup string
vnetMaskSize int
}
func New(config Config) (*Resource, error) {
if config.CtrlClient == nil {
return nil, microerror.Maskf(invalidConfigError, "%T.CtrlClient must not be empty", config)
}
if config.Logger == nil {
return nil, microerror.Maskf(invalidConfigError, "%T.Logger must not be empty", config)
}
if config.VnetMaskSize == 0 {
return nil, microerror.Maskf(invalidConfigError, "%T.VnetMaskSize must be set", config)
}
// No validation for configuration at this point. I'm not fully sure if any
// of that is actually needed.
newResource := &Resource{
ctrlClient: config.CtrlClient,
logger: config.Logger,
apiServerSecurePort: config.APIServerSecurePort,
calico: config.Calico,
clientFactory: config.ClientFactory,
clusterIPRange: config.ClusterIPRange,
etcdPrefix: config.EtcdPrefix,
managementClusterResourceGroup: config.ManagementClusterResourceGroup,
vnetMaskSize: config.VnetMaskSize,
}
return newResource, nil
}
func (r *Resource) Name() string {
return Name
}