-
Notifications
You must be signed in to change notification settings - Fork 53
Add DNS attributes to VPC
spec
#38
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,178 @@ | ||
// Copyright Amazon.com Inc. or its affiliates. All Rights Reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"). You may | ||
// not use this file except in compliance with the License. A copy of the | ||
// License is located at | ||
// | ||
// http://aws.amazon.com/apache2.0/ | ||
// | ||
// or in the "license" file accompanying this file. This file is distributed | ||
// on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either | ||
// express or implied. See the License for the specific language governing | ||
// permissions and limitations under the License. | ||
|
||
package vpc | ||
|
||
import ( | ||
"context" | ||
|
||
ackcompare "github.com/aws-controllers-k8s/runtime/pkg/compare" | ||
ackrtlog "github.com/aws-controllers-k8s/runtime/pkg/runtime/log" | ||
svcsdk "github.com/aws/aws-sdk-go/service/ec2" | ||
) | ||
|
||
type DNSAttrs struct { | ||
EnableSupport *bool | ||
EnableHostnames *bool | ||
} | ||
|
||
func newDescribeVpcAttributePayload( | ||
vpcID string, | ||
attribute string, | ||
) *svcsdk.DescribeVpcAttributeInput { | ||
res := &svcsdk.DescribeVpcAttributeInput{} | ||
res.SetVpcId(vpcID) | ||
res.SetAttribute(attribute) | ||
return res | ||
} | ||
|
||
func (rm *resourceManager) getDNSAttributes( | ||
ctx context.Context, | ||
vpcID string, | ||
) (res *DNSAttrs, err error) { | ||
res = &DNSAttrs{} | ||
dnsSupport, err := rm.sdkapi.DescribeVpcAttributeWithContext( | ||
ctx, | ||
newDescribeVpcAttributePayload(vpcID, svcsdk.VpcAttributeNameEnableDnsSupport), | ||
) | ||
if err != nil { | ||
return nil, err | ||
} | ||
res.EnableSupport = dnsSupport.EnableDnsSupport.Value | ||
|
||
dnsHostnames, err := rm.sdkapi.DescribeVpcAttributeWithContext( | ||
ctx, | ||
newDescribeVpcAttributePayload(vpcID, svcsdk.VpcAttributeNameEnableDnsHostnames), | ||
) | ||
if err != nil { | ||
return nil, err | ||
} | ||
res.EnableHostnames = dnsHostnames.EnableDnsHostnames.Value | ||
|
||
return res, nil | ||
} | ||
|
||
func newModifyDNSSupportAttributeInputPayload( | ||
r *resource, | ||
) *svcsdk.ModifyVpcAttributeInput { | ||
res := &svcsdk.ModifyVpcAttributeInput{} | ||
res.SetVpcId(*r.ko.Status.VPCID) | ||
|
||
if r.ko.Spec.EnableDNSSupport != nil { | ||
res.SetEnableDnsSupport(&svcsdk.AttributeBooleanValue{ | ||
Value: r.ko.Spec.EnableDNSSupport, | ||
}) | ||
} | ||
|
||
return res | ||
} | ||
|
||
func newModifyDNSHostnamesAttributeInputPayload( | ||
r *resource, | ||
) *svcsdk.ModifyVpcAttributeInput { | ||
res := &svcsdk.ModifyVpcAttributeInput{} | ||
res.SetVpcId(*r.ko.Status.VPCID) | ||
|
||
if r.ko.Spec.EnableDNSHostnames != nil { | ||
res.SetEnableDnsHostnames(&svcsdk.AttributeBooleanValue{ | ||
Value: r.ko.Spec.EnableDNSHostnames, | ||
}) | ||
} | ||
|
||
return res | ||
} | ||
|
||
func (rm *resourceManager) syncDNSSupportAttribute( | ||
ctx context.Context, | ||
r *resource, | ||
) (err error) { | ||
rlog := ackrtlog.FromContext(ctx) | ||
exit := rlog.Trace("rm.syncDNSSupportAttribute") | ||
defer exit(err) | ||
input := newModifyDNSSupportAttributeInputPayload(r) | ||
|
||
_, err = rm.sdkapi.ModifyVpcAttributeWithContext(ctx, input) | ||
rm.metrics.RecordAPICall("UPDATE", "ModifyVpcAttribute", err) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func (rm *resourceManager) syncDNSHostnamesAttribute( | ||
ctx context.Context, | ||
r *resource, | ||
) (err error) { | ||
rlog := ackrtlog.FromContext(ctx) | ||
exit := rlog.Trace("rm.syncDNSHostnamesAttribute") | ||
defer exit(err) | ||
input := newModifyDNSHostnamesAttributeInputPayload(r) | ||
|
||
_, err = rm.sdkapi.ModifyVpcAttributeWithContext(ctx, input) | ||
rm.metrics.RecordAPICall("UPDATE", "ModifyVpcAttribute", err) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func (rm *resourceManager) createAttributes( | ||
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. Currently this method makes two modify calls, can this be optimized to make single AWS API call? 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. Agree with @vijtrip2 here (though I'm confused why Vijay is reviewing code during his PTO...). 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. I share the concern over api calls (now and long-term), but I think if we consolidate the calls the api returns an error:
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. I'm so glad you asked!
|
||
ctx context.Context, | ||
r *resource, | ||
) (err error) { | ||
if r.ko.Spec.EnableDNSHostnames != nil { | ||
if err = rm.syncDNSHostnamesAttribute(ctx, r); err != nil { | ||
return err | ||
} | ||
} | ||
|
||
if r.ko.Spec.EnableDNSSupport != nil { | ||
if err = rm.syncDNSSupportAttribute(ctx, r); err != nil { | ||
return err | ||
} | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func (rm *resourceManager) customUpdate( | ||
ctx context.Context, | ||
desired *resource, | ||
latest *resource, | ||
delta *ackcompare.Delta, | ||
) (updated *resource, err error) { | ||
rlog := ackrtlog.FromContext(ctx) | ||
exit := rlog.Trace("rm.customUpdateVPC") | ||
defer exit(err) | ||
|
||
// Merge in the information we read from the API call above to the copy of | ||
// the original Kubernetes object we passed to the function | ||
ko := desired.ko.DeepCopy() | ||
|
||
if delta.DifferentAt("Spec.EnableDNSSupport") { | ||
if err := rm.syncDNSSupportAttribute(ctx, desired); err != nil { | ||
return nil, err | ||
} | ||
} | ||
|
||
if delta.DifferentAt("Spec.EnableDNSHostnames") { | ||
if err := rm.syncDNSHostnamesAttribute(ctx, desired); err != nil { | ||
return nil, err | ||
} | ||
} | ||
|
||
rm.setStatusDefaults(ko) | ||
return &resource{ko}, nil | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
err = rm.createAttributes(ctx, &resource{ko}) | ||
if err != nil { | ||
return nil, err | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
if dnsAttrs, err := rm.getDNSAttributes(ctx, *ko.Status.VPCID); err != nil { | ||
return nil, err | ||
} else { | ||
ko.Spec.EnableDNSSupport = dnsAttrs.EnableSupport | ||
ko.Spec.EnableDNSHostnames = dnsAttrs.EnableHostnames | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
__pycache__/ | ||
*.py[cod] | ||
**/bootstrap.pkl |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,5 +15,6 @@ | |
""" | ||
|
||
REPLACEMENT_VALUES = { | ||
|
||
"ENABLE_DNS_SUPPORT": "False", | ||
"ENABLE_DNS_HOSTNAMES": "False", | ||
} |
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.
LOL. Great description :)
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.
Creating an issue for custom documentation rn
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.
:) I didn't expect you to do that.
Uh oh!
There was an error while loading. Please reload this page.
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.
It's been really bugging me. Especially that now we are creating resource references, they should have proper documentation - rather than being the GoDoc for the
ACKResourceReference
type