Skip to content

Commit 9e1d85d

Browse files
author
Gereon Frey
committed
Improve the DNS attribute default handling
This improves #225. Using a custom pre-compare function the defaults can be set accordingly. This is now added with the defaults set to what the VPC defaults are. The `disallowSecurityGroupDefaultRules` option is also handled here, as it also has the issue describe in aws-controllers-k8s/community#1826.
1 parent faca85a commit 9e1d85d

File tree

3 files changed

+33
-8
lines changed

3 files changed

+33
-8
lines changed

apis/v1alpha1/generator.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -734,6 +734,8 @@ resources:
734734
type: bool
735735
is_read_only: true
736736
hooks:
737+
delta_pre_compare:
738+
code: customPreCompare(delta, a, b)
737739
sdk_create_post_build_request:
738740
template_path: hooks/vpc/sdk_create_post_build_request.go.tpl
739741
sdk_create_post_set_output:

generator.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -734,6 +734,8 @@ resources:
734734
type: bool
735735
is_read_only: true
736736
hooks:
737+
delta_pre_compare:
738+
code: customPreCompare(delta, a, b)
737739
sdk_create_post_build_request:
738740
template_path: hooks/vpc/sdk_create_post_build_request.go.tpl
739741
sdk_create_post_set_output:

pkg/resource/vpc/hooks.go

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -310,18 +310,14 @@ func (rm *resourceManager) customUpdateVPC(
310310
}
311311

312312
if delta.DifferentAt("Spec.EnableDNSSupport") {
313-
if desired.ko.Spec.EnableDNSSupport != nil {
314-
if err := rm.syncDNSSupportAttribute(ctx, desired); err != nil {
315-
return nil, err
316-
}
313+
if err := rm.syncDNSSupportAttribute(ctx, desired); err != nil {
314+
return nil, err
317315
}
318316
}
319317

320318
if delta.DifferentAt("Spec.EnableDNSHostnames") {
321-
if desired.ko.Spec.EnableDNSHostnames != nil {
322-
if err := rm.syncDNSHostnamesAttribute(ctx, desired); err != nil {
323-
return nil, err
324-
}
319+
if err := rm.syncDNSHostnamesAttribute(ctx, desired); err != nil {
320+
return nil, err
325321
}
326322
}
327323

@@ -571,3 +567,28 @@ func (rm *resourceManager) getDefaultSGId(
571567
func ptr[T any](t T) *T {
572568
return &t
573569
}
570+
571+
var (
572+
// Defaults for DNS related attributes as defined in https://docs.aws.amazon.com/vpc/latest/userguide/AmazonDNS-concepts.html#vpc-dns-support
573+
defaultEnableDNSHostnames = false
574+
defaultEnableDNSSupport = true
575+
)
576+
577+
// customPreCompare ensures that default values of nil-able types are
578+
// appropriately replaced with empty maps or structs depending on the default
579+
// output of the SDK.
580+
func customPreCompare(
581+
delta *ackcompare.Delta,
582+
a *resource,
583+
b *resource,
584+
) {
585+
if a.ko.Spec.EnableDNSHostnames == nil {
586+
a.ko.Spec.EnableDNSHostnames = &defaultEnableDNSHostnames
587+
}
588+
if a.ko.Spec.EnableDNSSupport == nil {
589+
a.ko.Spec.EnableDNSSupport = &defaultEnableDNSSupport
590+
}
591+
if a.ko.Spec.DisallowSecurityGroupDefaultRules == nil {
592+
a.ko.Spec.DisallowSecurityGroupDefaultRules = ptr(false)
593+
}
594+
}

0 commit comments

Comments
 (0)