Skip to content

Commit 47a92d4

Browse files
authored
Merge pull request #76 from Charliekenney23/feat/nodebal-id-annotation
add nodebalancer-id annotation
2 parents 1c92e16 + c9f1f3c commit 47a92d4

16 files changed

+838
-151
lines changed

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@ Annotation (Suffix) | Values | Default | Description
5252
`check-timeout` | int (1-30) | | Duration, in seconds, to wait for a health check to succeed before considering it a failure
5353
`check-attempts` | int (1-30) | | Number of health check failures necessary to remove a back-end from the service
5454
`check-passive` | [bool](#annotation-bool-values) | `false` | When `true`, `5xx` status codes will cause the health check to fail
55-
`preserve` | [bool](#annotation-bool-values) | `false` | When `true`, deleting a `LoadBalancer` service does not delete the underlying NodeBalancer
55+
`preserve` | [bool](#annotation-bool-values) | `false` | When `true`, deleting a `LoadBalancer` service does not delete the underlying NodeBalancer. This will also prevent deletion of the former LoadBalancer when another one is specified with the `nodebalancer-id` annotation.
56+
`nodebalancer-id` | string | | The ID of the NodeBalancer to front the service. When not specified, a new NodeBalancer will be created. This can be configured on service creation or patching
5657

5758
#### Deprecated Annotations
5859

@@ -251,7 +252,7 @@ dep ensure
251252

252253
#### Building Docker images
253254

254-
To build and push a Docker image, use the following make targets.
255+
To build and push a Docker image, use the following make targets.
255256

256257
```bash
257258
# Set the repo/image:tag with the TAG environment variable

cloud/linode/cloud.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77

88
"github.com/linode/linodego"
99
"github.com/spf13/pflag"
10+
"k8s.io/client-go/informers"
1011
"k8s.io/kubernetes/pkg/cloudprovider"
1112
"k8s.io/kubernetes/pkg/controller"
1213
)
@@ -70,6 +71,16 @@ func newCloud() (cloudprovider.Interface, error) {
7071
}
7172

7273
func (c *linodeCloud) Initialize(clientBuilder controller.ControllerClientBuilder) {
74+
kubeclient := clientBuilder.ClientOrDie("linode-shared-informers")
75+
sharedInformer := informers.NewSharedInformerFactory(kubeclient, 0)
76+
serviceInformer := sharedInformer.Core().V1().Services()
77+
78+
serviceController := newServiceController(c.loadbalancers.(*loadbalancers), serviceInformer)
79+
80+
// in future version of the cloudprovider package, we should use the stopCh provided to
81+
// (cloudprovider.Interface).Initialize instead
82+
forever := make(chan struct{})
83+
go serviceController.Run(forever)
7384
}
7485

7586
func (c *linodeCloud) LoadBalancer() (cloudprovider.LoadBalancer, bool) {

cloud/linode/fake_linode_test.go

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -341,14 +341,17 @@ func (f *fakeAPI) ServeHTTP(w http.ResponseWriter, r *http.Request) {
341341
ip := net.IPv4(byte(rand.Intn(100)), byte(rand.Intn(100)), byte(rand.Intn(100)), byte(rand.Intn(100))).String()
342342
hostname := fmt.Sprintf("nb-%s.%s.linode.com", strings.Replace(ip, ".", "-", 4), strings.ToLower(nbco.Region))
343343
nb := linodego.NodeBalancer{
344-
ID: rand.Intn(9999),
345-
Label: nbco.Label,
346-
Region: nbco.Region,
347-
ClientConnThrottle: *nbco.ClientConnThrottle,
348-
IPv4: &ip,
349-
Hostname: &hostname,
350-
CreatedStr: time.Now().Format("2006-01-02T15:04:05"),
351-
UpdatedStr: time.Now().Format("2006-01-02T15:04:05"),
344+
ID: rand.Intn(9999),
345+
Label: nbco.Label,
346+
Region: nbco.Region,
347+
IPv4: &ip,
348+
Hostname: &hostname,
349+
CreatedStr: time.Now().Format("2006-01-02T15:04:05"),
350+
UpdatedStr: time.Now().Format("2006-01-02T15:04:05"),
351+
}
352+
353+
if nbco.ClientConnThrottle != nil {
354+
nb.ClientConnThrottle = *nbco.ClientConnThrottle
352355
}
353356
f.nb[strconv.Itoa(nb.ID)] = &nb
354357

0 commit comments

Comments
 (0)