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
/
cluster_checker.go
56 lines (45 loc) · 1.53 KB
/
cluster_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
package ipam
import (
"context"
"github.com/giantswarm/apiextensions/pkg/clientset/versioned"
"github.com/giantswarm/microerror"
"github.com/giantswarm/micrologger"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"github.com/giantswarm/azure-operator/v4/service/controller/key"
)
type ClusterCheckerConfig struct {
G8sClient versioned.Interface
Logger micrologger.Logger
}
type ClusterChecker struct {
g8sClient versioned.Interface
logger micrologger.Logger
}
func NewClusterChecker(config ClusterCheckerConfig) (*ClusterChecker, error) {
if config.G8sClient == nil {
return nil, microerror.Maskf(invalidConfigError, "%T.G8sClient must not be empty", config)
}
if config.Logger == nil {
return nil, microerror.Maskf(invalidConfigError, "%T.Logger must not be empty", config)
}
a := &ClusterChecker{
g8sClient: config.G8sClient,
logger: config.Logger,
}
return a, nil
}
func (c *ClusterChecker) Check(ctx context.Context, namespace string, name string) (bool, error) {
cr, err := c.g8sClient.ProviderV1alpha1().AzureConfigs(namespace).Get(name, metav1.GetOptions{})
if err != nil {
return false, 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 true.
if key.AzureConfigNetworkCIDR(*cr) == "" {
return true, nil
}
// At this point the subnet is already allocated for the CR we check here. So
// we do not want to proceed further and return false.
return false, nil
}