forked from kubernetes-sigs/cluster-api-provider-aws
-
Notifications
You must be signed in to change notification settings - Fork 50
Load Balancer update #82
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 4 additions & 6 deletions
10
pkg/apis/awsproviderconfig/v1alpha1/zz_generated.deepcopy.go
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -35,6 +35,7 @@ import ( | |
|
|
||
| "github.com/aws/aws-sdk-go/aws" | ||
| "github.com/aws/aws-sdk-go/service/ec2" | ||
| "github.com/aws/aws-sdk-go/service/elb" | ||
|
|
||
| "k8s.io/apimachinery/pkg/runtime" | ||
| awsclient "sigs.k8s.io/cluster-api-provider-aws/pkg/cloud/aws/client" | ||
|
|
@@ -121,12 +122,6 @@ func (a *Actuator) Create(cluster *clusterv1.Cluster, machine *clusterv1.Machine | |
| } | ||
| return err | ||
| } | ||
|
|
||
| // TODO(csrwng): | ||
| // Part of the status that gets updated when the machine gets created is the PublicIP. | ||
| // However, after a call to runInstance, most of the time a PublicIP is not yet allocated. | ||
| // If we don't yet have complete status (ie. the instance state is Pending, instead of Running), | ||
| // maybe we should return an error so the machine controller keeps retrying until we have complete status we can set. | ||
| return a.updateStatus(machine, instance, mLog) | ||
| } | ||
|
|
||
|
|
@@ -433,14 +428,11 @@ func (a *Actuator) CreateMachine(cluster *clusterv1.Cluster, machine *clusterv1. | |
| return nil, fmt.Errorf("unexpected reservation creating instance") | ||
| } | ||
|
|
||
| // TOOD(csrwng): | ||
| // One issue we have right now with how this works, is that usually at the end of the RunInstances call, | ||
| // the instance state is not yet 'Running'. Rather it is 'Pending'. Therefore the status | ||
| // is not yet complete (like PublicIP). One possible fix would be to wait and poll here | ||
| // until the instance is in the Running state. The other approach is to return an error | ||
| // so that the machine is requeued and in the exists function return false if the status doesn't match. | ||
| // That would require making the create re-entrant so we can just update the status. | ||
| return runResult.Instances[0], nil | ||
| instance := runResult.Instances[0] | ||
|
|
||
| err = a.UpdateLoadBalancers(client, machineProviderConfig, instance, mLog) | ||
|
|
||
| return instance, err | ||
| } | ||
|
|
||
| // Delete deletes a machine and updates its finalizer | ||
|
|
@@ -547,6 +539,11 @@ func (a *Actuator) Update(cluster *clusterv1.Cluster, machine *clusterv1.Machine | |
|
|
||
| } | ||
|
|
||
| err = a.UpdateLoadBalancers(client, machineProviderConfig, newestInstance, mLog) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| // We do not support making changes to pre-existing instances, just update status. | ||
| return a.updateStatus(machine, newestInstance, mLog) | ||
| } | ||
|
|
@@ -613,6 +610,30 @@ func (a *Actuator) getMachineInstances(cluster *clusterv1.Cluster, machine *clus | |
| return GetRunningInstances(machine, client) | ||
| } | ||
|
|
||
| // UpdateLoadBalancers adds a given machine instance to the load balancers specified in its provider config | ||
| func (a *Actuator) UpdateLoadBalancers(client awsclient.Client, providerConfig *providerconfigv1.AWSMachineProviderConfig, instance *ec2.Instance, mLog log.FieldLogger) error { | ||
| if len(providerConfig.LoadBalancerNames) == 0 { | ||
| return nil | ||
| } | ||
| elbInstance := &elb.Instance{InstanceId: instance.InstanceId} | ||
| var errs []error | ||
| for _, elbName := range providerConfig.LoadBalancerNames { | ||
| req := &elb.RegisterInstancesWithLoadBalancerInput{ | ||
| Instances: []*elb.Instance{elbInstance}, | ||
| LoadBalancerName: aws.String(elbName), | ||
| } | ||
| _, err := client.RegisterInstancesWithLoadBalancer(req) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. could inline here as well |
||
| if err != nil { | ||
| errs = append(errs, fmt.Errorf("%s: %v", elbName, err)) | ||
| } | ||
| } | ||
|
|
||
| if len(errs) > 0 { | ||
| return fmt.Errorf("failed to register instances with elbs: %v", errs) | ||
| } | ||
| return nil | ||
| } | ||
|
|
||
| // updateStatus calculates the new machine status, checks if anything has changed, and updates if so. | ||
| func (a *Actuator) updateStatus(machine *clusterv1.Machine, instance *ec2.Instance, mLog log.FieldLogger) error { | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could inline it here