Skip to content

Improve the DNS attribute default handling #226

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 1 commit into from
Oct 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions apis/v1alpha1/generator.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -734,6 +734,8 @@ resources:
type: bool
is_read_only: true
hooks:
delta_pre_compare:
code: customPreCompare(delta, a, b)
sdk_create_post_build_request:
template_path: hooks/vpc/sdk_create_post_build_request.go.tpl
sdk_create_post_set_output:
Expand Down
2 changes: 2 additions & 0 deletions generator.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -734,6 +734,8 @@ resources:
type: bool
is_read_only: true
hooks:
delta_pre_compare:
code: customPreCompare(delta, a, b)
sdk_create_post_build_request:
template_path: hooks/vpc/sdk_create_post_build_request.go.tpl
sdk_create_post_set_output:
Expand Down
37 changes: 29 additions & 8 deletions pkg/resource/vpc/hooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -310,18 +310,14 @@ func (rm *resourceManager) customUpdateVPC(
}

if delta.DifferentAt("Spec.EnableDNSSupport") {
if desired.ko.Spec.EnableDNSSupport != nil {
if err := rm.syncDNSSupportAttribute(ctx, desired); err != nil {
return nil, err
}
if err := rm.syncDNSSupportAttribute(ctx, desired); err != nil {
return nil, err
}
}

if delta.DifferentAt("Spec.EnableDNSHostnames") {
if desired.ko.Spec.EnableDNSHostnames != nil {
if err := rm.syncDNSHostnamesAttribute(ctx, desired); err != nil {
return nil, err
}
if err := rm.syncDNSHostnamesAttribute(ctx, desired); err != nil {
return nil, err
}
}

Expand Down Expand Up @@ -571,3 +567,28 @@ func (rm *resourceManager) getDefaultSGId(
func ptr[T any](t T) *T {
return &t
}

var (
// Defaults for DNS related attributes as defined in https://docs.aws.amazon.com/vpc/latest/userguide/AmazonDNS-concepts.html#vpc-dns-support
defaultEnableDNSHostnames = false
defaultEnableDNSSupport = true
)

// customPreCompare ensures that default values of nil-able types are
// appropriately replaced with empty maps or structs depending on the default
// output of the SDK.
func customPreCompare(
delta *ackcompare.Delta,
a *resource,
b *resource,
) {
if a.ko.Spec.EnableDNSHostnames == nil {
a.ko.Spec.EnableDNSHostnames = &defaultEnableDNSHostnames
}
if a.ko.Spec.EnableDNSSupport == nil {
a.ko.Spec.EnableDNSSupport = &defaultEnableDNSSupport
}
if a.ko.Spec.DisallowSecurityGroupDefaultRules == nil {
a.ko.Spec.DisallowSecurityGroupDefaultRules = ptr(false)
}
}