This repository has been archived by the owner on Nov 30, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
/
azure_config_checker.go
61 lines (49 loc) · 1.61 KB
/
azure_config_checker.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
package ipam
import (
"context"
"net"
"github.com/giantswarm/apiextensions/v6/pkg/apis/provider/v1alpha1"
"github.com/giantswarm/microerror"
"github.com/giantswarm/micrologger"
"sigs.k8s.io/controller-runtime/pkg/client"
"github.com/giantswarm/azure-operator/v7/service/controller/key"
)
type AzureConfigCheckerConfig struct {
CtrlClient client.Client
Logger micrologger.Logger
}
type AzureConfigChecker struct {
ctrlClient client.Client
logger micrologger.Logger
}
func NewAzureConfigChecker(config AzureConfigCheckerConfig) (*AzureConfigChecker, 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)
}
a := &AzureConfigChecker{
ctrlClient: config.CtrlClient,
logger: config.Logger,
}
return a, nil
}
func (c *AzureConfigChecker) Check(ctx context.Context, namespace string, name string) (*net.IPNet, error) {
azureCluster := &v1alpha1.AzureConfig{}
err := c.ctrlClient.Get(ctx, client.ObjectKey{Namespace: namespace, Name: name}, azureCluster)
if err != nil {
return nil, microerror.Mask(err)
}
// We check the subnet we want to ensure in the CR status. In case there is no
// subnet tracked so far, we want to proceed with the allocation process. Thus
// we return nil.
if key.AzureConfigNetworkCIDR(*azureCluster) == "" {
return nil, nil
}
_, subnet, err := net.ParseCIDR(key.AzureConfigNetworkCIDR(*azureCluster))
if err != nil {
return nil, microerror.Mask(err)
}
return subnet, nil
}